mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2024-11-28 09:24:24 +01:00
(test) Group
This commit is contained in:
parent
5682d8b8e6
commit
f587dc3c32
76
test/integration/groups_test.rb
Normal file
76
test/integration/groups_test.rb
Normal file
@ -0,0 +1,76 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'test_helper'
|
||||
|
||||
class GroupsTest < ActionDispatch::IntegrationTest
|
||||
def setup
|
||||
@admin = User.find_by(username: 'admin')
|
||||
login_as(@admin, scope: :user)
|
||||
end
|
||||
|
||||
test 'create a group' do
|
||||
post '/api/groups',
|
||||
params: {
|
||||
name: 'Strange people',
|
||||
disabled: true
|
||||
}.to_json,
|
||||
headers: default_headers
|
||||
|
||||
# Check response format & status
|
||||
assert_equal 201, response.status, response.body
|
||||
assert_equal Mime[:json], response.content_type
|
||||
|
||||
# Check the correct group was created
|
||||
res = json_response(response.body)
|
||||
group = Group.where(id: res[:id]).first
|
||||
assert_not_nil group, 'group was not created in database'
|
||||
|
||||
assert_equal 'Strange people', res[:name]
|
||||
assert_equal true, res[:disabled]
|
||||
end
|
||||
|
||||
test 'update a group' do
|
||||
patch '/api/groups/1',
|
||||
params: {
|
||||
name: 'Normal people'
|
||||
}.to_json,
|
||||
headers: default_headers
|
||||
|
||||
# Check response format & status
|
||||
assert_equal 200, response.status, response.body
|
||||
assert_equal Mime[:json], response.content_type
|
||||
|
||||
# Check the group was updated
|
||||
res = json_response(response.body)
|
||||
assert_equal 1, res[:id]
|
||||
assert_equal 'Normal people', res[:name]
|
||||
end
|
||||
|
||||
test 'list all groups' do
|
||||
get '/api/groups'
|
||||
|
||||
# Check response format & status
|
||||
assert_equal 200, response.status, response.body
|
||||
assert_equal Mime[:json], response.content_type
|
||||
|
||||
# Check the list items are ok
|
||||
groups = json_response(response.body)
|
||||
assert_equal Group.count, groups.count
|
||||
end
|
||||
|
||||
test 'delete a group' do
|
||||
group = Group.create!(name: 'delete me')
|
||||
delete "/api/groups/#{group.id}"
|
||||
assert_response :success
|
||||
assert_empty response.body
|
||||
assert_raise ActiveRecord::RecordNotFound do
|
||||
group.reload
|
||||
end
|
||||
end
|
||||
|
||||
test 'unable to delete a used group' do
|
||||
delete '/api/groups/1'
|
||||
assert_response :forbidden
|
||||
assert_not_nil Group.find(1)
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue
Block a user