diff --git a/jest-disable-built-in-fetch.js b/jest-disable-built-in-fetch.js deleted file mode 100644 index 462ddabb..00000000 --- a/jest-disable-built-in-fetch.js +++ /dev/null @@ -1,5 +0,0 @@ -module.exports = function () { - // This is required for tests to work with "cross-fetch" on newer node versions, - // otherwise "cross-fetch" won't replace the builtin `fetch` - globalThis.fetch = undefined; -}; diff --git a/jest.config.js b/jest.config.js index d7c6aa41..1c52074f 100644 --- a/jest.config.js +++ b/jest.config.js @@ -16,7 +16,6 @@ const config = { 'jest-watch-typeahead/filename', 'jest-watch-typeahead/testname', ], - globalSetup: './jest-disable-built-in-fetch.js', projects: [ { preset: 'ts-jest', @@ -28,6 +27,8 @@ const config = { 'env/', 'token.test.ts', ], + // make sure built-in Node.js fetch doesn't get replaced for consistency + globals: { fetch: global.fetch, AbortController: global.AbortController }, }, { preset: 'ts-jest', diff --git a/package.json b/package.json index 01920953..1f57eab0 100644 --- a/package.json +++ b/package.json @@ -84,7 +84,6 @@ "@types/jest": "^29.5.11", "@typescript-eslint/eslint-plugin": "^6.19.0", "@typescript-eslint/parser": "^6.19.0", - "abort-controller": "^3.0.0", "brotli-size": "^4.0.0", "eslint": "^8.56.0", "eslint-config-prettier": "^9.1.0", diff --git a/src/errors/http-error-handler.ts b/src/errors/http-error-handler.ts deleted file mode 100644 index 78fb54f3..00000000 --- a/src/errors/http-error-handler.ts +++ /dev/null @@ -1,44 +0,0 @@ -import { MeiliSearchCommunicationError } from './meilisearch-communication-error'; -import { MeiliSearchApiError } from './meilisearch-api-error'; -import { FetchError } from '../types'; - -async function httpResponseErrorHandler(response: Response): Promise { - if (!response.ok) { - let responseBody; - try { - // If it is not possible to parse the return body it means there is none - // In which case it is a communication error with the Meilisearch instance - responseBody = await response.json(); - } catch (e: any) { - // Not sure on how to test this part of the code. - throw new MeiliSearchCommunicationError( - response.statusText, - response, - response.url, - ); - } - // If the body is parsable, then it means Meilisearch returned a body with - // information on the error. - throw new MeiliSearchApiError(responseBody, response.status); - } - - return response; -} - -function httpErrorHandler( - response: FetchError, - stack?: string, - url?: string, -): Promise { - if (response.name !== 'MeiliSearchApiError') { - throw new MeiliSearchCommunicationError( - response.message, - response, - url, - stack, - ); - } - throw response; -} - -export { httpResponseErrorHandler, httpErrorHandler }; diff --git a/src/errors/index.ts b/src/errors/index.ts index 02fe0811..27ff6676 100644 --- a/src/errors/index.ts +++ b/src/errors/index.ts @@ -1,6 +1,5 @@ -export * from './http-error-handler'; export * from './meilisearch-api-error'; -export * from './meilisearch-communication-error'; +export * from './meilisearch-request-error'; export * from './meilisearch-error'; export * from './meilisearch-timeout-error'; export * from './version-hint-message'; diff --git a/src/errors/meilisearch-api-error.ts b/src/errors/meilisearch-api-error.ts index b08866d5..68121074 100644 --- a/src/errors/meilisearch-api-error.ts +++ b/src/errors/meilisearch-api-error.ts @@ -1,30 +1,20 @@ -import { MeiliSearchErrorInfo } from '../types'; +import { MeiliSearchErrorResponse } from '../types'; import { MeiliSearchError } from './meilisearch-error'; -const MeiliSearchApiError = class extends MeiliSearchError { - httpStatus: number; - code: string; - link: string; - type: string; - stack?: string; +export class MeiliSearchApiError extends MeiliSearchError { + override name = 'MeiliSearchApiError'; + override cause?: MeiliSearchErrorResponse; + readonly response: Response; - constructor(error: MeiliSearchErrorInfo, status: number) { - super(error.message); + constructor(response: Response, responseBody?: MeiliSearchErrorResponse) { + super( + responseBody?.message ?? `${response.status}: ${response.statusText}`, + ); - // Make errors comparison possible. ex: error instanceof MeiliSearchApiError. - Object.setPrototypeOf(this, MeiliSearchApiError.prototype); + this.response = response; - this.name = 'MeiliSearchApiError'; - - this.code = error.code; - this.type = error.type; - this.link = error.link; - this.message = error.message; - this.httpStatus = status; - - if (Error.captureStackTrace) { - Error.captureStackTrace(this, MeiliSearchApiError); + if (responseBody !== undefined) { + this.cause = responseBody; } } -}; -export { MeiliSearchApiError }; +} diff --git a/src/errors/meilisearch-communication-error.ts b/src/errors/meilisearch-communication-error.ts deleted file mode 100644 index 92fe8e86..00000000 --- a/src/errors/meilisearch-communication-error.ts +++ /dev/null @@ -1,47 +0,0 @@ -import { FetchError } from '../types'; -import { MeiliSearchError } from './meilisearch-error'; - -class MeiliSearchCommunicationError extends MeiliSearchError { - statusCode?: number; - errno?: string; - code?: string; - stack?: string; - - constructor( - message: string, - body: Response | FetchError, - url?: string, - stack?: string, - ) { - super(message); - - // Make errors comparison possible. ex: error instanceof MeiliSearchCommunicationError. - Object.setPrototypeOf(this, MeiliSearchCommunicationError.prototype); - - this.name = 'MeiliSearchCommunicationError'; - - if (body instanceof Response) { - this.message = body.statusText; - this.statusCode = body.status; - } - if (body instanceof Error) { - this.errno = body.errno; - this.code = body.code; - } - if (stack) { - this.stack = stack; - this.stack = this.stack?.replace(/(TypeError|FetchError)/, this.name); - this.stack = this.stack?.replace( - 'Failed to fetch', - `request to ${url} failed, reason: connect ECONNREFUSED`, - ); - this.stack = this.stack?.replace('Not Found', `Not Found: ${url}`); - } else { - if (Error.captureStackTrace) { - Error.captureStackTrace(this, MeiliSearchCommunicationError); - } - } - } -} - -export { MeiliSearchCommunicationError }; diff --git a/src/errors/meilisearch-error.ts b/src/errors/meilisearch-error.ts index 39dff83a..09c33e7c 100644 --- a/src/errors/meilisearch-error.ts +++ b/src/errors/meilisearch-error.ts @@ -1,16 +1,7 @@ -class MeiliSearchError extends Error { - constructor(message: string) { - super(message); +export class MeiliSearchError extends Error { + override name = 'MeiliSearchError'; - // Make errors comparison possible. ex: error instanceof MeiliSearchError. - Object.setPrototypeOf(this, MeiliSearchError.prototype); - - this.name = 'MeiliSearchError'; - - if (Error.captureStackTrace) { - Error.captureStackTrace(this, MeiliSearchError); - } + constructor(...params: ConstructorParameters) { + super(...params); } } - -export { MeiliSearchError }; diff --git a/src/errors/meilisearch-request-error.ts b/src/errors/meilisearch-request-error.ts new file mode 100644 index 00000000..aef8e429 --- /dev/null +++ b/src/errors/meilisearch-request-error.ts @@ -0,0 +1,9 @@ +import { MeiliSearchError } from './meilisearch-error'; + +export class MeiliSearchRequestError extends MeiliSearchError { + override name = 'MeiliSearchRequestError'; + + constructor(url: string, cause: unknown) { + super(`Request to ${url} has failed`, { cause }); + } +} diff --git a/src/errors/meilisearch-timeout-error.ts b/src/errors/meilisearch-timeout-error.ts index 91b5f2d8..e6730e8a 100644 --- a/src/errors/meilisearch-timeout-error.ts +++ b/src/errors/meilisearch-timeout-error.ts @@ -1,18 +1,9 @@ import { MeiliSearchError } from './meilisearch-error'; -class MeiliSearchTimeOutError extends MeiliSearchError { +export class MeiliSearchTimeOutError extends MeiliSearchError { + override name = 'MeiliSearchTimeOutError'; + constructor(message: string) { super(message); - - // Make errors comparison possible. ex: error instanceof MeiliSearchTimeOutError. - Object.setPrototypeOf(this, MeiliSearchTimeOutError.prototype); - - this.name = 'MeiliSearchTimeOutError'; - - if (Error.captureStackTrace) { - Error.captureStackTrace(this, MeiliSearchTimeOutError); - } } } - -export { MeiliSearchTimeOutError }; diff --git a/src/http-requests.ts b/src/http-requests.ts index 90399403..96e2b606 100644 --- a/src/http-requests.ts +++ b/src/http-requests.ts @@ -3,8 +3,8 @@ import { PACKAGE_VERSION } from './package-version'; import { MeiliSearchError, - httpResponseErrorHandler, - httpErrorHandler, + MeiliSearchApiError, + MeiliSearchRequestError, } from './errors'; import { addTrailingSlash, addProtocolIfNotPresent } from './utils'; @@ -143,35 +143,36 @@ class HttpRequests { } const headers = { ...this.headers, ...config.headers }; + const responsePromise = this.fetchWithTimeout( + constructURL.toString(), + { + ...config, + ...this.requestConfig, + method, + body, + headers, + }, + this.requestTimeout, + ); - try { - const result = this.fetchWithTimeout( - constructURL.toString(), - { - ...config, - ...this.requestConfig, - method, - body, - headers, - }, - this.requestTimeout, - ); - - // When using a custom HTTP client, the response is returned to allow the user to parse/handle it as they see fit - if (this.httpClient) { - return await result; - } + const response = await responsePromise.catch((error: unknown) => { + throw new MeiliSearchRequestError(constructURL.toString(), error); + }); + + // When using a custom HTTP client, the response is returned to allow the user to parse/handle it as they see fit + if (this.httpClient !== undefined) { + return response; + } - const response = await result.then((res: any) => - httpResponseErrorHandler(res), - ); - const parsedBody = await response.json().catch(() => undefined); + const responseBody = await response.text(); + const parsedResponse = + responseBody === '' ? undefined : JSON.parse(responseBody); - return parsedBody; - } catch (e: any) { - const stack = e.stack; - httpErrorHandler(e, stack, constructURL.toString()); + if (!response.ok) { + throw new MeiliSearchApiError(response, parsedResponse); } + + return parsedResponse; } async fetchWithTimeout( diff --git a/src/indexes.ts b/src/indexes.ts index 3fb05111..a2451ae8 100644 --- a/src/indexes.ts +++ b/src/indexes.ts @@ -9,7 +9,7 @@ import { MeiliSearchError, - MeiliSearchCommunicationError, + MeiliSearchRequestError, versionErrorHintMessage, MeiliSearchApiError, } from './errors'; @@ -360,7 +360,7 @@ class Index = Record> { Promise> >(url, parameters); } catch (e) { - if (e instanceof MeiliSearchCommunicationError) { + if (e instanceof MeiliSearchRequestError) { e.message = versionErrorHintMessage(e.message, 'getDocuments'); } else if (e instanceof MeiliSearchApiError) { e.message = versionErrorHintMessage(e.message, 'getDocuments'); @@ -585,10 +585,7 @@ class Index = Record> { return new EnqueuedTask(task); } catch (e) { - if ( - e instanceof MeiliSearchCommunicationError && - isDocumentsDeletionQuery - ) { + if (e instanceof MeiliSearchRequestError && isDocumentsDeletionQuery) { e.message = versionErrorHintMessage(e.message, 'deleteDocuments'); } else if (e instanceof MeiliSearchApiError) { e.message = versionErrorHintMessage(e.message, 'deleteDocuments'); diff --git a/src/types/types.ts b/src/types/types.ts index 5b012f3b..a6d916b1 100644 --- a/src/types/types.ts +++ b/src/types/types.ts @@ -546,7 +546,7 @@ export type TaskObject = Omit & { // Query parameters used to filter the tasks originalFilter?: string; }; - error: MeiliSearchErrorInfo | null; + error: MeiliSearchErrorResponse | null; duration: string; startedAt: string; finishedAt: string; @@ -655,13 +655,16 @@ export interface FetchError extends Error { code: string; } -export type MeiliSearchErrorInfo = { - code: string; - link: string; +export type MeiliSearchErrorResponse = { message: string; + // @TODO: Could be typed, but will it be kept updated? https://www.meilisearch.com/docs/reference/errors/error_codes + code: string; + // @TODO: Could be typed https://www.meilisearch.com/docs/reference/errors/overview#errors type: string; + link: string; }; +// @TODO: This doesn't seem to be up to date, and its usefullness comes into question. export const ErrorStatusCode = { /** @see https://www.meilisearch.com/docs/reference/errors/error_codes#index_creation_failed */ INDEX_CREATION_FAILED: 'index_creation_failed', diff --git a/tests/client.test.ts b/tests/client.test.ts index 657fa19d..ab34088f 100644 --- a/tests/client.test.ts +++ b/tests/client.test.ts @@ -56,11 +56,11 @@ describe.each([ apiKey: key, requestConfig: { headers: { - Expect: '200-OK', + 'Hello-There!': 'General Kenobi', }, }, }); - expect(client.httpRequest.headers['Expect']).toBe('200-OK'); + expect(client.httpRequest.headers['Hello-There!']).toBe('General Kenobi'); const health = await client.isHealthy(); expect(health).toBe(true); }); @@ -71,10 +71,10 @@ describe.each([ ...config, apiKey: key, requestConfig: { - headers: [['Expect', '200-OK']], + headers: [['Hello-There!', 'General Kenobi']], }, }); - expect(client.httpRequest.headers['Expect']).toBe('200-OK'); + expect(client.httpRequest.headers['Hello-There!']).toBe('General Kenobi'); const health = await client.isHealthy(); expect(health).toBe(true); }); @@ -82,7 +82,7 @@ describe.each([ test(`${permission} key: Create client with custom headers (Headers)`, async () => { const key = await getKey(permission); const headers = new Headers(); - headers.append('Expect', '200-OK'); + headers.append('Hello-There!', 'General Kenobi'); const client = new MeiliSearch({ ...config, apiKey: key, @@ -90,7 +90,7 @@ describe.each([ headers, }, }); - expect(client.httpRequest.headers.expect).toBe('200-OK'); + expect(client.httpRequest.headers['hello-there!']).toBe('General Kenobi'); const health = await client.isHealthy(); expect(health).toBe(true); }); @@ -107,7 +107,7 @@ describe.each([ expect(health).toBe(false); // Left here to trigger failed test if error is not thrown } catch (e: any) { expect(e.message).toMatch(`${BAD_HOST}/api/health`); - expect(e.name).toBe('MeiliSearchCommunicationError'); + expect(e.name).toBe('MeiliSearchRequestError'); } }); @@ -123,7 +123,7 @@ describe.each([ expect(health).toBe(false); // Left here to trigger failed test if error is not thrown } catch (e: any) { expect(e.message).toMatch(`${BAD_HOST}/api/health`); - expect(e.name).toBe('MeiliSearchCommunicationError'); + expect(e.name).toBe('MeiliSearchRequestError'); } }); @@ -139,7 +139,7 @@ describe.each([ expect(health).toBe(false); // Left here to trigger failed test if error is not thrown } catch (e: any) { expect(e.message).toMatch(`${BAD_HOST}//health`); - expect(e.name).toBe('MeiliSearchCommunicationError'); + expect(e.name).toBe('MeiliSearchRequestError'); } }); @@ -155,7 +155,7 @@ describe.each([ expect(health).toBe(false); // Left here to trigger failed test if error is not thrown } catch (e: any) { expect(e.message).toMatch(`${BAD_HOST}/health`); - expect(e.name).toBe('MeiliSearchCommunicationError'); + expect(e.name).toBe('MeiliSearchRequestError'); } }); @@ -164,7 +164,7 @@ describe.each([ try { await client.health(); } catch (e: any) { - expect(e.name).toEqual('MeiliSearchCommunicationError'); + expect(e.name).toEqual('MeiliSearchRequestError'); } }); @@ -203,12 +203,12 @@ describe.each([{ permission: 'Master' }, { permission: 'Admin' }])( apiKey: key, requestConfig: { headers: { - Expect: '200-OK', + 'Hello-There!': 'General Kenobi', }, }, }); expect(client.config.requestConfig?.headers).toStrictEqual({ - Expect: '200-OK', + 'Hello-There!': 'General Kenobi', }); const health = await client.isHealthy(); @@ -365,7 +365,7 @@ describe.each([{ permission: 'Master' }, { permission: 'Admin' }])( const client = await getClient(permission); await expect(client.getIndex('does_not_exist')).rejects.toHaveProperty( - 'code', + 'cause.code', ErrorStatusCode.INDEX_NOT_FOUND, ); }); @@ -439,7 +439,7 @@ describe.each([{ permission: 'Master' }, { permission: 'Admin' }])( const client = await getClient(permission); const index = client.index(indexPk.uid); await expect(index.getRawInfo()).rejects.toHaveProperty( - 'code', + 'cause.code', ErrorStatusCode.INDEX_NOT_FOUND, ); }); @@ -505,7 +505,7 @@ describe.each([{ permission: 'Master' }, { permission: 'Admin' }])( ]; await expect(client.swapIndexes(swaps)).rejects.toHaveProperty( - 'code', + 'cause.code', ErrorStatusCode.INVALID_SWAP_DUPLICATE_INDEX_FOUND, ); }); @@ -563,7 +563,7 @@ describe.each([{ permission: 'Search' }])( test(`${permission} key: try to get all indexes and be denied`, async () => { const client = await getClient(permission); await expect(client.getIndexes()).rejects.toHaveProperty( - 'code', + 'cause.code', ErrorStatusCode.INVALID_API_KEY, ); }); @@ -574,13 +574,13 @@ describe.each([{ permission: 'Search' }])( client.createIndex(indexPk.uid, { primaryKey: indexPk.primaryKey, }), - ).rejects.toHaveProperty('code', ErrorStatusCode.INVALID_API_KEY); + ).rejects.toHaveProperty('cause.code', ErrorStatusCode.INVALID_API_KEY); }); test(`${permission} key: try to create Index with NO primary key and be denied`, async () => { const client = await getClient(permission); await expect(client.createIndex(indexNoPk.uid)).rejects.toHaveProperty( - 'code', + 'cause.code', ErrorStatusCode.INVALID_API_KEY, ); }); @@ -588,7 +588,7 @@ describe.each([{ permission: 'Search' }])( test(`${permission} key: try to delete index and be denied`, async () => { const client = await getClient(permission); await expect(client.deleteIndex(indexPk.uid)).rejects.toHaveProperty( - 'code', + 'cause.code', ErrorStatusCode.INVALID_API_KEY, ); }); @@ -599,7 +599,7 @@ describe.each([{ permission: 'Search' }])( client.updateIndex(indexPk.uid, { primaryKey: indexPk.primaryKey, }), - ).rejects.toHaveProperty('code', ErrorStatusCode.INVALID_API_KEY); + ).rejects.toHaveProperty('cause.code', ErrorStatusCode.INVALID_API_KEY); }); }); @@ -616,7 +616,7 @@ describe.each([{ permission: 'Search' }])( test(`${permission} key: try to get version and be denied`, async () => { const client = await getClient(permission); await expect(client.getVersion()).rejects.toHaveProperty( - 'code', + 'cause.code', ErrorStatusCode.INVALID_API_KEY, ); }); @@ -624,7 +624,7 @@ describe.each([{ permission: 'Search' }])( test(`${permission} key: try to get /stats information and be denied`, async () => { const client = await getClient(permission); await expect(client.getStats()).rejects.toHaveProperty( - 'code', + 'cause.code', ErrorStatusCode.INVALID_API_KEY, ); }); @@ -643,7 +643,7 @@ describe.each([{ permission: 'No' }])( test(`${permission} key: try to get all indexes and be denied`, async () => { const client = await getClient(permission); await expect(client.getIndexes()).rejects.toHaveProperty( - 'code', + 'cause.code', ErrorStatusCode.MISSING_AUTHORIZATION_HEADER, ); }); @@ -655,7 +655,7 @@ describe.each([{ permission: 'No' }])( primaryKey: indexPk.primaryKey, }), ).rejects.toHaveProperty( - 'code', + 'cause.code', ErrorStatusCode.MISSING_AUTHORIZATION_HEADER, ); }); @@ -663,7 +663,7 @@ describe.each([{ permission: 'No' }])( test(`${permission} key: try to create Index with NO primary key and be denied`, async () => { const client = await getClient(permission); await expect(client.createIndex(indexNoPk.uid)).rejects.toHaveProperty( - 'code', + 'cause.code', ErrorStatusCode.MISSING_AUTHORIZATION_HEADER, ); }); @@ -671,7 +671,7 @@ describe.each([{ permission: 'No' }])( test(`${permission} key: try to delete index and be denied`, async () => { const client = await getClient(permission); await expect(client.deleteIndex(indexPk.uid)).rejects.toHaveProperty( - 'code', + 'cause.code', ErrorStatusCode.MISSING_AUTHORIZATION_HEADER, ); }); @@ -683,7 +683,7 @@ describe.each([{ permission: 'No' }])( primaryKey: indexPk.primaryKey, }), ).rejects.toHaveProperty( - 'code', + 'cause.code', ErrorStatusCode.MISSING_AUTHORIZATION_HEADER, ); }); @@ -702,7 +702,7 @@ describe.each([{ permission: 'No' }])( test(`${permission} key: try to get version and be denied`, async () => { const client = await getClient(permission); await expect(client.getVersion()).rejects.toHaveProperty( - 'code', + 'cause.code', ErrorStatusCode.MISSING_AUTHORIZATION_HEADER, ); }); @@ -710,7 +710,7 @@ describe.each([{ permission: 'No' }])( test(`${permission} key: try to get /stats information and be denied`, async () => { const client = await getClient(permission); await expect(client.getStats()).rejects.toHaveProperty( - 'code', + 'cause.code', ErrorStatusCode.MISSING_AUTHORIZATION_HEADER, ); }); @@ -729,10 +729,7 @@ describe.each([ const strippedHost = trailing ? host.slice(0, -1) : host; await expect(client.getIndex(indexPk.uid)).rejects.toHaveProperty( 'message', - `request to ${strippedHost}/${route} failed, reason: connect ECONNREFUSED ${BAD_HOST.replace( - 'http://', - '', - )}`, + `Request to ${strippedHost}/${route} has failed`, ); }); @@ -742,10 +739,7 @@ describe.each([ const strippedHost = trailing ? host.slice(0, -1) : host; await expect(client.createIndex(indexPk.uid)).rejects.toHaveProperty( 'message', - `request to ${strippedHost}/${route} failed, reason: connect ECONNREFUSED ${BAD_HOST.replace( - 'http://', - '', - )}`, + `Request to ${strippedHost}/${route} has failed`, ); }); @@ -755,10 +749,7 @@ describe.each([ const strippedHost = trailing ? host.slice(0, -1) : host; await expect(client.updateIndex(indexPk.uid)).rejects.toHaveProperty( 'message', - `request to ${strippedHost}/${route} failed, reason: connect ECONNREFUSED ${BAD_HOST.replace( - 'http://', - '', - )}`, + `Request to ${strippedHost}/${route} has failed`, ); }); @@ -768,10 +759,7 @@ describe.each([ const strippedHost = trailing ? host.slice(0, -1) : host; await expect(client.deleteIndex(indexPk.uid)).rejects.toHaveProperty( 'message', - `request to ${strippedHost}/${route} failed, reason: connect ECONNREFUSED ${BAD_HOST.replace( - 'http://', - '', - )}`, + `Request to ${strippedHost}/${route} has failed`, ); }); @@ -781,10 +769,7 @@ describe.each([ const strippedHost = trailing ? host.slice(0, -1) : host; await expect(client.getIndexes()).rejects.toHaveProperty( 'message', - `request to ${strippedHost}/${route} failed, reason: connect ECONNREFUSED ${BAD_HOST.replace( - 'http://', - '', - )}`, + `Request to ${strippedHost}/${route} has failed`, ); }); @@ -794,10 +779,7 @@ describe.each([ const strippedHost = trailing ? host.slice(0, -1) : host; await expect(client.getKeys()).rejects.toHaveProperty( 'message', - `request to ${strippedHost}/${route} failed, reason: connect ECONNREFUSED ${BAD_HOST.replace( - 'http://', - '', - )}`, + `Request to ${strippedHost}/${route} has failed`, ); }); @@ -807,10 +789,7 @@ describe.each([ const strippedHost = trailing ? host.slice(0, -1) : host; await expect(client.health()).rejects.toHaveProperty( 'message', - `request to ${strippedHost}/${route} failed, reason: connect ECONNREFUSED ${BAD_HOST.replace( - 'http://', - '', - )}`, + `Request to ${strippedHost}/${route} has failed`, ); }); @@ -820,10 +799,7 @@ describe.each([ const strippedHost = trailing ? host.slice(0, -1) : host; await expect(client.getStats()).rejects.toHaveProperty( 'message', - `request to ${strippedHost}/${route} failed, reason: connect ECONNREFUSED ${BAD_HOST.replace( - 'http://', - '', - )}`, + `Request to ${strippedHost}/${route} has failed`, ); }); @@ -833,10 +809,7 @@ describe.each([ const strippedHost = trailing ? host.slice(0, -1) : host; await expect(client.getVersion()).rejects.toHaveProperty( 'message', - `request to ${strippedHost}/${route} failed, reason: connect ECONNREFUSED ${BAD_HOST.replace( - 'http://', - '', - )}`, + `Request to ${strippedHost}/${route} has failed`, ); }); }); diff --git a/tests/dictionary.test.ts b/tests/dictionary.test.ts index 12396665..4da65546 100644 --- a/tests/dictionary.test.ts +++ b/tests/dictionary.test.ts @@ -87,10 +87,7 @@ describe.each([ client.index(index.uid).getDictionary(), ).rejects.toHaveProperty( 'message', - `request to ${strippedHost}/${route} failed, reason: connect ECONNREFUSED ${BAD_HOST.replace( - 'http://', - '', - )}`, + `Request to ${strippedHost}/${route} has failed`, ); }); @@ -102,10 +99,7 @@ describe.each([ client.index(index.uid).updateDictionary([]), ).rejects.toHaveProperty( 'message', - `request to ${strippedHost}/${route} failed, reason: connect ECONNREFUSED ${BAD_HOST.replace( - 'http://', - '', - )}`, + `Request to ${strippedHost}/${route} has failed`, ); }); @@ -117,10 +111,7 @@ describe.each([ client.index(index.uid).resetDictionary(), ).rejects.toHaveProperty( 'message', - `request to ${strippedHost}/${route} failed, reason: connect ECONNREFUSED ${BAD_HOST.replace( - 'http://', - '', - )}`, + `Request to ${strippedHost}/${route} has failed`, ); }); }); diff --git a/tests/displayed_attributes.test.ts b/tests/displayed_attributes.test.ts index c5cba146..938df585 100644 --- a/tests/displayed_attributes.test.ts +++ b/tests/displayed_attributes.test.ts @@ -88,21 +88,21 @@ describe.each([{ permission: 'Search' }])( const client = await getClient(permission); await expect( client.index(index.uid).getDisplayedAttributes(), - ).rejects.toHaveProperty('code', ErrorStatusCode.INVALID_API_KEY); + ).rejects.toHaveProperty('cause.code', ErrorStatusCode.INVALID_API_KEY); }); test(`${permission} key: try to update displayed attributes and be denied`, async () => { const client = await getClient(permission); await expect( client.index(index.uid).updateDisplayedAttributes([]), - ).rejects.toHaveProperty('code', ErrorStatusCode.INVALID_API_KEY); + ).rejects.toHaveProperty('cause.code', ErrorStatusCode.INVALID_API_KEY); }); test(`${permission} key: try to reset displayed attributes and be denied`, async () => { const client = await getClient(permission); await expect( client.index(index.uid).resetDisplayedAttributes(), - ).rejects.toHaveProperty('code', ErrorStatusCode.INVALID_API_KEY); + ).rejects.toHaveProperty('cause.code', ErrorStatusCode.INVALID_API_KEY); }); }, ); @@ -122,7 +122,7 @@ describe.each([{ permission: 'No' }])( await expect( client.index(index.uid).getDisplayedAttributes(), ).rejects.toHaveProperty( - 'code', + 'cause.code', ErrorStatusCode.MISSING_AUTHORIZATION_HEADER, ); }); @@ -132,7 +132,7 @@ describe.each([{ permission: 'No' }])( await expect( client.index(index.uid).updateDisplayedAttributes([]), ).rejects.toHaveProperty( - 'code', + 'cause.code', ErrorStatusCode.MISSING_AUTHORIZATION_HEADER, ); }); @@ -142,7 +142,7 @@ describe.each([{ permission: 'No' }])( await expect( client.index(index.uid).resetDisplayedAttributes(), ).rejects.toHaveProperty( - 'code', + 'cause.code', ErrorStatusCode.MISSING_AUTHORIZATION_HEADER, ); }); @@ -162,10 +162,7 @@ describe.each([ client.index(index.uid).getDisplayedAttributes(), ).rejects.toHaveProperty( 'message', - `request to ${strippedHost}/${route} failed, reason: connect ECONNREFUSED ${BAD_HOST.replace( - 'http://', - '', - )}`, + `Request to ${strippedHost}/${route} has failed`, ); }); @@ -177,10 +174,7 @@ describe.each([ client.index(index.uid).updateDisplayedAttributes([]), ).rejects.toHaveProperty( 'message', - `request to ${strippedHost}/${route} failed, reason: connect ECONNREFUSED ${BAD_HOST.replace( - 'http://', - '', - )}`, + `Request to ${strippedHost}/${route} has failed`, ); }); @@ -192,10 +186,7 @@ describe.each([ client.index(index.uid).resetDisplayedAttributes(), ).rejects.toHaveProperty( 'message', - `request to ${strippedHost}/${route} failed, reason: connect ECONNREFUSED ${BAD_HOST.replace( - 'http://', - '', - )}`, + `Request to ${strippedHost}/${route} has failed`, ); }); }); diff --git a/tests/distinct_attribute.test.ts b/tests/distinct_attribute.test.ts index b579b5f4..0797ab18 100644 --- a/tests/distinct_attribute.test.ts +++ b/tests/distinct_attribute.test.ts @@ -81,21 +81,21 @@ describe.each([{ permission: 'Search' }])( const client = await getClient(permission); await expect( client.index(index.uid).getDistinctAttribute(), - ).rejects.toHaveProperty('code', ErrorStatusCode.INVALID_API_KEY); + ).rejects.toHaveProperty('cause.code', ErrorStatusCode.INVALID_API_KEY); }); test(`${permission} key: try to update distinct attribute and be denied`, async () => { const client = await getClient(permission); await expect( client.index(index.uid).updateDistinctAttribute('title'), - ).rejects.toHaveProperty('code', ErrorStatusCode.INVALID_API_KEY); + ).rejects.toHaveProperty('cause.code', ErrorStatusCode.INVALID_API_KEY); }); test(`${permission} key: try to reset distinct attribute and be denied`, async () => { const client = await getClient(permission); await expect( client.index(index.uid).resetDistinctAttribute(), - ).rejects.toHaveProperty('code', ErrorStatusCode.INVALID_API_KEY); + ).rejects.toHaveProperty('cause.code', ErrorStatusCode.INVALID_API_KEY); }); }, ); @@ -112,7 +112,7 @@ describe.each([{ permission: 'No' }])( await expect( client.index(index.uid).getDistinctAttribute(), ).rejects.toHaveProperty( - 'code', + 'cause.code', ErrorStatusCode.MISSING_AUTHORIZATION_HEADER, ); }); @@ -122,7 +122,7 @@ describe.each([{ permission: 'No' }])( await expect( client.index(index.uid).updateDistinctAttribute('title'), ).rejects.toHaveProperty( - 'code', + 'cause.code', ErrorStatusCode.MISSING_AUTHORIZATION_HEADER, ); }); @@ -132,7 +132,7 @@ describe.each([{ permission: 'No' }])( await expect( client.index(index.uid).resetDistinctAttribute(), ).rejects.toHaveProperty( - 'code', + 'cause.code', ErrorStatusCode.MISSING_AUTHORIZATION_HEADER, ); }); @@ -152,10 +152,7 @@ describe.each([ client.index(index.uid).getDistinctAttribute(), ).rejects.toHaveProperty( 'message', - `request to ${strippedHost}/${route} failed, reason: connect ECONNREFUSED ${BAD_HOST.replace( - 'http://', - '', - )}`, + `Request to ${strippedHost}/${route} has failed`, ); }); @@ -167,10 +164,7 @@ describe.each([ client.index(index.uid).updateDistinctAttribute('a'), ).rejects.toHaveProperty( 'message', - `request to ${strippedHost}/${route} failed, reason: connect ECONNREFUSED ${BAD_HOST.replace( - 'http://', - '', - )}`, + `Request to ${strippedHost}/${route} has failed`, ); }); @@ -182,10 +176,7 @@ describe.each([ client.index(index.uid).resetDistinctAttribute(), ).rejects.toHaveProperty( 'message', - `request to ${strippedHost}/${route} failed, reason: connect ECONNREFUSED ${BAD_HOST.replace( - 'http://', - '', - )}`, + `Request to ${strippedHost}/${route} has failed`, ); }); }); diff --git a/tests/documents.test.ts b/tests/documents.test.ts index ef3a5493..5340147b 100644 --- a/tests/documents.test.ts +++ b/tests/documents.test.ts @@ -157,7 +157,7 @@ describe('Documents tests', () => { expect(documents.results.length).toEqual(2); }); - test(`${permission} key: Get documents should trigger error with a MeilisearchCommunicationError`, async () => { + test(`${permission} key: Get documents should trigger error with a MeilisearchRequestError`, async () => { const apiKey = await getKey(permission); const client = new MeiliSearch({ host: `${HOST}/indexes`, apiKey }); @@ -169,7 +169,7 @@ describe('Documents tests', () => { ); } catch (e: any) { expect(e.message).toEqual( - "Not Found\nHint: It might not be working because maybe you're not up to date with the Meilisearch version that getDocuments call requires.", + "404: Not Found\nHint: It might not be working because maybe you're not up to date with the Meilisearch version that getDocuments call requires.", ); } }); @@ -579,7 +579,7 @@ Hint: It might not be working because maybe you're not up to date with the Meili } }); - test(`${permission} key: Delete some documents should trigger error with a hint on a MeilisearchCommunicationError`, async () => { + test(`${permission} key: Delete some documents should trigger error with a hint on a MeilisearchRequestError`, async () => { const apiKey = await getKey(permission); const client = new MeiliSearch({ host: `${HOST}/indexes`, apiKey }); @@ -591,7 +591,7 @@ Hint: It might not be working because maybe you're not up to date with the Meili ); } catch (e: any) { expect(e.message).toEqual( - "Not Found\nHint: It might not be working because maybe you're not up to date with the Meilisearch version that deleteDocuments call requires.", + "404: Not Found\nHint: It might not be working because maybe you're not up to date with the Meilisearch version that deleteDocuments call requires.", ); } }); @@ -620,14 +620,20 @@ Hint: It might not be working because maybe you're not up to date with the Meili const client = await getClient(permission); await expect( client.index(indexNoPk.uid).getDocument(1), - ).rejects.toHaveProperty('code', ErrorStatusCode.DOCUMENT_NOT_FOUND); + ).rejects.toHaveProperty( + 'cause.code', + ErrorStatusCode.DOCUMENT_NOT_FOUND, + ); }); test(`${permission} key: Try to get deleted document from index that has a primary key`, async () => { const client = await getClient(permission); await expect( client.index(indexPk.uid).getDocument(1), - ).rejects.toHaveProperty('code', ErrorStatusCode.DOCUMENT_NOT_FOUND); + ).rejects.toHaveProperty( + 'cause.code', + ErrorStatusCode.DOCUMENT_NOT_FOUND, + ); }); test(`${permission} key: Add documents from index with no primary key by giving a primary key as parameter`, async () => { @@ -702,42 +708,42 @@ Hint: It might not be working because maybe you're not up to date with the Meili const client = await getClient(permission); await expect( client.index(indexPk.uid).addDocuments([]), - ).rejects.toHaveProperty('code', ErrorStatusCode.INVALID_API_KEY); + ).rejects.toHaveProperty('cause.code', ErrorStatusCode.INVALID_API_KEY); }); test(`${permission} key: Try to update documents and be denied`, async () => { const client = await getClient(permission); await expect( client.index(indexPk.uid).updateDocuments([]), - ).rejects.toHaveProperty('code', ErrorStatusCode.INVALID_API_KEY); + ).rejects.toHaveProperty('cause.code', ErrorStatusCode.INVALID_API_KEY); }); test(`${permission} key: Try to get documents and be denied`, async () => { const client = await getClient(permission); await expect( client.index(indexPk.uid).getDocuments(), - ).rejects.toHaveProperty('code', ErrorStatusCode.INVALID_API_KEY); + ).rejects.toHaveProperty('cause.code', ErrorStatusCode.INVALID_API_KEY); }); test(`${permission} key: Try to delete one document and be denied`, async () => { const client = await getClient(permission); await expect( client.index(indexPk.uid).deleteDocument(1), - ).rejects.toHaveProperty('code', ErrorStatusCode.INVALID_API_KEY); + ).rejects.toHaveProperty('cause.code', ErrorStatusCode.INVALID_API_KEY); }); test(`${permission} key: Try to delete some documents and be denied`, async () => { const client = await getClient(permission); await expect( client.index(indexPk.uid).deleteDocuments([1, 2]), - ).rejects.toHaveProperty('code', ErrorStatusCode.INVALID_API_KEY); + ).rejects.toHaveProperty('cause.code', ErrorStatusCode.INVALID_API_KEY); }); test(`${permission} key: Try to delete all documents and be denied`, async () => { const client = await getClient(permission); await expect( client.index(indexPk.uid).deleteAllDocuments(), - ).rejects.toHaveProperty('code', ErrorStatusCode.INVALID_API_KEY); + ).rejects.toHaveProperty('cause.code', ErrorStatusCode.INVALID_API_KEY); }); }, ); @@ -754,7 +760,7 @@ Hint: It might not be working because maybe you're not up to date with the Meili await expect( client.index(indexPk.uid).addDocuments([]), ).rejects.toHaveProperty( - 'code', + 'cause.code', ErrorStatusCode.MISSING_AUTHORIZATION_HEADER, ); }); @@ -764,7 +770,7 @@ Hint: It might not be working because maybe you're not up to date with the Meili await expect( client.index(indexPk.uid).updateDocuments([]), ).rejects.toHaveProperty( - 'code', + 'cause.code', ErrorStatusCode.MISSING_AUTHORIZATION_HEADER, ); }); @@ -774,7 +780,7 @@ Hint: It might not be working because maybe you're not up to date with the Meili await expect( client.index(indexPk.uid).getDocuments(), ).rejects.toHaveProperty( - 'code', + 'cause.code', ErrorStatusCode.MISSING_AUTHORIZATION_HEADER, ); }); @@ -784,7 +790,7 @@ Hint: It might not be working because maybe you're not up to date with the Meili await expect( client.index(indexPk.uid).deleteDocument(1), ).rejects.toHaveProperty( - 'code', + 'cause.code', ErrorStatusCode.MISSING_AUTHORIZATION_HEADER, ); }); @@ -794,7 +800,7 @@ Hint: It might not be working because maybe you're not up to date with the Meili await expect( client.index(indexPk.uid).deleteDocuments([1, 2]), ).rejects.toHaveProperty( - 'code', + 'cause.code', ErrorStatusCode.MISSING_AUTHORIZATION_HEADER, ); }); @@ -804,7 +810,7 @@ Hint: It might not be working because maybe you're not up to date with the Meili await expect( client.index(indexPk.uid).deleteAllDocuments(), ).rejects.toHaveProperty( - 'code', + 'cause.code', ErrorStatusCode.MISSING_AUTHORIZATION_HEADER, ); }); @@ -824,10 +830,7 @@ Hint: It might not be working because maybe you're not up to date with the Meili client.index(indexPk.uid).getDocument(1), ).rejects.toHaveProperty( 'message', - `request to ${strippedHost}/${route} failed, reason: connect ECONNREFUSED ${BAD_HOST.replace( - 'http://', - '', - )}`, + `Request to ${strippedHost}/${route} has failed`, ); }); @@ -839,10 +842,7 @@ Hint: It might not be working because maybe you're not up to date with the Meili client.index(indexPk.uid).getDocuments(), ).rejects.toHaveProperty( 'message', - `request to ${strippedHost}/${route} failed, reason: connect ECONNREFUSED ${BAD_HOST.replace( - 'http://', - '', - )}`, + `Request to ${strippedHost}/${route} has failed`, ); }); @@ -854,10 +854,7 @@ Hint: It might not be working because maybe you're not up to date with the Meili client.index(indexPk.uid).addDocuments([]), ).rejects.toHaveProperty( 'message', - `request to ${strippedHost}/${route} failed, reason: connect ECONNREFUSED ${BAD_HOST.replace( - 'http://', - '', - )}`, + `Request to ${strippedHost}/${route} has failed`, ); }); @@ -869,10 +866,7 @@ Hint: It might not be working because maybe you're not up to date with the Meili client.index(indexPk.uid).updateDocuments([]), ).rejects.toHaveProperty( 'message', - `request to ${strippedHost}/${route} failed, reason: connect ECONNREFUSED ${BAD_HOST.replace( - 'http://', - '', - )}`, + `Request to ${strippedHost}/${route} has failed`, ); }); @@ -884,10 +878,7 @@ Hint: It might not be working because maybe you're not up to date with the Meili client.index(indexPk.uid).deleteDocument('1'), ).rejects.toHaveProperty( 'message', - `request to ${strippedHost}/${route} failed, reason: connect ECONNREFUSED ${BAD_HOST.replace( - 'http://', - '', - )}`, + `Request to ${strippedHost}/${route} has failed`, ); }); @@ -899,10 +890,7 @@ Hint: It might not be working because maybe you're not up to date with the Meili client.index(indexPk.uid).deleteDocuments([]), ).rejects.toHaveProperty( 'message', - `request to ${strippedHost}/${route} failed, reason: connect ECONNREFUSED ${BAD_HOST.replace( - 'http://', - '', - )}`, + `Request to ${strippedHost}/${route} has failed`, ); }); @@ -914,10 +902,7 @@ Hint: It might not be working because maybe you're not up to date with the Meili client.index(indexPk.uid).deleteAllDocuments(), ).rejects.toHaveProperty( 'message', - `request to ${strippedHost}/${route} failed, reason: connect ECONNREFUSED ${BAD_HOST.replace( - 'http://', - '', - )}`, + `Request to ${strippedHost}/${route} has failed`, ); }); }); diff --git a/tests/dump.test.ts b/tests/dump.test.ts index 39c68407..f23872ae 100644 --- a/tests/dump.test.ts +++ b/tests/dump.test.ts @@ -29,7 +29,7 @@ describe.each([{ permission: 'Search' }])( test(`${permission} key: try to create dump with search key and be denied`, async () => { const client = await getClient(permission); await expect(client.createDump()).rejects.toHaveProperty( - 'code', + 'cause.code', ErrorStatusCode.INVALID_API_KEY, ); }); @@ -42,7 +42,7 @@ describe.each([{ permission: 'No' }])( test(`${permission} key: try to create dump with no key and be denied`, async () => { const client = await getClient(permission); await expect(client.createDump()).rejects.toHaveProperty( - 'code', + 'cause.code', ErrorStatusCode.MISSING_AUTHORIZATION_HEADER, ); }); @@ -61,10 +61,7 @@ describe.each([ await expect(client.createDump()).rejects.toHaveProperty( 'message', - `request to ${strippedHost}/${route} failed, reason: connect ECONNREFUSED ${BAD_HOST.replace( - 'http://', - '', - )}`, + `Request to ${strippedHost}/${route} has failed`, ); }); }); diff --git a/tests/embedders.test.ts b/tests/embedders.test.ts index d6691581..450641d5 100644 --- a/tests/embedders.test.ts +++ b/tests/embedders.test.ts @@ -119,7 +119,7 @@ describe.each([{ permission: 'Master' }, { permission: 'Admin' }])( const task: EnqueuedTask = await client .index(index.uid) .updateEmbedders(newEmbedder); - await client.waitForTask(task.taskUid); + await client.waitForTask(task.taskUid, { timeOutMs: 60_000 }); const response: Embedders = await client.index(index.uid).getEmbedders(); @@ -237,10 +237,7 @@ describe.each([ const strippedHost = trailing ? host.slice(0, -1) : host; await expect(client.index(index.uid).getEmbedders()).rejects.toHaveProperty( 'message', - `request to ${strippedHost}/${route} failed, reason: connect ECONNREFUSED ${BAD_HOST.replace( - 'http://', - '', - )}`, + `Request to ${strippedHost}/${route} has failed`, ); }); @@ -252,10 +249,7 @@ describe.each([ client.index(index.uid).updateEmbedders({}), ).rejects.toHaveProperty( 'message', - `request to ${strippedHost}/${route} failed, reason: connect ECONNREFUSED ${BAD_HOST.replace( - 'http://', - '', - )}`, + `Request to ${strippedHost}/${route} has failed`, ); }); @@ -267,10 +261,7 @@ describe.each([ client.index(index.uid).resetEmbedders(), ).rejects.toHaveProperty( 'message', - `request to ${strippedHost}/${route} failed, reason: connect ECONNREFUSED ${BAD_HOST.replace( - 'http://', - '', - )}`, + `Request to ${strippedHost}/${route} has failed`, ); }); }); diff --git a/tests/errors.test.ts b/tests/errors.test.ts index 9eb79dc8..4b6541f8 100644 --- a/tests/errors.test.ts +++ b/tests/errors.test.ts @@ -2,7 +2,7 @@ import { MeiliSearch } from './utils/meilisearch-test-utils'; import { MeiliSearchError, MeiliSearchApiError, - MeiliSearchCommunicationError, + MeiliSearchRequestError, MeiliSearchTimeOutError, } from '../src/errors'; import 'jest-fetch-mock'; @@ -12,70 +12,40 @@ fetchMock.enableMocks(); jest.setTimeout(100 * 1000); +// @TODO: Have to review this in more detail describe('Test on updates', () => { beforeEach(() => { fetchMock.mockReset(); }); - test(`Throw MeiliSearchCommunicationError when throwned error is not MeiliSearchApiError`, async () => { + test(`Throw MeilisearchRequestError when throwned error is not MeiliSearchApiError`, async () => { fetchMock.mockReject(new Error('fake error message')); const client = new MeiliSearch({ host: 'http://localhost:9345' }); try { await client.health(); } catch (e: any) { - expect(e.name).toEqual('MeiliSearchCommunicationError'); + expect(e.name).toEqual('MeiliSearchRequestError'); } }); - test(`Not throw MeiliSearchCommunicationError when throwned error is MeiliSearchApiError`, async () => { - fetchMock.mockReject( - new MeiliSearchApiError( - { - message: 'Some error', - code: 'some_error', - type: 'random_error', - link: 'a link', - }, - 404, - ), - ); - - const client = new MeiliSearch({ host: 'http://localhost:9345' }); - try { - await client.health(); - } catch (e: any) { - expect(e.name).toEqual('MeiliSearchApiError'); - } - }); - - test('MeiliSearchApiError can be compared with the instanceof operator', async () => { - fetchMock.mockReject( - new MeiliSearchApiError( - { - message: 'Some error', - code: 'some_error', - type: 'random_error', - link: 'a link', - }, - 404, - ), - ); - - const client = new MeiliSearch({ host: 'http://localhost:9345' }); - try { - await client.health(); - } catch (e: any) { - expect(e instanceof MeiliSearchApiError).toEqual(true); - } + test('MeiliSearchApiError can be compared with the instanceof operator', () => { + expect( + new MeiliSearchApiError(new Response(), { + message: 'Some error', + code: 'some_error', + type: 'random_error', + link: 'a link', + }) instanceof MeiliSearchApiError, + ).toEqual(true); }); - test('MeiliSearchCommunicationError can be compared with the instanceof operator', async () => { + test('MeilisearchRequestError can be compared with the instanceof operator', async () => { fetchMock.mockReject(new Error('fake error message')); const client = new MeiliSearch({ host: 'http://localhost:9345' }); try { await client.health(); } catch (e: any) { - expect(e instanceof MeiliSearchCommunicationError).toEqual(true); + expect(e instanceof MeiliSearchRequestError).toEqual(true); } }); diff --git a/tests/facet_search.test.ts b/tests/facet_search.test.ts index d925c587..027dbde7 100644 --- a/tests/facet_search.test.ts +++ b/tests/facet_search.test.ts @@ -95,6 +95,7 @@ describe.each([ }; const response = await client.index(index.uid).searchForFacetValues(params); + // @TODO: This is flaky, processingTimeMs is not guaranteed expect(response).toMatchSnapshot(); }); }); diff --git a/tests/faceting.test.ts b/tests/faceting.test.ts index 84048113..5144659e 100644 --- a/tests/faceting.test.ts +++ b/tests/faceting.test.ts @@ -101,21 +101,21 @@ describe.each([{ permission: 'Search' }])( const client = await getClient(permission); await expect( client.index(index.uid).getFaceting(), - ).rejects.toHaveProperty('code', ErrorStatusCode.INVALID_API_KEY); + ).rejects.toHaveProperty('cause.code', ErrorStatusCode.INVALID_API_KEY); }); test(`${permission} key: try to update faceting and be denied`, async () => { const client = await getClient(permission); await expect( client.index(index.uid).updateFaceting({ maxValuesPerFacet: 13 }), - ).rejects.toHaveProperty('code', ErrorStatusCode.INVALID_API_KEY); + ).rejects.toHaveProperty('cause.code', ErrorStatusCode.INVALID_API_KEY); }); test(`${permission} key: try to reset faceting and be denied`, async () => { const client = await getClient(permission); await expect( client.index(index.uid).resetFaceting(), - ).rejects.toHaveProperty('code', ErrorStatusCode.INVALID_API_KEY); + ).rejects.toHaveProperty('cause.code', ErrorStatusCode.INVALID_API_KEY); }); }, ); @@ -130,7 +130,7 @@ describe.each([{ permission: 'No' }])('Test on faceting', ({ permission }) => { test(`${permission} key: try to get faceting and be denied`, async () => { const client = await getClient(permission); await expect(client.index(index.uid).getFaceting()).rejects.toHaveProperty( - 'code', + 'cause.code', ErrorStatusCode.MISSING_AUTHORIZATION_HEADER, ); }); @@ -140,7 +140,7 @@ describe.each([{ permission: 'No' }])('Test on faceting', ({ permission }) => { await expect( client.index(index.uid).updateFaceting({ maxValuesPerFacet: 13 }), ).rejects.toHaveProperty( - 'code', + 'cause.code', ErrorStatusCode.MISSING_AUTHORIZATION_HEADER, ); }); @@ -150,7 +150,7 @@ describe.each([{ permission: 'No' }])('Test on faceting', ({ permission }) => { await expect( client.index(index.uid).resetFaceting(), ).rejects.toHaveProperty( - 'code', + 'cause.code', ErrorStatusCode.MISSING_AUTHORIZATION_HEADER, ); }); @@ -167,10 +167,7 @@ describe.each([ const strippedHost = trailing ? host.slice(0, -1) : host; await expect(client.index(index.uid).getFaceting()).rejects.toHaveProperty( 'message', - `request to ${strippedHost}/${route} failed, reason: connect ECONNREFUSED ${BAD_HOST.replace( - 'http://', - '', - )}`, + `Request to ${strippedHost}/${route} has failed`, ); }); @@ -182,10 +179,7 @@ describe.each([ client.index(index.uid).updateFaceting({ maxValuesPerFacet: null }), ).rejects.toHaveProperty( 'message', - `request to ${strippedHost}/${route} failed, reason: connect ECONNREFUSED ${BAD_HOST.replace( - 'http://', - '', - )}`, + `Request to ${strippedHost}/${route} has failed`, ); }); @@ -197,10 +191,7 @@ describe.each([ client.index(index.uid).resetFaceting(), ).rejects.toHaveProperty( 'message', - `request to ${strippedHost}/${route} failed, reason: connect ECONNREFUSED ${BAD_HOST.replace( - 'http://', - '', - )}`, + `Request to ${strippedHost}/${route} has failed`, ); }); }); diff --git a/tests/filterable_attributes.test.ts b/tests/filterable_attributes.test.ts index f6cb1106..03b9df93 100644 --- a/tests/filterable_attributes.test.ts +++ b/tests/filterable_attributes.test.ts @@ -91,21 +91,21 @@ describe.each([{ permission: 'Search' }])( const client = await getClient(permission); await expect( client.index(index.uid).getFilterableAttributes(), - ).rejects.toHaveProperty('code', ErrorStatusCode.INVALID_API_KEY); + ).rejects.toHaveProperty('cause.code', ErrorStatusCode.INVALID_API_KEY); }); test(`${permission} key: try to update attributes for filtering and be denied`, async () => { const client = await getClient(permission); await expect( client.index(index.uid).updateFilterableAttributes([]), - ).rejects.toHaveProperty('code', ErrorStatusCode.INVALID_API_KEY); + ).rejects.toHaveProperty('cause.code', ErrorStatusCode.INVALID_API_KEY); }); test(`${permission} key: try to reset attributes for filtering and be denied`, async () => { const client = await getClient(permission); await expect( client.index(index.uid).resetFilterableAttributes(), - ).rejects.toHaveProperty('code', ErrorStatusCode.INVALID_API_KEY); + ).rejects.toHaveProperty('cause.code', ErrorStatusCode.INVALID_API_KEY); }); }, ); @@ -124,7 +124,7 @@ describe.each([{ permission: 'No' }])( await expect( client.index(index.uid).getFilterableAttributes(), ).rejects.toHaveProperty( - 'code', + 'cause.code', ErrorStatusCode.MISSING_AUTHORIZATION_HEADER, ); }); @@ -134,7 +134,7 @@ describe.each([{ permission: 'No' }])( await expect( client.index(index.uid).updateFilterableAttributes([]), ).rejects.toHaveProperty( - 'code', + 'cause.code', ErrorStatusCode.MISSING_AUTHORIZATION_HEADER, ); }); @@ -144,7 +144,7 @@ describe.each([{ permission: 'No' }])( await expect( client.index(index.uid).resetFilterableAttributes(), ).rejects.toHaveProperty( - 'code', + 'cause.code', ErrorStatusCode.MISSING_AUTHORIZATION_HEADER, ); }); @@ -164,10 +164,7 @@ describe.each([ client.index(index.uid).getFilterableAttributes(), ).rejects.toHaveProperty( 'message', - `request to ${strippedHost}/${route} failed, reason: connect ECONNREFUSED ${BAD_HOST.replace( - 'http://', - '', - )}`, + `Request to ${strippedHost}/${route} has failed`, ); }); @@ -179,10 +176,7 @@ describe.each([ client.index(index.uid).updateFilterableAttributes([]), ).rejects.toHaveProperty( 'message', - `request to ${strippedHost}/${route} failed, reason: connect ECONNREFUSED ${BAD_HOST.replace( - 'http://', - '', - )}`, + `Request to ${strippedHost}/${route} has failed`, ); }); @@ -194,10 +188,7 @@ describe.each([ client.index(index.uid).resetFilterableAttributes(), ).rejects.toHaveProperty( 'message', - `request to ${strippedHost}/${route} failed, reason: connect ECONNREFUSED ${BAD_HOST.replace( - 'http://', - '', - )}`, + `Request to ${strippedHost}/${route} has failed`, ); }); }); diff --git a/tests/get_search.test.ts b/tests/get_search.test.ts index 4e5edd61..e03b82de 100644 --- a/tests/get_search.test.ts +++ b/tests/get_search.test.ts @@ -96,7 +96,8 @@ describe.each([ const response = await client.index(index.uid).searchGet('prince', {}); - expect(response).toHaveProperty('hits', expect.any(Array)); + expect(response).toHaveProperty('hits'); + expect(Array.isArray(response.hits)).toBe(true); expect(response).toHaveProperty('limit', 20); expect(response).toHaveProperty('offset', 0); expect(response).toHaveProperty('processingTimeMs', expect.any(Number)); @@ -109,7 +110,8 @@ describe.each([ const response = await client .index(index.uid) .searchGet('prince', { limit: 1 }); - expect(response).toHaveProperty('hits', expect.any(Array)); + expect(response).toHaveProperty('hits'); + expect(Array.isArray(response.hits)).toBe(true); expect(response).toHaveProperty('offset', 0); expect(response).toHaveProperty('limit', 1); expect(response).toHaveProperty('processingTimeMs', expect.any(Number)); @@ -122,7 +124,8 @@ describe.each([ const response = await client .index(index.uid) .search('', { sort: ['id:asc'] }); - expect(response).toHaveProperty('hits', expect.any(Array)); + expect(response).toHaveProperty('hits'); + expect(Array.isArray(response.hits)).toBe(true); const hit = response.hits[0]; expect(hit.id).toEqual(1); }); @@ -134,7 +137,8 @@ describe.each([ }); const hit = response.hits[0]; - expect(response).toHaveProperty('hits', expect.any(Array)); + expect(response).toHaveProperty('hits'); + expect(Array.isArray(response.hits)).toBe(true); expect(response).toHaveProperty('query', 'prince'); expect(Object.keys(hit).join(',')).toEqual( Object.keys(dataset[1]).join(','), @@ -166,7 +170,8 @@ describe.each([ const response = await client .index(index.uid) .searchGet('prince', { limit: 1 }); - expect(response).toHaveProperty('hits', expect.any(Array)); + expect(response).toHaveProperty('hits'); + expect(Array.isArray(response.hits)).toBe(true); expect(response).toHaveProperty('offset', 0); expect(response).toHaveProperty('limit', 1); expect(response).toHaveProperty('processingTimeMs', expect.any(Number)); @@ -203,7 +208,8 @@ describe.each([ cropLength: 5, showMatchesPosition: true, }); - expect(response).toHaveProperty('hits', expect.any(Array)); + expect(response).toHaveProperty('hits'); + expect(Array.isArray(response.hits)).toBe(true); expect(response.hits[0]).toHaveProperty('_matchesPosition', { comment: [{ start: 22, length: 6 }], title: [{ start: 9, length: 6 }], @@ -223,7 +229,8 @@ describe.each([ showMatchesPosition: true, }); - expect(response).toHaveProperty('hits', expect.any(Array)); + expect(response).toHaveProperty('hits'); + expect(Array.isArray(response.hits)).toBe(true); expect(response).toHaveProperty('offset', 0); expect(response).toHaveProperty('limit', 5); expect(response).toHaveProperty('processingTimeMs', expect.any(Number)); @@ -297,7 +304,8 @@ describe.each([ filter: 'title = "Le Petit Prince"', showMatchesPosition: true, }); - expect(response).toHaveProperty('hits', expect.any(Array)); + expect(response).toHaveProperty('hits'); + expect(Array.isArray(response.hits)).toBe(true); expect(response).toHaveProperty('offset', 0); expect(response).toHaveProperty('limit', 5); expect(response).toHaveProperty('processingTimeMs', expect.any(Number)); @@ -326,7 +334,8 @@ describe.each([ filter: 'title = "Le Petit Prince"', showMatchesPosition: true, }); - expect(response).toHaveProperty('hits', expect.any(Array)); + expect(response).toHaveProperty('hits'); + expect(Array.isArray(response.hits)).toBe(true); expect(response).toHaveProperty('offset', 0); expect(response).toHaveProperty('limit', 5); expect(response).toHaveProperty('processingTimeMs', expect.any(Number)); @@ -360,7 +369,8 @@ describe.each([ expect(response).toHaveProperty('facetDistribution', { genre: { romance: 2 }, }); - expect(response).toHaveProperty('hits', expect.any(Array)); + expect(response).toHaveProperty('hits'); + expect(Array.isArray(response.hits)).toBe(true); expect(response.hits.length).toEqual(2); }); @@ -370,7 +380,8 @@ describe.each([ filter: 'id < 0', facets: ['genre'], }); - expect(response).toHaveProperty('hits', expect.any(Array)); + expect(response).toHaveProperty('hits'); + expect(Array.isArray(response.hits)).toBe(true); expect(response.hits.length).toEqual(0); }); @@ -379,7 +390,8 @@ describe.each([ const response = await client.index(index.uid).searchGet('h', { filter: 'genre = "sci fi"', }); - expect(response).toHaveProperty('hits', expect.any(Array)); + expect(response).toHaveProperty('hits'); + expect(Array.isArray(response.hits)).toBe(true); expect(response.hits.length).toEqual(1); }); @@ -392,7 +404,8 @@ describe.each([ expect(response).toHaveProperty('facetDistribution', { genre: { romance: 2 }, }); - expect(response).toHaveProperty('hits', expect.any(Array)); + expect(response).toHaveProperty('hits'); + expect(Array.isArray(response.hits)).toBe(true); expect(response.hits.length).toEqual(2); }); @@ -495,7 +508,7 @@ describe.each([ await masterClient.waitForTask(taskUid); await expect( client.index(index.uid).searchGet('prince'), - ).rejects.toHaveProperty('code', ErrorStatusCode.INDEX_NOT_FOUND); + ).rejects.toHaveProperty('cause.code', ErrorStatusCode.INDEX_NOT_FOUND); }); }); @@ -510,10 +523,7 @@ describe.each([ const strippedHost = trailing ? host.slice(0, -1) : host; await expect(client.index(index.uid).searchGet()).rejects.toHaveProperty( 'message', - `request to ${strippedHost}/${route} failed, reason: connect ECONNREFUSED ${BAD_HOST.replace( - 'http://', - '', - )}`, + `Request to ${strippedHost}/${route} has failed`, ); }); @@ -523,10 +533,7 @@ describe.each([ const strippedHost = trailing ? host.slice(0, -1) : host; await expect(client.index(index.uid).searchGet()).rejects.toHaveProperty( 'message', - `request to ${strippedHost}/${route} failed, reason: connect ECONNREFUSED ${BAD_HOST.replace( - 'http://', - '', - )}`, + `Request to ${strippedHost}/${route} has failed`, ); }); }); diff --git a/tests/index.test.ts b/tests/index.test.ts index 360b3dab..954533d2 100644 --- a/tests/index.test.ts +++ b/tests/index.test.ts @@ -88,7 +88,7 @@ describe.each([{ permission: 'Master' }, { permission: 'Admin' }])( test(`${permission} key: Get index that does not exist`, async () => { const client = await getClient(permission); await expect(client.getIndex('does_not_exist')).rejects.toHaveProperty( - 'code', + 'cause.code', ErrorStatusCode.INDEX_NOT_FOUND, ); }); @@ -96,7 +96,7 @@ describe.each([{ permission: 'Master' }, { permission: 'Admin' }])( test(`${permission} key: Get raw index that does not exist`, async () => { const client = await getClient(permission); await expect(client.getRawIndex('does_not_exist')).rejects.toHaveProperty( - 'code', + 'cause.code', ErrorStatusCode.INDEX_NOT_FOUND, ); }); @@ -331,7 +331,7 @@ describe.each([{ permission: 'Master' }, { permission: 'Admin' }])( const client = await getClient(permission); const index = client.index(indexNoPk.uid); await expect(index.getRawInfo()).rejects.toHaveProperty( - 'code', + 'cause.code', ErrorStatusCode.INDEX_NOT_FOUND, ); }); @@ -339,7 +339,7 @@ describe.each([{ permission: 'Master' }, { permission: 'Admin' }])( test(`${permission} key: get deleted raw index should fail through client`, async () => { const client = await getClient(permission); await expect(client.getRawIndex(indexNoPk.uid)).rejects.toHaveProperty( - 'code', + 'cause.code', ErrorStatusCode.INDEX_NOT_FOUND, ); }); @@ -406,13 +406,13 @@ describe.each([{ permission: 'Search' }])( const client = await getClient(permission); await expect( client.index(indexNoPk.uid).getRawInfo(), - ).rejects.toHaveProperty('code', ErrorStatusCode.INVALID_API_KEY); + ).rejects.toHaveProperty('cause.code', ErrorStatusCode.INVALID_API_KEY); }); test(`${permission} key: try to get raw index and be denied`, async () => { const client = await getClient(permission); await expect(client.getRawIndex(indexNoPk.uid)).rejects.toHaveProperty( - 'code', + 'cause.code', ErrorStatusCode.INVALID_API_KEY, ); }); @@ -420,7 +420,7 @@ describe.each([{ permission: 'Search' }])( test(`${permission} key: try to delete index and be denied`, async () => { const client = await getClient(permission); await expect(client.index(indexPk.uid).delete()).rejects.toHaveProperty( - 'code', + 'cause.code', ErrorStatusCode.INVALID_API_KEY, ); }); @@ -429,13 +429,13 @@ describe.each([{ permission: 'Search' }])( const client = await getClient(permission); await expect( client.index(indexPk.uid).update({ primaryKey: indexPk.primaryKey }), - ).rejects.toHaveProperty('code', ErrorStatusCode.INVALID_API_KEY); + ).rejects.toHaveProperty('cause.code', ErrorStatusCode.INVALID_API_KEY); }); test(`${permission} key: try to get stats and be denied`, async () => { const client = await getClient(permission); await expect(client.index(indexPk.uid).getStats()).rejects.toHaveProperty( - 'code', + 'cause.code', ErrorStatusCode.INVALID_API_KEY, ); }); @@ -452,7 +452,7 @@ describe.each([{ permission: 'No' }])( test(`${permission} key: try to get all indexes and be denied`, async () => { const client = await getClient(permission); await expect(client.getIndexes()).rejects.toHaveProperty( - 'code', + 'cause.code', ErrorStatusCode.MISSING_AUTHORIZATION_HEADER, ); }); @@ -462,7 +462,7 @@ describe.each([{ permission: 'No' }])( await expect( client.index(indexNoPk.uid).getRawInfo(), ).rejects.toHaveProperty( - 'code', + 'cause.code', ErrorStatusCode.MISSING_AUTHORIZATION_HEADER, ); }); @@ -470,7 +470,7 @@ describe.each([{ permission: 'No' }])( test(`${permission} key: try to get raw index and be denied`, async () => { const client = await getClient(permission); await expect(client.getRawIndex(indexNoPk.uid)).rejects.toHaveProperty( - 'code', + 'cause.code', ErrorStatusCode.MISSING_AUTHORIZATION_HEADER, ); }); @@ -478,7 +478,7 @@ describe.each([{ permission: 'No' }])( test(`${permission} key: try to delete index and be denied`, async () => { const client = await getClient(permission); await expect(client.index(indexPk.uid).delete()).rejects.toHaveProperty( - 'code', + 'cause.code', ErrorStatusCode.MISSING_AUTHORIZATION_HEADER, ); }); @@ -488,7 +488,7 @@ describe.each([{ permission: 'No' }])( await expect( client.index(indexPk.uid).update({ primaryKey: indexPk.primaryKey }), ).rejects.toHaveProperty( - 'code', + 'cause.code', ErrorStatusCode.MISSING_AUTHORIZATION_HEADER, ); }); @@ -506,10 +506,7 @@ describe.each([ const strippedHost = trailing ? host.slice(0, -1) : host; await expect(client.index(indexPk.uid).getStats()).rejects.toHaveProperty( 'message', - `request to ${strippedHost}/${route} failed, reason: connect ECONNREFUSED ${BAD_HOST.replace( - 'http://', - '', - )}`, + `Request to ${strippedHost}/${route} has failed`, ); }); @@ -519,14 +516,11 @@ describe.each([ const strippedHost = trailing ? host.slice(0, -1) : host; await expect(client.index(indexPk.uid).getRawInfo()).rejects.toHaveProperty( 'message', - `request to ${strippedHost}/${route} failed, reason: connect ECONNREFUSED ${BAD_HOST.replace( - 'http://', - '', - )}`, + `Request to ${strippedHost}/${route} has failed`, ); await expect(client.index(indexPk.uid).getRawInfo()).rejects.toHaveProperty( 'name', - 'MeiliSearchCommunicationError', + 'MeiliSearchRequestError', ); }); @@ -536,14 +530,11 @@ describe.each([ const strippedHost = trailing ? host.slice(0, -1) : host; await expect(client.getRawIndex(indexPk.uid)).rejects.toHaveProperty( 'message', - `request to ${strippedHost}/${route} failed, reason: connect ECONNREFUSED ${BAD_HOST.replace( - 'http://', - '', - )}`, + `Request to ${strippedHost}/${route} has failed`, ); await expect(client.getRawIndex(indexPk.uid)).rejects.toHaveProperty( 'name', - 'MeiliSearchCommunicationError', + 'MeiliSearchRequestError', ); }); @@ -553,10 +544,7 @@ describe.each([ const strippedHost = trailing ? host.slice(0, -1) : host; await expect(client.index(indexPk.uid).getRawInfo()).rejects.toHaveProperty( 'message', - `request to ${strippedHost}/${route} failed, reason: connect ECONNREFUSED ${BAD_HOST.replace( - 'http://', - '', - )}`, + `Request to ${strippedHost}/${route} has failed`, ); }); @@ -566,10 +554,7 @@ describe.each([ const strippedHost = trailing ? host.slice(0, -1) : host; await expect(client.index(indexPk.uid).getRawInfo()).rejects.toHaveProperty( 'message', - `request to ${strippedHost}/${route} failed, reason: connect ECONNREFUSED ${BAD_HOST.replace( - 'http://', - '', - )}`, + `Request to ${strippedHost}/${route} has failed`, ); }); }); diff --git a/tests/keys.test.ts b/tests/keys.test.ts index 6dff736c..ff171698 100644 --- a/tests/keys.test.ts +++ b/tests/keys.test.ts @@ -209,7 +209,7 @@ describe.each([{ permission: 'Search' }])( test(`${permission} key: get keys denied`, async () => { const client = await getClient(permission); await expect(client.getKeys()).rejects.toHaveProperty( - 'code', + 'cause.code', ErrorStatusCode.INVALID_API_KEY, ); }); @@ -223,7 +223,7 @@ describe.each([{ permission: 'Search' }])( indexes: ['products'], expiresAt: null, }), - ).rejects.toHaveProperty('code', ErrorStatusCode.INVALID_API_KEY); + ).rejects.toHaveProperty('cause.code', ErrorStatusCode.INVALID_API_KEY); }); }, ); @@ -234,7 +234,7 @@ describe.each([{ permission: 'No' }])( test(`${permission} key: get keys denied`, async () => { const client = await getClient(permission); await expect(client.getKeys()).rejects.toHaveProperty( - 'code', + 'cause.code', ErrorStatusCode.MISSING_AUTHORIZATION_HEADER, ); }); @@ -249,7 +249,7 @@ describe.each([{ permission: 'No' }])( expiresAt: null, }), ).rejects.toHaveProperty( - 'code', + 'cause.code', ErrorStatusCode.MISSING_AUTHORIZATION_HEADER, ); }); diff --git a/tests/non_separator_tokens.test.ts b/tests/non_separator_tokens.test.ts index f1dbfb71..6bf42ddb 100644 --- a/tests/non_separator_tokens.test.ts +++ b/tests/non_separator_tokens.test.ts @@ -95,10 +95,7 @@ describe.each([ client.index(index.uid).getNonSeparatorTokens(), ).rejects.toHaveProperty( 'message', - `request to ${strippedHost}/${route} failed, reason: connect ECONNREFUSED ${BAD_HOST.replace( - 'http://', - '', - )}`, + `Request to ${strippedHost}/${route} has failed`, ); }); @@ -110,10 +107,7 @@ describe.each([ client.index(index.uid).updateNonSeparatorTokens([]), ).rejects.toHaveProperty( 'message', - `request to ${strippedHost}/${route} failed, reason: connect ECONNREFUSED ${BAD_HOST.replace( - 'http://', - '', - )}`, + `Request to ${strippedHost}/${route} has failed`, ); }); @@ -125,10 +119,7 @@ describe.each([ client.index(index.uid).resetNonSeparatorTokens(), ).rejects.toHaveProperty( 'message', - `request to ${strippedHost}/${route} failed, reason: connect ECONNREFUSED ${BAD_HOST.replace( - 'http://', - '', - )}`, + `Request to ${strippedHost}/${route} has failed`, ); }); }); diff --git a/tests/pagination.test.ts b/tests/pagination.test.ts index 5153aa9a..1f325edb 100644 --- a/tests/pagination.test.ts +++ b/tests/pagination.test.ts @@ -97,21 +97,21 @@ describe.each([{ permission: 'Search' }])( const client = await getClient(permission); await expect( client.index(index.uid).getPagination(), - ).rejects.toHaveProperty('code', ErrorStatusCode.INVALID_API_KEY); + ).rejects.toHaveProperty('cause.code', ErrorStatusCode.INVALID_API_KEY); }); test(`${permission} key: try to update pagination and be denied`, async () => { const client = await getClient(permission); await expect( client.index(index.uid).updatePagination({ maxTotalHits: 10 }), - ).rejects.toHaveProperty('code', ErrorStatusCode.INVALID_API_KEY); + ).rejects.toHaveProperty('cause.code', ErrorStatusCode.INVALID_API_KEY); }); test(`${permission} key: try to reset pagination and be denied`, async () => { const client = await getClient(permission); await expect( client.index(index.uid).resetPagination(), - ).rejects.toHaveProperty('code', ErrorStatusCode.INVALID_API_KEY); + ).rejects.toHaveProperty('cause.code', ErrorStatusCode.INVALID_API_KEY); }); }, ); @@ -130,7 +130,7 @@ describe.each([{ permission: 'No' }])( await expect( client.index(index.uid).getPagination(), ).rejects.toHaveProperty( - 'code', + 'cause.code', ErrorStatusCode.MISSING_AUTHORIZATION_HEADER, ); }); @@ -140,7 +140,7 @@ describe.each([{ permission: 'No' }])( await expect( client.index(index.uid).updatePagination({ maxTotalHits: 10 }), ).rejects.toHaveProperty( - 'code', + 'cause.code', ErrorStatusCode.MISSING_AUTHORIZATION_HEADER, ); }); @@ -150,7 +150,7 @@ describe.each([{ permission: 'No' }])( await expect( client.index(index.uid).resetPagination(), ).rejects.toHaveProperty( - 'code', + 'cause.code', ErrorStatusCode.MISSING_AUTHORIZATION_HEADER, ); }); @@ -170,10 +170,7 @@ describe.each([ client.index(index.uid).getPagination(), ).rejects.toHaveProperty( 'message', - `request to ${strippedHost}/${route} failed, reason: connect ECONNREFUSED ${BAD_HOST.replace( - 'http://', - '', - )}`, + `Request to ${strippedHost}/${route} has failed`, ); }); @@ -185,10 +182,7 @@ describe.each([ client.index(index.uid).updatePagination({ maxTotalHits: null }), ).rejects.toHaveProperty( 'message', - `request to ${strippedHost}/${route} failed, reason: connect ECONNREFUSED ${BAD_HOST.replace( - 'http://', - '', - )}`, + `Request to ${strippedHost}/${route} has failed`, ); }); @@ -200,10 +194,7 @@ describe.each([ client.index(index.uid).resetPagination(), ).rejects.toHaveProperty( 'message', - `request to ${strippedHost}/${route} failed, reason: connect ECONNREFUSED ${BAD_HOST.replace( - 'http://', - '', - )}`, + `Request to ${strippedHost}/${route} has failed`, ); }); }); diff --git a/tests/proximity_precision.test.ts b/tests/proximity_precision.test.ts index 270cd879..1c885d4b 100644 --- a/tests/proximity_precision.test.ts +++ b/tests/proximity_precision.test.ts @@ -95,10 +95,7 @@ describe.each([ client.index(index.uid).getProximityPrecision(), ).rejects.toHaveProperty( 'message', - `request to ${strippedHost}/${route} failed, reason: connect ECONNREFUSED ${BAD_HOST.replace( - 'http://', - '', - )}`, + `Request to ${strippedHost}/${route} has failed`, ); }); @@ -110,10 +107,7 @@ describe.each([ client.index(index.uid).updateProximityPrecision('byAttribute'), ).rejects.toHaveProperty( 'message', - `request to ${strippedHost}/${route} failed, reason: connect ECONNREFUSED ${BAD_HOST.replace( - 'http://', - '', - )}`, + `Request to ${strippedHost}/${route} has failed`, ); }); @@ -125,10 +119,7 @@ describe.each([ client.index(index.uid).resetProximityPrecision(), ).rejects.toHaveProperty( 'message', - `request to ${strippedHost}/${route} failed, reason: connect ECONNREFUSED ${BAD_HOST.replace( - 'http://', - '', - )}`, + `Request to ${strippedHost}/${route} has failed`, ); }); }); diff --git a/tests/ranking_rules.test.ts b/tests/ranking_rules.test.ts index 663a9ad3..4cca6355 100644 --- a/tests/ranking_rules.test.ts +++ b/tests/ranking_rules.test.ts @@ -102,21 +102,21 @@ describe.each([{ permission: 'Search' }])( const client = await getClient(permission); await expect( client.index(index.uid).getRankingRules(), - ).rejects.toHaveProperty('code', ErrorStatusCode.INVALID_API_KEY); + ).rejects.toHaveProperty('cause.code', ErrorStatusCode.INVALID_API_KEY); }); test(`${permission} key: try to update ranking rules and be denied`, async () => { const client = await getClient(permission); await expect( client.index(index.uid).updateRankingRules([]), - ).rejects.toHaveProperty('code', ErrorStatusCode.INVALID_API_KEY); + ).rejects.toHaveProperty('cause.code', ErrorStatusCode.INVALID_API_KEY); }); test(`${permission} key: try to reset ranking rules and be denied`, async () => { const client = await getClient(permission); await expect( client.index(index.uid).resetRankingRules(), - ).rejects.toHaveProperty('code', ErrorStatusCode.INVALID_API_KEY); + ).rejects.toHaveProperty('cause.code', ErrorStatusCode.INVALID_API_KEY); }); }, ); @@ -133,7 +133,7 @@ describe.each([{ permission: 'No' }])( await expect( client.index(index.uid).getRankingRules(), ).rejects.toHaveProperty( - 'code', + 'cause.code', ErrorStatusCode.MISSING_AUTHORIZATION_HEADER, ); }); @@ -143,7 +143,7 @@ describe.each([{ permission: 'No' }])( await expect( client.index(index.uid).updateRankingRules([]), ).rejects.toHaveProperty( - 'code', + 'cause.code', ErrorStatusCode.MISSING_AUTHORIZATION_HEADER, ); }); @@ -153,7 +153,7 @@ describe.each([{ permission: 'No' }])( await expect( client.index(index.uid).resetRankingRules(), ).rejects.toHaveProperty( - 'code', + 'cause.code', ErrorStatusCode.MISSING_AUTHORIZATION_HEADER, ); }); @@ -173,10 +173,7 @@ describe.each([ client.index(index.uid).getRankingRules(), ).rejects.toHaveProperty( 'message', - `request to ${strippedHost}/${route} failed, reason: connect ECONNREFUSED ${BAD_HOST.replace( - 'http://', - '', - )}`, + `Request to ${strippedHost}/${route} has failed`, ); }); @@ -188,10 +185,7 @@ describe.each([ client.index(index.uid).updateRankingRules([]), ).rejects.toHaveProperty( 'message', - `request to ${strippedHost}/${route} failed, reason: connect ECONNREFUSED ${BAD_HOST.replace( - 'http://', - '', - )}`, + `Request to ${strippedHost}/${route} has failed`, ); }); @@ -203,10 +197,7 @@ describe.each([ client.index(index.uid).resetRankingRules(), ).rejects.toHaveProperty( 'message', - `request to ${strippedHost}/${route} failed, reason: connect ECONNREFUSED ${BAD_HOST.replace( - 'http://', - '', - )}`, + `Request to ${strippedHost}/${route} has failed`, ); }); }); diff --git a/tests/search.test.ts b/tests/search.test.ts index 0f9763b5..0f6bafeb 100644 --- a/tests/search.test.ts +++ b/tests/search.test.ts @@ -1,4 +1,3 @@ -import AbortController from 'abort-controller'; import { ErrorStatusCode, MatchingStrategies } from '../src/types'; import { EnqueuedTask } from '../src/enqueued-task'; import { @@ -148,7 +147,8 @@ describe.each([ const client = await getClient(permission); const response = await client.index(index.uid).search('prince', {}); - expect(response).toHaveProperty('hits', expect.any(Array)); + expect(response).toHaveProperty('hits'); + expect(Array.isArray(response.hits)).toBe(true); expect(response).toHaveProperty('limit', 20); expect(response).toHaveProperty('offset', 0); expect(response).toHaveProperty('processingTimeMs', expect.any(Number)); @@ -173,7 +173,8 @@ describe.each([ matchingStrategy: MatchingStrategies.ALL, }); - expect(response).toHaveProperty('hits', expect.any(Array)); + expect(response).toHaveProperty('hits'); + expect(Array.isArray(response.hits)).toBe(true); expect(response).toHaveProperty('offset', 0); expect(response).toHaveProperty('limit', 20); expect(response.hits.length).toEqual(1); @@ -185,7 +186,8 @@ describe.each([ .index(index.uid) .search('french book', { matchingStrategy: MatchingStrategies.LAST }); - expect(response).toHaveProperty('hits', expect.any(Array)); + expect(response).toHaveProperty('hits'); + expect(Array.isArray(response.hits)).toBe(true); expect(response).toHaveProperty('offset', 0); expect(response).toHaveProperty('limit', 20); expect(response.hits.length).toEqual(2); @@ -197,7 +199,8 @@ describe.each([ .index(index.uid) .search('other', { q: 'prince' }); - expect(response).toHaveProperty('hits', expect.any(Array)); + expect(response).toHaveProperty('hits'); + expect(Array.isArray(response.hits)).toBe(true); expect(response).toHaveProperty('limit', 20); expect(response).toHaveProperty('offset', 0); expect(response.estimatedTotalHits).toBeDefined(); @@ -212,7 +215,8 @@ describe.each([ .index(index.uid) .search(null, { q: 'prince' }); - expect(response).toHaveProperty('hits', expect.any(Array)); + expect(response).toHaveProperty('hits'); + expect(Array.isArray(response.hits)).toBe(true); expect(response).toHaveProperty('limit', 20); expect(response).toHaveProperty('offset', 0); expect(response.estimatedTotalHits).toBeDefined(); @@ -226,7 +230,8 @@ describe.each([ const response = await client .index(index.uid) .search('"french book" about', {}); - expect(response).toHaveProperty('hits', expect.any(Array)); + expect(response).toHaveProperty('hits'); + expect(Array.isArray(response.hits)).toBe(true); expect(response).toHaveProperty('limit', 20); expect(response).toHaveProperty('offset', 0); expect(response).toHaveProperty('processingTimeMs', expect.any(Number)); @@ -240,7 +245,8 @@ describe.each([ const response = await client .index(index.uid) .search('prince', { limit: 1 }); - expect(response).toHaveProperty('hits', expect.any(Array)); + expect(response).toHaveProperty('hits'); + expect(Array.isArray(response.hits)).toBe(true); expect(response).toHaveProperty('offset', 0); expect(response).toHaveProperty('limit', 1); expect(response.estimatedTotalHits).toEqual(2); @@ -254,7 +260,8 @@ describe.each([ const response = await client .index(index.uid) .search('', { sort: ['id:asc'] }); - expect(response).toHaveProperty('hits', expect.any(Array)); + expect(response).toHaveProperty('hits'); + expect(Array.isArray(response.hits)).toBe(true); const hit = response.hits[0]; expect(hit.id).toEqual(1); }); @@ -268,7 +275,8 @@ describe.each([ const hit = response.hits[0]; - expect(response).toHaveProperty('hits', expect.any(Array)); + expect(response).toHaveProperty('hits'); + expect(Array.isArray(response.hits)).toBe(true); expect(response).toHaveProperty('query', 'prince'); expect(hit).toHaveProperty('_rankingScore'); }); @@ -282,7 +290,8 @@ describe.each([ const hit = response.hits[0]; - expect(response).toHaveProperty('hits', expect.any(Array)); + expect(response).toHaveProperty('hits'); + expect(Array.isArray(response.hits)).toBe(true); expect(response).toHaveProperty('query', 'prince'); expect(hit).toHaveProperty('_rankingScoreDetails'); expect(Object.keys(hit._rankingScoreDetails || {})).toEqual([ @@ -302,7 +311,8 @@ describe.each([ }); const hit = response.hits[0]; - expect(response).toHaveProperty('hits', expect.any(Array)); + expect(response).toHaveProperty('hits'); + expect(Array.isArray(response.hits)).toBe(true); expect(response).toHaveProperty('query', 'prince'); expect(Object.keys(hit).join(',')).toEqual( Object.keys(dataset[1]).join(','), @@ -337,7 +347,8 @@ describe.each([ }); const hit = response.hits[0]; - expect(response).toHaveProperty('hits', expect.any(Array)); + expect(response).toHaveProperty('hits'); + expect(Array.isArray(response.hits)).toBe(true); expect(response).toHaveProperty('query', 'prince'); expect(Object.keys(hit).join(',')).toEqual( Object.keys(dataset[1]).join(','), @@ -349,7 +360,8 @@ describe.each([ const response = await client .index(index.uid) .search('prince', { limit: 1 }); - expect(response).toHaveProperty('hits', expect.any(Array)); + expect(response).toHaveProperty('hits'); + expect(Array.isArray(response.hits)).toBe(true); expect(response).toHaveProperty('offset', 0); expect(response).toHaveProperty('limit', 1); expect(response.estimatedTotalHits).toEqual(2); @@ -398,7 +410,8 @@ describe.each([ cropLength: 5, showMatchesPosition: true, }); - expect(response).toHaveProperty('hits', expect.any(Array)); + expect(response).toHaveProperty('hits'); + expect(Array.isArray(response.hits)).toBe(true); expect(response.hits[0]).toHaveProperty('_matchesPosition', { comment: [{ start: 22, length: 6 }], title: [{ start: 9, length: 6 }], @@ -417,7 +430,8 @@ describe.each([ filter: 'title = "Le Petit Prince"', showMatchesPosition: true, }); - expect(response).toHaveProperty('hits', expect.any(Array)); + expect(response).toHaveProperty('hits'); + expect(Array.isArray(response.hits)).toBe(true); expect(response).toHaveProperty('offset', 0); expect(response).toHaveProperty('limit', 5); expect(response.estimatedTotalHits).toEqual(1); @@ -492,7 +506,8 @@ describe.each([ filter: 'title = "Le Petit Prince"', showMatchesPosition: true, }); - expect(response).toHaveProperty('hits', expect.any(Array)); + expect(response).toHaveProperty('hits'); + expect(Array.isArray(response.hits)).toBe(true); expect(response).toHaveProperty('offset', 0); expect(response).toHaveProperty('limit', 5); expect(response).toHaveProperty('processingTimeMs', expect.any(Number)); @@ -521,7 +536,8 @@ describe.each([ filter: 'title = "Le Petit Prince"', showMatchesPosition: true, }); - expect(response).toHaveProperty('hits', expect.any(Array)); + expect(response).toHaveProperty('hits'); + expect(Array.isArray(response.hits)).toBe(true); expect(response).toHaveProperty('offset', 0); expect(response).toHaveProperty('limit', 5); expect(response).toHaveProperty('processingTimeMs', expect.any(Number)); @@ -580,7 +596,8 @@ describe.each([ expect(response.facetStats).toEqual({ id: { min: 2, max: 123 } }); expect(response.facetStats?.['id']?.max).toBe(123); - expect(response).toHaveProperty('hits', expect.any(Array)); + expect(response).toHaveProperty('hits'); + expect(Array.isArray(response.hits)).toBe(true); expect(response.hits.length).toEqual(2); }); @@ -589,7 +606,8 @@ describe.each([ const response = await client.index(index.uid).search('a', { filter: 'id < 0', }); - expect(response).toHaveProperty('hits', expect.any(Array)); + expect(response).toHaveProperty('hits'); + expect(Array.isArray(response.hits)).toBe(true); expect(response.hits.length).toEqual(0); }); @@ -599,7 +617,8 @@ describe.each([ filter: ['genre = "sci fi"'], }); - expect(response).toHaveProperty('hits', expect.any(Array)); + expect(response).toHaveProperty('hits'); + expect(Array.isArray(response.hits)).toBe(true); expect(response.hits.length).toEqual(1); }); @@ -612,7 +631,8 @@ describe.each([ expect(response).toHaveProperty('facetDistribution', { genre: { romance: 2 }, }); - expect(response).toHaveProperty('hits', expect.any(Array)); + expect(response).toHaveProperty('hits'); + expect(Array.isArray(response.hits)).toBe(true); expect(response.hits.length).toEqual(2); }); @@ -884,7 +904,7 @@ describe.each([ await expect( client.index(index.uid).search('prince', {}), - ).rejects.toHaveProperty('code', ErrorStatusCode.INDEX_NOT_FOUND); + ).rejects.toHaveProperty('cause.code', ErrorStatusCode.INDEX_NOT_FOUND); }); }); @@ -902,7 +922,7 @@ describe.each([{ permission: 'No' }])( await expect( client.index(index.uid).search('prince'), ).rejects.toHaveProperty( - 'code', + 'cause.code', ErrorStatusCode.MISSING_AUTHORIZATION_HEADER, ); }); @@ -910,7 +930,7 @@ describe.each([{ permission: 'No' }])( test(`${permission} key: Try multi search and be denied`, async () => { const client = await getClient(permission); await expect(client.multiSearch({ queries: [] })).rejects.toHaveProperty( - 'code', + 'cause.code', ErrorStatusCode.MISSING_AUTHORIZATION_HEADER, ); }); @@ -1019,7 +1039,10 @@ describe.each([ controller.abort(); searchPromise.catch((error: any) => { - expect(error).toHaveProperty('message', 'The user aborted a request.'); + expect(error).toHaveProperty( + 'cause.message', + 'This operation was aborted', + ); }); }); @@ -1074,7 +1097,10 @@ describe.each([ }); searchBPromise.catch((error: any) => { - expect(error).toHaveProperty('message', 'The user aborted a request.'); + expect(error).toHaveProperty( + 'cause.message', + 'This operation was aborted', + ); }); }); @@ -1088,8 +1114,8 @@ describe.each([ try { await client.health(); } catch (e: any) { - expect(e.message).toEqual('Error: Request Timed Out'); - expect(e.name).toEqual('MeiliSearchCommunicationError'); + expect(e.cause.message).toEqual('Error: Request Timed Out'); + expect(e.name).toEqual('MeiliSearchRequestError'); } }); }); @@ -1105,10 +1131,7 @@ describe.each([ const strippedHost = trailing ? host.slice(0, -1) : host; await expect(client.index(index.uid).search()).rejects.toHaveProperty( 'message', - `request to ${strippedHost}/${route} failed, reason: connect ECONNREFUSED ${BAD_HOST.replace( - 'http://', - '', - )}`, + `Request to ${strippedHost}/${route} has failed`, ); }); @@ -1118,10 +1141,7 @@ describe.each([ const strippedHost = trailing ? host.slice(0, -1) : host; await expect(client.index(index.uid).search()).rejects.toHaveProperty( 'message', - `request to ${strippedHost}/${route} failed, reason: connect ECONNREFUSED ${BAD_HOST.replace( - 'http://', - '', - )}`, + `Request to ${strippedHost}/${route} has failed`, ); }); }); diff --git a/tests/searchCutoffMs.ts b/tests/searchCutoffMs.ts index 9b60101d..a96a0708 100644 --- a/tests/searchCutoffMs.ts +++ b/tests/searchCutoffMs.ts @@ -70,7 +70,7 @@ describe.each([{ permission: 'Master' }, { permission: 'Admin' }])( await expect( client.index(index.uid).updateSearchCutoffMs(newSearchCutoffMs), ).rejects.toHaveProperty( - 'code', + 'cause.code', ErrorStatusCode.INVALID_SETTINGS_SEARCH_CUTOFF_MS, ); }); @@ -105,21 +105,21 @@ describe.each([{ permission: 'Search' }])( const client = await getClient(permission); await expect( client.index(index.uid).getSearchCutoffMs(), - ).rejects.toHaveProperty('code', ErrorStatusCode.INVALID_API_KEY); + ).rejects.toHaveProperty('cause.code', ErrorStatusCode.INVALID_API_KEY); }); test(`${permission} key: try to update searchCutoffMs and be denied`, async () => { const client = await getClient(permission); await expect( client.index(index.uid).updateSearchCutoffMs(100), - ).rejects.toHaveProperty('code', ErrorStatusCode.INVALID_API_KEY); + ).rejects.toHaveProperty('cause.code', ErrorStatusCode.INVALID_API_KEY); }); test(`${permission} key: try to reset searchCutoffMs and be denied`, async () => { const client = await getClient(permission); await expect( client.index(index.uid).resetSearchCutoffMs(), - ).rejects.toHaveProperty('code', ErrorStatusCode.INVALID_API_KEY); + ).rejects.toHaveProperty('cause.code', ErrorStatusCode.INVALID_API_KEY); }); }, ); @@ -138,7 +138,7 @@ describe.each([{ permission: 'No' }])( await expect( client.index(index.uid).getSearchCutoffMs(), ).rejects.toHaveProperty( - 'code', + 'cause.code', ErrorStatusCode.MISSING_AUTHORIZATION_HEADER, ); }); @@ -148,7 +148,7 @@ describe.each([{ permission: 'No' }])( await expect( client.index(index.uid).updateSearchCutoffMs(100), ).rejects.toHaveProperty( - 'code', + 'cause.code', ErrorStatusCode.MISSING_AUTHORIZATION_HEADER, ); }); @@ -158,7 +158,7 @@ describe.each([{ permission: 'No' }])( await expect( client.index(index.uid).resetSearchCutoffMs(), ).rejects.toHaveProperty( - 'code', + 'cause.code', ErrorStatusCode.MISSING_AUTHORIZATION_HEADER, ); }); @@ -178,10 +178,7 @@ describe.each([ client.index(index.uid).getSearchCutoffMs(), ).rejects.toHaveProperty( 'message', - `request to ${strippedHost}/${route} failed, reason: connect ECONNREFUSED ${BAD_HOST.replace( - 'http://', - '', - )}`, + `Request to ${strippedHost}/${route} has failed`, ); }); @@ -193,10 +190,7 @@ describe.each([ client.index(index.uid).updateSearchCutoffMs(null), ).rejects.toHaveProperty( 'message', - `request to ${strippedHost}/${route} failed, reason: connect ECONNREFUSED ${BAD_HOST.replace( - 'http://', - '', - )}`, + `Request to ${strippedHost}/${route} has failed`, ); }); @@ -208,10 +202,7 @@ describe.each([ client.index(index.uid).resetSearchCutoffMs(), ).rejects.toHaveProperty( 'message', - `request to ${strippedHost}/${route} failed, reason: connect ECONNREFUSED ${BAD_HOST.replace( - 'http://', - '', - )}`, + `Request to ${strippedHost}/${route} has failed`, ); }); }); diff --git a/tests/searchable_attributes.test.ts b/tests/searchable_attributes.test.ts index 4a8b1e01..82132d72 100644 --- a/tests/searchable_attributes.test.ts +++ b/tests/searchable_attributes.test.ts @@ -93,21 +93,21 @@ describe.each([{ permission: 'Search' }])( const client = await getClient(permission); await expect( client.index(index.uid).getSearchableAttributes(), - ).rejects.toHaveProperty('code', ErrorStatusCode.INVALID_API_KEY); + ).rejects.toHaveProperty('cause.code', ErrorStatusCode.INVALID_API_KEY); }); test(`${permission} key: try to update searchable attributes and be denied`, async () => { const client = await getClient(permission); await expect( client.index(index.uid).updateSearchableAttributes([]), - ).rejects.toHaveProperty('code', ErrorStatusCode.INVALID_API_KEY); + ).rejects.toHaveProperty('cause.code', ErrorStatusCode.INVALID_API_KEY); }); test(`${permission} key: try to reset searchable attributes and be denied`, async () => { const client = await getClient(permission); await expect( client.index(index.uid).resetSearchableAttributes(), - ).rejects.toHaveProperty('code', ErrorStatusCode.INVALID_API_KEY); + ).rejects.toHaveProperty('cause.code', ErrorStatusCode.INVALID_API_KEY); }); }, ); @@ -126,7 +126,7 @@ describe.each([{ permission: 'No' }])( await expect( client.index(index.uid).getSearchableAttributes(), ).rejects.toHaveProperty( - 'code', + 'cause.code', ErrorStatusCode.MISSING_AUTHORIZATION_HEADER, ); }); @@ -136,7 +136,7 @@ describe.each([{ permission: 'No' }])( await expect( client.index(index.uid).updateSearchableAttributes([]), ).rejects.toHaveProperty( - 'code', + 'cause.code', ErrorStatusCode.MISSING_AUTHORIZATION_HEADER, ); }); @@ -146,7 +146,7 @@ describe.each([{ permission: 'No' }])( await expect( client.index(index.uid).resetSearchableAttributes(), ).rejects.toHaveProperty( - 'code', + 'cause.code', ErrorStatusCode.MISSING_AUTHORIZATION_HEADER, ); }); @@ -166,10 +166,7 @@ describe.each([ client.index(index.uid).getSearchableAttributes(), ).rejects.toHaveProperty( 'message', - `request to ${strippedHost}/${route} failed, reason: connect ECONNREFUSED ${BAD_HOST.replace( - 'http://', - '', - )}`, + `Request to ${strippedHost}/${route} has failed`, ); }); @@ -181,10 +178,7 @@ describe.each([ client.index(index.uid).updateSearchableAttributes([]), ).rejects.toHaveProperty( 'message', - `request to ${strippedHost}/${route} failed, reason: connect ECONNREFUSED ${BAD_HOST.replace( - 'http://', - '', - )}`, + `Request to ${strippedHost}/${route} has failed`, ); }); @@ -196,10 +190,7 @@ describe.each([ client.index(index.uid).resetSearchableAttributes(), ).rejects.toHaveProperty( 'message', - `request to ${strippedHost}/${route} failed, reason: connect ECONNREFUSED ${BAD_HOST.replace( - 'http://', - '', - )}`, + `Request to ${strippedHost}/${route} has failed`, ); }); }); diff --git a/tests/separator_tokens.test.ts b/tests/separator_tokens.test.ts index f7320fb6..e571b701 100644 --- a/tests/separator_tokens.test.ts +++ b/tests/separator_tokens.test.ts @@ -95,10 +95,7 @@ describe.each([ client.index(index.uid).getSeparatorTokens(), ).rejects.toHaveProperty( 'message', - `request to ${strippedHost}/${route} failed, reason: connect ECONNREFUSED ${BAD_HOST.replace( - 'http://', - '', - )}`, + `Request to ${strippedHost}/${route} has failed`, ); }); @@ -110,10 +107,7 @@ describe.each([ client.index(index.uid).updateSeparatorTokens([]), ).rejects.toHaveProperty( 'message', - `request to ${strippedHost}/${route} failed, reason: connect ECONNREFUSED ${BAD_HOST.replace( - 'http://', - '', - )}`, + `Request to ${strippedHost}/${route} has failed`, ); }); @@ -125,10 +119,7 @@ describe.each([ client.index(index.uid).resetSeparatorTokens(), ).rejects.toHaveProperty( 'message', - `request to ${strippedHost}/${route} failed, reason: connect ECONNREFUSED ${BAD_HOST.replace( - 'http://', - '', - )}`, + `Request to ${strippedHost}/${route} has failed`, ); }); }); diff --git a/tests/settings.test.ts b/tests/settings.test.ts index c68a1f0f..9c77d74d 100644 --- a/tests/settings.test.ts +++ b/tests/settings.test.ts @@ -280,19 +280,19 @@ describe.each([{ permission: 'Search' }])( const client = await getClient(permission); await expect( client.index(index.uid).getSettings(), - ).rejects.toHaveProperty('code', ErrorStatusCode.INVALID_API_KEY); + ).rejects.toHaveProperty('cause.code', ErrorStatusCode.INVALID_API_KEY); }); test(`${permission} key: try to update settings and be denied`, async () => { const client = await getClient(permission); await expect( client.index(index.uid).updateSettings({}), - ).rejects.toHaveProperty('code', ErrorStatusCode.INVALID_API_KEY); + ).rejects.toHaveProperty('cause.code', ErrorStatusCode.INVALID_API_KEY); }); test(`${permission} key: try to reset settings and be denied`, async () => { const client = await getClient(permission); await expect( client.index(index.uid).resetSettings(), - ).rejects.toHaveProperty('code', ErrorStatusCode.INVALID_API_KEY); + ).rejects.toHaveProperty('cause.code', ErrorStatusCode.INVALID_API_KEY); }); }, ); @@ -304,7 +304,7 @@ describe.each([{ permission: 'No' }])('Test on settings', ({ permission }) => { test(`${permission} key: try to get settings and be denied`, async () => { const client = await getClient(permission); await expect(client.index(index.uid).getSettings()).rejects.toHaveProperty( - 'code', + 'cause.code', ErrorStatusCode.MISSING_AUTHORIZATION_HEADER, ); }); @@ -313,7 +313,7 @@ describe.each([{ permission: 'No' }])('Test on settings', ({ permission }) => { await expect( client.index(index.uid).updateSettings({}), ).rejects.toHaveProperty( - 'code', + 'cause.code', ErrorStatusCode.MISSING_AUTHORIZATION_HEADER, ); }); @@ -322,7 +322,7 @@ describe.each([{ permission: 'No' }])('Test on settings', ({ permission }) => { await expect( client.index(index.uid).resetSettings(), ).rejects.toHaveProperty( - 'code', + 'cause.code', ErrorStatusCode.MISSING_AUTHORIZATION_HEADER, ); }); @@ -339,10 +339,7 @@ describe.each([ const strippedHost = trailing ? host.slice(0, -1) : host; await expect(client.index(index.uid).getSettings()).rejects.toHaveProperty( 'message', - `request to ${strippedHost}/${route} failed, reason: connect ECONNREFUSED ${BAD_HOST.replace( - 'http://', - '', - )}`, + `Request to ${strippedHost}/${route} has failed`, ); }); @@ -354,10 +351,7 @@ describe.each([ client.index(index.uid).updateSettings({}), ).rejects.toHaveProperty( 'message', - `request to ${strippedHost}/${route} failed, reason: connect ECONNREFUSED ${BAD_HOST.replace( - 'http://', - '', - )}`, + `Request to ${strippedHost}/${route} has failed`, ); }); @@ -369,10 +363,7 @@ describe.each([ client.index(index.uid).resetSettings(), ).rejects.toHaveProperty( 'message', - `request to ${strippedHost}/${route} failed, reason: connect ECONNREFUSED ${BAD_HOST.replace( - 'http://', - '', - )}`, + `Request to ${strippedHost}/${route} has failed`, ); }); }); diff --git a/tests/snapshots.test.ts b/tests/snapshots.test.ts index f8763c37..bf78c87d 100644 --- a/tests/snapshots.test.ts +++ b/tests/snapshots.test.ts @@ -29,7 +29,7 @@ describe.each([{ permission: 'Search' }])( test(`${permission} key: try to create snapshot with search key and be denied`, async () => { const client = await getClient(permission); await expect(client.createSnapshot()).rejects.toHaveProperty( - 'code', + 'cause.code', ErrorStatusCode.INVALID_API_KEY, ); }); @@ -42,7 +42,7 @@ describe.each([{ permission: 'No' }])( test(`${permission} key: try to create snapshot with no key and be denied`, async () => { const client = await getClient(permission); await expect(client.createSnapshot()).rejects.toHaveProperty( - 'code', + 'cause.code', ErrorStatusCode.MISSING_AUTHORIZATION_HEADER, ); }); @@ -61,10 +61,7 @@ describe.each([ await expect(client.createSnapshot()).rejects.toHaveProperty( 'message', - `request to ${strippedHost}/${route} failed, reason: connect ECONNREFUSED ${BAD_HOST.replace( - 'http://', - '', - )}`, + `Request to ${strippedHost}/${route} has failed`, ); }); }); diff --git a/tests/sortable_attributes.test.ts b/tests/sortable_attributes.test.ts index 6581bb5f..a0306969 100644 --- a/tests/sortable_attributes.test.ts +++ b/tests/sortable_attributes.test.ts @@ -87,21 +87,21 @@ describe.each([{ permission: 'Search' }])( const client = await getClient(permission); await expect( client.index(index.uid).getSortableAttributes(), - ).rejects.toHaveProperty('code', ErrorStatusCode.INVALID_API_KEY); + ).rejects.toHaveProperty('cause.code', ErrorStatusCode.INVALID_API_KEY); }); test(`${permission} key: try to update sortable attributes and be denied`, async () => { const client = await getClient(permission); await expect( client.index(index.uid).updateSortableAttributes([]), - ).rejects.toHaveProperty('code', ErrorStatusCode.INVALID_API_KEY); + ).rejects.toHaveProperty('cause.code', ErrorStatusCode.INVALID_API_KEY); }); test(`${permission} key: try to reset sortable attributes and be denied`, async () => { const client = await getClient(permission); await expect( client.index(index.uid).resetSortableAttributes(), - ).rejects.toHaveProperty('code', ErrorStatusCode.INVALID_API_KEY); + ).rejects.toHaveProperty('cause.code', ErrorStatusCode.INVALID_API_KEY); }); }, ); @@ -120,7 +120,7 @@ describe.each([{ permission: 'No' }])( await expect( client.index(index.uid).getSortableAttributes(), ).rejects.toHaveProperty( - 'code', + 'cause.code', ErrorStatusCode.MISSING_AUTHORIZATION_HEADER, ); }); @@ -131,7 +131,7 @@ describe.each([{ permission: 'No' }])( await expect( client.index(index.uid).updateSortableAttributes(resetSortable), ).rejects.toHaveProperty( - 'code', + 'cause.code', ErrorStatusCode.MISSING_AUTHORIZATION_HEADER, ); }); @@ -141,7 +141,7 @@ describe.each([{ permission: 'No' }])( await expect( client.index(index.uid).resetSortableAttributes(), ).rejects.toHaveProperty( - 'code', + 'cause.code', ErrorStatusCode.MISSING_AUTHORIZATION_HEADER, ); }); @@ -161,10 +161,7 @@ describe.each([ client.index(index.uid).getSortableAttributes(), ).rejects.toHaveProperty( 'message', - `request to ${strippedHost}/${route} failed, reason: connect ECONNREFUSED ${BAD_HOST.replace( - 'http://', - '', - )}`, + `Request to ${strippedHost}/${route} has failed`, ); }); @@ -176,10 +173,7 @@ describe.each([ client.index(index.uid).updateSortableAttributes([]), ).rejects.toHaveProperty( 'message', - `request to ${strippedHost}/${route} failed, reason: connect ECONNREFUSED ${BAD_HOST.replace( - 'http://', - '', - )}`, + `Request to ${strippedHost}/${route} has failed`, ); }); @@ -191,10 +185,7 @@ describe.each([ client.index(index.uid).resetSortableAttributes(), ).rejects.toHaveProperty( 'message', - `request to ${strippedHost}/${route} failed, reason: connect ECONNREFUSED ${BAD_HOST.replace( - 'http://', - '', - )}`, + `Request to ${strippedHost}/${route} has failed`, ); }); }); diff --git a/tests/stop_words.test.ts b/tests/stop_words.test.ts index bf66d25b..5632b2b4 100644 --- a/tests/stop_words.test.ts +++ b/tests/stop_words.test.ts @@ -84,21 +84,21 @@ describe.each([{ permission: 'Search' }])( const client = await getClient(permission); await expect( client.index(index.uid).getStopWords(), - ).rejects.toHaveProperty('code', ErrorStatusCode.INVALID_API_KEY); + ).rejects.toHaveProperty('cause.code', ErrorStatusCode.INVALID_API_KEY); }); test(`${permission} key: try to update stop words and be denied`, async () => { const client = await getClient(permission); await expect( client.index(index.uid).updateStopWords([]), - ).rejects.toHaveProperty('code', ErrorStatusCode.INVALID_API_KEY); + ).rejects.toHaveProperty('cause.code', ErrorStatusCode.INVALID_API_KEY); }); test(`${permission} key: try to reset stop words and be denied`, async () => { const client = await getClient(permission); await expect( client.index(index.uid).resetStopWords(), - ).rejects.toHaveProperty('code', ErrorStatusCode.INVALID_API_KEY); + ).rejects.toHaveProperty('cause.code', ErrorStatusCode.INVALID_API_KEY); }); }, ); @@ -115,7 +115,7 @@ describe.each([{ permission: 'No' }])( await expect( client.index(index.uid).getStopWords(), ).rejects.toHaveProperty( - 'code', + 'cause.code', ErrorStatusCode.MISSING_AUTHORIZATION_HEADER, ); }); @@ -125,7 +125,7 @@ describe.each([{ permission: 'No' }])( await expect( client.index(index.uid).updateStopWords([]), ).rejects.toHaveProperty( - 'code', + 'cause.code', ErrorStatusCode.MISSING_AUTHORIZATION_HEADER, ); }); @@ -135,7 +135,7 @@ describe.each([{ permission: 'No' }])( await expect( client.index(index.uid).resetStopWords(), ).rejects.toHaveProperty( - 'code', + 'cause.code', ErrorStatusCode.MISSING_AUTHORIZATION_HEADER, ); }); @@ -153,10 +153,7 @@ describe.each([ const strippedHost = trailing ? host.slice(0, -1) : host; await expect(client.index(index.uid).getStopWords()).rejects.toHaveProperty( 'message', - `request to ${strippedHost}/${route} failed, reason: connect ECONNREFUSED ${BAD_HOST.replace( - 'http://', - '', - )}`, + `Request to ${strippedHost}/${route} has failed`, ); }); @@ -168,10 +165,7 @@ describe.each([ client.index(index.uid).updateStopWords([]), ).rejects.toHaveProperty( 'message', - `request to ${strippedHost}/${route} failed, reason: connect ECONNREFUSED ${BAD_HOST.replace( - 'http://', - '', - )}`, + `Request to ${strippedHost}/${route} has failed`, ); }); @@ -183,10 +177,7 @@ describe.each([ client.index(index.uid).resetStopWords(), ).rejects.toHaveProperty( 'message', - `request to ${strippedHost}/${route} failed, reason: connect ECONNREFUSED ${BAD_HOST.replace( - 'http://', - '', - )}`, + `Request to ${strippedHost}/${route} has failed`, ); }); }); diff --git a/tests/synonyms.test.ts b/tests/synonyms.test.ts index 95c184b0..bc1171d8 100644 --- a/tests/synonyms.test.ts +++ b/tests/synonyms.test.ts @@ -81,21 +81,21 @@ describe.each([{ permission: 'Search' }])( const client = await getClient(permission); await expect( client.index(index.uid).getSynonyms(), - ).rejects.toHaveProperty('code', ErrorStatusCode.INVALID_API_KEY); + ).rejects.toHaveProperty('cause.code', ErrorStatusCode.INVALID_API_KEY); }); test(`${permission} key: try to update synonyms and be denied`, async () => { const client = await getClient(permission); await expect( client.index(index.uid).updateSynonyms({}), - ).rejects.toHaveProperty('code', ErrorStatusCode.INVALID_API_KEY); + ).rejects.toHaveProperty('cause.code', ErrorStatusCode.INVALID_API_KEY); }); test(`${permission} key: try to reset synonyms and be denied`, async () => { const client = await getClient(permission); await expect( client.index(index.uid).resetSynonyms(), - ).rejects.toHaveProperty('code', ErrorStatusCode.INVALID_API_KEY); + ).rejects.toHaveProperty('cause.code', ErrorStatusCode.INVALID_API_KEY); }); }, ); @@ -108,7 +108,7 @@ describe.each([{ permission: 'No' }])('Test on synonyms', ({ permission }) => { test(`${permission} key: try to get synonyms and be denied`, async () => { const client = await getClient(permission); await expect(client.index(index.uid).getSynonyms()).rejects.toHaveProperty( - 'code', + 'cause.code', ErrorStatusCode.MISSING_AUTHORIZATION_HEADER, ); }); @@ -118,7 +118,7 @@ describe.each([{ permission: 'No' }])('Test on synonyms', ({ permission }) => { await expect( client.index(index.uid).updateSynonyms({}), ).rejects.toHaveProperty( - 'code', + 'cause.code', ErrorStatusCode.MISSING_AUTHORIZATION_HEADER, ); }); @@ -128,7 +128,7 @@ describe.each([{ permission: 'No' }])('Test on synonyms', ({ permission }) => { await expect( client.index(index.uid).resetSynonyms(), ).rejects.toHaveProperty( - 'code', + 'cause.code', ErrorStatusCode.MISSING_AUTHORIZATION_HEADER, ); }); @@ -145,10 +145,7 @@ describe.each([ const strippedHost = trailing ? host.slice(0, -1) : host; await expect(client.index(index.uid).getSynonyms()).rejects.toHaveProperty( 'message', - `request to ${strippedHost}/${route} failed, reason: connect ECONNREFUSED ${BAD_HOST.replace( - 'http://', - '', - )}`, + `Request to ${strippedHost}/${route} has failed`, ); }); @@ -160,10 +157,7 @@ describe.each([ client.index(index.uid).updateSynonyms({}), ).rejects.toHaveProperty( 'message', - `request to ${strippedHost}/${route} failed, reason: connect ECONNREFUSED ${BAD_HOST.replace( - 'http://', - '', - )}`, + `Request to ${strippedHost}/${route} has failed`, ); }); @@ -175,10 +169,7 @@ describe.each([ client.index(index.uid).resetSynonyms(), ).rejects.toHaveProperty( 'message', - `request to ${strippedHost}/${route} failed, reason: connect ECONNREFUSED ${BAD_HOST.replace( - 'http://', - '', - )}`, + `Request to ${strippedHost}/${route} has failed`, ); }); }); diff --git a/tests/task.test.ts b/tests/task.test.ts index 14099251..89cf421e 100644 --- a/tests/task.test.ts +++ b/tests/task.test.ts @@ -377,7 +377,10 @@ describe.each([{ permission: 'Master' }, { permission: 'Admin' }])( await expect( // @ts-expect-error testing wrong argument type client.getTasks({ types: ['wrong'] }), - ).rejects.toHaveProperty('code', ErrorStatusCode.INVALID_TASK_TYPES); + ).rejects.toHaveProperty( + 'cause.code', + ErrorStatusCode.INVALID_TASK_TYPES, + ); }); // filters error code: INVALID_TASK_STATUSES_FILTER @@ -387,7 +390,10 @@ describe.each([{ permission: 'Master' }, { permission: 'Admin' }])( await expect( // @ts-expect-error testing wrong argument type client.getTasks({ statuses: ['wrong'] }), - ).rejects.toHaveProperty('code', ErrorStatusCode.INVALID_TASK_STATUSES); + ).rejects.toHaveProperty( + 'cause.code', + ErrorStatusCode.INVALID_TASK_STATUSES, + ); }); // filters error code: INVALID_TASK_UIDS_FILTER @@ -397,7 +403,7 @@ describe.each([{ permission: 'Master' }, { permission: 'Admin' }])( await expect( // @ts-expect-error testing wrong argument type client.getTasks({ uids: ['wrong'] }), - ).rejects.toHaveProperty('code', ErrorStatusCode.INVALID_TASK_UIDS); + ).rejects.toHaveProperty('cause.code', ErrorStatusCode.INVALID_TASK_UIDS); }); // filters error code: INVALID_TASK_CANCELED_BY_FILTER @@ -408,7 +414,7 @@ describe.each([{ permission: 'Master' }, { permission: 'Admin' }])( // @ts-expect-error testing wrong canceledBy type client.getTasks({ canceledBy: ['wrong'] }), ).rejects.toHaveProperty( - 'code', + 'cause.code', ErrorStatusCode.INVALID_TASK_CANCELED_BY, ); }); @@ -421,7 +427,7 @@ describe.each([{ permission: 'Master' }, { permission: 'Admin' }])( // @ts-expect-error testing wrong date format client.getTasks({ beforeEnqueuedAt: 'wrong' }), ).rejects.toHaveProperty( - 'code', + 'cause.code', ErrorStatusCode.INVALID_TASK_BEFORE_ENQUEUED_AT, ); }); @@ -587,7 +593,10 @@ describe.each([{ permission: 'Master' }, { permission: 'Admin' }])( await expect( // @ts-expect-error testing wrong argument type client.cancelTasks(), - ).rejects.toHaveProperty('code', ErrorStatusCode.MISSING_TASK_FILTERS); + ).rejects.toHaveProperty( + 'cause.code', + ErrorStatusCode.MISSING_TASK_FILTERS, + ); }); // delete: uid @@ -605,7 +614,7 @@ describe.each([{ permission: 'Master' }, { permission: 'Admin' }])( expect(deleteTask.type).toEqual(TaskTypes.TASK_DELETION); expect(task.details?.deletedTasks).toBeDefined(); await expect(client.getTask(addDocuments.taskUid)).rejects.toHaveProperty( - 'code', + 'cause.code', ErrorStatusCode.TASK_NOT_FOUND, ); }); @@ -624,7 +633,7 @@ describe.each([{ permission: 'Master' }, { permission: 'Admin' }])( expect(deleteTask.type).toEqual(TaskTypes.TASK_DELETION); await expect(client.getTask(addDocuments.taskUid)).rejects.toHaveProperty( - 'code', + 'cause.code', ErrorStatusCode.TASK_NOT_FOUND, ); }); @@ -769,7 +778,7 @@ describe.each([{ permission: 'Master' }, { permission: 'Admin' }])( const client = await getClient(permission); await expect(client.getTask(254500)).rejects.toHaveProperty( - 'code', + 'cause.code', ErrorStatusCode.TASK_NOT_FOUND, ); }); @@ -784,7 +793,7 @@ describe.each([{ permission: 'Search' }])('Test on tasks', ({ permission }) => { test(`${permission} key: Try to get a task and be denied`, async () => { const client = await getClient(permission); await expect(client.getTask(0)).rejects.toHaveProperty( - 'code', + 'cause.code', ErrorStatusCode.INVALID_API_KEY, ); }); @@ -798,7 +807,7 @@ describe.each([{ permission: 'No' }])('Test on tasks', ({ permission }) => { test(`${permission} key: Try to get an task and be denied`, async () => { const client = await getClient(permission); await expect(client.getTask(0)).rejects.toHaveProperty( - 'code', + 'cause.code', ErrorStatusCode.MISSING_AUTHORIZATION_HEADER, ); }); @@ -816,10 +825,7 @@ describe.each([ await expect(client.index(index.uid).getTask(1)).rejects.toHaveProperty( 'message', - `request to ${strippedHost}/${route} failed, reason: connect ECONNREFUSED ${BAD_HOST.replace( - 'http://', - '', - )}`, + `Request to ${strippedHost}/${route} has failed`, ); }); @@ -830,10 +836,7 @@ describe.each([ await expect(client.index(index.uid).getTasks()).rejects.toHaveProperty( 'message', - `request to ${strippedHost}/${route} failed, reason: connect ECONNREFUSED ${BAD_HOST.replace( - 'http://', - '', - )}`, + `Request to ${strippedHost}/${route} has failed`, ); }); }); diff --git a/tests/token.test.ts b/tests/token.test.ts index 87d8d9b3..73ac88ee 100644 --- a/tests/token.test.ts +++ b/tests/token.test.ts @@ -222,7 +222,7 @@ describe.each([{ permission: 'Admin' }])( // search await expect( searchClient.index(UID).search('pride'), - ).rejects.toHaveProperty('code', 'invalid_api_key'); + ).rejects.toHaveProperty('cause.code', 'invalid_api_key'); }); test(`${permission} key: Search in tenant token on index with no permissions `, async () => { @@ -236,7 +236,7 @@ describe.each([{ permission: 'Admin' }])( // search await expect( searchClient.index(UID).search('pride'), - ).rejects.toHaveProperty('code', 'invalid_api_key'); + ).rejects.toHaveProperty('cause.code', 'invalid_api_key'); }); test(`${permission} key: Creates tenant token with an expiration date in the past throws an error`, async () => { diff --git a/tests/typed_search.test.ts b/tests/typed_search.test.ts index 85c69bb9..64cc019b 100644 --- a/tests/typed_search.test.ts +++ b/tests/typed_search.test.ts @@ -313,7 +313,8 @@ describe.each([ const response = await client.index(index.uid).search('h', { filter: ['genre="sci fi"'], }); - expect(response).toHaveProperty('hits', expect.any(Array)); + expect(response).toHaveProperty('hits'); + expect(Array.isArray(response.hits)).toBe(true); expect(response.hits.length === 1).toBeTruthy(); }); @@ -380,7 +381,7 @@ describe.each([ await expect( client.index(index.uid).search('prince'), - ).rejects.toHaveProperty('code', ErrorStatusCode.INDEX_NOT_FOUND); + ).rejects.toHaveProperty('cause.code', ErrorStatusCode.INDEX_NOT_FOUND); }); }); @@ -459,7 +460,7 @@ describe.each([{ permission: 'No' }])( await expect( client.index(index.uid).search('prince'), ).rejects.toHaveProperty( - 'code', + 'cause.code', ErrorStatusCode.MISSING_AUTHORIZATION_HEADER, ); }); @@ -479,10 +480,7 @@ describe.each([ client.index(index.uid).search(), ).rejects.toHaveProperty( 'message', - `request to ${strippedHost}/${route} failed, reason: connect ECONNREFUSED ${BAD_HOST.replace( - 'http://', - '', - )}`, + `Request to ${strippedHost}/${route} has failed`, ); }); @@ -494,10 +492,7 @@ describe.each([ client.index(index.uid).search(), ).rejects.toHaveProperty( 'message', - `request to ${strippedHost}/${route} failed, reason: connect ECONNREFUSED ${BAD_HOST.replace( - 'http://', - '', - )}`, + `Request to ${strippedHost}/${route} has failed`, ); }); }); diff --git a/tests/typo_tolerance.test.ts b/tests/typo_tolerance.test.ts index d8d917c0..e559bb2d 100644 --- a/tests/typo_tolerance.test.ts +++ b/tests/typo_tolerance.test.ts @@ -98,21 +98,21 @@ describe.each([{ permission: 'Search' }])( const client = await getClient(permission); await expect( client.index(index.uid).getTypoTolerance(), - ).rejects.toHaveProperty('code', ErrorStatusCode.INVALID_API_KEY); + ).rejects.toHaveProperty('cause.code', ErrorStatusCode.INVALID_API_KEY); }); test(`${permission} key: try to update typo tolerance settings and be denied`, async () => { const client = await getClient(permission); await expect( client.index(index.uid).updateTypoTolerance({}), - ).rejects.toHaveProperty('code', ErrorStatusCode.INVALID_API_KEY); + ).rejects.toHaveProperty('cause.code', ErrorStatusCode.INVALID_API_KEY); }); test(`${permission} key: try to reset typo tolerance settings and be denied`, async () => { const client = await getClient(permission); await expect( client.index(index.uid).resetTypoTolerance(), - ).rejects.toHaveProperty('code', ErrorStatusCode.INVALID_API_KEY); + ).rejects.toHaveProperty('cause.code', ErrorStatusCode.INVALID_API_KEY); }); }, ); @@ -129,7 +129,7 @@ describe.each([{ permission: 'No' }])( await expect( client.index(index.uid).getTypoTolerance(), ).rejects.toHaveProperty( - 'code', + 'cause.code', ErrorStatusCode.MISSING_AUTHORIZATION_HEADER, ); }); @@ -139,7 +139,7 @@ describe.each([{ permission: 'No' }])( await expect( client.index(index.uid).updateTypoTolerance({}), ).rejects.toHaveProperty( - 'code', + 'cause.code', ErrorStatusCode.MISSING_AUTHORIZATION_HEADER, ); }); @@ -149,7 +149,7 @@ describe.each([{ permission: 'No' }])( await expect( client.index(index.uid).resetTypoTolerance(), ).rejects.toHaveProperty( - 'code', + 'cause.code', ErrorStatusCode.MISSING_AUTHORIZATION_HEADER, ); }); @@ -169,10 +169,7 @@ describe.each([ client.index(index.uid).getTypoTolerance(), ).rejects.toHaveProperty( 'message', - `request to ${strippedHost}/${route} failed, reason: connect ECONNREFUSED ${BAD_HOST.replace( - 'http://', - '', - )}`, + `Request to ${strippedHost}/${route} has failed`, ); }); @@ -184,10 +181,7 @@ describe.each([ client.index(index.uid).updateTypoTolerance({}), ).rejects.toHaveProperty( 'message', - `request to ${strippedHost}/${route} failed, reason: connect ECONNREFUSED ${BAD_HOST.replace( - 'http://', - '', - )}`, + `Request to ${strippedHost}/${route} has failed`, ); }); @@ -199,10 +193,7 @@ describe.each([ client.index(index.uid).resetTypoTolerance(), ).rejects.toHaveProperty( 'message', - `request to ${strippedHost}/${route} failed, reason: connect ECONNREFUSED ${BAD_HOST.replace( - 'http://', - '', - )}`, + `Request to ${strippedHost}/${route} has failed`, ); }); }); diff --git a/yarn.lock b/yarn.lock index c149dbc1..e104911a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2141,13 +2141,6 @@ abbrev@1: resolved "https://registry.yarnpkg.com/abbrev/-/abbrev-1.1.1.tgz#f8f2c887ad10bf67f634f005b6987fed3179aac8" integrity sha512-nne9/IiQ/hzIhY6pdDnbBtz7DjPTKrY00P/zvPSm5pOFkl6xuGrGnXn/VtTNNfNtAfZ9/1RtehkszU9qcTii0Q== -abort-controller@^3.0.0: - version "3.0.0" - resolved "https://registry.yarnpkg.com/abort-controller/-/abort-controller-3.0.0.tgz#eaf54d53b62bae4138e809ca225c8439a6efb392" - integrity sha512-h8lQ8tacZYnR3vNQTgibj+tODHI5/+l06Au2Pcriv/Gmet0eaj4TwWH41sO9wnHDiQsEj19q0drzdWdeAHtweg== - dependencies: - event-target-shim "^5.0.0" - acorn-globals@^7.0.0: version "7.0.1" resolved "https://registry.yarnpkg.com/acorn-globals/-/acorn-globals-7.0.1.tgz#0dbf05c44fa7c94332914c02066d5beff62c40c3" @@ -3185,11 +3178,6 @@ esutils@^2.0.2: resolved "https://registry.yarnpkg.com/esutils/-/esutils-2.0.3.tgz#74d2eb4de0b8da1293711910d50775b9b710ef64" integrity sha512-kVscqXk4OCp68SZ0dkgEKVi6/8ij300KBWTJq32P/dYeWTSwK41WyTxalN1eRmA5Z9UU/LX9D7FWSmV9SAYx6g== -event-target-shim@^5.0.0: - version "5.0.1" - resolved "https://registry.yarnpkg.com/event-target-shim/-/event-target-shim-5.0.1.tgz#5d4d3ebdf9583d63a5333ce2deb7480ab2b05789" - integrity sha512-i/2XbnSz/uxRCU6+NdVJgKWDTM427+MqYbkQzD321DuCQJUqOuJKIA0IM2+W2xtYHdKOmZ4dR6fExsd4SXL+WQ== - execa@^5.0.0: version "5.0.0" resolved "https://registry.yarnpkg.com/execa/-/execa-5.0.0.tgz#4029b0007998a841fbd1032e5f4de86a3c1e3376"