You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
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.
The text was updated successfully, but these errors were encountered:
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)
}
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.
The text was updated successfully, but these errors were encountered: