Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import * as AWS from 'aws-sdk-mock';
import { DocumentClient } from 'aws-sdk/lib/dynamodb/document_client';
import { expect } from 'chai';
import * as lambdaLocal from 'lambda-local';
import ScanOutput = DocumentClient.ScanOutput;
import PutItemInput = DocumentClient.PutItemInput;
import ScanInput = DocumentClient.ScanInput;
import { env } from 'process';
import { listTodos, save, ToDo } from '../lib/data';
lambdaLocal.getLogger().level = 'error';
env.TABLE_NAME = 'SomeTable';
describe('Test ToDo DAO - save', () => {
it('should save todo', async () => {
AWS.mock('DynamoDB.DocumentClient', 'put', (params : PutItemInput, callback) => {
expect(params).to.haveOwnProperty('Item');
expect(params.Item).to.have.property('id', 'todoId');
expect(params.Item).to.have.property('text', 'ToDoText');
expect(params.Item).to.have.property('state', 'OPEN');
expect(params).to.have.property('TableName', 'SomeTable');
callback(null, {});
});
const todo : ToDo = await save({
import { APIGatewayProxyEvent, APIGatewayProxyResult } from 'aws-lambda';
import { expect } from 'chai';
import * as lambdaLocal from 'lambda-local';
import { describe, it } from 'mocha';
import * as proxyquire from 'proxyquire';
import { ToDo } from '../lib/data';
lambdaLocal.getLogger().level = 'error';
const todoStub = {
listTodos: undefined,
save: undefined,
};
const uuidStub = {
v4: undefined,
};
const api = proxyquire('../lib/index', { './data': todoStub, 'node-uuid': uuidStub });
describe('GetAPI', () => {
beforeEach(() => {
delete todoStub.listTodos;
});