-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
165 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
const APP_ROOT = '..'; | ||
const given = require(`${APP_ROOT}/test/steps/given`); | ||
const expect = require('chai').expect; | ||
const ApiGatewayCachingSettings = require(`${APP_ROOT}/src/ApiGatewayCachingSettings`); | ||
|
||
describe('Configuring a default base path', () => { | ||
const serviceName = 'cat-api'; | ||
const endpointPath = '/cat/{pawId}'; | ||
const functionName = 'get-cat-by-paw-id'; | ||
|
||
describe('when a base path is specified', () => { | ||
const scenarios = [ | ||
{ | ||
description: 'does not start with a forward slash', | ||
basePath: 'animals' | ||
}, | ||
{ | ||
description: 'starts with a forward slash', | ||
basePath: '/animals' | ||
}, | ||
{ | ||
description: 'has a trailing slash', | ||
basePath: 'animals/' | ||
} | ||
]; | ||
let settings; | ||
|
||
for (scenario of scenarios) { | ||
describe(`and ${scenario.description}`, () => { | ||
before(() => { | ||
const endpoint = given | ||
.a_serverless_function(functionName) | ||
.withHttpEndpoint('get', endpointPath, { enabled: true }); | ||
|
||
const serverless = given | ||
.a_serverless_instance(serviceName) | ||
.withApiGatewayCachingConfig({ basePath: scenario.basePath }) | ||
.withFunction(endpoint); | ||
|
||
settings = new ApiGatewayCachingSettings(serverless); | ||
}); | ||
|
||
it('should be prepended to each endpoint and form a valid path', () => { | ||
expect(path_of(functionName, settings)).to.equal(`/animals${endpointPath}`); | ||
}); | ||
}); | ||
} | ||
}); | ||
|
||
describe('when no base path is specified', () => { | ||
before(() => { | ||
const endpoint = given | ||
.a_serverless_function(functionName) | ||
.withHttpEndpoint('get', endpointPath, { enabled: true }); | ||
|
||
const serverless = given | ||
.a_serverless_instance(serviceName) | ||
.withApiGatewayCachingConfig() | ||
.withFunction(endpoint); | ||
|
||
settings = new ApiGatewayCachingSettings(serverless); | ||
}); | ||
|
||
it('should just use the endpoint path', () => { | ||
expect(path_of(functionName, settings)).to.equal(endpointPath); | ||
}); | ||
}); | ||
}); | ||
|
||
const path_of = (functionName, settings) => { | ||
return settings | ||
.endpointSettings | ||
.find(x => x.functionName === functionName) | ||
.path; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.