diff --git a/.code-samples.meilisearch.yaml b/.code-samples.meilisearch.yaml index 5370f8281..e9d18c22d 100644 --- a/.code-samples.meilisearch.yaml +++ b/.code-samples.meilisearch.yaml @@ -31,6 +31,8 @@ create_an_index_1: |- client.createIndex('movies', { primaryKey: 'id' }) update_an_index_1: |- client.updateIndex('movies', { primaryKey: 'id' }) +rename_an_index_1: |- + client.updateIndex('INDEX_A', { indexUid: 'INDEX_B' }) delete_an_index_1: |- client.deleteIndex('movies') swap_indexes_1: |- diff --git a/package.json b/package.json index e0272e35c..0ec39945d 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "build:docs": "typedoc", "build": "vite build && tsc -p tsconfig.build.json && vite --mode production-umd build", "postbuild": "node scripts/build.js", - "test": "vitest run --coverage", + "test": "vitest run --coverage --hook-timeout=120000 --test-timeout=120000", "types": "tsc -p tsconfig.json --noEmit", "types:watch": "yarn types --watch", "test:env:browser": "yarn build && node scripts/copy-umd-file.js --to ./tests/env/express/public && yarn --cwd tests/env/express && yarn --cwd tests/env/express test", diff --git a/src/types/types.ts b/src/types/types.ts index 3d57fb6d9..fb7915fa3 100644 --- a/src/types/types.ts +++ b/src/types/types.ts @@ -141,6 +141,7 @@ export type ResultsWrapper = { export type IndexOptions = { primaryKey?: string; + uid?: string; }; export type IndexObject = { @@ -408,6 +409,7 @@ export type SearchResponse< facetDistribution?: FacetDistribution; facetStats?: FacetStats; facetsByIndex?: FacetsByIndex; + queryVector?: number[]; } & (undefined extends S ? Partial : true extends IsFinitePagination> diff --git a/tests/client.test.ts b/tests/client.test.ts index a426d5515..aeca34757 100644 --- a/tests/client.test.ts +++ b/tests/client.test.ts @@ -566,6 +566,31 @@ describe.each([{ permission: "Master" }, { permission: "Admin" }])( ErrorStatusCode.INVALID_SWAP_DUPLICATE_INDEX_FOUND, ); }); + + test(`${permission} key: Swap two indexes with rename`, async () => { + const client = await getClient(permission); + const originalUid1 = index.uid; + const originalUid2 = index2.uid; + + await client + .index(originalUid1) + .addDocuments([{ id: 1, title: "index_1" }]) + .waitTask(); + await client + .index(originalUid2) + .addDocuments([{ id: 1, title: "index_2" }]) + .waitTask(); + + const swaps: IndexSwap[] = [ + { indexes: [originalUid1, originalUid2], rename: true }, + ]; + + const resolvedTask = await client.swapIndexes(swaps).waitTask(); + + // Verify the swap task completed with expected details + expect(resolvedTask.type).toEqual("indexSwap"); + expect(resolvedTask.details?.swaps).toEqual(swaps); + }); }); describe("Test on base routes", () => { diff --git a/tests/get_search.test.ts b/tests/get_search.test.ts index 3a6771b1d..a6bfbd661 100644 --- a/tests/get_search.test.ts +++ b/tests/get_search.test.ts @@ -542,7 +542,6 @@ describe.each([ }); }); - // This test deletes the index, so following tests may fail if they need an existing index test(`${permission} key: Try to search on deleted index and fail`, async () => { const client = await getClient(permission); const masterClient = await getClient("Master"); diff --git a/tests/index.test.ts b/tests/index.test.ts index faea55881..add24e670 100644 --- a/tests/index.test.ts +++ b/tests/index.test.ts @@ -292,6 +292,27 @@ describe.each([{ permission: "Master" }, { permission: "Admin" }])( expect(index).toHaveProperty("primaryKey", "newPrimaryKey"); }); + test(`${permission} key: rename index using update method`, async () => { + const client = await getClient(permission); + const originalUid = indexNoPk.uid; + const newUid = "renamed_index"; + + await client.createIndex(originalUid).waitTask(); + await client + .updateIndex(originalUid, { + uid: newUid, + }) + .waitTask(); + + await expect(client.getIndex(originalUid)).rejects.toHaveProperty( + "cause.code", + ErrorStatusCode.INDEX_NOT_FOUND, + ); + + const renamed = await client.getIndex(newUid); + expect(renamed).toHaveProperty("uid", newUid); + }); + test(`${permission} key: delete index`, async () => { const client = await getClient(permission); await client.createIndex(indexNoPk.uid).waitTask(); diff --git a/tests/utils/meilisearch-test-utils.ts b/tests/utils/meilisearch-test-utils.ts index 234e502d5..55d663e11 100644 --- a/tests/utils/meilisearch-test-utils.ts +++ b/tests/utils/meilisearch-test-utils.ts @@ -16,7 +16,7 @@ const BAD_HOST = "http://127.0.0.1:7701"; const config: Config = { host: HOST, apiKey: MASTER_KEY, - defaultWaitOptions: { interval: 10 }, + defaultWaitOptions: { interval: 10, timeout: 60_000 }, }; const badHostClient = new MeiliSearch({ host: BAD_HOST, @@ -25,12 +25,12 @@ const badHostClient = new MeiliSearch({ const masterClient = new MeiliSearch({ host: HOST, apiKey: MASTER_KEY, - defaultWaitOptions: { interval: 10 }, + defaultWaitOptions: { interval: 10, timeout: 60_000 }, }); const anonymousClient = new MeiliSearch({ host: HOST, - defaultWaitOptions: { interval: 10 }, + defaultWaitOptions: { interval: 10, timeout: 60_000 }, }); async function getKey(permission: string): Promise { @@ -70,7 +70,7 @@ async function getClient(permission: string): Promise { const searchClient = new MeiliSearch({ host: HOST, apiKey: searchKey, - defaultWaitOptions: { interval: 10 }, + defaultWaitOptions: { interval: 10, timeout: 60_000 }, }); return searchClient; } @@ -80,7 +80,7 @@ async function getClient(permission: string): Promise { const adminClient = new MeiliSearch({ host: HOST, apiKey: adminKey, - defaultWaitOptions: { interval: 10 }, + defaultWaitOptions: { interval: 10, timeout: 60_000 }, }); return adminClient; }