apicco-lib
Advanced tools
Comparing version 1.2.8 to 1.3.0
20
build.js
@@ -77,17 +77,13 @@ const path = require('path'); | ||
for (const param in validate) { | ||
if (!validate.hasOwnProperty(param)) { | ||
continue; | ||
} | ||
let joiSchema = validate; | ||
if (!joiSchema.isJoi) { | ||
joiSchema = joi.object(validate); | ||
} | ||
const { isJoi = true, _flags = {} } = validate[param]; | ||
const validateParams = joiSchema.describe().children; | ||
for (const param in validateParams) { | ||
const { flags = {} } = validateParams[param]; | ||
if (!isJoi) { | ||
throw new Error( | ||
`Invalid Joi validation for ${actionName} action: ${param}.` | ||
); | ||
} | ||
const paramsName = flags.presence === 'required' ? `*${param}` : param; | ||
const paramsName = _flags.presence === 'required' ? `*${param}` : param; | ||
params.push(paramsName); | ||
@@ -94,0 +90,0 @@ } |
@@ -20,3 +20,3 @@ /* eslint-env jest */ | ||
beforeAll(() => { | ||
jest.mock('require-directory', () => jest.fn(() => { | ||
this.mockedDirectory = jest.fn(() => { | ||
const Joi = require('joi'); | ||
@@ -47,3 +47,5 @@ | ||
}; | ||
})); | ||
}); | ||
jest.mock('require-directory', () => this.mockedDirectory); | ||
}); | ||
@@ -92,2 +94,47 @@ | ||
test('supports returning Joi.object in validation', async () => { | ||
const ctx = mockCtx({ | ||
method: 'GET', | ||
path: '/api/v1/discovery' | ||
}); | ||
const next = jest.fn(); | ||
this.mockedDirectory = jest.fn(() => { | ||
const Joi = require('joi'); | ||
return { | ||
movies: { | ||
list: { | ||
validate: {}, | ||
handle: () => {} | ||
}, | ||
play: { | ||
validate: { | ||
title: Joi.string().required() | ||
}, | ||
handle: () => {} | ||
} | ||
}, | ||
books: { | ||
read: { | ||
validate: Joi.object({ | ||
title: Joi.string().required(), | ||
author: Joi.string() | ||
}), | ||
handle: () => {} | ||
} | ||
} | ||
}; | ||
}); | ||
await buildAPI()(ctx, next); | ||
expect(ctx._matchedRoute).toBe('/api/v1/discovery'); | ||
expect(ctx.body).toEqual({ | ||
'books.read': expect.arrayContaining(['*title', 'author']), | ||
'movies.list': [], | ||
'movies.play': expect.arrayContaining(['*title']) | ||
}); | ||
}); | ||
test('assigns koa-router to returned apicco middleware', async () => { | ||
@@ -94,0 +141,0 @@ const middleware = buildAPI(); |
{ | ||
"name": "apicco-lib", | ||
"version": "1.2.8", | ||
"version": "1.3.0", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
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
20030
348