Skip to content

Commit 0db7030

Browse files
committed
rename wrappers, finish tests
1 parent 00195f1 commit 0db7030

File tree

22 files changed

+90
-23
lines changed

22 files changed

+90
-23
lines changed

__mocks__/epsagon.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@ const epsagon = jest.genMockFromModule('epsagon');
44
epsagon.label = function(key: string) {};
55

66
module.exports = epsagon;
7+
// module.exports = (function() {
8+
// throw new Error();
9+
// })();

src/api/wrapper.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import createEvent from '@serverless/event-mocks';
2-
import { apiWrapper, ApiSignature } from './wrapper';
2+
import { api, ApiSignature } from './wrapper';
33

44
describe('API wrapper', () => {
55
// @ts-ignore
@@ -36,6 +36,6 @@ describe('API wrapper', () => {
3636
expect(redirect).toBeInstanceOf(Function);
3737
expect(error).toBeInstanceOf(Function);
3838
}
39-
apiWrapper(mockHandler)(requestEvent);
39+
api(mockHandler)(requestEvent);
4040
});
4141
});

src/api/wrapper.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { APIGatewayEvent } from 'aws-lambda';
22
import { Request } from './parser';
33
import { success, invalid, redirect, error } from './responses';
44

5-
export function apiWrapper<T extends Function>(fn: T): T {
5+
export function api<T extends Function>(fn: T): T {
66
return <any>function(event: APIGatewayEvent) {
77
const { body, path, query, auth, headers, testRequest } = new Request(event).getProperties();
88

File renamed without changes.

src/auth/responses.test.ts renamed to src/authorizer/responses.test.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,26 @@ describe('Lambda Authorizer responses', () => {
4343
});
4444
});
4545

46+
it('Handles valid response without jwt subs or claims', () => {
47+
const jwt = {
48+
name: 'John Doe',
49+
admin: true
50+
};
51+
expect(valid(jwt)).toEqual({
52+
principalId: '',
53+
policyDocument: {
54+
Version: '2012-10-17',
55+
Statement: [
56+
{
57+
Action: 'execute-api:Invoke',
58+
Effect: 'Allow',
59+
Resource: 'arn:aws:execute-api:**'
60+
}
61+
]
62+
}
63+
});
64+
});
65+
4666
it('Handles invalid response', () => {
4767
expect(() => invalid()).toThrow('Unauthorized');
4868
});
File renamed without changes.

src/auth/wrapper.test.ts renamed to src/authorizer/wrapper.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { authWrapper, AuthorizerSignature } from './wrapper';
1+
import { authorizer, AuthorizerSignature } from './wrapper';
22

33
describe('Stream wrapper', () => {
44
const requestEvent = {
@@ -16,6 +16,6 @@ describe('Stream wrapper', () => {
1616
expect(error).toBeInstanceOf(Function);
1717
}
1818
// @ts-ignore
19-
authWrapper(mockHandler)(requestEvent);
19+
authorizer(mockHandler)(requestEvent);
2020
});
2121
});

src/auth/wrapper.ts renamed to src/authorizer/wrapper.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { valid, invalid, error } from './responses';
44

55
const metrics = new Metrics('Lambda Authorizer');
66

7-
export function authWrapper<T extends Function>(fn: T): T {
7+
export function authorizer<T extends Function>(fn: T): T {
88
return <any>function(event: CustomAuthorizerEvent) {
99
metrics.common(event);
1010
const token = event.authorizationToken;

src/cloudformation/wrapper.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { cloudFormationWrapper, CloudFormationSignature } from './wrapper';
1+
import { cloudFormation, CloudFormationSignature } from './wrapper';
22
import { CloudFormationCustomResourceEvent } from 'aws-lambda';
33

44
describe('Stream wrapper', () => {
@@ -22,6 +22,6 @@ describe('Stream wrapper', () => {
2222
expect(failure).toBeInstanceOf(Function);
2323
}
2424
// @ts-ignore
25-
cloudFormationWrapper(mockHandler)(requestEvent);
25+
cloudFormation(mockHandler)(requestEvent);
2626
});
2727
});

src/cloudformation/wrapper.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { successWrapper, failureWrapper } from './responses';
44

55
const metrics = new Metrics('CloudFormation');
66

7-
export function cloudFormationWrapper<T extends Function>(fn: T): T {
7+
export function cloudFormation<T extends Function>(fn: T): T {
88
return <any>function(event: CloudFormationCustomResourceEvent, context: Context) {
99
metrics.common(event);
1010

0 commit comments

Comments
 (0)