1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2024-11-29 10:24:20 +01:00
fab-manager/test/integration/statuses_test.rb

69 lines
1.8 KiB
Ruby
Raw Normal View History

2023-01-16 17:37:44 +01:00
# frozen_string_literal: true
require 'test_helper'
class StatusesTest < ActionDispatch::IntegrationTest
def setup
@admin = User.find_by(username: 'admin')
login_as(@admin, scope: :user)
end
test 'create a status' do
post '/api/statuses',
params: {
name: 'Open'
2023-01-16 17:37:44 +01:00
}.to_json,
headers: default_headers
# Check response format & status
assert_equal 201, response.status, response.body
2023-02-24 17:26:55 +01:00
assert_match Mime[:json].to_s, response.content_type
2023-01-16 17:37:44 +01:00
# Check the correct status was created
res = json_response(response.body)
status = Status.where(id: res[:id]).first
assert_not_nil status, 'status was not created in database'
assert_equal 'Open', res[:name]
2023-01-16 17:37:44 +01:00
end
test 'update a status' do
patch '/api/statuses/1',
params: {
name: 'Done'
2023-01-16 17:37:44 +01:00
}.to_json,
headers: default_headers
# Check response format & status
assert_equal 200, response.status, response.body
2023-02-24 17:26:55 +01:00
assert_match Mime[:json].to_s, response.content_type
2023-01-16 17:37:44 +01:00
# Check the status was updated
res = json_response(response.body)
assert_equal 1, res[:id]
assert_equal 'Done', res[:name]
2023-01-16 17:37:44 +01:00
end
test 'list all statuses' do
get '/api/statuses'
# Check response format & status
assert_equal 200, response.status, response.body
2023-02-24 17:26:55 +01:00
assert_match Mime[:json].to_s, response.content_type
2023-01-16 17:37:44 +01:00
# Check the list items are ok
statuses = json_response(response.body)
assert_equal Status.count, statuses.count
end
test 'delete a status' do
status = Status.create!(name: 'Gone too soon')
2023-01-16 17:37:44 +01:00
delete "/api/statuses/#{status.id}"
assert_response :success
assert_empty response.body
assert_raise ActiveRecord::RecordNotFound do
status.reload
end
end
end