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

add test for credits

This commit is contained in:
Sylvain 2017-12-21 12:00:11 +01:00
parent 72634162c6
commit 563eee40fa
2 changed files with 46 additions and 15 deletions

View File

@ -6,6 +6,7 @@
- Fix a bug: events order in public list
- Fix a bug: unable to create a training credit
- Corrected typos in documentation (#96)
- Improved test suite coverage
## v2.6.1 2017 December 14

View File

@ -1,23 +1,53 @@
require 'test/unit'
module Credits
class TrainingTest < ActionDispatch::IntegrationTest
class TrainingTest < Test::Unit::TestCase
# 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
# Called before every test method runs. Can be used
# to set up fixture information.
def setup
# Do nothing
end
test 'create training credit' do
# Called after every test method runs. Can be used to tear
# down fixture information.
# First, we create a new credit
post '/api/credits',
{
credit: {
creditable_id: 4,
creditable_type: 'Training',
plan_id: '1',
}
}.to_json,
default_headers
def teardown
# Do nothing
end
# Check response format & status
assert_equal 201, response.status, response.body
assert_equal Mime::JSON, response.content_type
# Fake test
def test_fail
# 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'
fail('Not implemented')
# Check that no hours were associated with the credit
assert_nil c.hours
end
test 'create a existing credit' do
post '/api/credits',
{
credit: {
creditable_id: 4,
creditable_type: 'Training',
plan_id: '2',
}
}.to_json,
default_headers
# Check response format & status
assert_equal 422, response.status, response.body
assert_equal Mime::JSON, response.content_type
end
end
end