discourse/spec/serializers/web_hook_topic_view_serializer_spec.rb
Blake Erickson 71f7f7ed49
FEATURE: Add external_id to topics (#15825)
* FEATURE: Add external_id to topics

This commit allows for topics to be created and fetched by an
external_id. These changes are API only for now as there aren't any
front changes.

* add annotations

* add external_id to this spec

* Several PR feedback changes

- Add guardian to find topic
- 403 is returned for not found as well now
- add `include_external_id?`
- external_id is now case insensitive
- added test for posts_controller
- added test for topic creator
- created constant for max length
- check that it redirects to the correct path
- restrain external id in routes file

* remove puts

* fix tests

* only check for external_id in webhook if exists

* Update index to exclude external_id if null

* annotate

* Update app/controllers/topics_controller.rb

We need to check whether the topic is present first before passing it to the guardian.

Co-authored-by: Alan Guo Xiang Tan <gxtan1990@gmail.com>

* Apply suggestions from code review

Co-authored-by: Alan Guo Xiang Tan <gxtan1990@gmail.com>

Co-authored-by: Alan Guo Xiang Tan <gxtan1990@gmail.com>
2022-02-08 20:55:32 -07:00

66 lines
1.3 KiB
Ruby

# frozen_string_literal: true
require 'rails_helper'
RSpec.describe WebHookTopicViewSerializer do
fab!(:admin) { Fabricate(:admin) }
fab!(:topic) { Fabricate(:topic) }
let(:serializer) do
WebHookTopicViewSerializer.new(TopicView.new(topic),
scope: Guardian.new(admin),
root: false
)
end
before do
SiteSetting.tagging_enabled = true
end
it 'should only include the keys that are sent out in the webhook' do
expected_keys = %i{
id
title
fancy_title
posts_count
created_at
views
reply_count
like_count
last_posted_at
visible
closed
archived
archetype
slug
category_id
word_count
deleted_at
user_id
featured_link
pinned_globally
pinned_at
pinned_until
unpinned
pinned
highest_post_number
deleted_by
bookmarked
participant_count
created_by
last_poster
tags
tags_descriptions
thumbnails
}
keys = serializer.as_json.keys
expect(serializer.as_json.keys).to contain_exactly(*expected_keys)
topic.external_id = 'external_id'
expected_keys << :external_id
expect(serializer.as_json.keys).to contain_exactly(*expected_keys)
end
end