-
Notifications
You must be signed in to change notification settings - Fork 0
/
handler-quote-api.spec.ts
26 lines (22 loc) · 1.19 KB
/
handler-quote-api.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import {APIGatewayProxyEvent} from "aws-lambda";
import {QuoteApiHandler, Quote} from "./handler-quote-api";
describe("Quote API", () => {
const quoteApiHandler = new QuoteApiHandler();
it("should be handled on /quote-api", () => {
expect(quoteApiHandler.canHandleThis({path: "/quote-api"} as APIGatewayProxyEvent)).toEqual(true);
});
it("should return an array of data for GET on /quote-api", async () => {
const response = await quoteApiHandler.handle({httpMethod: "GET", path: "/quote-api"} as APIGatewayProxyEvent);
expect(response.statusCode).toEqual(200);
const bodyData: Quote[] = JSON.parse(response.body);
expect(bodyData.length).toBe(4);
expect(bodyData[0].id).toBe(0);
expect(bodyData[0].text).toContain("a mosaic of single sparks");
});
it("should return a 405 response for an unexpected method on /quote-api", async () => {
const response = await quoteApiHandler.handle({httpMethod: "DELETE", path: "/quote-api"} as APIGatewayProxyEvent);
expect(response.statusCode).toEqual(405);
const bodyData: string = response.body;
expect(bodyData).toBe("Unsupported method 'DELETE'.");
});
});