Comparing version 1.0.0-alpha.2 to 1.0.0-alpha.3
{ | ||
"name": "hapi-mock", | ||
"version": "1.0.0-alpha.2", | ||
"version": "1.0.0-alpha.3", | ||
"description": "A simple HAPI plug-in for mocking endpoints", | ||
@@ -5,0 +5,0 @@ "main": "src/index.js", |
@@ -71,10 +71,22 @@ const Path = require('path'); | ||
options: { | ||
auth: { | ||
access: { | ||
scope: ['read'], | ||
auth: false, | ||
plugins: { | ||
'hapi-mock': { | ||
file: './cases', | ||
}, | ||
}, | ||
}, | ||
handler: () => { | ||
listener.handlers(); | ||
return 'ok'; | ||
}, | ||
}; | ||
const route3 = { | ||
method: 'GET', | ||
path: '/test3/{id}', | ||
options: { | ||
auth: false, | ||
plugins: { | ||
'hapi-mock': { | ||
file: './cases', | ||
file: './faulty', | ||
}, | ||
@@ -97,3 +109,3 @@ }, | ||
server.auth.default('simple'); | ||
await server.route([route1, route2]); | ||
await server.route([route1, route2, route3]); | ||
await server.start(); | ||
@@ -119,6 +131,28 @@ return server; | ||
it('should mock routes / condition by params', async () => { | ||
it('should not mock routes / no mocks for this route', async () => { | ||
const res = await server.inject({ | ||
method: 'GET', | ||
url: '/test1/4711', | ||
headers: { | ||
'x-hapi-mock': true, | ||
}, | ||
}); | ||
expect(res.statusCode).to.be.equal(400); | ||
expect(JSON.parse(res.payload).message).to.be.equal('no mocks for this route'); | ||
expect(listener.handlers.called).to.equal(false); | ||
}); | ||
it('should not mock routes / pass on to handler', async () => { | ||
const res = await server.inject({ | ||
method: 'GET', | ||
url: '/test2/4711', | ||
}); | ||
expect(res.statusCode).to.be.equal(200); | ||
expect(listener.handlers.calledOnce).to.equal(true); | ||
}); | ||
it('should mock routes / find condition by params', async () => { | ||
const res = await server.inject({ | ||
method: 'GET', | ||
url: '/test2/4711', | ||
headers: { | ||
@@ -132,3 +166,3 @@ 'x-hapi-mock': true, | ||
it('should mock routes / condition by headers', async () => { | ||
it('should mock routes / find condition by headers', async () => { | ||
const res = await server.inject({ | ||
@@ -155,4 +189,18 @@ method: 'GET', | ||
expect(res.statusCode).to.be.equal(400); | ||
expect(JSON.parse(res.payload).message).to.be.equal('no matching mock found'); | ||
expect(listener.handlers.called).to.equal(false); | ||
}); | ||
it('should detect and log faulty condition', async () => { | ||
const res = await server.inject({ | ||
method: 'GET', | ||
url: '/test3/4711', | ||
headers: { | ||
'x-hapi-mock': true, | ||
}, | ||
}); | ||
expect(res.statusCode).to.be.equal(500); | ||
expect(listener.handlers.called).to.equal(false); | ||
expect(listener.errors.calledOnce).to.be.equals(true); | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
10986
10
260