Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Regarding setting up the states in pact provider test #3

Open
210178 opened this issue Jan 23, 2018 · 0 comments
Open

Regarding setting up the states in pact provider test #3

210178 opened this issue Jan 23, 2018 · 0 comments

Comments

@210178
Copy link

210178 commented Jan 23, 2018

Hi,
I am trying to implement the pact provider test in Koa JS. My scenario is like this,

Scenario-1:

GIVEN I have a student id
WHEN I request to retrieve the student details by id
AND id is available in DB
THEN I should get a success response with student mark summary

Scenario-2:

GIVEN I have a student id
WHEN I request to retrieve the student details by id
AND id is not available in DB
THEN I should get a failure response

My rest endpoint is,
GET
http://localhost:8080/students/{id}/mark/summary

My provider configuration:

const opts = {
provider: 'Receive',
providerBaseUrl: 'http://localhost:8080',
providerStatesUrl: 'http://localhost:8080/states',
providerStatesSetupUrl: 'http://localhost:8080/setup',
pactUrls: [ path.resolve(process.cwd(), './app/pacts/receive-summary.json') ],
tags: [ 'prod', 'test' ],
publishVerificationResult: false,
providerVersion: '0.0.50'
}

and I have the following code for setting my states and setup end points,

const app = require('../index')
const path = require('path')
const Verifier = require('pact').Verifier
const impress = require('impress-router')
const router = new impress()

router.get('/states', setStates)
async function setStates(ctx, next) {
console.log('Entering into setStates() !!!!!!')
const response = {
'My Consumer': [ 'I have a valid delivery number', 'I have an invalid delivery number' ]
}
ctx.body = JSON.stringify(response)
next()
}

router.post('/setup', setup)

async function setup(ctx, next) {
console.log('Entering into setup() !!!!!!')
let deliveryNumber
const state = ctx.request.body
console.log('state value:', state)

switch (state) {
    case 'I have a delivery number':

        deliveryNumber = 'us12345'
        break
    case 'I have an invalid delivery number':
        deliveryNumber = '12345'
        break
    default:
       console.log('here in DEFAULT')
}

ctx.body = 200
next()

}

app.use(router)
app.listen(8080)

For this scenario, how can I setup my states() and setup()??? With the above code, it never hits the setStaes() and I am not sure how and when those endpoints will be triggered.

Please clarify.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant