|
1 |
| -require 'spec/support/test_data_builder' |
2 |
| - |
3 | 1 | describe "Get provider pacts" do
|
4 |
| - |
5 |
| - let(:path) { "/pacts/provider/Provider/latest" } |
6 | 2 | let(:last_response_body) { JSON.parse(subject.body, symbolize_names: true) }
|
7 |
| - |
| 3 | + let(:pact_links) { last_response_body[:_links][:'pb:pacts'] } |
8 | 4 | subject { get path; last_response }
|
9 | 5 |
|
10 | 6 | context "when the provider exists" do
|
11 |
| - |
12 | 7 | before do
|
13 | 8 | TestDataBuilder.new
|
14 | 9 | .create_provider("Provider")
|
15 | 10 | .create_consumer("Consumer")
|
| 11 | + .create_consumer_version("0.0.1") |
| 12 | + .create_consumer_version_tag("prod") |
| 13 | + .create_pact |
16 | 14 | .create_consumer_version("1.0.0")
|
17 | 15 | .create_consumer_version_tag("prod")
|
18 | 16 | .create_pact
|
19 | 17 | .create_consumer_version("1.2.3")
|
20 | 18 | .create_pact
|
21 | 19 | .create_consumer("Consumer 2")
|
22 | 20 | .create_consumer_version("4.5.6")
|
| 21 | + .create_consumer_version_tag("prod") |
23 | 22 | .create_pact
|
24 | 23 | end
|
25 | 24 |
|
26 | 25 | context "with no tag specified" do
|
| 26 | + let(:path) { "/pacts/provider/Provider/latest" } |
27 | 27 |
|
28 | 28 | it "returns a 200 HAL JSON response" do
|
29 | 29 | expect(subject).to be_a_hal_json_success_response
|
30 | 30 | end
|
31 | 31 |
|
32 | 32 | it "returns a list of links to the pacts" do
|
33 |
| - expect(last_response_body[:_links][:pacts].size).to eq 2 |
| 33 | + expect(pact_links.size).to eq 2 |
34 | 34 | end
|
35 | 35 | end
|
36 | 36 |
|
37 | 37 | context "with a tag specified" do
|
38 |
| - |
39 | 38 | let(:path) { "/pacts/provider/Provider/latest/prod" }
|
40 | 39 |
|
41 | 40 | it "returns a 200 HAL JSON response" do
|
42 | 41 | expect(subject).to be_a_hal_json_success_response
|
43 | 42 | end
|
44 | 43 |
|
45 | 44 | it "returns a list of links to the pacts" do
|
46 |
| - expect(last_response_body[:_links][:pacts].size).to eq 1 |
| 45 | + expect(pact_links.size).to eq 2 |
47 | 46 | end
|
48 | 47 | end
|
49 | 48 |
|
50 | 49 | context "with a tag with no pacts" do
|
51 |
| - |
52 | 50 | let(:path) { "/pacts/provider/Provider/latest/foo" }
|
53 | 51 |
|
54 | 52 | it "returns a 200 HAL JSON response" do
|
55 | 53 | expect(subject).to be_a_hal_json_success_response
|
56 | 54 | end
|
57 | 55 |
|
58 | 56 | it "returns a list of links to the pacts" do
|
59 |
| - expect(last_response_body[:_links][:pacts].size).to eq 0 |
| 57 | + expect(pact_links.size).to eq 0 |
60 | 58 | end
|
61 | 59 | end
|
62 | 60 |
|
| 61 | + context "with a tag for all pacts" do |
| 62 | + let(:path) { "/pacts/provider/Provider/tag/prod" } |
| 63 | + |
| 64 | + it "returns a 200 HAL JSON response" do |
| 65 | + expect(subject).to be_a_hal_json_success_response |
| 66 | + end |
| 67 | + |
| 68 | + it "returns a list of links to the pacts" do |
| 69 | + expect(pact_links.size).to eq 3 |
| 70 | + end |
| 71 | + end |
| 72 | + |
| 73 | + context "with no tag for all pacts" do |
| 74 | + let(:path) { "/pacts/provider/Provider" } |
| 75 | + |
| 76 | + it "returns a 200 HAL JSON response" do |
| 77 | + expect(subject).to be_a_hal_json_success_response |
| 78 | + end |
| 79 | + |
| 80 | + it "returns a list of links to the pacts" do |
| 81 | + expect(last_response_body[:_links][:'pb:pacts'].size).to eq 4 |
| 82 | + end |
| 83 | + end |
63 | 84 | end
|
64 | 85 |
|
65 | 86 | context "when the provider does not exist" do
|
| 87 | + let(:path) { "/pacts/provider/Provider" } |
66 | 88 |
|
67 | 89 | it "returns a 404 response" do
|
68 | 90 | expect(subject).to be_a_404_response
|
69 | 91 | end
|
70 |
| - |
71 | 92 | end
|
72 | 93 | end
|
0 commit comments