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

65 lines
1.7 KiB
Ruby
Raw Normal View History

2023-01-06 17:18:44 +01:00
# frozen_string_literal: true
require 'test_helper'
class AgeRangesTest < ActionDispatch::IntegrationTest
def setup
@admin = User.find_by(username: 'admin')
login_as(@admin, scope: :user)
end
test 'create an age range' do
post '/api/age_ranges',
params: {
name: '8 - 10 ans'
}.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-06 17:18:44 +01:00
# Check the correct age range was created
res = json_response(response.body)
range = AgeRange.where(id: res[:id]).first
assert_not_nil range, 'range was not created in database'
assert_equal '8 - 10 ans', res[:name]
end
test 'update an age range' do
patch '/api/age_ranges/1',
params: {
name: "Jusqu'à 17 ans"
}.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-06 17:18:44 +01:00
# Check the age range was updated
res = json_response(response.body)
assert_equal 1, res[:id]
assert_equal "Jusqu'à 17 ans", res[:name]
2023-01-06 17:18:44 +01:00
end
test 'list all age ranges' do
get '/api/age_ranges'
# 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-06 17:18:44 +01:00
# Check the list items are ok
ranges = json_response(response.body)
assert_equal AgeRange.count, ranges.count
end
test 'delete an age range' do
delete '/api/age_ranges/1'
assert_response :success
assert_empty response.body
end
end