Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

hapi-mock

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hapi-mock - npm Package Compare versions

Comparing version 1.0.0-alpha.2 to 1.0.0-alpha.3

test/mocks/faulty.js

2

package.json
{
"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);
});
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc