Skip to content

Commit

Permalink
fix(index): fix OW Method name and handling of empty parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
trieloff committed Jun 16, 2019
1 parent 559d373 commit 79f1c00
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ async function report() {
function wrap(func, checks) {
return (params) => {
// eslint-disable-next-line no-underscore-dangle
if (params.__ow_methd === 'get') {
if (params && params.__ow_method === 'get') {
return report(checks);
}
return func(params);
Expand Down
12 changes: 10 additions & 2 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,20 @@ const { AssertionError } = require('assert');
const index = require('../src/index.js').main;

describe('Index Tests', () => {
it('index function is present', async () => {
it('index function returns function for function', async () => {
const wrapped = await index(() => 'foo');
assert.deepEqual(typeof wrapped, 'function');
assert.deepEqual(wrapped(), 'foo');
const result = await wrapped({ __ow_method: 'get' });
assert.equal(result.statusCode, 200);
});

it('index function returns status code for objects', async () => {
const result = await index({});
assert.deepEqual(result.statusCode, 200);
});

it('index function returns an object', async () => {
it('index function throws if passed invalid arguments', async () => {
try {
await index();
assert.fail('this should never happen');
Expand Down

0 comments on commit 79f1c00

Please sign in to comment.