-
-
Notifications
You must be signed in to change notification settings - Fork 171
/
provider_pacts_for_verification_spec.rb
82 lines (73 loc) · 2.85 KB
/
provider_pacts_for_verification_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
require 'pact_broker/api/resources/provider_pacts_for_verification'
module PactBroker
module Api
module Resources
describe ProviderPactsForVerification do
before do
allow(PactBroker::Pacts::Service).to receive(:find_for_verification).and_return(pacts)
allow(PactBroker::Api::Decorators::VerifiablePactsDecorator).to receive(:new).and_return(decorator)
allow_any_instance_of(ProviderPactsForVerification).to receive(:resource_exists?).and_return(provider)
end
let(:provider) { double('provider') }
let(:pacts) { [] }
let(:path) { '/pacts/provider/Bar/for-verification' }
let(:decorator) { instance_double('PactBroker::Api::Decorators::VerifiablePactsDecorator') }
let(:query) do
{
provider_version_tags: ['master'],
consumer_version_selectors: [ { tag: 'dev', latest: 'true' }],
include_pending_status: 'true',
include_wip_pacts_since: '2018-01-01'
}
end
subject { post(path, request_body.to_json, request_headers) }
describe "POST" do
let(:request_body) do
{
providerVersionTags: ['master'],
consumerVersionSelectors: [ { tag: 'dev', latest: true }],
includePendingStatus: true,
includeWipPactsSince: '2018-01-01',
}
end
let(:request_headers) do
{
'CONTENT_TYPE' => 'application/json',
'HTTP_ACCEPT' => 'application/hal+json'
}
end
it "finds the pacts for verification by the provider" do
# Naughty not mocking out the query parsing...
expect(PactBroker::Pacts::Service).to receive(:find_for_verification).with(
"Bar",
["master"],
PactBroker::Pacts::Selectors.new([PactBroker::Pacts::Selector.latest_for_tag("dev")]),
{
include_wip_pacts_since: DateTime.parse('2018-01-01'),
include_pending_status: true
}
)
subject
end
context "when there are validation errors" do
let(:request_body) do
{
providerVersionTags: true
}
end
it "returns the keys with the right case" do
expect(JSON.parse(subject.body)['errors']).to have_key('providerVersionTags')
end
end
it "uses the correct options for the decorator" do
expect(decorator).to receive(:to_json) do | options |
expect(options[:user_options][:title]).to eq "Pacts to be verified by provider Bar"
expect(options[:user_options][:include_pending_status]).to eq true
end
subject
end
end
end
end
end
end