@@ -3,55 +3,65 @@ const isCI = require('is-ci')
33const { Verifier } = require ( '@pact-foundation/pact' )
44
55const app = require ( '../../src/app' )
6+ const {
7+ dateOneMonthAgo,
8+ currentGitBranch,
9+ currentGitHash,
10+ isDefaultBranch
11+ } = require ( './util' )
612
713describe ( 'ServeRest - Verificação do contrato' , ( ) => {
814 const SERVER_URL = 'http://localhost:3001'
915 const server = http . createServer ( app )
1016
11- const gitHash = require ( 'child_process' )
12- . execSync ( 'git rev-parse HEAD' )
13- . toString ( )
14- . trim ( )
15-
16- const gitBranch = require ( 'child_process' )
17- . execSync ( 'git branch --show-current' )
18- . toString ( )
19- . trim ( )
20-
2117 before ( ( ) => {
22- server . listen ( 3001 , ( ) => {
23- console . log ( `Clients Service listening on ${ SERVER_URL } ` )
24- } )
18+ server . listen ( 3001 , ( ) => console . log ( `Server listening on ${ SERVER_URL } ` ) )
2519 } )
2620
2721 after ( ( ) => {
2822 server . close ( )
2923 } )
3024
3125 it ( 'Validates the expectations of ServeRest' , ( ) => {
32- const options = {
26+ const baseOptions = {
3327 provider : 'ServeRest - API Rest' ,
3428 logLevel : 'INFO' ,
3529 pactBrokerToken : process . env . PACT_BROKER_TOKEN ,
3630 providerBaseUrl : SERVER_URL ,
37- providerVersionTags : process . env . GITHUB_BRANCH || gitBranch ,
38- providerVersion : gitHash ,
39- publishVerificationResult : isCI
31+ providerVersionTags : currentGitBranch ,
32+ providerVersion : currentGitHash ,
33+ publishVerificationResult : isCI ,
34+ verbose : process . env . VERBOSE === 'true'
4035 }
4136
42- // https://docs.pact.io/provider/recommended_configuration/#verification-triggered-by-pact-change
43- if ( process . env . TRIGGERED_BY_PACT_CHANGE ) {
44- options . pactUrls = [ process . env . PACT_URL ]
45- } else {
46- const consumerVersionTags = process . env . CONSUMER_VERSION_TAG
47- ? [ 'production' , 'main' , process . env . CONSUMER_VERSION_TAG ]
48- : [ 'production' , 'main' ]
37+ // Para builds que foram 'trigados' por webhook de 'mudança de conteúdo de contrato' é preciso verificar apenas o contrato (pact) alterado.
38+ // A URL (env PACT_URL) será passada pelo webhook para o job de CI.
39+ // https://docs.pact.io/provider/recommended_configurtion/#verification-triggered-by-pact-change
40+ const pactChangedOptions = {
41+ pactUrls : [ process . env . PACT_URL ]
42+ }
4943
50- options . consumerVersionTags = consumerVersionTags
51- options . pactBrokerUrl = process . env . PACT_BROKER_BASE_URL
44+ const fetchPactsDynamicallyOptions = {
45+ pactBrokerUrl : 'https://paulogoncalves.pactflow.io' ,
46+ consumerVersionSelectors : [
47+ {
48+ tag : currentGitBranch ,
49+ fallbackTag : 'main' ,
50+ latest : true
51+ } ,
52+ {
53+ tag : 'production' ,
54+ latest : true
55+ }
56+ ] ,
57+ includeWipPactsSince : isDefaultBranch ? dateOneMonthAgo ( ) : undefined ,
58+ enablePending : true
5259 }
5360
54- return new Verifier ( options )
61+ return new Verifier ( {
62+ ...baseOptions ,
63+ ...( process . env . PACT_URL ? pactChangedOptions : fetchPactsDynamicallyOptions )
64+ } )
5565 . verifyProvider ( )
5666 . then ( ( output ) => {
5767 console . log ( 'Pact Verification Complete!' )
0 commit comments