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]
|
2023-01-09 09:36:36 +01:00
|
|
|
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
|