@@ -5,53 +5,41 @@ module Api
5
5
module Decorators
6
6
describe VerifiablePactDecorator do
7
7
before do
8
- allow_any_instance_of ( PactBroker ::Api ::PactBrokerUrls ) . to receive ( :pact_version_url ) . and_return ( '/pact-version-url' )
9
- allow_any_instance_of ( PactBroker ::Pacts ::VerifiablePactMessages ) . to receive ( :inclusion_reason ) . and_return ( "the inclusion reason" )
10
- allow_any_instance_of ( PactBroker ::Pacts ::VerifiablePactMessages ) . to receive ( :pending_reason ) . and_return ( pending_reason )
11
- allow_any_instance_of ( PactBroker ::Pacts ::VerifiablePactMessages ) . to receive ( :verification_success_true_published_false ) . and_return ( 'verification_success_true_published_false' )
12
- allow_any_instance_of ( PactBroker ::Pacts ::VerifiablePactMessages ) . to receive ( :verification_success_false_published_false ) . and_return ( 'verification_success_false_published_false' )
13
- allow_any_instance_of ( PactBroker ::Pacts ::VerifiablePactMessages ) . to receive ( :verification_success_true_published_true ) . and_return ( 'verification_success_true_published_true' )
14
- allow_any_instance_of ( PactBroker ::Pacts ::VerifiablePactMessages ) . to receive ( :verification_success_false_published_true ) . and_return ( 'verification_success_false_published_true' )
8
+ allow_any_instance_of ( PactBroker ::Api ::PactBrokerUrls ) . to receive ( :pact_version_url ) . and_return ( 'http://pact' )
9
+ allow ( PactBroker ::Pacts ::BuildVerifiablePactNotices ) . to receive ( :call ) . and_return ( notices )
10
+ allow_any_instance_of ( PactBroker ::Pacts ::VerifiablePactMessages ) . to receive ( :pact_version_short_description ) . and_return ( 'short desc' )
15
11
end
12
+
16
13
let ( :pending_reason ) { "the pending reason" }
14
+ let ( :notices ) do
15
+ [
16
+ {
17
+ some : "notice"
18
+ }
19
+ ]
20
+ end
17
21
let ( :expected_hash ) do
18
22
{
23
+ "shortDescription" => "short desc" ,
19
24
"verificationProperties" => {
20
25
"pending" => true ,
21
26
"notices" => [
22
27
{
23
- "when" => "before_verification" ,
24
- "text" => "the inclusion reason"
25
- } , {
26
- "when" => "before_verification" ,
27
- "text" => pending_reason
28
- } , {
29
- "when" => "after_verification:success_true_published_false" ,
30
- "text" => "verification_success_true_published_false"
31
- } , {
32
- "when" => "after_verification:success_false_published_false" ,
33
- "text" => "verification_success_false_published_false"
34
- } , {
35
- "when" => "after_verification:success_true_published_true" ,
36
- "text" => "verification_success_true_published_true"
37
- } , {
38
- "when" => "after_verification:success_false_published_true" ,
39
- "text" => "verification_success_false_published_true"
28
+ "some" => "notice"
40
29
}
41
30
]
42
31
} ,
43
32
"_links" => {
44
33
"self" => {
45
- "href" => "/ pact-version-url " ,
34
+ "href" => "http:// pact" ,
46
35
"name" => "name"
47
36
}
48
37
}
49
38
}
50
39
end
51
-
52
40
let ( :decorator ) { VerifiablePactDecorator . new ( pact ) }
53
41
let ( :pact ) do
54
- double ( 'pact ' ,
42
+ double ( 'PactBroker::Pacts::VerifiablePact ' ,
55
43
pending : true ,
56
44
wip : wip ,
57
45
name : "name" ,
@@ -61,10 +49,10 @@ module Decorators
61
49
end
62
50
let ( :pending_provider_tags ) { %w[ dev ] }
63
51
let ( :consumer_tags ) { %w[ dev ] }
64
- let ( :json ) { decorator . to_json ( options ) }
65
52
let ( :options ) { { user_options : { base_url : 'http://example.org' , include_pending_status : include_pending_status } } }
66
53
let ( :include_pending_status ) { true }
67
54
let ( :wip ) { false }
55
+ let ( :json ) { decorator . to_json ( options ) }
68
56
69
57
subject { JSON . parse ( json ) }
70
58
@@ -77,27 +65,17 @@ module Decorators
77
65
subject
78
66
end
79
67
80
- it "creates the inclusion message " do
81
- expect ( PactBroker ::Pacts ::VerifiablePactMessages ) . to receive ( :new ) . with ( pact , '/ pact-version-url' ) . and_call_original
68
+ it "creates the notices " do
69
+ allow ( PactBroker ::Pacts ::BuildVerifiablePactNotices ) . to receive ( :call ) . with ( pact , 'http:// pact' , include_pending_status : include_pending_status )
82
70
subject
83
71
end
84
72
85
73
context "when include_pending_status is false" do
86
74
let ( :include_pending_status ) { false }
87
- let ( :notices ) { subject [ 'verificationProperties' ] [ 'notices' ] . collect { | notice | notice [ 'text' ] } }
88
75
89
76
it "does not include the pending flag" do
90
77
expect ( subject [ 'verificationProperties' ] ) . to_not have_key ( 'pending' )
91
78
end
92
-
93
- it "does not include the pending reason" do
94
- expect ( subject [ 'verificationProperties' ] ) . to_not have_key ( 'pendingReason' )
95
- expect ( notices ) . to_not include ( pending_reason )
96
- end
97
-
98
- it "does not include the pending notices" do
99
- expect ( subject [ 'verificationProperties' ] [ 'notices' ] . size ) . to eq 1
100
- end
101
79
end
102
80
103
81
context "when wip is true" do
0 commit comments