Skip to content

No longer configuring whether parameters are required on request validation #13

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "serverless-api-gateway-caching",
"version": "1.1.3",
"version": "1.1.4-rc2",
"description": "A plugin for the serverless framework which helps with configuring caching for API Gateway endpoints.",
"main": "src/apiGatewayCachingPlugin.js",
"scripts": {
Expand Down
3 changes: 2 additions & 1 deletion src/pathParametersCache.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ const addPathParametersCacheConfig = (settings, serverless) => {
}

for (let cacheKeyParameter of endpointSettings.cacheKeyParameters) {
method.resource.Properties.RequestParameters[`method.${cacheKeyParameter.name}`] = true;
let existingValue = method.resource.Properties.RequestParameters[`method.${cacheKeyParameter.name}`];
method.resource.Properties.RequestParameters[`method.${cacheKeyParameter.name}`] = (existingValue == null || existingValue == undefined) ? {} : existingValue;
method.resource.Properties.Integration.RequestParameters[`integration.${cacheKeyParameter.name}`] = `method.${cacheKeyParameter.name}`;
method.resource.Properties.Integration.CacheKeyParameters.push(`method.${cacheKeyParameter.name}`);
}
Expand Down
62 changes: 54 additions & 8 deletions test/configuring-path-parameters.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,13 @@ describe('Configuring path parameter caching', () => {
method = serverless.getMethodResourceForFunction(functionWithCachingName);
});

it('should set that request parameters are part of the cache key', () => {
for (let parameter of cacheKeyParameters) {
expect(method.Properties.RequestParameters)
.to.deep.include({
[`method.${parameter.name}`]: true
});
}
it('should configure them as request parameters', () => {
for (let parameter of cacheKeyParameters) {
expect(method.Properties.RequestParameters)
.to.deep.include({
[`method.${parameter.name}`]: {}
});
}
});

it('should set integration request parameters', () => {
Expand All @@ -101,7 +101,7 @@ describe('Configuring path parameter caching', () => {
});
});

describe('on the method resource correspondin with the endpoint without cache key parameters', () => {
describe('on the method resource corresponding with the endpoint without cache key parameters', () => {
before(() => {
method = serverless.getMethodResourceForFunction(functionWithoutCachingName);
});
Expand All @@ -123,6 +123,52 @@ describe('Configuring path parameter caching', () => {
});
});
});

describe('when one endpoint has cache key parameters', () => {
let cacheKeyParameters, functionWithCachingName;
before(() => {
functionWithCachingName = 'get-cat-by-paw-id';
cacheKeyParameters = [{ name: 'request.path.pawId' }, { name: 'request.header.Accept-Language' }];

let functionWithCaching = given.a_serverless_function(functionWithCachingName)
.withHttpEndpoint('get', '/cat/{pawId}', { enabled: true, cacheKeyParameters });

serverless = given.a_serverless_instance(serviceName)
.withApiGatewayCachingConfig(true, '0.5', 45)
.forStage(stage)
.withFunction(functionWithCaching);
});

let alreadyConfiguredParamsScenarios = [
{
description: "required",
isRequired: true
},
{
description: "not required",
isRequired: false
}
];
for (let { description, isRequired } of alreadyConfiguredParamsScenarios) {
describe(`and one of them has been already configured as ${description} for http request validation by another plugin`, () => {
let method;
before(() => {
method = serverless.getMethodResourceForFunction(functionWithCachingName);
method.Properties.RequestParameters[`method.${cacheKeyParameters[0].name}`] = isRequired;

cacheSettings = new ApiGatewayCachingSettings(serverless);
when_configuring_path_parameters(cacheSettings, serverless)
});

it('should keep configuration', () => {
expect(method.Properties.RequestParameters)
.to.deep.include({
[`method.${cacheKeyParameters[0].name}`]: isRequired
});
});
});
}
});
});

const when_configuring_path_parameters = (settings, serverless) => {
Expand Down