payout / rester

An exceedingly quick way of creating restful interfaces between Ruby services.
https://www.payout.com
MIT License
2 stars 0 forks source link

Research Testing Strategy #23

Closed kayvonghaffari closed 8 years ago

kayvonghaffari commented 9 years ago

Consumer-based testing vs Producer-based testing

kayvonghaffari commented 9 years ago

Reasons for having CONSUMERS define their contracts

Sources:

kayvonghaffari commented 9 years ago

Tools that aid in contract tests

kayvonghaffari commented 9 years ago

Questions:

roberthoner commented 9 years ago
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
kayvonghaffari commented 9 years ago

Sharing pacts between consumers and producers: https://github.com/realestate-com-au/pact/wiki/Sharing-pacts-between-consumer-and-provider

roberthoner commented 8 years ago

Our research is done. Closing this out since we've implemented both consumer and producer testing.