7
7
module Pact
8
8
module PactBroker
9
9
class FetchPactURIsForVerification
10
- attr_reader :provider , :consumer_version_selectors , :provider_version_tags , :broker_base_url , :http_client_options , :http_client
10
+ attr_reader :provider , :consumer_version_selectors , :provider_version_tags , :broker_base_url , :http_client_options , :http_client , :options
11
11
12
12
PACTS_FOR_VERIFICATION_RELATION = 'beta:provider-pacts-for-verification' . freeze
13
13
PACTS = 'pacts' . freeze
@@ -16,17 +16,18 @@ class FetchPactURIsForVerification
16
16
SELF = 'self' . freeze
17
17
EMBEDDED = '_embedded' . freeze
18
18
19
- def initialize ( provider , consumer_version_selectors , provider_version_tags , broker_base_url , http_client_options )
19
+ def initialize ( provider , consumer_version_selectors , provider_version_tags , broker_base_url , http_client_options , options = { } )
20
20
@provider = provider
21
21
@consumer_version_selectors = consumer_version_selectors || [ ]
22
22
@provider_version_tags = provider_version_tags || [ ]
23
23
@http_client_options = http_client_options
24
24
@broker_base_url = broker_base_url
25
25
@http_client = Pact ::Hal ::HttpClient . new ( http_client_options )
26
+ @options = options
26
27
end
27
28
28
- def self . call ( provider , consumer_version_selectors , provider_version_tags , broker_base_url , http_client_options )
29
- new ( provider , consumer_version_selectors , provider_version_tags , broker_base_url , http_client_options ) . call
29
+ def self . call ( provider , consumer_version_selectors , provider_version_tags , broker_base_url , http_client_options , options = { } )
30
+ new ( provider , consumer_version_selectors , provider_version_tags , broker_base_url , http_client_options , options ) . call
30
31
end
31
32
32
33
def call
@@ -50,8 +51,7 @@ def pacts_for_verification
50
51
pacts_for_verification_entity . response . body [ EMBEDDED ] [ PACTS ] . collect do | pact |
51
52
metadata = {
52
53
pending : pact [ "verificationProperties" ] [ "pending" ] ,
53
- pending_reason : pact [ "verificationProperties" ] [ "pendingReason" ] ,
54
- inclusion_reason : pact [ "verificationProperties" ] [ "inclusionReason" ] ,
54
+ notices : extract_notices ( pact )
55
55
}
56
56
Pact ::Provider ::PactURI . new ( pact [ LINKS ] [ SELF ] [ HREF ] , http_client_options , metadata )
57
57
end
@@ -61,22 +61,21 @@ def pacts_for_verification_entity
61
61
index
62
62
. _link ( PACTS_FOR_VERIFICATION_RELATION )
63
63
. expand ( provider : provider )
64
- . with_query ( query )
65
- . get!
64
+ . post! ( query )
66
65
end
67
66
68
67
def query
69
68
q = { }
70
- if consumer_version_selectors . any?
71
- q [ "consumer_version_selectors" ] = consumer_version_selectors
72
- end
73
-
74
- if provider_version_tags . any?
75
- q [ "provider_version_tags" ] = provider_version_tags
76
- end
69
+ q [ "includePendingStatus" ] = true if options [ :include_pending_status ]
70
+ q [ "consumerVersionSelectors" ] = consumer_version_selectors if consumer_version_selectors . any?
71
+ q [ "providerVersionTags" ] = provider_version_tags if provider_version_tags . any?
77
72
q
78
73
end
79
74
75
+ def extract_notices ( pact )
76
+ ( pact [ "verificationProperties" ] [ "notices" ] || [ ] ) . collect { |notice | notice [ "text" ] } . compact
77
+ end
78
+
80
79
def log_message
81
80
latest = consumer_version_selectors . any? ? "" : "latest "
82
81
message = "INFO: Fetching #{ latest } pacts for #{ provider } from #{ broker_base_url } "
0 commit comments