1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2024-12-10 21:24:20 +01:00
fab-manager/test/integration/credits/training_test.rb

56 lines
1.5 KiB
Ruby
Raw Normal View History

2020-03-13 17:10:38 +01:00
# frozen_string_literal: true
require 'test_helper'
2017-12-21 12:00:11 +01:00
module Credits
class TrainingTest < ActionDispatch::IntegrationTest
# Called before every test method runs. Can be used
# to set up fixture information.
def setup
admin = User.with_role(:admin).first
login_as(admin, scope: :user)
end
2017-12-21 11:49:51 +01:00
2017-12-21 12:00:11 +01:00
test 'create training credit' do
# First, we create a new credit
post '/api/credits',
2020-03-13 17:10:38 +01:00
params: {
2018-12-11 17:27:25 +01:00
credit: {
creditable_id: 4,
creditable_type: 'Training',
2020-03-13 17:10:38 +01:00
plan_id: '1'
2018-12-11 17:27:25 +01:00
}
}.to_json,
2020-03-13 17:10:38 +01:00
headers: default_headers
2017-12-21 11:49:51 +01:00
2017-12-21 12:00:11 +01:00
# Check response format & status
assert_equal 201, response.status, response.body
2020-03-13 17:10:38 +01:00
assert_equal Mime[:json], response.content_type
2017-12-21 12:00:11 +01:00
# Check the credit was created correctly
credit = json_response(response.body)
c = Credit.where(id: credit[:id]).first
assert_not_nil c, 'Credit was not created in database'
# Check that no hours were associated with the credit
assert_nil c.hours
end
2017-12-21 11:49:51 +01:00
2017-12-21 12:00:11 +01:00
test 'create a existing credit' do
post '/api/credits',
2020-03-13 17:10:38 +01:00
params: {
2018-12-11 17:27:25 +01:00
credit: {
creditable_id: 4,
creditable_type: 'Training',
plan_id: '2'
}
2017-12-21 12:00:11 +01:00
}.to_json,
2020-03-13 17:10:38 +01:00
headers: default_headers
2017-12-21 11:49:51 +01:00
2017-12-21 12:00:11 +01:00
# Check response format & status
assert_equal 422, response.status, response.body
2020-03-13 17:10:38 +01:00
assert_equal Mime[:json], response.content_type
2017-12-21 12:00:11 +01:00
end
2017-12-21 11:49:51 +01:00
end
2020-03-13 17:10:38 +01:00
end