Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
maguimarijuan committed May 22, 2020
1 parent 3445e30 commit e23fd9e
Show file tree
Hide file tree
Showing 2 changed files with 104 additions and 34 deletions.
70 changes: 36 additions & 34 deletions lib/export-serverless.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,43 @@

const path = require('path');

const handlerPath = path.join(process.env.MS_PATH || '', 'lambda', 'ExportProcess', 'index.handler');
const clientModelPath = path.join(process.env.MS_PATH || '', 'models', 'client.js');
const controllersPath = path.join(process.env.MS_PATH || '', 'controllers', 'export', '**');
const modelsPath = path.join(process.env.MS_PATH || '', 'models', '**');
module.exports = serviceName => {

const resourceAux = '${self:custom.stage}';// eslint-disable-line
const handlerPath = path.join(process.env.MS_PATH || '', 'lambda', 'ExportProcess', 'index.handler');
const clientModelPath = path.join(process.env.MS_PATH || '', 'models', 'client.js');
const controllersPath = path.join(process.env.MS_PATH || '', 'controllers', 'export', '**');
const modelsPath = path.join(process.env.MS_PATH || '', 'models', '**');
const resourceAux = '${self:custom.stage}';// eslint-disable-line

module.exports = serviceName => [
[
'janis.apiPost', {
entityName: 'export',
authorizer: 'ImportExportAuthorizer',
cors: true,
timeout: 10,
package: { include: [modelsPath, controllersPath] }
}
],
return [
[
'janis.apiPost', {
entityName: 'export',
authorizer: 'ImportExportAuthorizer',
cors: true,
timeout: 10,
package: { include: [modelsPath, controllersPath] }
}
],

[
'function', {
functionName: 'ExportProcess',
handler: handlerPath,
description: 'Export Process Lambda',
timeout: 60,
package: { include: ['schemas/mongo/**', clientModelPath] }
}
],
[
'function', {
functionName: 'ExportProcess',
handler: handlerPath,
description: 'Export Process Lambda',
timeout: 60,
package: { include: ['schemas/mongo/**', clientModelPath] }
}
],

[
'iamStatement', {
action: [
's3:PutObject',
's3:GetObject'
],
resource: `arn:aws:s3:::janis-${serviceName}-service-${resourceAux}/*`// eslint-disable-line
}
]
];
[
'iamStatement', {
action: [
's3:PutObject',
's3:GetObject'
],
resource: `arn:aws:s3:::janis-${serviceName}-service-${resourceAux}/*`// eslint-disable-line
}
]
];
};
68 changes: 68 additions & 0 deletions tests/export-serverless.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
'use strict';

const assert = require('assert');
const path = require('path');
const { exportServerless } = require('../lib/index');

const handlerPathWithSrc = path.join('src', 'lambda', 'ExportProcess', 'index.handler');
const clientModelPathWithSrc = path.join('src', 'models', 'client.js');
const controllersPathWithSrc = path.join('src', 'controllers', 'export', '**');
const modelsPathWithSrc = path.join('src', 'models', '**');

const handlerPathWithoutSrc = path.join('lambda', 'ExportProcess', 'index.handler');
const clientModelPathWithoutSrc = path.join('models', 'client.js');
const controllersPathWithoutSrc = path.join('controllers', 'export', '**');
const modelsPathWithoutSrc = path.join('models', '**');

const resourceAux = '${self:custom.stage}';// eslint-disable-line

const getHooks = (handlerPath, modelsPath, controllersPath, clientModelPath) => [
[
'janis.apiPost', {
entityName: 'export',
authorizer: 'ImportExportAuthorizer',
cors: true,
timeout: 10,
package: { include: [modelsPath, controllersPath] }
}
],

[
'function', {
functionName: 'ExportProcess',
handler: handlerPath,
description: 'Export Process Lambda',
timeout: 60,
package: { include: ['schemas/mongo/**', clientModelPath] }
}
],

[
'iamStatement', {
action: [
's3:PutObject',
's3:GetObject'
],
resource: `arn:aws:s3:::janis-wms-service-${resourceAux}/*`// eslint-disable-line
}
]
];


describe('export-serveless', () => {

describe('Export Serverless', () => {

it('Should return the correct hooks with MS_PATH ', () => {
process.env.MS_PATH = 'src';
assert.deepStrictEqual(exportServerless('wms'),
getHooks(handlerPathWithSrc, modelsPathWithSrc, controllersPathWithSrc, clientModelPathWithSrc));
});

it('Should return the correct hooks without MS_Path', () => {
delete (process.env.MS_PATH);
assert.deepStrictEqual(exportServerless('wms'),
getHooks(handlerPathWithoutSrc, modelsPathWithoutSrc, controllersPathWithoutSrc, clientModelPathWithoutSrc));
});
});
});

0 comments on commit e23fd9e

Please sign in to comment.