How to use aws-sdk-mock - 10 common examples

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, {
          CiphertextBlob: Buffer.from(plaintext),
        })
  },
)
github motdotla / node-lambda / test / s3_deploy.js View on Github external
'use strict'

const { assert } = require('chai')
const path = require('path')
const aws = require('aws-sdk-mock')
aws.setSDK(path.resolve('node_modules/aws-sdk'))
const S3Deploy = require('../lib/s3_deploy')

const mockResponse = {
  createBucket: { Location: 'createBucket' },
  putObject: { ETag: 'putObject' }
}

var s3Deploy = null

/* global describe, it, before, after */
describe('lib/s3_deploy', () => {
  before(() => {
    aws.mock('S3', 'putObject', (params, callback) => {
      callback(null, mockResponse.putObject)
    })
    aws.mock('S3', 'createBucket', (params, callback) => {
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 motdotla / node-lambda / test / main.js View on Github external
const _mockSetting = () => {
  awsMock.mock('CloudWatchEvents', 'putRule', (params, callback) => {
    callback(null, {})
  })
  awsMock.mock('CloudWatchEvents', 'putTargets', (params, callback) => {
    callback(null, {})
  })
  awsMock.mock('CloudWatchLogs', 'createLogGroup', (params, callback) => {
    callback(null, {})
  })
  awsMock.mock('CloudWatchLogs', 'putRetentionPolicy', (params, callback) => {
    callback(null, {})
  })
  awsMock.mock('S3', 'putBucketNotificationConfiguration', (params, callback) => {
    callback(null, {})
  })
  awsMock.mock('S3', 'putObject', (params, callback) => {
    callback(null, { test: 'putObject' })
  })

  Object.keys(lambdaMockSettings).forEach((method) => {
    awsMock.mock('Lambda', method, (params, callback) => {
      callback(null, lambdaMockSettings[method])
    })
  })

  return require('aws-sdk')
}
github laconiajs / laconia / packages / laconia-aws-batch / acceptance-test / batch-handler-helper.js View on Github external
beforeEach(() => {
      invokeMock = jest.fn();
      AWSMock.mock("Lambda", "invoke", invokeMock);

      itemListener = jest.fn();
      stopListener = jest.fn();
      endListener = jest.fn();
      startListener = jest.fn();
      event = {};
      context = {
        functionName: "blah",
        getRemainingTimeInMillis: () => 100000
      };
      callback = jest.fn();
    });
github motdotla / node-lambda / test / main.js View on Github external
awsMock.mock('CloudWatchEvents', 'putRule', (params, callback) => {
    callback(null, {})
  })
  awsMock.mock('CloudWatchEvents', 'putTargets', (params, callback) => {
    callback(null, {})
  })
  awsMock.mock('CloudWatchLogs', 'createLogGroup', (params, callback) => {
    callback(null, {})
  })
  awsMock.mock('CloudWatchLogs', 'putRetentionPolicy', (params, callback) => {
    callback(null, {})
  })
  awsMock.mock('S3', 'putBucketNotificationConfiguration', (params, callback) => {
    callback(null, {})
  })
  awsMock.mock('S3', 'putObject', (params, callback) => {
    callback(null, { test: 'putObject' })
  })

  Object.keys(lambdaMockSettings).forEach((method) => {
    awsMock.mock('Lambda', method, (params, callback) => {
      callback(null, lambdaMockSettings[method])
    })
  })

  return require('aws-sdk')
}
github BrianMacIntosh / alexa-skill-test-framework / index.js View on Github external
unmockDynamoDB: function () {
		'use strict';
		AWSMOCK.restore('DynamoDB.DocumentClient');
	},

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