From 563eee40fa7cebb2c97bfb81971095a76d1846c3 Mon Sep 17 00:00:00 2001 From: Sylvain Date: Thu, 21 Dec 2017 12:00:11 +0100 Subject: [PATCH] add test for credits --- CHANGELOG.md | 1 + test/integration/credits/training_test.rb | 60 +++++++++++++++++------ 2 files changed, 46 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f1309e89b..e04e25299 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/test/integration/credits/training_test.rb b/test/integration/credits/training_test.rb index 833e019c4..2ba4a46e4 100644 --- a/test/integration/credits/training_test.rb +++ b/test/integration/credits/training_test.rb @@ -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 \ No newline at end of file