Skip to content

Commit 589e4e3

Browse files
authored
Merge pull request dherault#247 from sgleadow/add-test-for-default-content-type
Add test for default content-type and content-size
2 parents 4c1e107 + 83f5dc9 commit 589e4e3

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

test/support/RequestBuilder.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ module.exports = class RequestBuilder {
2121
this.request.headers[key] = value;
2222
}
2323

24+
addBody(body) {
25+
this.request.payload = body;
26+
}
27+
2428
toObject() {
2529
return this.request;
2630
}

test/unit/createLambdaProxyContextTest.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,28 @@ describe('createLambdaProxyContext', () => {
8282
expect(lambdaProxyContext.headers.Authorization).to.eq('Token token="1234567890"');
8383
});
8484
});
85+
86+
context('with a POST /fn1 request with no headers', () => {
87+
const requestBuilder = new RequestBuilder('POST', '/fn1');
88+
requestBuilder.addBody({ key: 'value' });
89+
const request = requestBuilder.toObject();
90+
91+
let lambdaProxyContext;
92+
93+
before(() => {
94+
lambdaProxyContext = createLambdaProxyContext(request, options, stageVariables);
95+
});
96+
97+
it('should calculate the Content-Length header', () => {
98+
expect(lambdaProxyContext.headers['Content-Length']).to.eq(15);
99+
});
100+
101+
it('should inject a default Content-Type header', () => {
102+
expect(lambdaProxyContext.headers['Content-Type']).to.eq('application/json');
103+
});
104+
105+
it('should stringify the payload for the body', () => {
106+
expect(lambdaProxyContext.body).to.eq("{\"key\":\"value\"}");
107+
});
108+
});
85109
});

0 commit comments

Comments
 (0)