diff --git a/src/errors/meilisearch-api-error.ts b/src/errors/meilisearch-api-error.ts index aeb1dd0cb..eac05b540 100644 --- a/src/errors/meilisearch-api-error.ts +++ b/src/errors/meilisearch-api-error.ts @@ -1,12 +1,12 @@ -import type { MeiliSearchErrorResponse } from "../types/index.js"; +import type { ResponseError } from "../types/index.js"; import { MeiliSearchError } from "./meilisearch-error.js"; export class MeiliSearchApiError extends MeiliSearchError { override name = "MeiliSearchApiError"; - override cause?: MeiliSearchErrorResponse; + override cause?: ResponseError; readonly response: Response; - constructor(response: Response, responseBody?: MeiliSearchErrorResponse) { + constructor(response: Response, responseBody?: ResponseError) { super( responseBody?.message ?? `${response.status}: ${response.statusText}`, ); diff --git a/src/http-requests.ts b/src/http-requests.ts index 2e3ff400e..596e280ca 100644 --- a/src/http-requests.ts +++ b/src/http-requests.ts @@ -4,7 +4,7 @@ import type { RequestOptions, MainRequestOptions, URLSearchParamsRecord, - MeiliSearchErrorResponse, + ResponseError, } from "./types/index.js"; import { PACKAGE_VERSION } from "./package-version.js"; import { @@ -251,12 +251,12 @@ export class HttpRequests { const parsedResponse = responseBody === "" ? undefined - : (JSON.parse(responseBody) as T | MeiliSearchErrorResponse); + : (JSON.parse(responseBody) as T | ResponseError); if (!response.ok) { throw new MeiliSearchApiError( response, - parsedResponse as MeiliSearchErrorResponse | undefined, + parsedResponse as ResponseError | undefined, ); } diff --git a/src/indexes.ts b/src/indexes.ts index a3cc3f020..dcb9c91fb 100644 --- a/src/indexes.ts +++ b/src/indexes.ts @@ -277,15 +277,9 @@ export class Index { /// STATS /// - /** - * Get stats of an index - * - * @returns Promise containing object with stats of the index - */ + /** {@link https://www.meilisearch.com/docs/reference/api/stats#get-stats-of-an-index} */ async getStats(): Promise { - return await this.httpRequest.get({ - path: `indexes/${this.uid}/stats`, - }); + return await this.httpRequest.get({ path: `indexes/${this.uid}/stats` }); } /// diff --git a/src/meilisearch.ts b/src/meilisearch.ts index 018e02a0f..f921cba5d 100644 --- a/src/meilisearch.ts +++ b/src/meilisearch.ts @@ -12,9 +12,9 @@ import type { IndexOptions, IndexObject, Key, - Health, + HealthResponse, Stats, - Version, + VersionResponse, KeyUpdate, IndexesQuery, IndexesResults, @@ -30,7 +30,6 @@ import type { RecordAny, RuntimeTogglableFeatures, } from "./types/index.js"; -import { ErrorStatusCode } from "./types/index.js"; import { HttpRequests } from "./http-requests.js"; import { getHttpRequestsWithEnqueuedTaskPromise, @@ -186,10 +185,7 @@ export class MeiliSearch { await this.deleteIndex(uid); return true; } catch (e) { - if ( - (e as MeiliSearchApiError)?.cause?.code === - ErrorStatusCode.INDEX_NOT_FOUND - ) { + if ((e as MeiliSearchApiError)?.cause?.code === "index_not_found") { return false; } @@ -377,13 +373,9 @@ export class MeiliSearch { /// HEALTH /// - /** - * Checks if the server is healthy, otherwise an error will be thrown. - * - * @returns Promise returning an object with health details - */ - async health(): Promise { - return await this.httpRequest.get({ path: "health" }); + /** {@link https://www.meilisearch.com/docs/reference/api/health#get-health} */ + async health(): Promise { + return await this.httpRequest.get({ path: "health" }); } /** @@ -404,56 +396,36 @@ export class MeiliSearch { /// STATS /// - /** - * Get the stats of all the database - * - * @returns Promise returning object of all the stats - */ + /** {@link https://www.meilisearch.com/docs/reference/api/stats#get-stats-of-all-indexes} */ async getStats(): Promise { - return await this.httpRequest.get({ path: "stats" }); + return await this.httpRequest.get({ path: "stats" }); } /// /// VERSION /// - /** - * Get the version of MeiliSearch - * - * @returns Promise returning object with version details - */ - async getVersion(): Promise { - return await this.httpRequest.get({ path: "version" }); + /** {@link https://www.meilisearch.com/docs/reference/api/version} */ + async getVersion(): Promise { + return await this.httpRequest.get({ path: "version" }); } /// /// DUMPS /// - /** - * Creates a dump - * - * @returns Promise returning object of the enqueued task - */ + /** {@link https://www.meilisearch.com/docs/reference/api/dump#create-a-dump} */ createDump(): EnqueuedTaskPromise { - return this.#httpRequestsWithTask.post({ - path: "dumps", - }); + return this.#httpRequestsWithTask.post({ path: "dumps" }); } /// /// SNAPSHOTS /// - /** - * Creates a snapshot - * - * @returns Promise returning object of the enqueued task - */ + /** {@link https://www.meilisearch.com/docs/reference/api/snapshots#create-a-snapshot} */ createSnapshot(): EnqueuedTaskPromise { - return this.#httpRequestsWithTask.post({ - path: "snapshots", - }); + return this.#httpRequestsWithTask.post({ path: "snapshots" }); } /// diff --git a/src/types/error.ts b/src/types/error.ts new file mode 100644 index 000000000..9a5423174 --- /dev/null +++ b/src/types/error.ts @@ -0,0 +1,225 @@ +type CamelToSnakeCase = S extends `${infer T}${infer U}` + ? `${T extends Capitalize ? "_" : ""}${Lowercase}${CamelToSnakeCase}` + : S; +type PascalToSnakeCase = CamelToSnakeCase>; + +/** + * {@link https://www.meilisearch.com/docs/reference/errors/error_codes} + * + * @see `meilisearch_types::error::Code` + */ +export type Code = PascalToSnakeCase< + | "ApiKeyAlreadyExists" + | "ApiKeyNotFound" + | "BadParameter" + | "BadRequest" + | "DatabaseSizeLimitReached" + | "DocumentNotFound" + | "DumpAlreadyProcessing" + | "DumpNotFound" + | "DumpProcessFailed" + | "DuplicateIndexFound" + | "ImmutableApiKeyActions" + | "ImmutableApiKeyCreatedAt" + | "ImmutableApiKeyExpiresAt" + | "ImmutableApiKeyIndexes" + | "ImmutableApiKeyKey" + | "ImmutableApiKeyUid" + | "ImmutableApiKeyUpdatedAt" + | "ImmutableIndexCreatedAt" + | "ImmutableIndexUid" + | "ImmutableIndexUpdatedAt" + | "IndexAlreadyExists" + | "IndexCreationFailed" + | "IndexNotFound" + | "IndexPrimaryKeyAlreadyExists" + | "IndexPrimaryKeyMultipleCandidatesFound" + | "IndexPrimaryKeyNoCandidateFound" + | "Internal" + | "InvalidApiKey" + | "InvalidApiKeyActions" + | "InvalidApiKeyDescription" + | "InvalidApiKeyExpiresAt" + | "InvalidApiKeyIndexes" + | "InvalidApiKeyLimit" + | "InvalidApiKeyName" + | "InvalidApiKeyOffset" + | "InvalidApiKeyUid" + | "InvalidContentType" + | "InvalidDocumentCsvDelimiter" + | "InvalidDocumentFields" + | "InvalidDocumentRetrieveVectors" + | "MissingDocumentFilter" + | "MissingDocumentEditionFunction" + | "InvalidDocumentFilter" + | "InvalidDocumentGeoField" + | "InvalidVectorDimensions" + | "InvalidVectorsType" + | "InvalidDocumentId" + | "InvalidDocumentIds" + | "InvalidDocumentLimit" + | "InvalidDocumentOffset" + | "InvalidSearchEmbedder" + | "InvalidSimilarEmbedder" + | "InvalidSearchHybridQuery" + | "InvalidIndexLimit" + | "InvalidIndexOffset" + | "InvalidIndexPrimaryKey" + | "InvalidIndexUid" + | "InvalidMultiSearchFacets" + | "InvalidMultiSearchFacetsByIndex" + | "InvalidMultiSearchFacetOrder" + | "InvalidMultiSearchFederated" + | "InvalidMultiSearchFederationOptions" + | "InvalidMultiSearchMaxValuesPerFacet" + | "InvalidMultiSearchMergeFacets" + | "InvalidMultiSearchQueryFacets" + | "InvalidMultiSearchQueryPagination" + | "InvalidMultiSearchQueryRankingRules" + | "InvalidMultiSearchQueryPosition" + | "InvalidMultiSearchRemote" + | "InvalidMultiSearchWeight" + | "InvalidNetworkRemotes" + | "InvalidNetworkSelf" + | "InvalidNetworkSearchApiKey" + | "InvalidNetworkUrl" + | "InvalidSearchAttributesToSearchOn" + | "InvalidSearchAttributesToCrop" + | "InvalidSearchAttributesToHighlight" + | "InvalidSimilarAttributesToRetrieve" + | "InvalidSimilarRetrieveVectors" + | "InvalidSearchAttributesToRetrieve" + | "InvalidSearchRankingScoreThreshold" + | "InvalidSimilarRankingScoreThreshold" + | "InvalidSearchRetrieveVectors" + | "InvalidSearchCropLength" + | "InvalidSearchCropMarker" + | "InvalidSearchFacets" + | "InvalidSearchSemanticRatio" + | "InvalidSearchLocales" + | "InvalidFacetSearchExhaustiveFacetCount" + | "InvalidFacetSearchFacetName" + | "InvalidSimilarId" + | "InvalidSearchFilter" + | "InvalidSimilarFilter" + | "InvalidSearchHighlightPostTag" + | "InvalidSearchHighlightPreTag" + | "InvalidSearchHitsPerPage" + | "InvalidSimilarLimit" + | "InvalidSearchLimit" + | "InvalidSearchMatchingStrategy" + | "InvalidSimilarOffset" + | "InvalidSearchOffset" + | "InvalidSearchPage" + | "InvalidSearchQ" + | "InvalidFacetSearchQuery" + | "InvalidFacetSearchName" + | "FacetSearchDisabled" + | "InvalidSearchVector" + | "InvalidSearchShowMatchesPosition" + | "InvalidSearchShowRankingScore" + | "InvalidSimilarShowRankingScore" + | "InvalidSearchShowRankingScoreDetails" + | "InvalidSimilarShowRankingScoreDetails" + | "InvalidSearchSort" + | "InvalidSearchDistinct" + | "InvalidSettingsDisplayedAttributes" + | "InvalidSettingsDistinctAttribute" + | "InvalidSettingsProximityPrecision" + | "InvalidSettingsFacetSearch" + | "InvalidSettingsPrefixSearch" + | "InvalidSettingsFaceting" + | "InvalidSettingsFilterableAttributes" + | "InvalidSettingsPagination" + | "InvalidSettingsSearchCutoffMs" + | "InvalidSettingsEmbedders" + | "InvalidSettingsRankingRules" + | "InvalidSettingsSearchableAttributes" + | "InvalidSettingsSortableAttributes" + | "InvalidSettingsStopWords" + | "InvalidSettingsNonSeparatorTokens" + | "InvalidSettingsSeparatorTokens" + | "InvalidSettingsDictionary" + | "InvalidSettingsSynonyms" + | "InvalidSettingsTypoTolerance" + | "InvalidSettingsLocalizedAttributes" + | "InvalidState" + | "InvalidStoreFile" + | "InvalidSwapDuplicateIndexFound" + | "InvalidSwapIndexes" + | "InvalidTaskAfterEnqueuedAt" + | "InvalidTaskAfterFinishedAt" + | "InvalidTaskAfterStartedAt" + | "InvalidTaskBeforeEnqueuedAt" + | "InvalidTaskBeforeFinishedAt" + | "InvalidTaskBeforeStartedAt" + | "InvalidTaskCanceledBy" + | "InvalidTaskFrom" + | "InvalidTaskLimit" + | "InvalidTaskReverse" + | "InvalidTaskStatuses" + | "InvalidTaskTypes" + | "InvalidTaskUids" + | "InvalidBatchUids" + | "IoError" + | "FeatureNotEnabled" + | "MalformedPayload" + | "MaxFieldsLimitExceeded" + | "MissingApiKeyActions" + | "MissingApiKeyExpiresAt" + | "MissingApiKeyIndexes" + | "MissingAuthorizationHeader" + | "MissingContentType" + | "MissingDocumentId" + | "MissingFacetSearchFacetName" + | "MissingIndexUid" + | "MissingMasterKey" + | "MissingNetworkUrl" + | "MissingPayload" + | "MissingSearchHybrid" + | "MissingSwapIndexes" + | "MissingTaskFilters" + | "NoSpaceLeftOnDevice" + | "PayloadTooLarge" + | "RemoteBadResponse" + | "RemoteBadRequest" + | "RemoteCouldNotSendRequest" + | "RemoteInvalidApiKey" + | "RemoteRemoteError" + | "RemoteTimeout" + | "TooManySearchRequests" + | "TaskNotFound" + | "TaskFileNotFound" + | "BatchNotFound" + | "TooManyOpenFiles" + | "TooManyVectors" + | "UnretrievableDocument" + | "UnretrievableErrorCode" + | "UnsupportedMediaType" + | "VectorEmbeddingError" + | "NotFoundSimilarId" + | "InvalidDocumentEditionContext" + | "InvalidDocumentEditionFunctionFilter" + | "EditDocumentsByFunctionError" +>; + +/** + * {@link https://www.meilisearch.com/docs/reference/errors/overview#errors} + * + * @see `meilisearch_types::error::ErrorType` + */ +export type ErrorType = PascalToSnakeCase< + "Internal" | "InvalidRequest" | "Auth" | "System" +>; + +/** + * {@link https://www.meilisearch.com/docs/reference/errors/overview#error-format} + * + * @see `meilisearch_types::error::ResponseError` + */ +export type ResponseError = { + message: string; + code: Code; + type: ErrorType; + link: string; +}; diff --git a/src/types/health.ts b/src/types/health.ts new file mode 100644 index 000000000..abcb09e8b --- /dev/null +++ b/src/types/health.ts @@ -0,0 +1,9 @@ +/** @see `meilisearch::routes::HealthStatus` */ +export type HealthStatus = "available"; + +/** + * {@link https://www.meilisearch.com/docs/reference/api/health#response-200-ok} + * + * @see `meilisearch::routes::HealthResponse` + */ +export type HealthResponse = { status: HealthStatus }; diff --git a/src/types/index.ts b/src/types/index.ts index 8aaa23dba..8b50606bb 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -1,4 +1,8 @@ +export * from "./error.js"; export * from "./experimental-features.js"; +export * from "./health.js"; +export * from "./stats.js"; export * from "./task_and_batch.js"; export * from "./token.js"; export * from "./types.js"; +export * from "./version.js"; diff --git a/src/types/shared.ts b/src/types/shared.ts index d475d6948..e0cc1d3a4 100644 --- a/src/types/shared.ts +++ b/src/types/shared.ts @@ -1,5 +1,3 @@ -import type { RecordAny } from "./types.js"; - export type CursorResults = { results: T[]; limit: number; @@ -7,12 +5,3 @@ export type CursorResults = { next: number; total: number; }; - -export type NonNullableDeepRecordValues = { - // eslint-disable-next-line @typescript-eslint/no-explicit-any - [P in keyof T]: T[P] extends any[] - ? Array> - : T[P] extends RecordAny - ? NonNullableDeepRecordValues - : NonNullable; -}; diff --git a/src/types/stats.ts b/src/types/stats.ts new file mode 100644 index 000000000..3fa25f91f --- /dev/null +++ b/src/types/stats.ts @@ -0,0 +1,24 @@ +import type { FieldDistribution } from "./types.js"; + +/** @see `meilisearch::routes::indexes::IndexStats` */ +export type IndexStats = { + numberOfDocuments: number; + rawDocumentDbSize: number; + avgDocumentSize: number; + isIndexing: boolean; + numberOfEmbeddings?: number; + numberOfEmbeddedDocuments?: number; + fieldDistribution: FieldDistribution; +}; + +/** + * {@link https://www.meilisearch.com/docs/reference/api/stats#stats-object} + * + * @see `meilisearch::routes::Stats` + */ +export type Stats = { + databaseSize: number; + usedDatabaseSize: number; + lastUpdate: string; + indexes: Record; +}; diff --git a/src/types/task_and_batch.ts b/src/types/task_and_batch.ts index ea61fbea9..b954f96fe 100644 --- a/src/types/task_and_batch.ts +++ b/src/types/task_and_batch.ts @@ -1,6 +1,6 @@ import type { Settings } from "./types.js"; import type { CursorResults } from "./shared.js"; -import type { MeiliSearchErrorResponse } from "./types.js"; +import type { ResponseError } from "./error.js"; /** Options for awaiting {@link EnqueuedTask}. */ export type WaitOptions = { @@ -124,7 +124,7 @@ export type Task = Omit & { batchUid: number | null; canceledBy: number | null; details?: TaskDetails; - error: MeiliSearchErrorResponse | null; + error: ResponseError | null; duration: string | null; startedAt: string | null; finishedAt: string | null; diff --git a/src/types/types.ts b/src/types/types.ts index 91d29f4b5..58ee3961a 100644 --- a/src/types/types.ts +++ b/src/types/types.ts @@ -430,9 +430,7 @@ export type MultiSearchResponseOrSearchResponse< ? SearchResponse : MultiSearchResponse; -export type FieldDistribution = { - [field: string]: number; -}; +export type FieldDistribution = Record; export type SearchSimilarDocumentsParams = { id: string | number; @@ -666,37 +664,6 @@ export type Settings = { prefixSearch?: "indexingTime" | "disabled"; }; -/* - *** HEALTH - */ - -export type Health = { - status: "available"; -}; - -/* - *** STATS - */ - -export type IndexStats = { - numberOfDocuments: number; - isIndexing: boolean; - fieldDistribution: FieldDistribution; - numberOfEmbeddedDocuments: number; - numberOfEmbeddings: number; - rawDocumentDbSize: number; - avgDocumentSize: number; -}; - -export type Stats = { - databaseSize: number; - usedDatabaseSize: number; - lastUpdate: string; - indexes: { - [index: string]: IndexStats; - }; -}; - /* ** Keys */ @@ -730,397 +697,3 @@ export type KeyUpdate = { export type KeysQuery = ResourceQuery & {}; export type KeysResults = ResourceResults & {}; - -/* - ** version - */ -export type Version = { - commitSha: string; - commitDate: string; - pkgVersion: string; -}; - -/* - ** ERROR HANDLER - */ - -export interface FetchError extends Error { - type: string; - errno: string; - code: string; -} - -export type MeiliSearchErrorResponse = { - message: string; - // https://www.meilisearch.com/docs/reference/errors/error_codes - code: string; - // 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 usefulness 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", - - /** @see https://www.meilisearch.com/docs/reference/errors/error_codes#missing_index_uid */ - MISSING_INDEX_UID: "missing_index_uid", - - /** @see https://www.meilisearch.com/docs/reference/errors/error_codes#index_already_exists */ - INDEX_ALREADY_EXISTS: "index_already_exists", - - /** @see https://www.meilisearch.com/docs/reference/errors/error_codes#index_not_found */ - INDEX_NOT_FOUND: "index_not_found", - - /** @see https://www.meilisearch.com/docs/reference/errors/error_codes#invalid_index_uid */ - INVALID_INDEX_UID: "invalid_index_uid", - - /** @see https://www.meilisearch.com/docs/reference/errors/error_codes#index_not_accessible */ - INDEX_NOT_ACCESSIBLE: "index_not_accessible", - - /** @see https://www.meilisearch.com/docs/reference/errors/error_codes#invalid_index_offset */ - INVALID_INDEX_OFFSET: "invalid_index_offset", - - /** @see https://www.meilisearch.com/docs/reference/errors/error_codes#invalid_index_limit */ - INVALID_INDEX_LIMIT: "invalid_index_limit", - - /** @see https://www.meilisearch.com/docs/reference/errors/error_codes#invalid_state */ - INVALID_STATE: "invalid_state", - - /** @see https://www.meilisearch.com/docs/reference/errors/error_codes#primary_key_inference_failed */ - PRIMARY_KEY_INFERENCE_FAILED: "primary_key_inference_failed", - - /** @see https://www.meilisearch.com/docs/reference/errors/error_codes#index_primary_key_already_exists */ - INDEX_PRIMARY_KEY_ALREADY_EXISTS: "index_primary_key_already_exists", - - /** @see https://www.meilisearch.com/docs/reference/errors/error_codes#invalid_index_primary_key */ - INVALID_INDEX_PRIMARY_KEY: "invalid_index_primary_key", - - /** @see https://www.meilisearch.com/docs/reference/errors/error_codes#max_fields_limit_exceeded */ - DOCUMENTS_FIELDS_LIMIT_REACHED: "document_fields_limit_reached", - - /** @see https://www.meilisearch.com/docs/reference/errors/error_codes#missing_document_id */ - MISSING_DOCUMENT_ID: "missing_document_id", - - /** @see https://www.meilisearch.com/docs/reference/errors/error_codes#missing_document_id */ - INVALID_DOCUMENT_ID: "invalid_document_id", - - /** @see https://www.meilisearch.com/docs/reference/errors/error_codes#invalid_content_type */ - INVALID_CONTENT_TYPE: "invalid_content_type", - - /** @see https://www.meilisearch.com/docs/reference/errors/error_codes#missing_content_type */ - MISSING_CONTENT_TYPE: "missing_content_type", - - /** @see https://www.meilisearch.com/docs/reference/errors/error_codes#invalid_document_fields */ - INVALID_DOCUMENT_FIELDS: "invalid_document_fields", - - /** @see https://www.meilisearch.com/docs/reference/errors/error_codes#invalid_document_limit */ - INVALID_DOCUMENT_LIMIT: "invalid_document_limit", - - /** @see https://www.meilisearch.com/docs/reference/errors/error_codes#invalid_document_offset */ - INVALID_DOCUMENT_OFFSET: "invalid_document_offset", - - /** @see https://www.meilisearch.com/docs/reference/errors/error_codes#invalid_document_filter */ - INVALID_DOCUMENT_FILTER: "invalid_document_filter", - - /** @see https://www.meilisearch.com/docs/reference/errors/error_codes#missing_document_filter */ - MISSING_DOCUMENT_FILTER: "missing_document_filter", - - /** @see https://www.meilisearch.com/docs/reference/errors/error_codes#invalid_document_vectors_field */ - INVALID_DOCUMENT_VECTORS_FIELD: "invalid_document_vectors_field", - - /** @see https://www.meilisearch.com/docs/reference/errors/error_codes#payload_too_large */ - PAYLOAD_TOO_LARGE: "payload_too_large", - - /** @see https://www.meilisearch.com/docs/reference/errors/error_codes#missing_payload */ - MISSING_PAYLOAD: "missing_payload", - - /** @see https://www.meilisearch.com/docs/reference/errors/error_codes#malformed_payload */ - MALFORMED_PAYLOAD: "malformed_payload", - - /** @see https://www.meilisearch.com/docs/reference/errors/error_codes#no_space_left_on_device */ - NO_SPACE_LEFT_ON_DEVICE: "no_space_left_on_device", - - /** @see https://www.meilisearch.com/docs/reference/errors/error_codes#invalid_store_file */ - INVALID_STORE_FILE: "invalid_store_file", - - /** @see https://www.meilisearch.com/docs/reference/errors/error_codes#invalid_ranking_rules */ - INVALID_RANKING_RULES: "missing_document_id", - - /** @see https://www.meilisearch.com/docs/reference/errors/error_codes#invalid_request */ - INVALID_REQUEST: "invalid_request", - - /** @see https://www.meilisearch.com/docs/reference/errors/error_codes#invalid_document_geo_field */ - INVALID_DOCUMENT_GEO_FIELD: "invalid_document_geo_field", - - /** @see https://www.meilisearch.com/docs/reference/errors/error_codes#invalid_search_q */ - INVALID_SEARCH_Q: "invalid_search_q", - - /** @see https://www.meilisearch.com/docs/reference/errors/error_codes#invalid_search_offset */ - INVALID_SEARCH_OFFSET: "invalid_search_offset", - - /** @see https://www.meilisearch.com/docs/reference/errors/error_codes#invalid_search_limit */ - INVALID_SEARCH_LIMIT: "invalid_search_limit", - - /** @see https://www.meilisearch.com/docs/reference/errors/error_codes#invalid_search_page */ - INVALID_SEARCH_PAGE: "invalid_search_page", - - /** @see https://www.meilisearch.com/docs/reference/errors/error_codes#invalid_search_hits_per_page */ - INVALID_SEARCH_HITS_PER_PAGE: "invalid_search_hits_per_page", - - /** @see https://www.meilisearch.com/docs/reference/errors/error_codes#invalid_search_attributes_to_retrieve */ - INVALID_SEARCH_ATTRIBUTES_TO_RETRIEVE: - "invalid_search_attributes_to_retrieve", - - /** @see https://www.meilisearch.com/docs/reference/errors/error_codes#invalid_search_attributes_to_crop */ - INVALID_SEARCH_ATTRIBUTES_TO_CROP: "invalid_search_attributes_to_crop", - - /** @see https://www.meilisearch.com/docs/reference/errors/error_codes#invalid_search_crop_length */ - INVALID_SEARCH_CROP_LENGTH: "invalid_search_crop_length", - - /** @see https://www.meilisearch.com/docs/reference/errors/error_codes#invalid_search_attributes_to_highlight */ - INVALID_SEARCH_ATTRIBUTES_TO_HIGHLIGHT: - "invalid_search_attributes_to_highlight", - - /** @see https://www.meilisearch.com/docs/reference/errors/error_codes#invalid_search_show_matches_position */ - INVALID_SEARCH_SHOW_MATCHES_POSITION: "invalid_search_show_matches_position", - - /** @see https://www.meilisearch.com/docs/reference/errors/error_codes#invalid_search_filter */ - INVALID_SEARCH_FILTER: "invalid_search_filter", - - /** @see https://www.meilisearch.com/docs/reference/errors/error_codes#invalid_search_sort */ - INVALID_SEARCH_SORT: "invalid_search_sort", - - /** @see https://www.meilisearch.com/docs/reference/errors/error_codes#invalid_search_facets */ - INVALID_SEARCH_FACETS: "invalid_search_facets", - - /** @see https://www.meilisearch.com/docs/reference/errors/error_codes#invalid_search_highlight_pre_tag */ - INVALID_SEARCH_HIGHLIGHT_PRE_TAG: "invalid_search_highlight_pre_tag", - - /** @see https://www.meilisearch.com/docs/reference/errors/error_codes#invalid_search_highlight_post_tag */ - INVALID_SEARCH_HIGHLIGHT_POST_TAG: "invalid_search_highlight_post_tag", - - /** @see https://www.meilisearch.com/docs/reference/errors/error_codes#invalid_search_crop_marker */ - INVALID_SEARCH_CROP_MARKER: "invalid_search_crop_marker", - - /** @see https://www.meilisearch.com/docs/reference/errors/error_codes#invalid_search_matching_strategy */ - INVALID_SEARCH_MATCHING_STRATEGY: "invalid_search_matching_strategy", - - /** @see https://www.meilisearch.com/docs/reference/errors/error_codes#invalid_search_vector */ - INVALID_SEARCH_VECTOR: "invalid_search_vector", - - /** @see https://www.meilisearch.com/docs/reference/errors/error_codes#invalid_search_attributes_to_search_on */ - INVALID_SEARCH_ATTRIBUTES_TO_SEARCH_ON: - "invalid_search_attributes_to_search_on", - - /** @see https://www.meilisearch.com/docs/reference/errors/error_codes#bad_request */ - BAD_REQUEST: "bad_request", - - /** @see https://www.meilisearch.com/docs/reference/errors/error_codes#document_not_found */ - DOCUMENT_NOT_FOUND: "document_not_found", - - /** @see https://www.meilisearch.com/docs/reference/errors/error_codes#internal */ - INTERNAL: "internal", - - /** @see https://www.meilisearch.com/docs/reference/errors/error_codes#invalid_api_key */ - INVALID_API_KEY: "invalid_api_key", - - /** @see https://www.meilisearch.com/docs/reference/errors/error_codes#invalid_api_key_description */ - INVALID_API_KEY_DESCRIPTION: "invalid_api_key_description", - - /** @see https://www.meilisearch.com/docs/reference/errors/error_codes#invalid_api_key_actions */ - INVALID_API_KEY_ACTIONS: "invalid_api_key_actions", - - /** @see https://www.meilisearch.com/docs/reference/errors/error_codes#invalid_api_key_indexes */ - INVALID_API_KEY_INDEXES: "invalid_api_key_indexes", - - /** @see https://www.meilisearch.com/docs/reference/errors/error_codes#invalid_api_key_expires_at */ - INVALID_API_KEY_EXPIRES_AT: "invalid_api_key_expires_at", - - /** @see https://www.meilisearch.com/docs/reference/errors/error_codes#api_key_not_found */ - API_KEY_NOT_FOUND: "api_key_not_found", - - /** @see https://www.meilisearch.com/docs/reference/errors/error_codes#immutable_api_key_uid */ - IMMUTABLE_API_KEY_UID: "immutable_api_key_uid", - - /** @see https://www.meilisearch.com/docs/reference/errors/error_codes#immutable_api_key_actions */ - IMMUTABLE_API_KEY_ACTIONS: "immutable_api_key_actions", - - /** @see https://www.meilisearch.com/docs/reference/errors/error_codes#immutable_api_key_indexes */ - IMMUTABLE_API_KEY_INDEXES: "immutable_api_key_indexes", - - /** @see https://www.meilisearch.com/docs/reference/errors/error_codes#immutable_api_key_expires_at */ - IMMUTABLE_API_KEY_EXPIRES_AT: "immutable_api_key_expires_at", - - /** @see https://www.meilisearch.com/docs/reference/errors/error_codes#immutable_api_key_created_at */ - IMMUTABLE_API_KEY_CREATED_AT: "immutable_api_key_created_at", - - /** @see https://www.meilisearch.com/docs/reference/errors/error_codes#immutable_api_key_updated_at */ - IMMUTABLE_API_KEY_UPDATED_AT: "immutable_api_key_updated_at", - - /** @see https://www.meilisearch.com/docs/reference/errors/error_codes#missing_authorization_header */ - MISSING_AUTHORIZATION_HEADER: "missing_authorization_header", - - /** @see https://www.meilisearch.com/docs/reference/errors/error_codes#unretrievable_document */ - UNRETRIEVABLE_DOCUMENT: "unretrievable_document", - - /** @see https://www.meilisearch.com/docs/reference/errors/error_codes#database_size_limit_reached */ - MAX_DATABASE_SIZE_LIMIT_REACHED: "database_size_limit_reached", - - /** @see https://www.meilisearch.com/docs/reference/errors/error_codes#task_not_found */ - TASK_NOT_FOUND: "task_not_found", - - /** @see https://www.meilisearch.com/docs/reference/errors/error_codes#dump_process_failed */ - DUMP_PROCESS_FAILED: "dump_process_failed", - - /** @see https://www.meilisearch.com/docs/reference/errors/error_codes#dump_not_found */ - DUMP_NOT_FOUND: "dump_not_found", - - /** @see https://www.meilisearch.com/docs/reference/errors/error_codes#invalid_swap_duplicate_index_found */ - INVALID_SWAP_DUPLICATE_INDEX_FOUND: "invalid_swap_duplicate_index_found", - - /** @see https://www.meilisearch.com/docs/reference/errors/error_codes#invalid_swap_indexes */ - INVALID_SWAP_INDEXES: "invalid_swap_indexes", - - /** @see https://www.meilisearch.com/docs/reference/errors/error_codes#missing_swap_indexes */ - MISSING_SWAP_INDEXES: "missing_swap_indexes", - - /** @see https://www.meilisearch.com/docs/reference/errors/error_codes#missing_master_key */ - MISSING_MASTER_KEY: "missing_master_key", - - /** @see https://www.meilisearch.com/docs/reference/errors/error_codes#invalid_task_types */ - INVALID_TASK_TYPES: "invalid_task_types", - - /** @see https://www.meilisearch.com/docs/reference/errors/error_codes#invalid_task_uids */ - INVALID_TASK_UIDS: "invalid_task_uids", - - /** @see https://www.meilisearch.com/docs/reference/errors/error_codes#invalid_task_statuses */ - INVALID_TASK_STATUSES: "invalid_task_statuses", - - /** @see https://www.meilisearch.com/docs/reference/errors/error_codes#invalid_task_limit */ - INVALID_TASK_LIMIT: "invalid_task_limit", - - /** @see https://www.meilisearch.com/docs/reference/errors/error_codes#invalid_task_from */ - INVALID_TASK_FROM: "invalid_task_from", - - /** @see https://www.meilisearch.com/docs/reference/errors/error_codes#invalid_task_canceled_by */ - INVALID_TASK_CANCELED_BY: "invalid_task_canceled_by", - - /** @see https://www.meilisearch.com/docs/reference/errors/error_codes#missing_task_filters */ - MISSING_TASK_FILTERS: "missing_task_filters", - - /** @see https://www.meilisearch.com/docs/reference/errors/error_codes#too_many_open_files */ - TOO_MANY_OPEN_FILES: "too_many_open_files", - - /** @see https://www.meilisearch.com/docs/reference/errors/error_codes#io_error */ - IO_ERROR: "io_error", - - /** @see https://www.meilisearch.com/docs/reference/errors/error_codes#invalid_task_index_uids */ - INVALID_TASK_INDEX_UIDS: "invalid_task_index_uids", - - /** @see https://www.meilisearch.com/docs/reference/errors/error_codes#immutable_index_uid */ - IMMUTABLE_INDEX_UID: "immutable_index_uid", - - /** @see https://www.meilisearch.com/docs/reference/errors/error_codes#immutable_index_created_at */ - IMMUTABLE_INDEX_CREATED_AT: "immutable_index_created_at", - - /** @see https://www.meilisearch.com/docs/reference/errors/error_codes#immutable_index_updated_at */ - IMMUTABLE_INDEX_UPDATED_AT: "immutable_index_updated_at", - - /** @see https://www.meilisearch.com/docs/reference/errors/error_codes#invalid_settings_displayed_attributes */ - INVALID_SETTINGS_DISPLAYED_ATTRIBUTES: - "invalid_settings_displayed_attributes", - - /** @see https://www.meilisearch.com/docs/reference/errors/error_codes#invalid_settings_searchable_attributes */ - INVALID_SETTINGS_SEARCHABLE_ATTRIBUTES: - "invalid_settings_searchable_attributes", - - /** @see https://www.meilisearch.com/docs/reference/errors/error_codes#invalid_settings_filterable_attributes */ - INVALID_SETTINGS_FILTERABLE_ATTRIBUTES: - "invalid_settings_filterable_attributes", - - /** @see https://www.meilisearch.com/docs/reference/errors/error_codes#invalid_settings_sortable_attributes */ - INVALID_SETTINGS_SORTABLE_ATTRIBUTES: "invalid_settings_sortable_attributes", - - /** @see https://www.meilisearch.com/docs/reference/errors/error_codes#invalid_settings_ranking_rules */ - INVALID_SETTINGS_RANKING_RULES: "invalid_settings_ranking_rules", - - /** @see https://www.meilisearch.com/docs/reference/errors/error_codes#invalid_settings_stop_words */ - INVALID_SETTINGS_STOP_WORDS: "invalid_settings_stop_words", - - /** @see https://www.meilisearch.com/docs/reference/errors/error_codes#invalid_settings_synonyms */ - INVALID_SETTINGS_SYNONYMS: "invalid_settings_synonyms", - - /** @see https://www.meilisearch.com/docs/reference/errors/error_codes#invalid_settings_distinct_attribute */ - INVALID_SETTINGS_DISTINCT_ATTRIBUTE: "invalid_settings_distinct_attribute", - - /** @see https://www.meilisearch.com/docs/reference/errors/error_codes#invalid_settings_typo_tolerance */ - INVALID_SETTINGS_TYPO_TOLERANCE: "invalid_settings_typo_tolerance", - - /** @see https://www.meilisearch.com/docs/reference/errors/error_codes#invalid_settings_faceting */ - INVALID_SETTINGS_FACETING: "invalid_settings_faceting", - - /** @see https://www.meilisearch.com/docs/reference/errors/error_codes#invalid_settings_pagination */ - INVALID_SETTINGS_PAGINATION: "invalid_settings_pagination", - - /** @see https://www.meilisearch.com/docs/reference/errors/error_codes#invalid_settings_search_cutoff_ms */ - INVALID_SETTINGS_SEARCH_CUTOFF_MS: "invalid_settings_search_cutoff_ms", - - /** @see https://www.meilisearch.com/docs/reference/errors/error_codes#invalid_settings_search_cutoff_ms */ - INVALID_SETTINGS_LOCALIZED_ATTRIBUTES: - "invalid_settings_localized_attributes", - - /** @see https://www.meilisearch.com/docs/reference/errors/error_codes#invalid_task_before_enqueued_at */ - INVALID_TASK_BEFORE_ENQUEUED_AT: "invalid_task_before_enqueued_at", - - /** @see https://www.meilisearch.com/docs/reference/errors/error_codes#invalid_task_after_enqueued_at */ - INVALID_TASK_AFTER_ENQUEUED_AT: "invalid_task_after_enqueued_at", - - /** @see https://www.meilisearch.com/docs/reference/errors/error_codes#invalid_task_before_started_at */ - INVALID_TASK_BEFORE_STARTED_AT: "invalid_task_before_started_at", - - /** @see https://www.meilisearch.com/docs/reference/errors/error_codes#invalid_task_after_started_at */ - INVALID_TASK_AFTER_STARTED_AT: "invalid_task_after_started_at", - - /** @see https://www.meilisearch.com/docs/reference/errors/error_codes#invalid_task_before_finished_at */ - INVALID_TASK_BEFORE_FINISHED_AT: "invalid_task_before_finished_at", - - /** @see https://www.meilisearch.com/docs/reference/errors/error_codes#invalid_task_after_finished_at */ - INVALID_TASK_AFTER_FINISHED_AT: "invalid_task_after_finished_at", - - /** @see https://www.meilisearch.com/docs/reference/errors/error_codes#missing_api_key_actions */ - MISSING_API_KEY_ACTIONS: "missing_api_key_actions", - - /** @see https://www.meilisearch.com/docs/reference/errors/error_codes#missing_api_key_indexes */ - MISSING_API_KEY_INDEXES: "missing_api_key_indexes", - - /** @see https://www.meilisearch.com/docs/reference/errors/error_codes#missing_api_key_expires_at */ - MISSING_API_KEY_EXPIRES_AT: "missing_api_key_expires_at", - - /** @see https://www.meilisearch.com/docs/reference/errors/error_codes#invalid_api_key_limit */ - INVALID_API_KEY_LIMIT: "invalid_api_key_limit", - - /** @see https://www.meilisearch.com/docs/reference/errors/error_codes#invalid_api_key_offset */ - INVALID_API_KEY_OFFSET: "invalid_api_key_offset", - - /** @see https://www.meilisearch.com/docs/reference/errors/error_codes#invalid_facet_search_facet_name */ - INVALID_FACET_SEARCH_FACET_NAME: "invalid_facet_search_facet_name", - - /** @see https://www.meilisearch.com/docs/reference/errors/error_codes#missing_facet_search_facet_name */ - MISSING_FACET_SEARCH_FACET_NAME: "missing_facet_search_facet_name", - - /** @see https://www.meilisearch.com/docs/reference/errors/error_codes#invalid_facet_search_facet_query */ - INVALID_FACET_SEARCH_FACET_QUERY: "invalid_facet_search_facet_query", - - /** @see https://www.meilisearch.com/docs/reference/errors/error_codes#invalid_search_ranking_score_threshold */ - INVALID_SEARCH_RANKING_SCORE_THRESHOLD: - "invalid_search_ranking_score_threshold", - - /** @see https://www.meilisearch.com/docs/reference/errors/error_codes#invalid_similar_ranking_score_threshold */ - INVALID_SIMILAR_RANKING_SCORE_THRESHOLD: - "invalid_similar_ranking_score_threshold", -}; - -export type ErrorStatusCode = - (typeof ErrorStatusCode)[keyof typeof ErrorStatusCode]; diff --git a/src/types/version.ts b/src/types/version.ts new file mode 100644 index 000000000..33403c6f0 --- /dev/null +++ b/src/types/version.ts @@ -0,0 +1,10 @@ +/** + * {@link https://www.meilisearch.com/docs/reference/api/version#version-object} + * + * @see `meilisearch::routes::VersionResponse` + */ +export type VersionResponse = { + commitSha: string; + commitDate: string; + pkgVersion: string; +}; diff --git a/tests/client.test.ts b/tests/client.test.ts index c1b5b5926..fd0001e17 100644 --- a/tests/client.test.ts +++ b/tests/client.test.ts @@ -8,8 +8,8 @@ import { type MockInstance, beforeAll, } from "vitest"; -import type { Health, Version, Stats, IndexSwap } from "../src/index.js"; -import { ErrorStatusCode, MeiliSearchRequestError } from "../src/index.js"; +import type { IndexSwap } from "../src/index.js"; +import { MeiliSearchRequestError } from "../src/index.js"; import { PACKAGE_VERSION } from "../src/package-version.js"; import { clearAllIndexes, @@ -436,7 +436,7 @@ describe.each([{ permission: "Master" }, { permission: "Admin" }])( await expect(client.getIndex("does_not_exist")).rejects.toHaveProperty( "cause.code", - ErrorStatusCode.INDEX_NOT_FOUND, + "index_not_found", ); }); @@ -506,7 +506,7 @@ describe.each([{ permission: "Master" }, { permission: "Admin" }])( const index = client.index(indexPk.uid); await expect(index.getRawInfo()).rejects.toHaveProperty( "cause.code", - ErrorStatusCode.INDEX_NOT_FOUND, + "index_not_found", ); }); @@ -546,9 +546,7 @@ describe.each([{ permission: "Master" }, { permission: "Admin" }])( const resolvedTask = await client.swapIndexes(swaps).waitTask(); expect(resolvedTask.type).toEqual("indexSwap"); - expect(resolvedTask.error?.code).toEqual( - ErrorStatusCode.INDEX_NOT_FOUND, - ); + expect(resolvedTask.error?.code).toEqual("index_not_found"); expect(resolvedTask.details!.swaps).toEqual(swaps); }); @@ -560,7 +558,7 @@ describe.each([{ permission: "Master" }, { permission: "Admin" }])( await expect(client.swapIndexes(swaps)).rejects.toHaveProperty( "cause.code", - ErrorStatusCode.INVALID_SWAP_DUPLICATE_INDEX_FOUND, + "invalid_swap_duplicate_index_found", ); }); }); @@ -568,7 +566,7 @@ describe.each([{ permission: "Master" }, { permission: "Admin" }])( describe("Test on base routes", () => { test(`${permission} key: get health`, async () => { const client = await getClient(permission); - const response: Health = await client.health(); + const response = await client.health(); expect(response).toHaveProperty( "status", expect.stringMatching("available"), @@ -589,7 +587,7 @@ describe.each([{ permission: "Master" }, { permission: "Admin" }])( test(`${permission} key: get version`, async () => { const client = await getClient(permission); - const response: Version = await client.getVersion(); + const response = await client.getVersion(); expect(response).toHaveProperty("commitSha", expect.any(String)); expect(response).toHaveProperty("commitDate", expect.any(String)); expect(response).toHaveProperty("pkgVersion", expect.any(String)); @@ -597,7 +595,7 @@ describe.each([{ permission: "Master" }, { permission: "Admin" }])( test(`${permission} key: get /stats information`, async () => { const client = await getClient(permission); - const response: Stats = await client.getStats(); + const response = await client.getStats(); expect(response).toHaveProperty("databaseSize", expect.any(Number)); expect(response).toHaveProperty("usedDatabaseSize", expect.any(Number)); expect(response).toHaveProperty("lastUpdate"); // TODO: Could be null, find out why @@ -619,7 +617,7 @@ describe.each([{ permission: "Search" }])( const client = await getClient(permission); await expect(client.getIndexes()).rejects.toHaveProperty( "cause.code", - ErrorStatusCode.INVALID_API_KEY, + "invalid_api_key", ); }); @@ -629,14 +627,14 @@ describe.each([{ permission: "Search" }])( client.createIndex(indexPk.uid, { primaryKey: indexPk.primaryKey, }), - ).rejects.toHaveProperty("cause.code", ErrorStatusCode.INVALID_API_KEY); + ).rejects.toHaveProperty("cause.code", "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( "cause.code", - ErrorStatusCode.INVALID_API_KEY, + "invalid_api_key", ); }); @@ -644,7 +642,7 @@ describe.each([{ permission: "Search" }])( const client = await getClient(permission); await expect(client.deleteIndex(indexPk.uid)).rejects.toHaveProperty( "cause.code", - ErrorStatusCode.INVALID_API_KEY, + "invalid_api_key", ); }); @@ -654,14 +652,14 @@ describe.each([{ permission: "Search" }])( client.updateIndex(indexPk.uid, { primaryKey: indexPk.primaryKey, }), - ).rejects.toHaveProperty("cause.code", ErrorStatusCode.INVALID_API_KEY); + ).rejects.toHaveProperty("cause.code", "invalid_api_key"); }); }); describe("Test on misc client methods", () => { test(`${permission} key: get health`, async () => { const client = await getClient(permission); - const response: Health = await client.health(); + const response = await client.health(); expect(response).toHaveProperty( "status", expect.stringMatching("available"), @@ -672,7 +670,7 @@ describe.each([{ permission: "Search" }])( const client = await getClient(permission); await expect(client.getVersion()).rejects.toHaveProperty( "cause.code", - ErrorStatusCode.INVALID_API_KEY, + "invalid_api_key", ); }); @@ -680,7 +678,7 @@ describe.each([{ permission: "Search" }])( const client = await getClient(permission); await expect(client.getStats()).rejects.toHaveProperty( "cause.code", - ErrorStatusCode.INVALID_API_KEY, + "invalid_api_key", ); }); }); @@ -699,7 +697,7 @@ describe.each([{ permission: "No" }])( const client = await getClient(permission); await expect(client.getIndexes()).rejects.toHaveProperty( "cause.code", - ErrorStatusCode.MISSING_AUTHORIZATION_HEADER, + "missing_authorization_header", ); }); @@ -709,17 +707,14 @@ describe.each([{ permission: "No" }])( client.createIndex(indexPk.uid, { primaryKey: indexPk.primaryKey, }), - ).rejects.toHaveProperty( - "cause.code", - ErrorStatusCode.MISSING_AUTHORIZATION_HEADER, - ); + ).rejects.toHaveProperty("cause.code", "missing_authorization_header"); }); 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( "cause.code", - ErrorStatusCode.MISSING_AUTHORIZATION_HEADER, + "missing_authorization_header", ); }); @@ -727,7 +722,7 @@ describe.each([{ permission: "No" }])( const client = await getClient(permission); await expect(client.deleteIndex(indexPk.uid)).rejects.toHaveProperty( "cause.code", - ErrorStatusCode.MISSING_AUTHORIZATION_HEADER, + "missing_authorization_header", ); }); @@ -737,17 +732,14 @@ describe.each([{ permission: "No" }])( client.updateIndex(indexPk.uid, { primaryKey: indexPk.primaryKey, }), - ).rejects.toHaveProperty( - "cause.code", - ErrorStatusCode.MISSING_AUTHORIZATION_HEADER, - ); + ).rejects.toHaveProperty("cause.code", "missing_authorization_header"); }); }); describe("Test on misc client methods", () => { test(`${permission} key: get health`, async () => { const client = await getClient(permission); - const response: Health = await client.health(); + const response = await client.health(); expect(response).toHaveProperty( "status", expect.stringMatching("available"), @@ -758,7 +750,7 @@ describe.each([{ permission: "No" }])( const client = await getClient(permission); await expect(client.getVersion()).rejects.toHaveProperty( "cause.code", - ErrorStatusCode.MISSING_AUTHORIZATION_HEADER, + "missing_authorization_header", ); }); @@ -766,7 +758,7 @@ describe.each([{ permission: "No" }])( const client = await getClient(permission); await expect(client.getStats()).rejects.toHaveProperty( "cause.code", - ErrorStatusCode.MISSING_AUTHORIZATION_HEADER, + "missing_authorization_header", ); }); }); diff --git a/tests/displayed_attributes.test.ts b/tests/displayed_attributes.test.ts index b2779437d..c757bee8d 100644 --- a/tests/displayed_attributes.test.ts +++ b/tests/displayed_attributes.test.ts @@ -1,5 +1,4 @@ import { afterAll, expect, test, describe, beforeEach } from "vitest"; -import { ErrorStatusCode } from "../src/types/index.js"; import { clearAllIndexes, config, @@ -81,21 +80,21 @@ describe.each([{ permission: "Search" }])( const client = await getClient(permission); await expect( client.index(index.uid).getDisplayedAttributes(), - ).rejects.toHaveProperty("cause.code", ErrorStatusCode.INVALID_API_KEY); + ).rejects.toHaveProperty("cause.code", "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("cause.code", ErrorStatusCode.INVALID_API_KEY); + ).rejects.toHaveProperty("cause.code", "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("cause.code", ErrorStatusCode.INVALID_API_KEY); + ).rejects.toHaveProperty("cause.code", "invalid_api_key"); }); }, ); @@ -113,30 +112,21 @@ describe.each([{ permission: "No" }])( const client = await getClient(permission); await expect( client.index(index.uid).getDisplayedAttributes(), - ).rejects.toHaveProperty( - "cause.code", - ErrorStatusCode.MISSING_AUTHORIZATION_HEADER, - ); + ).rejects.toHaveProperty("cause.code", "missing_authorization_header"); }); 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( - "cause.code", - ErrorStatusCode.MISSING_AUTHORIZATION_HEADER, - ); + ).rejects.toHaveProperty("cause.code", "missing_authorization_header"); }); 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( - "cause.code", - ErrorStatusCode.MISSING_AUTHORIZATION_HEADER, - ); + ).rejects.toHaveProperty("cause.code", "missing_authorization_header"); }); }, ); diff --git a/tests/distinct_attribute.test.ts b/tests/distinct_attribute.test.ts index ae9907ac7..9573d6aef 100644 --- a/tests/distinct_attribute.test.ts +++ b/tests/distinct_attribute.test.ts @@ -1,5 +1,4 @@ import { afterAll, expect, test, describe, beforeEach } from "vitest"; -import { ErrorStatusCode } from "../src/types/index.js"; import { clearAllIndexes, config, @@ -77,21 +76,21 @@ describe.each([{ permission: "Search" }])( const client = await getClient(permission); await expect( client.index(index.uid).getDistinctAttribute(), - ).rejects.toHaveProperty("cause.code", ErrorStatusCode.INVALID_API_KEY); + ).rejects.toHaveProperty("cause.code", "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("cause.code", ErrorStatusCode.INVALID_API_KEY); + ).rejects.toHaveProperty("cause.code", "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("cause.code", ErrorStatusCode.INVALID_API_KEY); + ).rejects.toHaveProperty("cause.code", "invalid_api_key"); }); }, ); @@ -107,30 +106,21 @@ describe.each([{ permission: "No" }])( const client = await getClient(permission); await expect( client.index(index.uid).getDistinctAttribute(), - ).rejects.toHaveProperty( - "cause.code", - ErrorStatusCode.MISSING_AUTHORIZATION_HEADER, - ); + ).rejects.toHaveProperty("cause.code", "missing_authorization_header"); }); 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( - "cause.code", - ErrorStatusCode.MISSING_AUTHORIZATION_HEADER, - ); + ).rejects.toHaveProperty("cause.code", "missing_authorization_header"); }); 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( - "cause.code", - ErrorStatusCode.MISSING_AUTHORIZATION_HEADER, - ); + ).rejects.toHaveProperty("cause.code", "missing_authorization_header"); }); }, ); diff --git a/tests/documents.test.ts b/tests/documents.test.ts index e9c958761..59b77900d 100644 --- a/tests/documents.test.ts +++ b/tests/documents.test.ts @@ -1,5 +1,5 @@ import { afterAll, expect, test, describe, beforeEach } from "vitest"; -import { ErrorStatusCode, type ResourceResults } from "../src/index.js"; +import type { ResourceResults } from "../src/index.js"; import { clearAllIndexes, config, @@ -601,20 +601,14 @@ describe("Documents tests", () => { const client = await getClient(permission); await expect( client.index(indexNoPk.uid).getDocument(1), - ).rejects.toHaveProperty( - "cause.code", - ErrorStatusCode.DOCUMENT_NOT_FOUND, - ); + ).rejects.toHaveProperty("cause.code", "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( - "cause.code", - ErrorStatusCode.DOCUMENT_NOT_FOUND, - ); + ).rejects.toHaveProperty("cause.code", "document_not_found"); }); test(`${permission} key: Add documents from index with no primary key by giving a primary key as parameter`, async () => { @@ -717,42 +711,42 @@ describe("Documents tests", () => { const client = await getClient(permission); await expect( client.index(indexPk.uid).addDocuments([]), - ).rejects.toHaveProperty("cause.code", ErrorStatusCode.INVALID_API_KEY); + ).rejects.toHaveProperty("cause.code", "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("cause.code", ErrorStatusCode.INVALID_API_KEY); + ).rejects.toHaveProperty("cause.code", "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("cause.code", ErrorStatusCode.INVALID_API_KEY); + ).rejects.toHaveProperty("cause.code", "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("cause.code", ErrorStatusCode.INVALID_API_KEY); + ).rejects.toHaveProperty("cause.code", "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("cause.code", ErrorStatusCode.INVALID_API_KEY); + ).rejects.toHaveProperty("cause.code", "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("cause.code", ErrorStatusCode.INVALID_API_KEY); + ).rejects.toHaveProperty("cause.code", "invalid_api_key"); }); test(`${permission} key: Try updateDocumentsByFunction and be denied`, async () => { @@ -766,7 +760,7 @@ describe("Documents tests", () => { await expect( client.index(indexPk.uid).updateDocumentsByFunction({ function: "" }), - ).rejects.toHaveProperty("cause.code", ErrorStatusCode.INVALID_API_KEY); + ).rejects.toHaveProperty("cause.code", "invalid_api_key"); }); }, ); @@ -782,60 +776,42 @@ describe("Documents tests", () => { const client = await getClient(permission); await expect( client.index(indexPk.uid).addDocuments([]), - ).rejects.toHaveProperty( - "cause.code", - ErrorStatusCode.MISSING_AUTHORIZATION_HEADER, - ); + ).rejects.toHaveProperty("cause.code", "missing_authorization_header"); }); 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( - "cause.code", - ErrorStatusCode.MISSING_AUTHORIZATION_HEADER, - ); + ).rejects.toHaveProperty("cause.code", "missing_authorization_header"); }); 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( - "cause.code", - ErrorStatusCode.MISSING_AUTHORIZATION_HEADER, - ); + ).rejects.toHaveProperty("cause.code", "missing_authorization_header"); }); 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( - "cause.code", - ErrorStatusCode.MISSING_AUTHORIZATION_HEADER, - ); + ).rejects.toHaveProperty("cause.code", "missing_authorization_header"); }); 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( - "cause.code", - ErrorStatusCode.MISSING_AUTHORIZATION_HEADER, - ); + ).rejects.toHaveProperty("cause.code", "missing_authorization_header"); }); 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( - "cause.code", - ErrorStatusCode.MISSING_AUTHORIZATION_HEADER, - ); + ).rejects.toHaveProperty("cause.code", "missing_authorization_header"); }); test(`${permission} key: Try updateDocumentsByFunction and be denied`, async () => { @@ -849,10 +825,7 @@ describe("Documents tests", () => { await expect( client.index(indexPk.uid).updateDocumentsByFunction({ function: "" }), - ).rejects.toHaveProperty( - "cause.code", - ErrorStatusCode.MISSING_AUTHORIZATION_HEADER, - ); + ).rejects.toHaveProperty("cause.code", "missing_authorization_header"); }); }, ); diff --git a/tests/dump.test.ts b/tests/dump.test.ts index 75c971533..2d0b5f472 100644 --- a/tests/dump.test.ts +++ b/tests/dump.test.ts @@ -1,5 +1,4 @@ import { expect, test, describe, beforeEach, assert } from "vitest"; -import { ErrorStatusCode } from "../src/types/index.js"; import { clearAllIndexes, config, @@ -31,7 +30,7 @@ describe.each([{ permission: "Search" }])( const client = await getClient(permission); await expect(client.createDump()).rejects.toHaveProperty( "cause.code", - ErrorStatusCode.INVALID_API_KEY, + "invalid_api_key", ); }); }, @@ -44,7 +43,7 @@ describe.each([{ permission: "No" }])( const client = await getClient(permission); await expect(client.createDump()).rejects.toHaveProperty( "cause.code", - ErrorStatusCode.MISSING_AUTHORIZATION_HEADER, + "missing_authorization_header", ); }); }, diff --git a/tests/facet_search_settings.test.ts b/tests/facet_search_settings.test.ts index d1bb67dbe..92b3cff35 100644 --- a/tests/facet_search_settings.test.ts +++ b/tests/facet_search_settings.test.ts @@ -1,5 +1,4 @@ import { afterAll, expect, test, describe, beforeEach } from "vitest"; -import { ErrorStatusCode } from "../src/types/index.js"; import { clearAllIndexes, config, @@ -66,21 +65,21 @@ describe.each([{ permission: "Search" }])( const client = await getClient(permission); await expect( client.index(index.uid).getFacetSearch(), - ).rejects.toHaveProperty("cause.code", ErrorStatusCode.INVALID_API_KEY); + ).rejects.toHaveProperty("cause.code", "invalid_api_key"); }); test(`${permission} key: try to update facet search settings and be denied`, async () => { const client = await getClient(permission); await expect( client.index(index.uid).updateFacetSearch(false), - ).rejects.toHaveProperty("cause.code", ErrorStatusCode.INVALID_API_KEY); + ).rejects.toHaveProperty("cause.code", "invalid_api_key"); }); test(`${permission} key: try to reset facet search settings and be denied`, async () => { const client = await getClient(permission); await expect( client.index(index.uid).resetFacetSearch(), - ).rejects.toHaveProperty("cause.code", ErrorStatusCode.INVALID_API_KEY); + ).rejects.toHaveProperty("cause.code", "invalid_api_key"); }); }, ); @@ -98,30 +97,21 @@ describe.each([{ permission: "No" }])( const client = await getClient(permission); await expect( client.index(index.uid).getFacetSearch(), - ).rejects.toHaveProperty( - "cause.code", - ErrorStatusCode.MISSING_AUTHORIZATION_HEADER, - ); + ).rejects.toHaveProperty("cause.code", "missing_authorization_header"); }); test(`${permission} key: try to update facet search settings and be denied`, async () => { const client = await getClient(permission); await expect( client.index(index.uid).updateFacetSearch(false), - ).rejects.toHaveProperty( - "cause.code", - ErrorStatusCode.MISSING_AUTHORIZATION_HEADER, - ); + ).rejects.toHaveProperty("cause.code", "missing_authorization_header"); }); test(`${permission} key: try to reset facet search settings and be denied`, async () => { const client = await getClient(permission); await expect( client.index(index.uid).resetFacetSearch(), - ).rejects.toHaveProperty( - "cause.code", - ErrorStatusCode.MISSING_AUTHORIZATION_HEADER, - ); + ).rejects.toHaveProperty("cause.code", "missing_authorization_header"); }); }, ); diff --git a/tests/faceting.test.ts b/tests/faceting.test.ts index dc942b810..2b536c55c 100644 --- a/tests/faceting.test.ts +++ b/tests/faceting.test.ts @@ -6,7 +6,7 @@ import { afterAll, beforeAll, } from "vitest"; -import { ErrorStatusCode, type Faceting } from "../src/index.js"; +import type { Faceting } from "../src/index.js"; import { clearAllIndexes, config, @@ -96,21 +96,21 @@ describe.each([{ permission: "Search" }])( const client = await getClient(permission); await expect( client.index(index.uid).getFaceting(), - ).rejects.toHaveProperty("cause.code", ErrorStatusCode.INVALID_API_KEY); + ).rejects.toHaveProperty("cause.code", "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("cause.code", ErrorStatusCode.INVALID_API_KEY); + ).rejects.toHaveProperty("cause.code", "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("cause.code", ErrorStatusCode.INVALID_API_KEY); + ).rejects.toHaveProperty("cause.code", "invalid_api_key"); }); }, ); @@ -125,7 +125,7 @@ describe.each([{ permission: "No" }])("Test on faceting", ({ permission }) => { const client = await getClient(permission); await expect(client.index(index.uid).getFaceting()).rejects.toHaveProperty( "cause.code", - ErrorStatusCode.MISSING_AUTHORIZATION_HEADER, + "missing_authorization_header", ); }); @@ -133,20 +133,14 @@ describe.each([{ permission: "No" }])("Test on faceting", ({ permission }) => { const client = await getClient(permission); await expect( client.index(index.uid).updateFaceting({ maxValuesPerFacet: 13 }), - ).rejects.toHaveProperty( - "cause.code", - ErrorStatusCode.MISSING_AUTHORIZATION_HEADER, - ); + ).rejects.toHaveProperty("cause.code", "missing_authorization_header"); }); 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( - "cause.code", - ErrorStatusCode.MISSING_AUTHORIZATION_HEADER, - ); + ).rejects.toHaveProperty("cause.code", "missing_authorization_header"); }); }); diff --git a/tests/filterable_attributes.test.ts b/tests/filterable_attributes.test.ts index c59c87942..bc1f9bf4e 100644 --- a/tests/filterable_attributes.test.ts +++ b/tests/filterable_attributes.test.ts @@ -1,5 +1,4 @@ import { expect, test, describe, beforeEach, afterAll } from "vitest"; -import { ErrorStatusCode } from "../src/types/index.js"; import { clearAllIndexes, config, @@ -97,21 +96,21 @@ describe.each([{ permission: "Search" }])( const client = await getClient(permission); await expect( client.index(index.uid).getFilterableAttributes(), - ).rejects.toHaveProperty("cause.code", ErrorStatusCode.INVALID_API_KEY); + ).rejects.toHaveProperty("cause.code", "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("cause.code", ErrorStatusCode.INVALID_API_KEY); + ).rejects.toHaveProperty("cause.code", "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("cause.code", ErrorStatusCode.INVALID_API_KEY); + ).rejects.toHaveProperty("cause.code", "invalid_api_key"); }); }, ); @@ -128,30 +127,21 @@ describe.each([{ permission: "No" }])( const client = await getClient(permission); await expect( client.index(index.uid).getFilterableAttributes(), - ).rejects.toHaveProperty( - "cause.code", - ErrorStatusCode.MISSING_AUTHORIZATION_HEADER, - ); + ).rejects.toHaveProperty("cause.code", "missing_authorization_header"); }); 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( - "cause.code", - ErrorStatusCode.MISSING_AUTHORIZATION_HEADER, - ); + ).rejects.toHaveProperty("cause.code", "missing_authorization_header"); }); 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( - "cause.code", - ErrorStatusCode.MISSING_AUTHORIZATION_HEADER, - ); + ).rejects.toHaveProperty("cause.code", "missing_authorization_header"); }); }, ); diff --git a/tests/get_search.test.ts b/tests/get_search.test.ts index 3a6771b1d..592887583 100644 --- a/tests/get_search.test.ts +++ b/tests/get_search.test.ts @@ -1,5 +1,4 @@ import { expect, test, describe, afterAll, beforeAll } from "vitest"; -import { ErrorStatusCode } from "../src/types/index.js"; import { clearAllIndexes, config, @@ -549,7 +548,7 @@ describe.each([ await masterClient.index(index.uid).delete().waitTask(); await expect( client.index(index.uid).searchGet("prince"), - ).rejects.toHaveProperty("cause.code", ErrorStatusCode.INDEX_NOT_FOUND); + ).rejects.toHaveProperty("cause.code", "index_not_found"); }); }); diff --git a/tests/index.test.ts b/tests/index.test.ts index faea55881..20a118388 100644 --- a/tests/index.test.ts +++ b/tests/index.test.ts @@ -1,5 +1,4 @@ import { expect, test, describe, beforeEach, afterAll } from "vitest"; -import { ErrorStatusCode } from "../src/types/index.js"; import { clearAllIndexes, config, @@ -86,7 +85,7 @@ describe.each([{ permission: "Master" }, { permission: "Admin" }])( const client = await getClient(permission); await expect(client.getIndex("does_not_exist")).rejects.toHaveProperty( "cause.code", - ErrorStatusCode.INDEX_NOT_FOUND, + "index_not_found", ); }); @@ -94,7 +93,7 @@ describe.each([{ permission: "Master" }, { permission: "Admin" }])( const client = await getClient(permission); await expect(client.getRawIndex("does_not_exist")).rejects.toHaveProperty( "cause.code", - ErrorStatusCode.INDEX_NOT_FOUND, + "index_not_found", ); }); @@ -317,7 +316,7 @@ describe.each([{ permission: "Master" }, { permission: "Admin" }])( const index = client.index(indexNoPk.uid); await expect(index.getRawInfo()).rejects.toHaveProperty( "cause.code", - ErrorStatusCode.INDEX_NOT_FOUND, + "index_not_found", ); }); @@ -325,7 +324,7 @@ describe.each([{ permission: "Master" }, { permission: "Admin" }])( const client = await getClient(permission); await expect(client.getRawIndex(indexNoPk.uid)).rejects.toHaveProperty( "cause.code", - ErrorStatusCode.INDEX_NOT_FOUND, + "index_not_found", ); }); @@ -390,14 +389,14 @@ describe.each([{ permission: "Search" }])( const client = await getClient(permission); await expect( client.index(indexNoPk.uid).getRawInfo(), - ).rejects.toHaveProperty("cause.code", ErrorStatusCode.INVALID_API_KEY); + ).rejects.toHaveProperty("cause.code", "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( "cause.code", - ErrorStatusCode.INVALID_API_KEY, + "invalid_api_key", ); }); @@ -405,7 +404,7 @@ describe.each([{ permission: "Search" }])( const client = await getClient(permission); await expect(client.index(indexPk.uid).delete()).rejects.toHaveProperty( "cause.code", - ErrorStatusCode.INVALID_API_KEY, + "invalid_api_key", ); }); @@ -413,14 +412,14 @@ describe.each([{ permission: "Search" }])( const client = await getClient(permission); await expect( client.index(indexPk.uid).update({ primaryKey: indexPk.primaryKey }), - ).rejects.toHaveProperty("cause.code", ErrorStatusCode.INVALID_API_KEY); + ).rejects.toHaveProperty("cause.code", "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( "cause.code", - ErrorStatusCode.INVALID_API_KEY, + "invalid_api_key", ); }); }, @@ -437,7 +436,7 @@ describe.each([{ permission: "No" }])( const client = await getClient(permission); await expect(client.getIndexes()).rejects.toHaveProperty( "cause.code", - ErrorStatusCode.MISSING_AUTHORIZATION_HEADER, + "missing_authorization_header", ); }); @@ -445,17 +444,14 @@ describe.each([{ permission: "No" }])( const client = await getClient(permission); await expect( client.index(indexNoPk.uid).getRawInfo(), - ).rejects.toHaveProperty( - "cause.code", - ErrorStatusCode.MISSING_AUTHORIZATION_HEADER, - ); + ).rejects.toHaveProperty("cause.code", "missing_authorization_header"); }); 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( "cause.code", - ErrorStatusCode.MISSING_AUTHORIZATION_HEADER, + "missing_authorization_header", ); }); @@ -463,7 +459,7 @@ describe.each([{ permission: "No" }])( const client = await getClient(permission); await expect(client.index(indexPk.uid).delete()).rejects.toHaveProperty( "cause.code", - ErrorStatusCode.MISSING_AUTHORIZATION_HEADER, + "missing_authorization_header", ); }); @@ -471,10 +467,7 @@ describe.each([{ permission: "No" }])( const client = await getClient(permission); await expect( client.index(indexPk.uid).update({ primaryKey: indexPk.primaryKey }), - ).rejects.toHaveProperty( - "cause.code", - ErrorStatusCode.MISSING_AUTHORIZATION_HEADER, - ); + ).rejects.toHaveProperty("cause.code", "missing_authorization_header"); }); }, ); diff --git a/tests/keys.test.ts b/tests/keys.test.ts index a1e305d07..9e1372178 100644 --- a/tests/keys.test.ts +++ b/tests/keys.test.ts @@ -1,6 +1,5 @@ import { expect, test, describe, beforeEach, afterAll } from "vitest"; import { MeiliSearch } from "../src/index.js"; -import { ErrorStatusCode } from "../src/types/index.js"; import { clearAllIndexes, config, @@ -211,7 +210,7 @@ describe.each([{ permission: "Search" }])( const client = await getClient(permission); await expect(client.getKeys()).rejects.toHaveProperty( "cause.code", - ErrorStatusCode.INVALID_API_KEY, + "invalid_api_key", ); }); @@ -224,7 +223,7 @@ describe.each([{ permission: "Search" }])( indexes: ["products"], expiresAt: null, }), - ).rejects.toHaveProperty("cause.code", ErrorStatusCode.INVALID_API_KEY); + ).rejects.toHaveProperty("cause.code", "invalid_api_key"); }); }, ); @@ -236,7 +235,7 @@ describe.each([{ permission: "No" }])( const client = await getClient(permission); await expect(client.getKeys()).rejects.toHaveProperty( "cause.code", - ErrorStatusCode.MISSING_AUTHORIZATION_HEADER, + "missing_authorization_header", ); }); @@ -249,10 +248,7 @@ describe.each([{ permission: "No" }])( indexes: ["products"], expiresAt: null, }), - ).rejects.toHaveProperty( - "cause.code", - ErrorStatusCode.MISSING_AUTHORIZATION_HEADER, - ); + ).rejects.toHaveProperty("cause.code", "missing_authorization_header"); }); }, ); diff --git a/tests/localized_attributes.test.ts b/tests/localized_attributes.test.ts index 963f406be..a6f7fe586 100644 --- a/tests/localized_attributes.test.ts +++ b/tests/localized_attributes.test.ts @@ -6,10 +6,7 @@ import { expect, test, } from "vitest"; -import { - ErrorStatusCode, - type LocalizedAttributes, -} from "../src/types/index.js"; +import type { LocalizedAttributes } from "../src/types/index.js"; import { clearAllIndexes, config, @@ -83,7 +80,7 @@ describe.each([{ permission: "Master" }, { permission: "Admin" }])( .updateLocalizedAttributes(newLocalizedAttributes), ).rejects.toHaveProperty( "cause.code", - ErrorStatusCode.INVALID_SETTINGS_LOCALIZED_ATTRIBUTES, + "invalid_settings_localized_attributes", ); }); @@ -115,21 +112,21 @@ describe.each([{ permission: "Search" }])( const client = await getClient(permission); await expect( client.index(index.uid).getLocalizedAttributes(), - ).rejects.toHaveProperty("cause.code", ErrorStatusCode.INVALID_API_KEY); + ).rejects.toHaveProperty("cause.code", "invalid_api_key"); }); test(`${permission} key: try to update localizedAttributes and be denied`, async () => { const client = await getClient(permission); await expect( client.index(index.uid).updateLocalizedAttributes([]), - ).rejects.toHaveProperty("cause.code", ErrorStatusCode.INVALID_API_KEY); + ).rejects.toHaveProperty("cause.code", "invalid_api_key"); }); test(`${permission} key: try to reset localizedAttributes and be denied`, async () => { const client = await getClient(permission); await expect( client.index(index.uid).resetLocalizedAttributes(), - ).rejects.toHaveProperty("cause.code", ErrorStatusCode.INVALID_API_KEY); + ).rejects.toHaveProperty("cause.code", "invalid_api_key"); }); }, ); @@ -146,30 +143,21 @@ describe.each([{ permission: "No" }])( const client = await getClient(permission); await expect( client.index(index.uid).getLocalizedAttributes(), - ).rejects.toHaveProperty( - "cause.code", - ErrorStatusCode.MISSING_AUTHORIZATION_HEADER, - ); + ).rejects.toHaveProperty("cause.code", "missing_authorization_header"); }); test(`${permission} key: try to update localizedAttributes and be denied`, async () => { const client = await getClient(permission); await expect( client.index(index.uid).updateLocalizedAttributes([]), - ).rejects.toHaveProperty( - "cause.code", - ErrorStatusCode.MISSING_AUTHORIZATION_HEADER, - ); + ).rejects.toHaveProperty("cause.code", "missing_authorization_header"); }); test(`${permission} key: try to reset localizedAttributes and be denied`, async () => { const client = await getClient(permission); await expect( client.index(index.uid).resetLocalizedAttributes(), - ).rejects.toHaveProperty( - "cause.code", - ErrorStatusCode.MISSING_AUTHORIZATION_HEADER, - ); + ).rejects.toHaveProperty("cause.code", "missing_authorization_header"); }); }, ); diff --git a/tests/pagination.test.ts b/tests/pagination.test.ts index f8736bf53..dfe23a214 100644 --- a/tests/pagination.test.ts +++ b/tests/pagination.test.ts @@ -6,7 +6,6 @@ afterAll, beforeAll, } from "vitest"; -import { ErrorStatusCode } from "../src/types/index.js"; import { clearAllIndexes, config, @@ -91,21 +90,21 @@ describe.each([{ permission: "Search" }])( const client = await getClient(permission); await expect( client.index(index.uid).getPagination(), - ).rejects.toHaveProperty("cause.code", ErrorStatusCode.INVALID_API_KEY); + ).rejects.toHaveProperty("cause.code", "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("cause.code", ErrorStatusCode.INVALID_API_KEY); + ).rejects.toHaveProperty("cause.code", "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("cause.code", ErrorStatusCode.INVALID_API_KEY); + ).rejects.toHaveProperty("cause.code", "invalid_api_key"); }); }, ); @@ -122,30 +121,21 @@ describe.each([{ permission: "No" }])( const client = await getClient(permission); await expect( client.index(index.uid).getPagination(), - ).rejects.toHaveProperty( - "cause.code", - ErrorStatusCode.MISSING_AUTHORIZATION_HEADER, - ); + ).rejects.toHaveProperty("cause.code", "missing_authorization_header"); }); 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( - "cause.code", - ErrorStatusCode.MISSING_AUTHORIZATION_HEADER, - ); + ).rejects.toHaveProperty("cause.code", "missing_authorization_header"); }); 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( - "cause.code", - ErrorStatusCode.MISSING_AUTHORIZATION_HEADER, - ); + ).rejects.toHaveProperty("cause.code", "missing_authorization_header"); }); }, ); diff --git a/tests/prefix_search_settings.test.ts b/tests/prefix_search_settings.test.ts index 77685c5fc..6fa9c7c5e 100644 --- a/tests/prefix_search_settings.test.ts +++ b/tests/prefix_search_settings.test.ts @@ -1,5 +1,4 @@ import { afterAll, expect, test, describe, beforeEach } from "vitest"; -import { ErrorStatusCode } from "../src/types/index.js"; import { clearAllIndexes, config, @@ -66,21 +65,21 @@ describe.each([{ permission: "Search" }])( const client = await getClient(permission); await expect( client.index(index.uid).getPrefixSearch(), - ).rejects.toHaveProperty("cause.code", ErrorStatusCode.INVALID_API_KEY); + ).rejects.toHaveProperty("cause.code", "invalid_api_key"); }); test(`${permission} key: try to update prefix search settings and be denied`, async () => { const client = await getClient(permission); await expect( client.index(index.uid).updatePrefixSearch("disabled"), - ).rejects.toHaveProperty("cause.code", ErrorStatusCode.INVALID_API_KEY); + ).rejects.toHaveProperty("cause.code", "invalid_api_key"); }); test(`${permission} key: try to reset prefix search settings and be denied`, async () => { const client = await getClient(permission); await expect( client.index(index.uid).resetPrefixSearch(), - ).rejects.toHaveProperty("cause.code", ErrorStatusCode.INVALID_API_KEY); + ).rejects.toHaveProperty("cause.code", "invalid_api_key"); }); }, ); @@ -98,30 +97,21 @@ describe.each([{ permission: "No" }])( const client = await getClient(permission); await expect( client.index(index.uid).getPrefixSearch(), - ).rejects.toHaveProperty( - "cause.code", - ErrorStatusCode.MISSING_AUTHORIZATION_HEADER, - ); + ).rejects.toHaveProperty("cause.code", "missing_authorization_header"); }); test(`${permission} key: try to update prefix search settings and be denied`, async () => { const client = await getClient(permission); await expect( client.index(index.uid).updatePrefixSearch("disabled"), - ).rejects.toHaveProperty( - "cause.code", - ErrorStatusCode.MISSING_AUTHORIZATION_HEADER, - ); + ).rejects.toHaveProperty("cause.code", "missing_authorization_header"); }); test(`${permission} key: try to reset prefix search settings and be denied`, async () => { const client = await getClient(permission); await expect( client.index(index.uid).resetPrefixSearch(), - ).rejects.toHaveProperty( - "cause.code", - ErrorStatusCode.MISSING_AUTHORIZATION_HEADER, - ); + ).rejects.toHaveProperty("cause.code", "missing_authorization_header"); }); }, ); diff --git a/tests/ranking_rules.test.ts b/tests/ranking_rules.test.ts index 5025ea2c0..7605e8cbc 100644 --- a/tests/ranking_rules.test.ts +++ b/tests/ranking_rules.test.ts @@ -1,5 +1,4 @@ import { expect, test, describe, beforeEach, afterAll } from "vitest"; -import { ErrorStatusCode } from "../src/types/index.js"; import { clearAllIndexes, config, @@ -85,21 +84,21 @@ describe.each([{ permission: "Search" }])( const client = await getClient(permission); await expect( client.index(index.uid).getRankingRules(), - ).rejects.toHaveProperty("cause.code", ErrorStatusCode.INVALID_API_KEY); + ).rejects.toHaveProperty("cause.code", "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("cause.code", ErrorStatusCode.INVALID_API_KEY); + ).rejects.toHaveProperty("cause.code", "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("cause.code", ErrorStatusCode.INVALID_API_KEY); + ).rejects.toHaveProperty("cause.code", "invalid_api_key"); }); }, ); @@ -115,30 +114,21 @@ describe.each([{ permission: "No" }])( const client = await getClient(permission); await expect( client.index(index.uid).getRankingRules(), - ).rejects.toHaveProperty( - "cause.code", - ErrorStatusCode.MISSING_AUTHORIZATION_HEADER, - ); + ).rejects.toHaveProperty("cause.code", "missing_authorization_header"); }); 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( - "cause.code", - ErrorStatusCode.MISSING_AUTHORIZATION_HEADER, - ); + ).rejects.toHaveProperty("cause.code", "missing_authorization_header"); }); 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( - "cause.code", - ErrorStatusCode.MISSING_AUTHORIZATION_HEADER, - ); + ).rejects.toHaveProperty("cause.code", "missing_authorization_header"); }); }, ); diff --git a/tests/search.test.ts b/tests/search.test.ts index 8cacb0e6b..d0919e9e3 100644 --- a/tests/search.test.ts +++ b/tests/search.test.ts @@ -7,7 +7,7 @@ import { beforeAll, vi, } from "vitest"; -import { ErrorStatusCode, MatchingStrategies } from "../src/types/index.js"; +import { MatchingStrategies } from "../src/types/index.js"; import type { FederatedMultiSearchParams, MultiSearchParams, @@ -1244,7 +1244,7 @@ describe.each([ await expect( client.index(index.uid).search("prince", {}), - ).rejects.toHaveProperty("cause.code", ErrorStatusCode.INDEX_NOT_FOUND); + ).rejects.toHaveProperty("cause.code", "index_not_found"); }); }); @@ -1260,17 +1260,14 @@ describe.each([{ permission: "No" }])( const client = await getClient(permission); await expect( client.index(index.uid).search("prince"), - ).rejects.toHaveProperty( - "cause.code", - ErrorStatusCode.MISSING_AUTHORIZATION_HEADER, - ); + ).rejects.toHaveProperty("cause.code", "missing_authorization_header"); }); test(`${permission} key: Try multi search and be denied`, async () => { const client = await getClient(permission); await expect(client.multiSearch({ queries: [] })).rejects.toHaveProperty( "cause.code", - ErrorStatusCode.MISSING_AUTHORIZATION_HEADER, + "missing_authorization_header", ); }); }, diff --git a/tests/search_cutoff_ms.test.ts b/tests/search_cutoff_ms.test.ts index 7c96faa04..fea15cb92 100644 --- a/tests/search_cutoff_ms.test.ts +++ b/tests/search_cutoff_ms.test.ts @@ -6,7 +6,7 @@ import { expect, test, } from "vitest"; -import { ErrorStatusCode, type SearchCutoffMs } from "../src/index.js"; +import type { SearchCutoffMs } from "../src/index.js"; import { clearAllIndexes, config, @@ -76,7 +76,7 @@ describe.each([{ permission: "Master" }, { permission: "Admin" }])( client.index(index.uid).updateSearchCutoffMs(newSearchCutoffMs), ).rejects.toHaveProperty( "cause.code", - ErrorStatusCode.INVALID_SETTINGS_SEARCH_CUTOFF_MS, + "invalid_settings_search_cutoff_ms", ); }); @@ -108,21 +108,21 @@ describe.each([{ permission: "Search" }])( const client = await getClient(permission); await expect( client.index(index.uid).getSearchCutoffMs(), - ).rejects.toHaveProperty("cause.code", ErrorStatusCode.INVALID_API_KEY); + ).rejects.toHaveProperty("cause.code", "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("cause.code", ErrorStatusCode.INVALID_API_KEY); + ).rejects.toHaveProperty("cause.code", "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("cause.code", ErrorStatusCode.INVALID_API_KEY); + ).rejects.toHaveProperty("cause.code", "invalid_api_key"); }); }, ); @@ -139,30 +139,21 @@ describe.each([{ permission: "No" }])( const client = await getClient(permission); await expect( client.index(index.uid).getSearchCutoffMs(), - ).rejects.toHaveProperty( - "cause.code", - ErrorStatusCode.MISSING_AUTHORIZATION_HEADER, - ); + ).rejects.toHaveProperty("cause.code", "missing_authorization_header"); }); 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( - "cause.code", - ErrorStatusCode.MISSING_AUTHORIZATION_HEADER, - ); + ).rejects.toHaveProperty("cause.code", "missing_authorization_header"); }); 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( - "cause.code", - ErrorStatusCode.MISSING_AUTHORIZATION_HEADER, - ); + ).rejects.toHaveProperty("cause.code", "missing_authorization_header"); }); }, ); diff --git a/tests/searchable_attributes.test.ts b/tests/searchable_attributes.test.ts index 8a1b1030f..6329bbb7b 100644 --- a/tests/searchable_attributes.test.ts +++ b/tests/searchable_attributes.test.ts @@ -6,7 +6,6 @@ import { expect, test, } from "vitest"; -import { ErrorStatusCode } from "../src/types/index.js"; import { clearAllIndexes, config, @@ -85,21 +84,21 @@ describe.each([{ permission: "Search" }])( const client = await getClient(permission); await expect( client.index(index.uid).getSearchableAttributes(), - ).rejects.toHaveProperty("cause.code", ErrorStatusCode.INVALID_API_KEY); + ).rejects.toHaveProperty("cause.code", "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("cause.code", ErrorStatusCode.INVALID_API_KEY); + ).rejects.toHaveProperty("cause.code", "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("cause.code", ErrorStatusCode.INVALID_API_KEY); + ).rejects.toHaveProperty("cause.code", "invalid_api_key"); }); }, ); @@ -116,30 +115,21 @@ describe.each([{ permission: "No" }])( const client = await getClient(permission); await expect( client.index(index.uid).getSearchableAttributes(), - ).rejects.toHaveProperty( - "cause.code", - ErrorStatusCode.MISSING_AUTHORIZATION_HEADER, - ); + ).rejects.toHaveProperty("cause.code", "missing_authorization_header"); }); 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( - "cause.code", - ErrorStatusCode.MISSING_AUTHORIZATION_HEADER, - ); + ).rejects.toHaveProperty("cause.code", "missing_authorization_header"); }); 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( - "cause.code", - ErrorStatusCode.MISSING_AUTHORIZATION_HEADER, - ); + ).rejects.toHaveProperty("cause.code", "missing_authorization_header"); }); }, ); diff --git a/tests/settings.test.ts b/tests/settings.test.ts index c6c71dd75..6db3ef0f4 100644 --- a/tests/settings.test.ts +++ b/tests/settings.test.ts @@ -1,5 +1,5 @@ import { afterAll, beforeEach, describe, expect, test } from "vitest"; -import { ErrorStatusCode, type Settings } from "../src/types/index.js"; +import type { Settings } from "../src/types/index.js"; import { clearAllIndexes, config, @@ -270,19 +270,19 @@ describe.each([{ permission: "Search" }])( const client = await getClient(permission); await expect( client.index(index.uid).getSettings(), - ).rejects.toHaveProperty("cause.code", ErrorStatusCode.INVALID_API_KEY); + ).rejects.toHaveProperty("cause.code", "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("cause.code", ErrorStatusCode.INVALID_API_KEY); + ).rejects.toHaveProperty("cause.code", "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("cause.code", ErrorStatusCode.INVALID_API_KEY); + ).rejects.toHaveProperty("cause.code", "invalid_api_key"); }); }, ); @@ -295,26 +295,20 @@ describe.each([{ permission: "No" }])("Test on settings", ({ permission }) => { const client = await getClient(permission); await expect(client.index(index.uid).getSettings()).rejects.toHaveProperty( "cause.code", - ErrorStatusCode.MISSING_AUTHORIZATION_HEADER, + "missing_authorization_header", ); }); 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( - "cause.code", - ErrorStatusCode.MISSING_AUTHORIZATION_HEADER, - ); + ).rejects.toHaveProperty("cause.code", "missing_authorization_header"); }); 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( - "cause.code", - ErrorStatusCode.MISSING_AUTHORIZATION_HEADER, - ); + ).rejects.toHaveProperty("cause.code", "missing_authorization_header"); }); }); diff --git a/tests/snapshots.test.ts b/tests/snapshots.test.ts index 7b07ab897..a931e5b0c 100644 --- a/tests/snapshots.test.ts +++ b/tests/snapshots.test.ts @@ -1,5 +1,4 @@ import { beforeEach, describe, expect, test, assert } from "vitest"; -import { ErrorStatusCode } from "../src/types/index.js"; import { clearAllIndexes, config, @@ -31,7 +30,7 @@ describe.each([{ permission: "Search" }])( const client = await getClient(permission); await expect(client.createSnapshot()).rejects.toHaveProperty( "cause.code", - ErrorStatusCode.INVALID_API_KEY, + "invalid_api_key", ); }); }, @@ -44,7 +43,7 @@ describe.each([{ permission: "No" }])( const client = await getClient(permission); await expect(client.createSnapshot()).rejects.toHaveProperty( "cause.code", - ErrorStatusCode.MISSING_AUTHORIZATION_HEADER, + "missing_authorization_header", ); }); }, diff --git a/tests/sortable_attributes.test.ts b/tests/sortable_attributes.test.ts index 814c7f7f0..7fb58cf1e 100644 --- a/tests/sortable_attributes.test.ts +++ b/tests/sortable_attributes.test.ts @@ -6,7 +6,6 @@ import { expect, test, } from "vitest"; -import { ErrorStatusCode } from "../src/types/index.js"; import { clearAllIndexes, config, @@ -86,21 +85,21 @@ describe.each([{ permission: "Search" }])( const client = await getClient(permission); await expect( client.index(index.uid).getSortableAttributes(), - ).rejects.toHaveProperty("cause.code", ErrorStatusCode.INVALID_API_KEY); + ).rejects.toHaveProperty("cause.code", "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("cause.code", ErrorStatusCode.INVALID_API_KEY); + ).rejects.toHaveProperty("cause.code", "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("cause.code", ErrorStatusCode.INVALID_API_KEY); + ).rejects.toHaveProperty("cause.code", "invalid_api_key"); }); }, ); @@ -117,10 +116,7 @@ describe.each([{ permission: "No" }])( const client = await getClient(permission); await expect( client.index(index.uid).getSortableAttributes(), - ).rejects.toHaveProperty( - "cause.code", - ErrorStatusCode.MISSING_AUTHORIZATION_HEADER, - ); + ).rejects.toHaveProperty("cause.code", "missing_authorization_header"); }); test(`${permission} key: try to update sortable attributes and be denied`, async () => { @@ -128,20 +124,14 @@ describe.each([{ permission: "No" }])( const resetSortable: string[] = []; await expect( client.index(index.uid).updateSortableAttributes(resetSortable), - ).rejects.toHaveProperty( - "cause.code", - ErrorStatusCode.MISSING_AUTHORIZATION_HEADER, - ); + ).rejects.toHaveProperty("cause.code", "missing_authorization_header"); }); 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( - "cause.code", - ErrorStatusCode.MISSING_AUTHORIZATION_HEADER, - ); + ).rejects.toHaveProperty("cause.code", "missing_authorization_header"); }); }, ); diff --git a/tests/stop_words.test.ts b/tests/stop_words.test.ts index e56582c2c..bb76584dd 100644 --- a/tests/stop_words.test.ts +++ b/tests/stop_words.test.ts @@ -1,5 +1,4 @@ import { afterAll, beforeEach, describe, expect, test } from "vitest"; -import { ErrorStatusCode } from "../src/types/index.js"; import { clearAllIndexes, config, @@ -74,21 +73,21 @@ describe.each([{ permission: "Search" }])( const client = await getClient(permission); await expect( client.index(index.uid).getStopWords(), - ).rejects.toHaveProperty("cause.code", ErrorStatusCode.INVALID_API_KEY); + ).rejects.toHaveProperty("cause.code", "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("cause.code", ErrorStatusCode.INVALID_API_KEY); + ).rejects.toHaveProperty("cause.code", "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("cause.code", ErrorStatusCode.INVALID_API_KEY); + ).rejects.toHaveProperty("cause.code", "invalid_api_key"); }); }, ); @@ -104,30 +103,21 @@ describe.each([{ permission: "No" }])( const client = await getClient(permission); await expect( client.index(index.uid).getStopWords(), - ).rejects.toHaveProperty( - "cause.code", - ErrorStatusCode.MISSING_AUTHORIZATION_HEADER, - ); + ).rejects.toHaveProperty("cause.code", "missing_authorization_header"); }); 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( - "cause.code", - ErrorStatusCode.MISSING_AUTHORIZATION_HEADER, - ); + ).rejects.toHaveProperty("cause.code", "missing_authorization_header"); }); 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( - "cause.code", - ErrorStatusCode.MISSING_AUTHORIZATION_HEADER, - ); + ).rejects.toHaveProperty("cause.code", "missing_authorization_header"); }); }, ); diff --git a/tests/synonyms.test.ts b/tests/synonyms.test.ts index 48a11835b..3b924f088 100644 --- a/tests/synonyms.test.ts +++ b/tests/synonyms.test.ts @@ -1,5 +1,4 @@ import { afterAll, beforeEach, describe, expect, test } from "vitest"; -import { ErrorStatusCode } from "../src/types/index.js"; import { clearAllIndexes, config, @@ -76,21 +75,21 @@ describe.each([{ permission: "Search" }])( const client = await getClient(permission); await expect( client.index(index.uid).getSynonyms(), - ).rejects.toHaveProperty("cause.code", ErrorStatusCode.INVALID_API_KEY); + ).rejects.toHaveProperty("cause.code", "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("cause.code", ErrorStatusCode.INVALID_API_KEY); + ).rejects.toHaveProperty("cause.code", "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("cause.code", ErrorStatusCode.INVALID_API_KEY); + ).rejects.toHaveProperty("cause.code", "invalid_api_key"); }); }, ); @@ -104,7 +103,7 @@ describe.each([{ permission: "No" }])("Test on synonyms", ({ permission }) => { const client = await getClient(permission); await expect(client.index(index.uid).getSynonyms()).rejects.toHaveProperty( "cause.code", - ErrorStatusCode.MISSING_AUTHORIZATION_HEADER, + "missing_authorization_header", ); }); @@ -112,20 +111,14 @@ describe.each([{ permission: "No" }])("Test on synonyms", ({ permission }) => { const client = await getClient(permission); await expect( client.index(index.uid).updateSynonyms({}), - ).rejects.toHaveProperty( - "cause.code", - ErrorStatusCode.MISSING_AUTHORIZATION_HEADER, - ); + ).rejects.toHaveProperty("cause.code", "missing_authorization_header"); }); 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( - "cause.code", - ErrorStatusCode.MISSING_AUTHORIZATION_HEADER, - ); + ).rejects.toHaveProperty("cause.code", "missing_authorization_header"); }); }); diff --git a/tests/task.test.ts b/tests/task.test.ts index 2032e9747..047ee5ecd 100644 --- a/tests/task.test.ts +++ b/tests/task.test.ts @@ -1,5 +1,4 @@ import { afterAll, assert, beforeEach, describe, expect, test } from "vitest"; -import { ErrorStatusCode } from "../src/types/index.js"; import { sleep } from "../src/utils.js"; import { BAD_HOST, @@ -348,10 +347,7 @@ describe.each([{ permission: "Master" }, { permission: "Admin" }])( // @ts-expect-error testing wrong argument type { types: ["wrong"] }, ), - ).rejects.toHaveProperty( - "cause.code", - ErrorStatusCode.INVALID_TASK_TYPES, - ); + ).rejects.toHaveProperty("cause.code", "invalid_task_types"); }); // filters error code: INVALID_TASK_STATUSES_FILTER @@ -363,10 +359,7 @@ describe.each([{ permission: "Master" }, { permission: "Admin" }])( // @ts-expect-error testing wrong argument type { statuses: ["wrong"] }, ), - ).rejects.toHaveProperty( - "cause.code", - ErrorStatusCode.INVALID_TASK_STATUSES, - ); + ).rejects.toHaveProperty("cause.code", "invalid_task_statuses"); }); // filters error code: INVALID_TASK_UIDS_FILTER @@ -378,7 +371,7 @@ describe.each([{ permission: "Master" }, { permission: "Admin" }])( // @ts-expect-error testing wrong argument type { uids: ["wrong"] }, ), - ).rejects.toHaveProperty("cause.code", ErrorStatusCode.INVALID_TASK_UIDS); + ).rejects.toHaveProperty("cause.code", "invalid_task_uids"); }); // filters error code: INVALID_TASK_CANCELED_BY_FILTER @@ -390,10 +383,7 @@ describe.each([{ permission: "Master" }, { permission: "Admin" }])( // @ts-expect-error testing wrong canceledBy type { canceledBy: ["wrong"] }, ), - ).rejects.toHaveProperty( - "cause.code", - ErrorStatusCode.INVALID_TASK_CANCELED_BY, - ); + ).rejects.toHaveProperty("cause.code", "invalid_task_canceled_by"); }); // filters error code: INVALID_TASK_DATE_FILTER @@ -402,10 +392,7 @@ describe.each([{ permission: "Master" }, { permission: "Admin" }])( await expect( client.tasks.getTasks({ beforeEnqueuedAt: "wrong" }), - ).rejects.toHaveProperty( - "cause.code", - ErrorStatusCode.INVALID_TASK_BEFORE_ENQUEUED_AT, - ); + ).rejects.toHaveProperty("cause.code", "invalid_task_before_enqueued_at"); }); // cancel: uid @@ -557,7 +544,7 @@ describe.each([{ permission: "Master" }, { permission: "Admin" }])( await expect(client.tasks.cancelTasks({})).rejects.toHaveProperty( "cause.code", - ErrorStatusCode.MISSING_TASK_FILTERS, + "missing_task_filters", ); }); @@ -576,7 +563,7 @@ describe.each([{ permission: "Master" }, { permission: "Admin" }])( expect(task.details?.deletedTasks).toBeDefined(); await expect( client.tasks.getTask(addDocuments.taskUid), - ).rejects.toHaveProperty("cause.code", ErrorStatusCode.TASK_NOT_FOUND); + ).rejects.toHaveProperty("cause.code", "task_not_found"); }); // delete: indexUid @@ -593,7 +580,7 @@ describe.each([{ permission: "Master" }, { permission: "Admin" }])( assert.strictEqual(deleteTask.type, "taskDeletion"); await expect( client.tasks.getTask(addDocuments.taskUid), - ).rejects.toHaveProperty("cause.code", ErrorStatusCode.TASK_NOT_FOUND); + ).rejects.toHaveProperty("cause.code", "task_not_found"); }); // delete: type @@ -715,7 +702,7 @@ describe.each([{ permission: "Master" }, { permission: "Admin" }])( await expect(client.tasks.getTask(254500)).rejects.toHaveProperty( "cause.code", - ErrorStatusCode.TASK_NOT_FOUND, + "task_not_found", ); }); }, @@ -730,7 +717,7 @@ describe.each([{ permission: "Search" }])("Test on tasks", ({ permission }) => { const client = await getClient(permission); await expect(client.tasks.getTask(0)).rejects.toHaveProperty( "cause.code", - ErrorStatusCode.INVALID_API_KEY, + "invalid_api_key", ); }); }); @@ -744,7 +731,7 @@ describe.each([{ permission: "No" }])("Test on tasks", ({ permission }) => { const client = await getClient(permission); await expect(client.tasks.getTask(0)).rejects.toHaveProperty( "cause.code", - ErrorStatusCode.MISSING_AUTHORIZATION_HEADER, + "missing_authorization_header", ); }); }); diff --git a/tests/typed_search.test.ts b/tests/typed_search.test.ts index a34381989..d92908674 100644 --- a/tests/typed_search.test.ts +++ b/tests/typed_search.test.ts @@ -6,7 +6,7 @@ import { expect, test, } from "vitest"; -import { ErrorStatusCode, type SearchResponse } from "../src/types/index.js"; +import type { SearchResponse } from "../src/types/index.js"; import { clearAllIndexes, config, @@ -397,7 +397,7 @@ describe.each([ await expect( client.index(index.uid).search("prince"), - ).rejects.toHaveProperty("cause.code", ErrorStatusCode.INDEX_NOT_FOUND); + ).rejects.toHaveProperty("cause.code", "index_not_found"); }); }); @@ -472,10 +472,7 @@ describe.each([{ permission: "No" }])( const client = await getClient(permission); await expect( client.index(index.uid).search("prince"), - ).rejects.toHaveProperty( - "cause.code", - ErrorStatusCode.MISSING_AUTHORIZATION_HEADER, - ); + ).rejects.toHaveProperty("cause.code", "missing_authorization_header"); }); }, ); diff --git a/tests/typo_tolerance.test.ts b/tests/typo_tolerance.test.ts index 7cad1e126..38221629a 100644 --- a/tests/typo_tolerance.test.ts +++ b/tests/typo_tolerance.test.ts @@ -1,5 +1,4 @@ import { afterAll, beforeEach, describe, expect, test } from "vitest"; -import { ErrorStatusCode } from "../src/types/index.js"; import { clearAllIndexes, config, @@ -94,21 +93,21 @@ describe.each([{ permission: "Search" }])( const client = await getClient(permission); await expect( client.index(index.uid).getTypoTolerance(), - ).rejects.toHaveProperty("cause.code", ErrorStatusCode.INVALID_API_KEY); + ).rejects.toHaveProperty("cause.code", "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("cause.code", ErrorStatusCode.INVALID_API_KEY); + ).rejects.toHaveProperty("cause.code", "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("cause.code", ErrorStatusCode.INVALID_API_KEY); + ).rejects.toHaveProperty("cause.code", "invalid_api_key"); }); }, ); @@ -124,30 +123,21 @@ describe.each([{ permission: "No" }])( const client = await getClient(permission); await expect( client.index(index.uid).getTypoTolerance(), - ).rejects.toHaveProperty( - "cause.code", - ErrorStatusCode.MISSING_AUTHORIZATION_HEADER, - ); + ).rejects.toHaveProperty("cause.code", "missing_authorization_header"); }); 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( - "cause.code", - ErrorStatusCode.MISSING_AUTHORIZATION_HEADER, - ); + ).rejects.toHaveProperty("cause.code", "missing_authorization_header"); }); 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( - "cause.code", - ErrorStatusCode.MISSING_AUTHORIZATION_HEADER, - ); + ).rejects.toHaveProperty("cause.code", "missing_authorization_header"); }); }, );