1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2025-02-17 11:54:22 +01:00

members tests

This commit is contained in:
Sylvain 2018-12-17 10:43:57 +01:00
parent d01a93e0f0
commit 425927900a
2 changed files with 52 additions and 8 deletions

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
class MemebersTest < ActionDispatch::IntegrationTest
# Called before every test method runs. Can be used
@ -31,9 +33,55 @@ class MemebersTest < ActionDispatch::IntegrationTest
assert_equal 201, response.status, response.body
assert_equal Mime::JSON, response.content_type
# Check the user was subscribed
# Check that the user's match
user = json_response(response.body)
assert_equal email, user[:email], "user's mail does not match"
assert_equal group_id, user[:group_id], "user's group does not match"
end
test 'admin fails to update member group' do
user = User.friendly.find('kdumas')
# we cannot update an kevin's group because he's got a running subscription
put "/api/members/#{user.id}", { user: {
group_id: 1
} }.to_json, default_headers
# Check response format & status
assert_equal 422, response.status, response.body
assert_equal Mime::JSON, response.content_type
# Check error message
res = json_response(response.body)
assert_equal I18n.t('members.unable_to_change_the_group_while_a_subscription_is_running'), res[:group_id][0], 'invalid error message'
end
test 'admin successfully updates a member' do
user = User.friendly.find('vlonchamp')
user_hash = {
user: {
profile_attributes: JSON.parse(user.to_json)['profile']
}.merge(JSON.parse(user.to_json))
}
instagram = 'https://www.instagram.com/vanessa/'
put "/api/members/#{user.id}", user_hash.deep_merge(
user: {
group_id: 2,
profile_attributes: {
instagram: instagram
}
}
).to_json, default_headers
# Check response format & status
assert_equal 200, response.status, response.body
assert_equal Mime::JSON, response.content_type
# Check update result
res = json_response(response.body)
assert_equal 2, res[:group_id], "user's group does not match"
assert_equal instagram, res[:profile][:instagram], "user's social network not updated"
end
end

View File

@ -16,11 +16,9 @@ class SettingsTest < ActionDispatch::IntegrationTest
test 'update setting value' do
put '/api/settings/fablab_name',
{
setting: {
value: 'Test Fablab'
}
}
setting: {
value: 'Test Fablab'
}
assert_equal 200, response.status
assert_equal Mime::JSON, response.content_type
resp = json_response(response.body)
@ -31,11 +29,9 @@ class SettingsTest < ActionDispatch::IntegrationTest
test 'update setting with wrong name' do
put '/api/settings/does_not_exists',
{
setting: {
value: 'ERROR EXPECTED'
}
}
assert_equal 422, response.status
assert_match /Name is not included in the list/, response.body
end