Closed leelaprasadv closed 1 year ago
#148
Support for HTTPS mock server.
Changes:
await mock.setDefaults({port, host, httpsOpts})
httpsOpts
setDefaults
{httpsOpts: {key: key, cert: cert}}
Example with self signed certs
const pactum = require('pactum'); const fs = require('fs') const https = require('https') const mock = pactum.mock; const key = fs.readFileSync("server.key") const cert = fs.readFileSync("server.crt") const agent = new https.Agent({ cert: cert, key: key, rejectUnauthorized: false // Ignore self-signed certificate errors }); before(async () => { await mock.setDefaults({port: 3001, host: '127.0.0.1', httpsOpts: {key: "server.key", cert: "server.crt"}}) await mock.start(); }) after(async () => { await mock.stop(); }) const { addInteractionHandler } = pactum.handler; addInteractionHandler('get users with id 1 & 2', (ctx) => { return [ { request: { method: 'GET', path: `/api/users/${ctx.data[0]}` }, response: { status: 200 } } ]; }); it('GET - multiple interactions', async () => { await pactum.spec() .useInteraction('get users with id 1 & 2', [2]) .get('https://localhost:3001/api/users/2') .withCore({agent: agent }) .expectStatus(200) mock.clearInteractions(); });
#148
Support for HTTPS mock server.
Changes:
await mock.setDefaults({port, host, httpsOpts})
.httpsOpts
are provided in mock serverssetDefaults
.{httpsOpts: {key: key, cert: cert}}
- httpsOpts structureExample with self signed certs