Skip to content

Simplify URL construction and API error tests #1945

@flevi29

Description

@flevi29

Test files usually contain a set of the following tests:

  • URL construction tests
describe.each([
  { host: BAD_HOST, trailing: false },
  { host: `${BAD_HOST}/api`, trailing: false },
  { host: `${BAD_HOST}/trailing/`, trailing: true },
])("Tests on url construction", ({ host, trailing }) => {
  test(`get search route`, async () => {
    // ...
  });

  test(`post search route`, async () => {
    // ...
  });
});

These tests always do the same thing on each method: create the client with an unreachable host, call method, get MeiliSearchRequestError, check that its message contains this unreachable path.

I believe it is enough to test one method to see if MeiliSearchRequestError is properly formed, for the rest it should be implicit that it works the same way, since all of these methods rely on the same http request class.

  • API errors regarding insufficient permission level
describe.each([{ permission: "No" }])(
  "Test on searchable attributes",
  ({ permission }) => {
    test(`${permission} key: try to get searchable attributes and be denied`, async () => {
      // ...
    });

    test(`${permission} key: try to update searchable attributes and be denied`, async () => {
      // ...
    });

    test(`${permission} key: try to reset searchable attributes and be denied`, async () => {
      // ...
    });
  },
);

More or less the same thing happens here as in the previous problem. We rely on the same class. It is enough to check once whether MeiliSearchApiError is well formed. The rest can stay implicit.

Metadata

Metadata

Assignees

No one assigned

    Labels

    integrationsmaintenanceIssue about maintenance (CI, tests, refacto...)

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions