meilisearch-js icon indicating copy to clipboard operation
meilisearch-js copied to clipboard

Simplify URL construction and API error tests

Open flevi29 opened this issue 6 months ago • 0 comments

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.

flevi29 avatar May 12 '25 07:05 flevi29