Skip to content

Commit 8e061e9

Browse files
committed
added test for qualifiers method of the subscriptions controller
1 parent ba4425d commit 8e061e9

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

test/controllers/subscriptions_controller_test.rb

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,4 +109,30 @@ class SubscriptionsControllerTest < ActionController::TestCase
109109
assert_valid_json_response
110110
assert_equal 'success', JSON.parse(response.body)['status']
111111
end
112+
113+
test 'qualifiers should correctly return available items based on type' do
114+
sign_in users(:admin)
115+
116+
Subscription::TYPES.each do |type|
117+
try_subscription_qualifiers(type)
118+
119+
assert_response(:success)
120+
assert_valid_json_response
121+
122+
items = JSON.parse(response.body)
123+
124+
if Subscription::QUALIFIED_TYPES.include?(type)
125+
assert_not items.empty?
126+
assert(items.all? { |i| i['id'].present? && i['text'].present? })
127+
else
128+
assert items.empty?
129+
end
130+
end
131+
end
132+
133+
private
134+
135+
def try_subscription_qualifiers(type, search: nil)
136+
get :qualifiers, params: { type: type, q: search }
137+
end
112138
end

0 commit comments

Comments
 (0)