Skip to content

Commit

Permalink
Added unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pchynoweth committed Feb 4, 2019
1 parent 73d95c2 commit 9a25ade
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/plugins/aws/package/compile/events/apiGateway/lib/cors.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ module.exports = {
origins = origin.split(',').map(a => a.trim());
}

if (origins.length) {
if (!_.isEmpty(origins)) {
origin = origins[0];
}

if (!origin && !origins.length) {
if (!origin) {
const errorMessage = 'must specify either origin or origins';
throw new this.serverless.classes.Error(errorMessage);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ describe('#compileCors()', () => {
awsCompileApigEvents.validated.corsPreflight = {
'users/update': {
origin: 'http://example.com',
origins: [],
headers: ['*'],
methods: ['OPTIONS', 'PUT'],
allowCredentials: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,7 @@ describe('#validate()', () => {
origins: ['acme.com'],
methods: ['POST', 'OPTIONS'],
maxAge: 86400,
cacheControl: 'max-age=600, s-maxage=600, proxy-revalidate'
},
},
},
Expand All @@ -659,6 +660,7 @@ describe('#validate()', () => {
origins: ['acme.com'],
allowCredentials: false,
maxAge: 86400,
cacheControl: 'max-age=600, s-maxage=600, proxy-revalidate'
});
});

Expand All @@ -676,6 +678,7 @@ describe('#validate()', () => {
],
allowCredentials: true,
maxAge: 10000,
cacheControl: 'max-age=600, s-maxage=600, proxy-revalidate'
},
},
}, {
Expand Down Expand Up @@ -723,6 +726,8 @@ describe('#validate()', () => {
.to.deep.equal(['TestHeader2', 'TestHeader']);
expect(validated.corsPreflight.users.maxAge)
.to.equal(86400);
expect(validated.corsPreflight.users.cacheControl)
.to.equal('max-age=600, s-maxage=600, proxy-revalidate');
expect(validated.corsPreflight.users.allowCredentials)
.to.equal(true);
expect(validated.corsPreflight['users/{id}'].allowCredentials)
Expand Down

0 comments on commit 9a25ade

Please sign in to comment.