Skip to content

Commit

Permalink
refactor: improve E2E testing documentation and enhance test structure
Browse files Browse the repository at this point in the history
  • Loading branch information
rsaz committed Nov 27, 2024
1 parent a09f981 commit a9db1bb
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions versioned_docs/version-3.0.0/features/test.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -66,34 +66,36 @@ describe("PingUseCase", () => {

## E2E testing with supertest

We have available a method called `getHttpServer` in the `AppExpress` class that returns a proxy to the Express server. This method is useful for testing the application using **[Supertest](https://www.npmjs.com/package/supertest)**.
We have available a method called `getHttpServer()` in the `AppExpress` class that returns a proxy to the Express server. This method is useful for testing the application using **[Supertest](https://www.npmjs.com/package/supertest)**.

```typescript title="POST /organization :: Creating a new organization use case"
Alonside with this method, we have the `close()` method that closes the server and releases the resources.

```typescript title="GET /v1 test"
import { AppFactory, StatusCode } from "@expressots/core";
import { App } from "./app";
import { IWebServerPublic } from "@expressots/shared";

import express from "express";
import request from "supertest";

describe("api test", () => {
import { App } from "../src/app";

describe("App Test", () => {
let server: express.Application;
let appInstance: IWebServerPublic;

beforeAll(async () => {
const appInstance = await AppFactory.create(App);
appInstance = await AppFactory.create(App);
await appInstance.listen(3000);

server = await appInstance.getHttpServer();
});

describe("organization.module", () => {
test("POST /organization", async () => {
const newOrg = {
name: "test org",
};

const response = await request(server).post("/organization").send(newOrg);
afterAll(async () => {
await appInstance.close();
});

expect(response.status).toBe(StatusCode.Created);
expect(response.body).toEqual(newOrg);
});
it("returns a valid app response", async () => {
return request(server).get("/v1").expect(StatusCode.OK).expect("Hello from ExpressoTS!");
});
});
```
Expand Down

0 comments on commit a9db1bb

Please sign in to comment.