|
| 1 | +require File.expand_path('../../test_helper', __FILE__) |
| 2 | + |
| 3 | +module Checkr |
| 4 | + class ProgramTest < Test::Unit::TestCase |
| 5 | + setup do |
| 6 | + @program_url = "#{Checkr.api_base}/v1/programs" |
| 7 | + end |
| 8 | + |
| 9 | + context 'Program class' do |
| 10 | + should 'be retrieveable' do |
| 11 | + id = 'program_id' |
| 12 | + @mock.expects(:get).once.with("#{@program_url}/#{id}", anything, anything) |
| 13 | + .returns(test_response(test_program)) |
| 14 | + program = Program.retrieve(id) |
| 15 | + assert(program.is_a?(Program)) |
| 16 | + end |
| 17 | + |
| 18 | + should 'be createable' do |
| 19 | + @mock.expects(:post).once.with(@program_url, anything, test_program) |
| 20 | + .returns(test_response(test_program)) |
| 21 | + program = Program.create(test_program) |
| 22 | + assert(program.is_a?(Program)) |
| 23 | + assert_equal(program.id, test_program[:id]) |
| 24 | + end |
| 25 | + end |
| 26 | + |
| 27 | + context 'Program instance' do |
| 28 | + should 'be refreshable' do |
| 29 | + @mock.expects(:get).once.with("#{@program_url}/#{test_program[:id]}", anything, anything) |
| 30 | + .returns(test_response(test_program)) |
| 31 | + program = Program.new(test_program[:id]) |
| 32 | + program.refresh |
| 33 | + assert_equal(program.name, test_program[:name]) |
| 34 | + end |
| 35 | + end |
| 36 | + |
| 37 | + context 'Retrieved Program instance' do |
| 38 | + setup do |
| 39 | + @mock.expects(:get).once.returns(test_response(test_program)) |
| 40 | + @program = Program.retrieve('program_id') |
| 41 | + end |
| 42 | + |
| 43 | + should 'have the id attribute' do |
| 44 | + assert_equal(@program.id, test_program[:id]) |
| 45 | + end |
| 46 | + |
| 47 | + should 'have the object attribute' do |
| 48 | + assert_equal(@program.object, test_program[:object]) |
| 49 | + end |
| 50 | + |
| 51 | + should 'have the uri attribute' do |
| 52 | + assert_equal(@program.uri, test_program[:uri]) |
| 53 | + end |
| 54 | + |
| 55 | + should 'have the created_at attribute' do |
| 56 | + assert_equal(@program.created_at, test_program[:created_at]) |
| 57 | + end |
| 58 | + |
| 59 | + should 'have the deleted_at attribute' do |
| 60 | + assert_equal(@program.deleted_at, test_program[:deleted_at]) |
| 61 | + end |
| 62 | + |
| 63 | + should 'have the name attribute' do |
| 64 | + assert_equal(@program.name, test_program[:name]) |
| 65 | + end |
| 66 | + |
| 67 | + should 'have the geo_ids attribute' do |
| 68 | + assert_equal(@program.geos.json, test_program[:geo_ids]) |
| 69 | + assert(@program.geos.is_a?(APIList)) |
| 70 | + end |
| 71 | + |
| 72 | + # should 'have the packages attribute' do |
| 73 | + # assert(@candidate.packages.any?) |
| 74 | + # assert(@candidate.packages.is_a?(PackageList)) |
| 75 | + # end |
| 76 | + |
| 77 | + should 'have the package_ids attribute' do |
| 78 | + assert_equal(@program.packages.json, test_program[:package_ids]) |
| 79 | + assert(@program.packages.is_a?(APIList)) |
| 80 | + end |
| 81 | + end |
| 82 | + |
| 83 | + should 'be registered' do |
| 84 | + assert(APIClass.subclasses.include?(Program)) |
| 85 | + assert_equal(Program, APIClass.subclass_fetch('program')) |
| 86 | + end |
| 87 | + |
| 88 | + end |
| 89 | +end |
0 commit comments