Comparing version 0.19.5 to 0.20.0
{ | ||
"name": "middy", | ||
"version": "0.19.5", | ||
"version": "0.20.0", | ||
"description": "🛵 The stylish Node.js middleware engine for AWS Lambda", | ||
@@ -5,0 +5,0 @@ "main": "./index.js", |
@@ -12,2 +12,3 @@ jest.mock('aws-sdk') | ||
SSM.prototype.getParametersByPath = getParametersByPathMock | ||
const onChange = jest.fn() | ||
@@ -19,2 +20,4 @@ beforeEach(() => { | ||
getParametersByPathMock.mockClear() | ||
onChange.mockReset() | ||
onChange.mockClear() | ||
delete process.env.KEY_NAME | ||
@@ -164,2 +167,27 @@ }) | ||
test(`It should call onChange handler on first run`, (done) => { | ||
testScenario({ | ||
ssmMockResponse: { | ||
Parameters: [{Name: '/dev/service_name/secure_param', Value: 'something-secure'}] | ||
}, | ||
middlewareOptions: { | ||
names: { | ||
secureValue: '/dev/service_name/secure_param' | ||
}, | ||
cache: true, | ||
onChange: onChange, | ||
setToContext: true, | ||
paramsLoaded: false | ||
}, | ||
callbacks: [ | ||
(_, {context}) => { | ||
expect(onChange).toHaveBeenCalledTimes(1) | ||
expect(context.secureValue).toEqual('something-secure') | ||
expect(getParametersMock).toBeCalledWith({'Names': ['/dev/service_name/secure_param'], 'WithDecryption': true}) | ||
} | ||
], | ||
done | ||
}) | ||
}) | ||
test(`It should call aws-sdk if cache enabled but cached param has expired`, (done) => { | ||
@@ -195,2 +223,35 @@ testScenario({ | ||
test(`It should call onChange along with aws-sdk if cache enabled but cached param has expired`, (done) => { | ||
testScenario({ | ||
ssmMockResponse: { | ||
Parameters: [{Name: '/dev/service_name/secure_param', Value: 'something-secure'}] | ||
}, | ||
middlewareOptions: { | ||
names: { | ||
secureValue: '/dev/service_name/secure_param' | ||
}, | ||
cache: true, | ||
onChange: onChange, | ||
cacheExpiryInMillis: 10, | ||
setToContext: true, | ||
paramsLoaded: false | ||
}, | ||
callbacks: [ | ||
(_, {context}) => { | ||
expect(onChange).toHaveBeenCalledTimes(1) | ||
expect(context.secureValue).toEqual('something-secure') | ||
expect(getParametersMock).toBeCalledWith({'Names': ['/dev/service_name/secure_param'], 'WithDecryption': true}) | ||
getParametersMock.mockClear() | ||
}, | ||
(_, {context}) => { | ||
expect(onChange).toHaveBeenCalledTimes(2) | ||
expect(context.secureValue).toEqual('something-secure') | ||
expect(getParametersMock).toBeCalledWith({'Names': ['/dev/service_name/secure_param'], 'WithDecryption': true}) | ||
} | ||
], | ||
done, | ||
delay: 20 // 20 > 10, so cache has expired | ||
}) | ||
}) | ||
test(`It should not call aws-sdk if cache enabled and cached param has not expired`, (done) => { | ||
@@ -197,0 +258,0 @@ testScenario({ |
@@ -9,2 +9,3 @@ let ssmInstance | ||
}, | ||
onChange: undefined, | ||
paths: {}, | ||
@@ -67,2 +68,6 @@ names: {}, | ||
}) | ||
if (typeof options.onChange === 'function') { | ||
options.onChange() | ||
} | ||
options.paramsLoaded = true | ||
@@ -69,0 +74,0 @@ options.paramsCache = objectsToMap |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
162534
4102