pact-foundation / pact-stub-server

Standalone pact stub server
MIT License
75 stars 19 forks source link

Response is 404 when term matcher added on path of api on using pact-stub-server #26

Closed Dolly2315 closed 4 years ago

Dolly2315 commented 5 years ago

describe('Getting asset for player', () => { before(() => { return provider.addInteraction({ given: 'GET call', uponReceiving: 'Get asset for player', withRequest: { method: 'GET', path: term({ matcher: '/api/assets/[0-9]+', generate: '/api/assets/10006' }), }, willRespondWith: { status: 200, headers: { 'Content-Type': 'application/json' }, body: assetByPlayer } }); });

it('Get the asset by player', () => {
    return request.get(`http://localhost:${PORT}/api/assets/10006`)
    .set({ 'Accept': 'application/json' }).then((response) => {
        return expect(Promise.resolve(response.statusCode)).to.eventually.equals(200);
    }).catch(err => {
        console.log("Error in asset with player listing", err);

    });
});

}); I get the json file as : https://pastebin.com/TqRbTmNS

When i use the json file in other code base by pact stub server , it gets the request from UI as ===> Received Request ( method: GET, path: /api/assets/10006, query: None, headers: Some({"actasuserid": "5", "content-type": "application/vnd.nativ.mio.v1+json", "host": "masteraccount.local.nativ.tv:30044", "accept": "application/json", "authorization": "Basic bWFzdGVydXNlcjptYXN0ZXJ1c2Vy", "connection": "close", "content-length": "2"}), body: Present(2 bytes) )

but does not sends any response

But if i just remove the matching rules part "matchingRules": { "$.path": { "match": "regex", "regex": "\/api\/assets\/[0-9]+" } } it starts to work again

===> Received Request ( method: GET, path: /api/assets/10006, query: None, headers: Some({"authorization": "Basic bWFzdGVydXNlcjptYXN0ZXJ1c2Vy", "accept": "application/json", "content-length": "2", "connection": "close", "host": "masteraccount.local.nativ.tv:30044", "content-type": "application/vnd.nativ.mio.v1+json", "actasuserid": "5"}), body: Present(2 bytes) )

<=== Sending Response ( status: 200, headers: Some({"Content-Type": "application/json"}), body: Present(4500 bytes) )

and I can see the data to be present

Could you let me what is wrong here ?

uglyog commented 5 years ago

Could you provide the JSON pact file again, the link in pastebin has been removed