Skip to content

Commit 6735820

Browse files
committed
Merge branch 'master' into add_authorizer_support
2 parents 32ada3b + 14252f9 commit 6735820

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

lib/deploy/events/apiGateway/resources.test.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,17 +434,46 @@ describe('#compileResources()', () => {
434434
.to.throw(Error, 'Resource ID for path users is required');
435435
});
436436

437+
it('should throw error if API root resourceId of existing resource is required', () => {
438+
serverlessStepFunctions.serverless.service.provider.apiGateway = {
439+
restApiId: '6fyzt1pfpk',
440+
restApiRootResourceId: '',
441+
restApiResources: {
442+
'users/friends': 'fcasdoojp1',
443+
},
444+
};
445+
446+
serverlessStepFunctions.pluginhttpValidated.events = [
447+
{
448+
http: {
449+
path: 'users/test/{id}',
450+
method: 'GET',
451+
},
452+
},
453+
];
454+
455+
expect(() => serverlessStepFunctions.compileResources())
456+
.to.throw(Error, 'Resource ID for path users is required');
457+
});
458+
437459
it('should named all method paths if all resources are predefined', () => {
438460
serverlessStepFunctions.serverless.service.provider.apiGateway = {
439461
restApiId: '6fyzt1pfpk',
440462
restApiRootResourceId: 'z5d4qh4oqi',
441463
restApiResources: {
464+
'users/{id}': 'fcasdoojp1',
442465
'users/friends': 'fcasdoojp1',
443466
'users/friends/{id}': 'fcasdoojp1',
444467
},
445468
};
446469

447470
serverlessStepFunctions.pluginhttpValidated.events = [
471+
{
472+
http: {
473+
path: '/users/{id}',
474+
method: 'GET',
475+
},
476+
},
448477
{
449478
http: {
450479
path: 'users/friends',
@@ -485,4 +514,23 @@ describe('#compileResources()', () => {
485514
.to.equal(true);
486515
});
487516
});
517+
518+
it('should return empty string if path is empty', () => {
519+
expect(serverlessStepFunctions.getResourceName('')).to.equal('');
520+
});
521+
522+
it('should return empty string if no resources', () => {
523+
expect(serverlessStepFunctions.getResourceName('users/friends')).to.equal('');
524+
});
525+
526+
it('should return resource name for given path', () => {
527+
serverlessStepFunctions.apiGatewayResources = {
528+
'users/create': {
529+
name: 'UsersCreate',
530+
resourceLogicalId: 'ApiGatewayResourceUsersCreate',
531+
},
532+
};
533+
534+
expect(serverlessStepFunctions.getResourceName('users/create')).to.equal('UsersCreate');
535+
});
488536
});

0 commit comments

Comments
 (0)