artemis_api 0.2.0 → 0.7.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,38 @@
1
+ require "test_helper"
2
+
3
+ class CompletionTest < Minitest::Test
4
+ def setup
5
+ get_client
6
+ get_facility
7
+
8
+ stub_request(:get, "http://localhost:3000/api/v3/facilities/#{@facility.id}/completions")
9
+ .to_return(body: {data: [{id: '1', type: 'completions', attributes: {id: 1, action_type: 'start'}}, {id: '2', type: 'completions', attributes: {id: 2, action_type: 'move'}}]}.to_json)
10
+
11
+ stub_request(:get, "http://localhost:3000/api/v3/facilities/#{@facility.id}/completions/2")
12
+ .to_return(body: {data: {id: '2', type: 'completions', attributes: {id: 2, action_type: 'move'}, relationships: { batch: { data: { id: 1, type: 'batches' }}}}}.to_json)
13
+
14
+ stub_request(:get, "http://localhost:3000/api/v3/facilities/#{@facility.id}/completions/2")
15
+ .to_return(body: {data: {id: '2', type: 'completions', attributes: {id: 2, action_type: 'move'}, relationships: { batch: { data: { id: 1, type: 'batches' }}}}}.to_json)
16
+
17
+ stub_request(:get, "http://localhost:3000/api/v3/facilities/#{@facility.id}/completions?filter[crop_batch_ids][]=2&filter[crop_batch_ids][]=3")
18
+ .to_return(body: {data: [{id: '1', type: 'completions', attributes: {id: 1, action_type: 'start'}}]}.to_json)
19
+
20
+ stub_request(:get, "http://localhost:3000/api/v3/facilities/#{@facility.id}/completions?filter[parent_id]=2")
21
+ .to_return(body: {data: [{id: '3', type: 'completions', attributes: {id: 3, action_type: 'process'}}, {id: '4', type: 'completions', attributes: {id: 4, action_type: 'process'}}]}.to_json)
22
+ end
23
+
24
+ def test_finding_all_completions
25
+ completions = ArtemisApi::Completion.find_all(facility_id: @facility.id, client: @client)
26
+ assert_equal 2, completions.count
27
+ end
28
+
29
+ def test_finding_a_specific_completion
30
+ completion = ArtemisApi::Completion.find(id: 2, facility_id: @facility.id, client: @client)
31
+ assert_equal 'move', completion.action_type
32
+ end
33
+
34
+ def test_filtering_completion_by_crop_batch_ids
35
+ completions = ArtemisApi::Completion.find_all(facility_id: @facility.id, client: @client, filters: {crop_batch_ids: [2, 3]})
36
+ assert_equal 1, completions.count
37
+ end
38
+ end
@@ -0,0 +1,93 @@
1
+ require "test_helper"
2
+
3
+ class DiscardTest < Minitest::Test
4
+ def setup
5
+ get_client
6
+ get_facility
7
+
8
+ stub_request(:get, "http://localhost:3000/api/v3/facilities/2/discards/2")
9
+ .to_return(body: {
10
+ data: {
11
+ id: '2',
12
+ type: 'discards',
13
+ attributes: {
14
+ id: 2,
15
+ quantity: 20,
16
+ reason_type: 'disease',
17
+ reason_description: ''
18
+ },
19
+ relationships: {
20
+ batch: {
21
+ meta: {
22
+ included: false
23
+ }
24
+ },
25
+ completion: {
26
+ meta: {
27
+ included: false
28
+ }
29
+ }
30
+ }
31
+ }
32
+ }.to_json)
33
+
34
+ stub_request(:get, "http://localhost:3000/api/v3/facilities/2/discards/2?include=batch")
35
+ .to_return(body: {
36
+ data: {
37
+ id: '2',
38
+ type: 'discards',
39
+ attributes: {
40
+ id: 2,
41
+ quantity: 20,
42
+ reason_type: 'disease',
43
+ reason_description: ''
44
+ },
45
+ relationships: {
46
+ batch: {
47
+ data: {
48
+ id: '156',
49
+ type: 'batches'
50
+ }
51
+ },
52
+ completion: {
53
+ meta: {
54
+ included: false
55
+ }
56
+ }
57
+ }
58
+ }
59
+ }.to_json)
60
+
61
+ stub_request(:get, "http://localhost:3000/api/v3/facilities/#{@facility.id}/discards")
62
+ .to_return(body: {data: [{id: '1', type: 'discards', attributes: {id: 1, reason_type: 'disease', quantity: 20}}, {id: '2', type: 'discards', attributes: {id: 2, reason_type: 'pests', quantity: 5}}]}.to_json)
63
+
64
+ stub_request(:get, "http://localhost:3000/api/v3/facilities/#{@facility.id}/discards?filter[crop_batch_ids][]=2&filter[crop_batch_ids][]=3")
65
+ .to_return(body: {data: [{id: '1', type: 'discards', attributes: {id: 1, quantity: 4, reason_type: 'pests'}}]}.to_json)
66
+ end
67
+
68
+ def test_finding_a_specific_discard
69
+ discard = ArtemisApi::Discard.find(id: 2, facility_id: @facility.id, client: @client)
70
+ assert_equal 20, discard.quantity
71
+ assert_equal 'disease', discard.reason_type
72
+ assert_equal false, discard.relationships['batch']['meta']['included']
73
+ assert discard.relationships['batch']['data'].nil?
74
+ end
75
+
76
+ def test_finding_a_specific_discard_with_batch_included
77
+ discard = ArtemisApi::Discard.find(id: 2, facility_id: @facility.id, client: @client, include: 'batch')
78
+ assert_equal 20, discard.quantity
79
+ assert_equal 'disease', discard.reason_type
80
+ assert_equal '156', discard.relationships['batch']['data']['id']
81
+ assert discard.relationships['batch']['meta'].nil?
82
+ end
83
+
84
+ def test_finding_all_discards
85
+ discards = ArtemisApi::Discard.find_all(facility_id: @facility.id, client: @client)
86
+ assert_equal 2, discards.count
87
+ end
88
+
89
+ def test_filtering_discard_by_crop_batch_ids
90
+ discards = ArtemisApi::Discard.find_all(facility_id: @facility.id, client: @client, filters: {crop_batch_ids: [2, 3]})
91
+ assert_equal 1, discards.count
92
+ end
93
+ end
@@ -0,0 +1,42 @@
1
+ require "test_helper"
2
+
3
+ class FacilityTest < Minitest::Test
4
+ def setup
5
+ get_client
6
+
7
+ stub_request(:get, 'http://localhost:3000/api/v3/facilities')
8
+ .to_return(body: {data: [{id: '1', type: 'facilities', attributes: {id: 1, name: 'Sky Fresh'}}, {id: '2', type: 'facilities', attributes: {id: 2, name: 'Rare Dankness'}}]}.to_json)
9
+ end
10
+
11
+ def test_finding_all_facilities
12
+ facilities = ArtemisApi::Facility.find_all(client: @client)
13
+ assert_equal 2, facilities.count
14
+ end
15
+
16
+ def test_finding_all_facilities_through_client
17
+ facilities = @client.facilities
18
+ assert_equal 2, facilities.count
19
+ end
20
+
21
+ def test_finding_a_specific_facility
22
+ stub_request(:get, 'http://localhost:3000/api/v3/facilities/2')
23
+ .to_return(body: {data: {id: '2', type: 'facilities', attributes: {id: 2, name: 'Rare Dankness'}}}.to_json)
24
+
25
+ facility = ArtemisApi::Facility.find(id: 2, client: @client)
26
+ assert_equal 'Rare Dankness', facility.name
27
+ end
28
+
29
+ def test_finding_a_specific_facility_through_client
30
+ stub_request(:get, 'http://localhost:3000/api/v3/facilities/2')
31
+ .to_return(body: {data: {id: '2', type: 'facilities', attributes: {id: 2, name: 'Rare Dankness'}}}.to_json)
32
+
33
+ facility = @client.facility(2)
34
+ assert_equal 'Rare Dankness', facility.name
35
+ end
36
+
37
+ def test_finding_a_specific_facility_thats_already_in_memory
38
+ ArtemisApi::Facility.find_all(client: @client)
39
+ facility = ArtemisApi::Facility.find(id: 2, client: @client)
40
+ assert_equal 'Rare Dankness', facility.name
41
+ end
42
+ end
@@ -0,0 +1,33 @@
1
+ require "test_helper"
2
+
3
+ class HarvestTest < Minitest::Test
4
+ def setup
5
+ get_client
6
+ get_facility
7
+
8
+ stub_request(:get, "http://localhost:3000/api/v3/facilities/#{@facility.id}/harvests")
9
+ .to_return(body: {data: [{id: '1', type: 'harvests', attributes: {id: 1, quantity: 4, harvest_type: 'complete'}}, {id: '2', type: 'harvests', attributes: {id: 2, quantity: 1, harvest_type: 'partial'}}]}.to_json)
10
+
11
+ stub_request(:get, "http://localhost:3000/api/v3/facilities/#{@facility.id}/harvests/2")
12
+ .to_return(body: {data: {id: '2', type: 'harvests', attributes: {id: 2, quantity: 1, harvest_type: 'partial'}}}.to_json)
13
+
14
+ stub_request(:get, "http://localhost:3000/api/v3/facilities/#{@facility.id}/harvests?filter[crop_batch_ids][]=2&filter[crop_batch_ids][]=3")
15
+ .to_return(body: {data: [{id: '1', type: 'harvests', attributes: {id: 1, quantity: 4, harvest_type: 'complete'}}]}.to_json)
16
+ end
17
+
18
+ def test_finding_all_harvests
19
+ harvests = ArtemisApi::Harvest.find_all(facility_id: @facility.id, client: @client)
20
+ assert_equal 2, harvests.count
21
+ end
22
+
23
+ def test_finding_a_specific_harvest
24
+ harvest = ArtemisApi::Harvest.find(id: 2, facility_id: @facility.id, client: @client)
25
+ assert_equal 'partial', harvest.harvest_type
26
+ assert_equal 1, harvest.quantity
27
+ end
28
+
29
+ def test_filtering_harvest_by_crop_batch_ids
30
+ harvests = ArtemisApi::Harvest.find_all(facility_id: @facility.id, client: @client, filters: {crop_batch_ids: [2, 3]})
31
+ assert_equal 1, harvests.count
32
+ end
33
+ end
@@ -0,0 +1,25 @@
1
+ require "test_helper"
2
+
3
+ class HarvestUnitTest < Minitest::Test
4
+ def setup
5
+ get_client
6
+ get_facility
7
+
8
+ stub_request(:get, "http://localhost:3000/api/v3/facilities/#{@facility.id}/harvest_units")
9
+ .to_return(body: {data: [{id: '1', type: 'harvest_units', attributes: {id: 1, name: 'pound', weight: 1}}, {id: '2', type: 'harvest_units', attributes: {id: 2, name: 'kilogram', weight: 2.2}}]}.to_json)
10
+
11
+ stub_request(:get, "http://localhost:3000/api/v3/facilities/#{@facility.id}/harvest_units/2")
12
+ .to_return(body: {data: {id: '2', type: 'harvest_units', attributes: {id: 2, name: 'kilogram', weight: 2.2}}}.to_json)
13
+ end
14
+
15
+ def test_finding_all_harvest_units
16
+ harvest_units = ArtemisApi::HarvestUnit.find_all(facility_id: @facility.id, client: @client)
17
+ assert_equal 2, harvest_units.count
18
+ end
19
+
20
+ def test_finding_a_specific_harvest_unit
21
+ harvest_unit = ArtemisApi::HarvestUnit.find(id: 2, facility_id: @facility.id, client: @client)
22
+ assert_equal 'kilogram', harvest_unit.name
23
+ assert_equal 2.2, harvest_unit.weight
24
+ end
25
+ end
@@ -0,0 +1,38 @@
1
+ require "test_helper"
2
+
3
+ class ItemTest < Minitest::Test
4
+ def setup
5
+ get_client
6
+
7
+ stub_request(:get, 'http://localhost:3000/api/v3/facilities/2')
8
+ .to_return(body: {data: {id: '2', type: 'facilities', attributes: {id: 2, name: 'Rare Dankness'}}}.to_json)
9
+ @facility = ArtemisApi::Facility.find(id: 2, client: @client)
10
+
11
+ stub_request(:get, "http://localhost:3000/api/v3/facilities/#{@facility.id}/batches/2")
12
+ .to_return(body: {data: {id: '2', type: 'batches', attributes: {id: 2, arbitrary_id: 'Jun19-Bok-Cho'}, relationships: {seeding_unit: {data: {id: '3479', type: 'seeding_units'}}}}}.to_json)
13
+ @batch = ArtemisApi::Batch.find(id: 2, facility_id: @facility.id, client: @client)
14
+
15
+ stub_request(:get, "http://localhost:3000/api/v3/facilities/#{@facility.id}/batches/2/items")
16
+ .to_return(body: {data: [{id: '326515', type: 'items', attributes: {id: 326515, status: 'active'}, relationships: {barcode: {data: {id: '1A4FF0200000022000000207', type: 'barcodes'}}}}]}.to_json)
17
+
18
+ stub_request(:get, "http://localhost:3000/api/v3/facilities/#{@facility.id}/batches/2/items?filter[seeding_unit_id]=100")
19
+ .to_return(body: {data: [{id: '326515', type: 'items', attributes: {id: 326515, status: 'active'}, relationships: {barcode: {data: {id: '1A4FF0200000022000000207', type: 'barcodes'}}, seeding_unit: {data: {id: '100', type: 'seeding_units'}}}}]}.to_json)
20
+ end
21
+
22
+ def test_finding_all_items_of_facility_and_batch
23
+ items = ArtemisApi::Item.find_all(facility_id: @facility.id, batch_id: @batch.id, client: @client)
24
+ assert_equal 1, items.count
25
+ assert_equal 326_515, items.first.id
26
+ assert_equal '1A4FF0200000022000000207', items.first.relationships.dig('barcode', 'data', 'id')
27
+ end
28
+
29
+ def test_finding_all_items_with_seeding_unit
30
+ seeding_unit_id = 100
31
+ items = ArtemisApi::Item.find_all(facility_id: @facility.id,
32
+ batch_id: @batch.id,
33
+ client: @client,
34
+ filters: {seeding_unit_id: seeding_unit_id})
35
+ assert_equal 1, items.count
36
+ assert_equal seeding_unit_id.to_s, items.first.relationships.dig('seeding_unit', 'data', 'id')
37
+ end
38
+ end
@@ -0,0 +1,39 @@
1
+ require "test_helper"
2
+
3
+ class OrganizationTest < Minitest::Test
4
+ def setup
5
+ get_client
6
+
7
+ stub_request(:get, 'http://localhost:3000/api/v3/organizations')
8
+ .to_return(body: {data: [{id: '1', type: 'organizations', attributes: {id: 1, name: 'Sky Fresh'}}, {id: '2', type: 'organizations', attributes: {id: 2, name: 'Rare Dankness'}}]}.to_json)
9
+ end
10
+
11
+ def test_finding_all_organizations
12
+ organizations = ArtemisApi::Organization.find_all(client: @client)
13
+ assert_equal 2, organizations.count
14
+ end
15
+
16
+ def test_finding_a_specific_organization
17
+ stub_request(:get, 'http://localhost:3000/api/v3/organizations/2')
18
+ .to_return(body: {data: {id: '2', type: 'organizations', attributes: {id: 2, name: 'Rare Dankness'}}}.to_json)
19
+
20
+ org = ArtemisApi::Organization.find(id: 2, client: @client)
21
+ assert_equal 'Rare Dankness', org.name
22
+ end
23
+
24
+ def test_finding_a_specific_org_thats_already_in_memory
25
+ ArtemisApi::Organization.find_all(client: @client)
26
+ org = ArtemisApi::Organization.find(id: 2, client: @client)
27
+ assert_equal 'Rare Dankness', org.name
28
+ end
29
+
30
+ def test_getting_orgs_with_facilities_included
31
+ stub_request(:get, 'http://localhost:3000/api/v3/organizations/2?include=facilities')
32
+ .to_return(body: {data: {id: '2', type: 'organizations', attributes: {id: 2, name: 'Rare Dankness'}}, included: [{id: 1, type: "facilities", attributes: {id: 1, name: 'Sky Fresh'}}]}.to_json)
33
+
34
+ org = ArtemisApi::Organization.find(id: 2, client: @client, include: 'facilities')
35
+ facility = ArtemisApi::Facility.find(id: 1, client: @client)
36
+ assert_equal 'Rare Dankness', org.name
37
+ assert_equal 'Sky Fresh', facility.name
38
+ end
39
+ end
@@ -0,0 +1,33 @@
1
+ require "test_helper"
2
+
3
+ class ResourceUnitTest < Minitest::Test
4
+ def setup
5
+ get_client
6
+ get_facility
7
+
8
+ stub_request(:get, "http://localhost:3000/api/v3/facilities/#{@facility.id}/resource_units?include=crop_variety")
9
+ .to_return(body: {data: [{id: '1', type: 'resource_units', attributes: {id: 1, name: 'Bunch', kind: 'count', conversion_si: 1.0}}, {id: '2', type: 'resource_units', attributes: {id: 2, name: 'grams', kind: 'weight', conversion_si: 1.0}, relationships: { crop_variety: { data: { type: 'crop_varieties', id: 1 }}}}], included: [{ type: 'crop_varieties', id: 1, attributes: { name: '5th Element' } }]}.to_json)
10
+
11
+ stub_request(:get, "http://localhost:3000/api/v3/facilities/#{@facility.id}/resource_units/2")
12
+ .to_return(body: {data: {id: '2', type: 'resource_units', attributes: {id: 2, name: 'grams', kind: 'weight', conversion_is: 1.0}}}.to_json)
13
+
14
+ stub_request(:get, "http://localhost:3000/api/v3/facilities/#{@facility.id}/resource_units/3?include=crop_variety")
15
+ .to_return(body: {data: {id: '2', type: 'resource_units', attributes: {id: 3, name: 'grams', kind: 'weight', conversion_is: 1.0}, relationships: { crop_variety: { data: { type: 'crop_varieties', id: 2 } } }}, included: [{ type: 'crop_varieties', id: 2, attributes: { name: 'Boss Hog' } }]}.to_json)
16
+ end
17
+
18
+ def test_finding_all_resource_units
19
+ resource_units = ArtemisApi::ResourceUnit.find_all(facility_id: @facility.id, client: @client, include: 'crop_variety')
20
+ assert_equal 2, resource_units.count
21
+ assert_equal '5th Element', resource_units.last.crop_variety.name
22
+ end
23
+
24
+ def test_finding_a_specific_resource_unit
25
+ resource_unit = ArtemisApi::ResourceUnit.find(id: 2, facility_id: @facility.id, client: @client)
26
+ assert_equal 'grams', resource_unit.name
27
+ end
28
+
29
+ def test_resource_unit_has_crop_variety
30
+ resource_unit = ArtemisApi::ResourceUnit.find(id: 3, facility_id: @facility.id, client: @client, include: 'crop_variety')
31
+ assert_equal 'Boss Hog', resource_unit.crop_variety.name
32
+ end
33
+ end
@@ -0,0 +1,24 @@
1
+ require "test_helper"
2
+
3
+ class SeedingUnitTest < Minitest::Test
4
+ def setup
5
+ get_client
6
+ get_facility
7
+
8
+ stub_request(:get, "http://localhost:3000/api/v3/facilities/#{@facility.id}/seeding_units")
9
+ .to_return(body: {data: [{id: '1', type: 'seeding_units', attributes: {id: 1, name: 'board'}}, {id: '2', type: 'seeding_units', attributes: {id: 2, name: 'raft'}}]}.to_json)
10
+
11
+ stub_request(:get, "http://localhost:3000/api/v3/facilities/#{@facility.id}/seeding_units/2")
12
+ .to_return(body: {data: {id: '2', type: 'seeding_units', attributes: {id: 2, name: 'raft'}}}.to_json)
13
+ end
14
+
15
+ def test_finding_all_seeding_units
16
+ seeding_units = ArtemisApi::SeedingUnit.find_all(facility_id: @facility.id, client: @client)
17
+ assert_equal 2, seeding_units.count
18
+ end
19
+
20
+ def test_finding_a_specific_seeding_unit
21
+ seeding_unit = ArtemisApi::SeedingUnit.find(id: 2, facility_id: @facility.id, client: @client)
22
+ assert_equal 'raft', seeding_unit.name
23
+ end
24
+ end
@@ -0,0 +1,39 @@
1
+ require "test_helper"
2
+
3
+ class StageTest < Minitest::Test
4
+ def setup
5
+ get_client
6
+ get_facility
7
+
8
+ stub_request(:get, 'http://localhost:3000/api/v3/facilities/2')
9
+ .to_return(body: {data: {id: '2', type: 'facilities', attributes: {id: 2, name: 'Rare Dankness'}}}.to_json)
10
+
11
+ stub_request(:get, "http://localhost:3000/api/v3/facilities/#{@facility.id}/stages?include=sub_stages,zones")
12
+ .to_return(body: {data: [{id: '1', type: 'stages', attributes: {id: 1, name: 'Growth', stage_type: 'growth'}}, {id: '2', type: 'stages', attributes: {id: 2, name: 'Stage 2', stage_type: 'stage_2'}}]}.to_json)
13
+
14
+ stub_request(:get, "http://localhost:3000/api/v3/facilities/#{@facility.id}/stages/1?include=sub_stages,zones")
15
+ .to_return(body: {data: {id: '1', type: 'stages', attributes: {id: 1, name: 'Growth', stage_type: 'growth'}}}.to_json)
16
+ end
17
+
18
+ def test_finding_all_stages
19
+ stages = ArtemisApi::Stage.find_all(@facility.id, @client)
20
+ assert_equal 2, stages.count
21
+ end
22
+
23
+ def test_finding_all_stages_through_facility
24
+ stages = @facility.stages
25
+ assert_equal 2, stages.count
26
+ end
27
+
28
+ def test_finding_a_specific_stage
29
+ stage = ArtemisApi::Stage.find(1, @facility.id, @client)
30
+ assert_equal 'Growth', stage.name
31
+ assert_equal 'growth', stage.stage_type
32
+ end
33
+
34
+ def test_finding_a_specific_stage_through_facility
35
+ stage = @facility.stage(1)
36
+ assert_equal 'Growth', stage.name
37
+ assert_equal 'growth', stage.stage_type
38
+ end
39
+ end
@@ -0,0 +1,63 @@
1
+ require "test_helper"
2
+
3
+ class SubscriptionTest < Minitest::Test
4
+ def setup
5
+ get_client
6
+ get_facility
7
+
8
+ stub_request(:get, "http://localhost:3000/api/v3/facilities/#{@facility.id}/subscriptions")
9
+ .to_return(body: {data: [{id: '1', type: 'subscriptions', attributes: {id: 1, subject: 'completions', destination: 'http://localhost:8080/a/fake/url'}}, {id: '2', type: 'subscriptions', attributes: {id: 2, subject: 'batches', destination: 'http://localhost:8080/another/fake/url'}}]}.to_json)
10
+
11
+ stub_request(:get, "http://localhost:3000/api/v3/facilities/#{@facility.id}/subscriptions/2")
12
+ .to_return(body: {data: {id: '2', type: 'subscriptions', attributes: {id: 2, subject: 'batches', destination: 'http://localhost:8080/another/fake/url'}}}.to_json)
13
+
14
+ stub_request(:post, "http://localhost:3000/api/v3/facilities/#{@facility.id}/subscriptions")
15
+ .with(body: {"subscription"=>{"destination"=>"http://localhost:8080/a/fake/url", "subject"=>"completions"}})
16
+ .to_return(status: 200, body: {data: {id: '3', type: 'subscriptions', attributes: {id: 3, subject: 'completions', destination: 'http://localhost:8080/a/fake/url'}}}.to_json)
17
+
18
+ stub_request(:delete, "http://localhost:3000/api/v3/facilities/#{@facility.id}/subscriptions/2")
19
+ .to_return(status: 204, body: {}.to_json)
20
+ end
21
+
22
+ def test_finding_all_subscriptions
23
+ subscriptions = ArtemisApi::Subscription.find_all(facility_id: @facility.id, client: @client)
24
+ assert_equal 2, subscriptions.count
25
+ end
26
+
27
+ def test_finding_all_subscriptions_through_facility
28
+ subscriptions = @facility.subscriptions
29
+ assert_equal 2, subscriptions.count
30
+ end
31
+
32
+ def test_finding_a_specific_subscription
33
+ subscription = ArtemisApi::Subscription.find(id: 2, facility_id: @facility.id, client: @client)
34
+ assert_equal 'batches', subscription.subject
35
+ assert_equal 'http://localhost:8080/another/fake/url', subscription.destination
36
+ end
37
+
38
+ def test_finding_a_specific_subscription_through_facility
39
+ subscription = @facility.subscription(2)
40
+ assert_equal 'batches', subscription.subject
41
+ assert_equal 'http://localhost:8080/another/fake/url', subscription.destination
42
+ end
43
+
44
+ def test_creating_a_new_subscription
45
+ subscription = ArtemisApi::Subscription.create(facility_id: @facility.id,
46
+ subject: 'completions',
47
+ destination: 'http://localhost:8080/a/fake/url',
48
+ client: @client)
49
+ assert_equal 'completions', subscription.subject
50
+ assert_equal 'http://localhost:8080/a/fake/url', subscription.destination
51
+ assert_equal 1, @client.objects['subscriptions'].count
52
+ end
53
+
54
+ def test_deleting_a_subscription
55
+ # find the subscription first to ensure it's in the objects hash
56
+ ArtemisApi::Subscription.find(id: 2, facility_id: @facility.id, client: @client)
57
+ assert_equal 1, @client.objects['subscriptions'].count
58
+
59
+ # then delete it and ensure it has been removed from the objects hash
60
+ ArtemisApi::Subscription.delete(id: 2, facility_id: @facility.id, client: @client)
61
+ assert_equal 0, @client.objects['subscriptions'].count
62
+ end
63
+ end