How to use the aws-sdk-mock.setSDKInstance function in aws-sdk-mock

To help you get started, we’ve selected a few aws-sdk-mock examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github adieuadieu / aws-kms-thingy / test / setup.ts View on Github external
// 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, {
github lifeomic / alpha / test / setup.js View on Github external
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'));
github alexa / alexa-skills-kit-sdk-for-nodejs / ask-sdk-dynamodb-persistence-adapter / tst / attributes / persistence / DynamoDbPersistenceAdapter.spec.ts View on Github external
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) => {
github serverless-cqrs / serverless-cqrs / packages / dynamodb-adapter / src / __test__ / index.js View on Github external
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' },
  ]
github laconiajs / laconia / packages / laconia-batch / integration-test / dynamodb-batch-handler.spec.js View on Github external
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);
  });
github rapid7 / propsd / test / tags.js View on Github external
beforeEach(function () {
    AWS.setSDKInstance(AWS_SDK);
  });
github alexa / alexa-skills-kit-sdk-for-nodejs / ask-sdk-s3-persistence-adapter / tst / attributes / persistence / S3PersistenceAdapter.spec.ts View on Github external
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);

aws-sdk-mock

Functions to mock the JavaScript aws-sdk

Apache-2.0
Latest version published 3 months ago

Package Health Score

86 / 100
Full package analysis