Closed kayvonghaffari closed 8 years ago
Reasons for having CONSUMERS define their contracts
Sources:
Tools that aid in contract tests
Questions:
version: 1.0
consumer: api
producer: core
/v1/cards:
POST:
With valid card details:
request:
body: |
{
"card_number": "4111111111111111",
"exp_month": "08",
"exp_year": "2017"
}
response:
code: 200
body: |
{
"token": "CTABCDEFG",
"exp_month": "08",
"exp_year": "2017",
"status": "ready"
}
With expired card:
request:
body: |
{
"card_number": "411111111",
"exp_month": "01",
"exp_year": "2000"
}
response:
code: 400
body: |
{
"error": "validation_error",
"message": "card expired"
}
/v1/cards/CTabcdef:
GET:
With card existing:
response:
code: 200
body: |
{
"token": "CTabcdef",
"status": "ready"
}
With non-existing card:
response:
code: 404
body: |
{
"error": "validation_error",
"message": "card not found"
}
/v1/cards/CTabcdef/credits:
POST:
With card existing:
request:
body: |
{
"amount_cents": 100
}
response:
code: 200
body: |
{
"token": "CCaoeu",
"amount_cents": 100
}
# spec/api/do_something_spec.rb
describe '/v1/do_something' do
context "with something" do
around { |ex|
ApiAuthService.with_context("valid credentials") { ex.run }
CoreService.with_context("With card existing") { ex.run }
}
let(:token) { 'CTabcdef' }
it 'should do something' do
lookup_card(token)
CoreService.cards('CTabcdef').get
process_transaction
# resp = CoreService
# authenticate
# -> ApiAuthService.api_keys(resp[:token]).get
# details = CoreService.cards('CTabcdef').get
# CoreService.cards('CTabcdef').credits!(amount_cents: 100)
end
end
end
Sharing pacts between consumers and producers: https://github.com/realestate-com-au/pact/wiki/Sharing-pacts-between-consumer-and-provider
Our research is done. Closing this out since we've implemented both consumer and producer testing.
Consumer-based testing vs Producer-based testing