-
-
Save soundstep/4991f67b98d274efbe18ef4eb0c53baa to your computer and use it in GitHub Desktop.
Pact test with the pact-mock-service for a POST request with matchers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"consumer": { | |
"name": "Consumer Name" | |
}, | |
"provider": { | |
"name": "Provider Name" | |
}, | |
"interactions": [ | |
{ | |
"description": "duh", | |
"request": { | |
"method": "POST", | |
"path": "/auth", | |
"headers": { | |
"Content-Type": "application/json", | |
"Accept": "application/json" | |
}, | |
"body": { | |
"nonce": "abc123", | |
"username": "ctv.integration.test@example.com", | |
"scope": "content", | |
"grant_type": "password", | |
"password": "pw123456" | |
} | |
}, | |
"response": { | |
"status": 200, | |
"headers": { | |
"Content-Type": "application/json; charset=UTF-8", | |
"Access-Control-Allow-Origin": "*", | |
"Cache-Control": "no-store" | |
}, | |
"body": { | |
"access_token": "eyJhbGc", | |
"token_type": "bearer", | |
"refresh_token": "eyJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwcz" | |
}, | |
"matchingRules": { | |
"$.body.access_token": { | |
"match": "type" | |
}, | |
"$.body.refresh_token": { | |
"match": "type" | |
} | |
} | |
} | |
}, | |
{ | |
"description": "duh preflight", | |
"request": { | |
"method": "OPTIONS", | |
"path": "/auth", | |
"headers": { | |
"Access-Control-Request-Headers": "content-type" | |
} | |
}, | |
"response": { | |
"status": 200, | |
"headers": { | |
"Access-Control-Allow-Methods": "OPTIONS, GET", | |
"Access-Control-Allow-Origin": "*", | |
"Access-Control-Allow-Headers": "content-type" | |
} | |
} | |
} | |
], | |
"metadata": { | |
"pactSpecificationVersion": "2.0.0" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"description": "duh", | |
"request": { | |
"method": "POST", | |
"path": "/auth", | |
"headers": { | |
"Content-Type": "application/json", | |
"Accept": "application/json" | |
}, | |
"body": { | |
"nonce": { | |
"json_class": "Pact::SomethingLike", | |
"contents": "abc123" | |
}, | |
"username": "ctv.integration.test@example.com", | |
"scope": "content", | |
"grant_type": "password", | |
"password": "pw123456" | |
} | |
}, | |
"response": { | |
"status": 200, | |
"headers": { | |
"Content-Type": "application/json; charset=UTF-8", | |
"Access-Control-Allow-Origin": "*", | |
"Cache-Control": "no-store" | |
}, | |
"body": { | |
"access_token": { | |
"json_class": "Pact::SomethingLike", | |
"contents": "eyJhbGc" | |
}, | |
"token_type": "bearer", | |
"refresh_token": { | |
"json_class": "Pact::SomethingLike", | |
"contents": "eyJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwcz" | |
} | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"description": "duh preflight", | |
"request": { | |
"method": "OPTIONS", | |
"path": "/auth", | |
"headers": { | |
"Access-Control-Request-Headers": { | |
"json_class": "Pact::SomethingLike", | |
"contents": "content-type" | |
} | |
} | |
}, | |
"response": { | |
"status": 200, | |
"headers": { | |
"Access-Control-Allow-Methods": "OPTIONS, GET", | |
"Access-Control-Allow-Origin": "*", | |
"Access-Control-Allow-Headers": "content-type" | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"consumer" : { | |
"name": "Consumer Name" | |
}, | |
"provider": { | |
"name": "Provider Name" | |
}, | |
"pact_dir": "pacts", | |
"pact_specification_version": "2" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mkdir -p /tmp/pacts | |
# before each | |
curl -XDELETE -H "X-Pact-Mock-Service: true" localhost:1234/interactions | |
echo '' | |
echo '' | |
# before test | |
curl -XPOST -H "X-Pact-Mock-Service: true" -H "Content-Type: application/json" localhost:1234/interactions -d@interaction1.json | |
curl -XPOST -H "X-Pact-Mock-Service: true" -H "Content-Type: application/json" localhost:1234/interactions -d@interaction2.json | |
echo '' | |
echo '' | |
# test | |
curl 'http://localhost:1234/auth' -X OPTIONS -H 'Pragma: no-cache' -H 'Access-Control-Request-Method: POST' -H 'Origin: http://localhost:8001' -H 'Accept-Encoding: gzip, deflate, sdch, br' -H 'Accept-Language: en-GB,en-US;q=0.8,en;q=0.6,fr;q=0.4,ms;q=0.2' -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.71 Safari/537.36' -H 'Accept: */*' -H 'Cache-Control: no-cache' -H 'Referer: http://localhost:8001/debug.html?bypassLoading=1&debug=1' -H 'Connection: keep-alive' -H 'Access-Control-Request-Headers: content-type' --compressed | |
curl 'http://localhost:1234/auth' -H 'Pragma: no-cache' -H 'Origin: http://localhost:8001' -H 'Accept-Encoding: gzip, deflate, br' -H 'Accept-Language: en-GB,en-US;q=0.8,en;q=0.6,fr;q=0.4,ms;q=0.2' -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.71 Safari/537.36' -H 'Content-Type: application/json' -H 'Accept: application/json' -H 'Cache-Control: no-cache' -H 'Referer: http://localhost:8001/debug.html?bypassLoading=1&debug=1' -H 'Connection: keep-alive' --data-binary '{"nonce":"abc123","username":"ctv.integration.test@example.com","scope":"content","grant_type":"password","password":"pw123456"}' --compressed | |
echo '' | |
echo '' | |
#curl -XGET localhost:1234/blah | |
# after each | |
curl -XGET -H "X-Pact-Mock-Service: true" localhost:1234/interactions/verification | |
echo '' | |
echo '' | |
# after suite | |
curl -XPOST -H "X-Pact-Mock-Service: true" localhost:1234/pact -d@pact-details.json | |
echo '' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment