1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2025-01-18 07:52:23 +01:00

(test) AgeRange, Category, Component, EventTheme

This commit is contained in:
Sylvain 2023-01-09 09:36:36 +01:00
parent d191712ec0
commit 5682d8b8e6
4 changed files with 143 additions and 4 deletions

View File

@ -41,7 +41,7 @@ class AgeRangesTest < ActionDispatch::IntegrationTest
# Check the age range was updated
res = json_response(response.body)
assert_equal 1, res[:id]
assert_equal res[:name], "Jusqu'à 17 ans"
assert_equal "Jusqu'à 17 ans", res[:name]
end
test 'list all age ranges' do

View File

@ -21,8 +21,8 @@ class CategoriesTest < ActionDispatch::IntegrationTest
# Check the correct category was created
res = json_response(response.body)
range = Category.where(id: res[:id]).first
assert_not_nil range, 'category was not created in database'
cat = Category.where(id: res[:id]).first
assert_not_nil cat, 'category was not created in database'
assert_equal 'Workshop', res[:name]
end
@ -41,7 +41,7 @@ class CategoriesTest < ActionDispatch::IntegrationTest
# Check the category was updated
res = json_response(response.body)
assert_equal 1, res[:id]
assert_equal res[:name], 'Stage pratique'
assert_equal 'Stage pratique', res[:name]
end
test 'list all categories' do
@ -61,5 +61,8 @@ class CategoriesTest < ActionDispatch::IntegrationTest
delete "/api/categories/#{cat.id}"
assert_response :success
assert_empty response.body
assert_raise ActiveRecord::RecordNotFound do
cat.reload
end
end
end

View File

@ -0,0 +1,68 @@
# frozen_string_literal: true
require 'test_helper'
class ComponentsTest < ActionDispatch::IntegrationTest
def setup
@admin = User.find_by(username: 'admin')
login_as(@admin, scope: :user)
end
test 'create a component' do
post '/api/components',
params: {
name: 'Wood'
}.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 component was created
res = json_response(response.body)
comp = Component.where(id: res[:id]).first
assert_not_nil comp, 'component was not created in database'
assert_equal 'Wood', res[:name]
end
test 'update a component' do
patch '/api/components/1',
params: {
name: 'Silicon'
}.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 component was updated
res = json_response(response.body)
assert_equal 1, res[:id]
assert_equal 'Silicon', res[:name]
end
test 'list all components' do
get '/api/components'
# Check response format & status
assert_equal 200, response.status, response.body
assert_equal Mime[:json], response.content_type
# Check the list items are ok
comps = json_response(response.body)
assert_equal Component.count, comps.count
end
test 'delete a component' do
comp = Component.create!(name: 'delete me')
delete "/api/components/#{comp.id}"
assert_response :success
assert_empty response.body
assert_raise ActiveRecord::RecordNotFound do
comp.reload
end
end
end

View File

@ -0,0 +1,68 @@
# frozen_string_literal: true
require 'test_helper'
class EventThemesTest < ActionDispatch::IntegrationTest
def setup
@admin = User.find_by(username: 'admin')
login_as(@admin, scope: :user)
end
test 'create an event theme' do
post '/api/event_themes',
params: {
name: 'Cuisine'
}.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 event theme was created
res = json_response(response.body)
theme = EventTheme.where(id: res[:id]).first
assert_not_nil theme, 'event theme was not created in database'
assert_equal 'Cuisine', res[:name]
end
test 'update an event theme' do
patch '/api/event_themes/1',
params: {
name: 'DIY'
}.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 event theme was updated
res = json_response(response.body)
assert_equal 1, res[:id]
assert_equal 'DIY', res[:name]
end
test 'list all event themes' do
get '/api/event_themes'
# Check response format & status
assert_equal 200, response.status, response.body
assert_equal Mime[:json], response.content_type
# Check the list items are ok
themes = json_response(response.body)
assert_equal EventTheme.count, themes.count
end
test 'delete an event theme' do
theme = EventTheme.create!(name: 'delete me')
delete "/api/event_themes/#{theme.id}"
assert_response :success
assert_empty response.body
assert_raise ActiveRecord::RecordNotFound do
theme.reload
end
end
end