node-lambda 1.3.0 → 2.0.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/test/s3_events.js CHANGED
@@ -1,9 +1,14 @@
1
1
  'use strict'
2
2
 
3
- const assert = require('chai').assert
4
- const path = require('path')
5
- const aws = require('aws-sdk-mock')
6
- aws.setSDK(path.resolve('node_modules/aws-sdk'))
3
+ let assert
4
+ import('chai').then(chai => {
5
+ assert = chai.assert
6
+ })
7
+ const { S3Client, PutBucketNotificationConfigurationCommand } = require('@aws-sdk/client-s3')
8
+ const { LambdaClient, AddPermissionCommand } = require('@aws-sdk/client-lambda')
9
+ const { mockClient } = require('aws-sdk-client-mock')
10
+ const mockS3Client = mockClient(S3Client)
11
+ const mockLambdaClient = mockClient(LambdaClient)
7
12
  const S3Events = require('../lib/s3_events')
8
13
 
9
14
  const params = {
@@ -30,22 +35,15 @@ const mockResponse = {
30
35
 
31
36
  let s3Events = null
32
37
 
33
- /* global before, after, describe, it */
38
+ /* global before, describe, it */
34
39
  describe('lib/s3_events', () => {
35
40
  before(() => {
36
- aws.mock('Lambda', 'addPermission', (params, callback) => {
37
- callback(null, mockResponse.addPermission)
38
- })
39
- aws.mock('S3', 'putBucketNotificationConfiguration', (params, callback) => {
40
- callback(null, mockResponse.putBucketNotificationConfiguration)
41
- })
42
-
43
- s3Events = new S3Events(require('aws-sdk'))
44
- })
41
+ mockS3Client.reset()
42
+ mockS3Client.on(PutBucketNotificationConfigurationCommand).resolves(mockResponse.putBucketNotificationConfiguration)
43
+ mockLambdaClient.reset()
44
+ mockLambdaClient.on(AddPermissionCommand).resolves(mockResponse.addPermission)
45
45
 
46
- after(() => {
47
- aws.restore('Lambda')
48
- aws.restore('S3')
46
+ s3Events = new S3Events({ region: 'us-west-1' })
49
47
  })
50
48
 
51
49
  describe('_functionName', () => {
@@ -1,9 +1,15 @@
1
1
  'use strict'
2
2
 
3
- const assert = require('chai').assert
3
+ let assert
4
+ import('chai').then(chai => {
5
+ assert = chai.assert
6
+ })
4
7
  const path = require('path')
5
- const aws = require('aws-sdk-mock')
6
- aws.setSDK(path.resolve('node_modules/aws-sdk'))
8
+ const { CloudWatchEventsClient, PutRuleCommand, PutTargetsCommand } = require('@aws-sdk/client-cloudwatch-events')
9
+ const { LambdaClient, AddPermissionCommand } = require('@aws-sdk/client-lambda')
10
+ const { mockClient } = require('aws-sdk-client-mock')
11
+ const mockCloudWatchEventsClient = mockClient(CloudWatchEventsClient)
12
+ const mockLambdaClient = mockClient(LambdaClient)
7
13
  const ScheduleEvents = require(path.join('..', 'lib', 'schedule_events'))
8
14
 
9
15
  const params = {
@@ -41,22 +47,14 @@ let schedule = null
41
47
  /* global before, after, describe, it */
42
48
  describe('lib/schedule_events', () => {
43
49
  before(() => {
44
- aws.mock('CloudWatchEvents', 'putRule', (params, callback) => {
45
- callback(null, mockResponse.putRule)
46
- })
47
- aws.mock('CloudWatchEvents', 'putTargets', (params, callback) => {
48
- callback(null, mockResponse.putTargets)
49
- })
50
- aws.mock('Lambda', 'addPermission', (params, callback) => {
51
- callback(null, mockResponse.addPermission)
52
- })
50
+ mockCloudWatchEventsClient.reset()
51
+ mockCloudWatchEventsClient.on(PutRuleCommand).resolves(mockResponse.putRule)
52
+ mockCloudWatchEventsClient.on(PutTargetsCommand).resolves(mockResponse.putTargets)
53
53
 
54
- schedule = new ScheduleEvents(require('aws-sdk'))
55
- })
54
+ mockLambdaClient.reset()
55
+ mockLambdaClient.on(AddPermissionCommand).resolves(mockResponse.addPermission)
56
56
 
57
- after(() => {
58
- aws.restore('CloudWatchEvents')
59
- aws.restore('Lambda')
57
+ schedule = new ScheduleEvents({ region: 'us-west-1' })
60
58
  })
61
59
 
62
60
  describe('_ruleDescription (default)', () => {