Bringing it Together
Explore how to combine TypeScript and fp-ts constructs to create a hotel reservations backend. Understand setting up RESTful responses, testing components, deploying to AWS with Lambdas and DynamoDB, and leveraging Cloudwatch for monitoring. Gain practical skills to integrate functional programming techniques in real-world TypeScript projects.
We'll cover the following...
Setting up files
Two things are still missing. The obvious one is the index file that glues everything together. We also need to respond in a RESTful way when answering our callers, that is , giving a status code and other details. Add this to our specifics folder:
import {okResponse} from "../../../util/common/responses";
describe('responses test', () => {
it('should return a 200 response for ok response', () => {
const result = okResponse('OK')
expect(result.statusCode).toBe(200);
expect(result.body).toBe('OK');
});
});
That should be easy enough to implement.
Note that we created a new type, which we add to our types:
We also want to be able to report a failure with a 400 message. So, we add a test and implementation.
import {badRequestResponse} from "../../../util/common/responses";
describe('responses test', () => {
it('should return a 400 response for bad request response', () => {
const result = badRequestResponse('Error')
expect(result.statusCode).toBe(400);
expect(result.body).toBe('Error');
});
});
Now we are ready to combine all of the parts. Let us write tests for the index.
As we mentioned earlier, it might become difficult to test our ...