# Supertest

### Example

It uses the `bookRoutes` definitions [from here](https://jeromebu.gitbook.io/shared-routes/defining-routes#example).

```typescript
import supertest from "supertest";
import { createSupertestSharedClient } from "shared-routes/supertest";

// tiny helper to make sure the types are matching
const expectToEqual = <T>(actual: T, expected: T) =>
  expect(actual).toEqual(expected);

describe("testing book routes with supertest", () => {
  const supertestRequest = supertest(createApp());
  const request = createSupertestSharedClient(bookRoutes, supertestRequest);

  it("should add a book", async () => {
    const response = await request.addBook({
      headers: {
        authorization: "my-token",
      },
      body: {
        title: "Le compte de Monte Cristo",
        author: "Alexandre Dumas",
      },
    });

    expectToEqual(response.body, { bookId: 123 });
    expect(response.status).toBe(201);
  });

  it("should get all books", async () => {
    const response = await request.getBooks({
      queryParams: { authorContains: "dumas" },
    });

    expect(response.status).toBe(200);
    expectToEqual(response.body, [
      {
        id: "abc",
        title: "Le compte de Monte Cristo",
        author: "Alexandre Dumas",
      },
    ]);
  });

  it("should get a book by id", async () => {
    const response = await request.getBookById({
      urlParams: { bookId: "abc" },
    });

    expect(response.status).toBe(200);
    expectToEqual(response.body, {
      id: "abc",
      title: "Le compte de Monte Cristo",
      author: "Alexandre Dumas",
    });
  });
});
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://jeromebu.gitbook.io/shared-routes/adapters/supertest.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
