Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// tslint:disable:no-expression-statement
import * as AWS from 'aws-sdk'
import * as mockAWS from 'aws-sdk-mock'
mockAWS.setSDKInstance(AWS)
mockAWS.mock('KMS', 'decrypt', (params: any, callback: any) => {
const plain = params.CiphertextBlob.toString()
return plain === 'mockError'
? callback(null, {})
: callback(null, { Plaintext: plain })
})
mockAWS.mock(
'KMS',
'encrypt',
({ Plaintext: plaintext }: any, callback: any) => {
return plaintext === 'mockError'
? callback(null, {})
: callback(null, {
const AWS = require('aws-sdk-mock');
// Force aws-sdk-mock to use the same instance of the SDK that the code uses.
// This is necessary due to transpiling. See
// https://github.com/dwyl/aws-sdk-mock#setting-the-aws-sdk-object-explicitly
AWS.setSDKInstance(require('aws-sdk'));
before( (done) => {
AWS_MOCK.setSDKInstance(AWS);
AWS_MOCK.mock('DynamoDB.DocumentClient', 'get', (params, callback) => {
if (params.TableName !== tableName) {
// table name not valid
callback(resourceNotFoundError, null);
} else {
if (params.Key[defaultPartitionKeyName] === defaultPartitionKey) {
callback(null, {Item: defaultGetItemOutput });
} else if (params.Key[customPartitionKeyName] === customPartitionKey) {
callback(null, {Item: customGetItemOutput });
} else {
// item not found
callback(null, {});
}
}
});
AWS_MOCK.mock('DynamoDB.DocumentClient', 'put', (params, callback) => {
const { test } = require('tap')
const AWS = require('aws-sdk-mock')
const AWS_SDK = require('aws-sdk')
AWS.setSDKInstance(AWS_SDK);
const { build } = require('../index')
const clientParams = {
tableName: 'fooTable',
indexName: 'fooIndex',
}
test('loadEvents', async assert => {
var sentParams
const events = [
{ foo: 'bar' },
{ bar: 'baz' },
{ baz: 'bar '},
{ zab: 'foo' },
]
const DynamoDbLocal = require("dynamodb-local");
const AWSMock = require("aws-sdk-mock");
const AWS = require("aws-sdk");
const DynamoDbMusicRepository = require("./DynamoDbMusicRepository");
const { sharedBehaviour } = require("../test/shared-batch-handler-spec");
const dynamoDb = require("../src/dynamoDb");
const laconiaBatch = require("../src/laconiaBatch");
AWSMock.setSDKInstance(AWS);
describe("dynamodb batch handler", () => {
const dynamoLocalPort = 8000;
const dynamoDbOptions = {
region: "eu-west-1",
endpoint: new AWS.Endpoint(`http://localhost:${dynamoLocalPort}`)
};
let itemListener, event, context, callback, documentClient;
beforeAll(() => {
return DynamoDbLocal.launch(dynamoLocalPort, null, ["-sharedDb"]);
}, 60000);
afterAll(() => {
return DynamoDbLocal.stop(dynamoLocalPort);
});
beforeEach(function () {
AWS.setSDKInstance(AWS_SDK);
});
before((done) => {
AWS_MOCK.setSDKInstance(AWS);
AWS_MOCK.mock('S3', 'getObject', (params, callback) => {
if (params.Bucket !== bucketName) {
callback(bucketInvalidError, null);
} else {
if (params.Key === defaultObjectKey) {
callback(null, {Body : Buffer.from(JSON.stringify(defaultAttributes))});
} else if (params.Key === customObjectKey) {
callback(null, {Body : Buffer.from(JSON.stringify(customAttributes))});
} else if (params.Key === pathPrefixObjectKey) {
callback(null, {Body : Buffer.from(JSON.stringify(pathPrefixObjectAttributes))});
} else if (params.Key === nonJsonObjectKey) {
callback(null, {Body : Buffer.from(nonJsonObjectAttributes)});
} else if (params.Key === emptyBodyKey) {
callback(null, {});
} else {
callback(noSuchKeyError, null);