diff --git a/test/manual/search-index-management.prose.test.ts b/test/manual/search-index-management.prose.test.ts index 139cf24328..69b366583b 100644 --- a/test/manual/search-index-management.prose.test.ts +++ b/test/manual/search-index-management.prose.test.ts @@ -4,7 +4,13 @@ import { Readable } from 'stream'; import { clearTimeout, setTimeout as setTimeoutCb } from 'timers'; import { setInterval } from 'timers/promises'; -import { type Collection, type Document, type MongoClient, ObjectId, MongoServerError } from '../mongodb'; +import { + type Collection, + type Document, + type MongoClient, + MongoServerError, + ObjectId +} from '../mongodb'; class TimeoutController extends AbortController { timeoutId: NodeJS.Timeout; @@ -284,156 +290,163 @@ describe('Index Management Prose Tests', function () { } ); - it('Case 7: Driver can successfully handle search index types when creating indexes', metadata, async function () { - // 01. Create a collection with the "create" command using a randomly generated name (referred to as `coll0`). - const coll0 = collection; - { - // 02. Create a new search index on `coll0` with the `createSearchIndex` helper. Use the following definition: - // ```typescript - // { - // name: 'test-search-index-case7-implicit', - // definition: { - // mappings: { dynamic: false } - // } - // } - // ``` - const indexName = await coll0.createSearchIndex({ - name: 'test-search-index-case7-implicit', - definition: { - mappings: { dynamic: false } - } - }) - // 03. Assert that the command returns the name of the index: `"test-search-index-case7-implicit"`. - expect(indexName).to.equal('test-search-index-case7-implicit') - // 04. Run `coll0.listSearchIndexes('test-search-index-case7-implicit')` repeatedly every 5 seconds until the following - // condition is satisfied and store the value in a variable `index1`: - - // - An index with the `name` of `test-search-index-case7-implicit` is present and the index has a field `queryable` - // with a value of `true`. - - const [index1] = await waitForIndexes({ - predicate: indexes => indexes.every(index => index.queryable), - indexNames: 'test-search-index-case7-implicit' - }); - - // 05. Assert that `index1` has a property `type` whose value is `search`. - expect(index1).to.have.property('type', 'search'); - } - { - // 06. Create a new search index on `coll0` with the `createSearchIndex` helper. Use the following definition: - // ```typescript - // { - // name: 'test-search-index-case7-explicit', - // type: 'search', - // definition: { - // mappings: { dynamic: false } - // } - // } - // ``` - const indexName = await coll0.createSearchIndex({ - name: 'test-search-index-case7-explicit', - type: 'search', - definition: { - mappings: { dynamic: false } - } + it( + 'Case 7: Driver can successfully handle search index types when creating indexes', + metadata, + async function () { + // 01. Create a collection with the "create" command using a randomly generated name (referred to as `coll0`). + const coll0 = collection; + { + // 02. Create a new search index on `coll0` with the `createSearchIndex` helper. Use the following definition: + // ```typescript + // { + // name: 'test-search-index-case7-implicit', + // definition: { + // mappings: { dynamic: false } + // } + // } + // ``` + const indexName = await coll0.createSearchIndex({ + name: 'test-search-index-case7-implicit', + definition: { + mappings: { dynamic: false } + } + }); + // 03. Assert that the command returns the name of the index: `"test-search-index-case7-implicit"`. + expect(indexName).to.equal('test-search-index-case7-implicit'); + // 04. Run `coll0.listSearchIndexes('test-search-index-case7-implicit')` repeatedly every 5 seconds until the following + // condition is satisfied and store the value in a variable `index1`: + + // - An index with the `name` of `test-search-index-case7-implicit` is present and the index has a field `queryable` + // with a value of `true`. + + const [index1] = await waitForIndexes({ + predicate: indexes => indexes.every(index => index.queryable), + indexNames: 'test-search-index-case7-implicit' + }); + + // 05. Assert that `index1` has a property `type` whose value is `search`. + expect(index1).to.have.property('type', 'search'); + } + { + // 06. Create a new search index on `coll0` with the `createSearchIndex` helper. Use the following definition: + // ```typescript + // { + // name: 'test-search-index-case7-explicit', + // type: 'search', + // definition: { + // mappings: { dynamic: false } + // } + // } + // ``` + const indexName = await coll0.createSearchIndex({ + name: 'test-search-index-case7-explicit', + type: 'search', + definition: { + mappings: { dynamic: false } + } + }); + // 07. Assert that the command returns the name of the index: `"test-search-index-case7-explicit"`. + expect(indexName).to.equal('test-search-index-case7-explicit'); + // 08. Run `coll0.listSearchIndexes('test-search-index-case7-explicit')` repeatedly every 5 seconds until the following + // condition is satisfied and store the value in a variable `index2`: + + // - An index with the `name` of `test-search-index-case7-explicit` is present and the index has a field `queryable` + // with a value of `true`. + + const [index2] = await waitForIndexes({ + predicate: indexes => indexes.every(index => index.queryable), + indexNames: 'test-search-index-case7-explicit' + }); + // 09. Assert that `index2` has a property `type` whose value is `search`. + expect(index2).to.have.property('type', 'search'); + } + { + // 10. Create a new vector search index on `coll0` with the `createSearchIndex` helper. Use the following definition: + // ```typescript + // { + // name: 'test-search-index-case7-vector', + // type: 'vectorSearch', + // definition: { + // "fields": [ + // { + // "type": "vector", + // "path": "plot_embedding", + // "numDimensions": 1536, + // "similarity": "euclidean", + // }, + // ] + // } + // } + // ``` + + const indexName = await coll0.createSearchIndex({ + name: 'test-search-index-case7-vector', + type: 'vectorSearch', + definition: { + fields: [ + { + type: 'vector', + path: 'plot_embedding', + numDimensions: 1536, + similarity: 'euclidean' + } + ] + } + }); + // 11. Assert that the command returns the name of the index: `"test-search-index-case7-vector"`. + expect(indexName).to.equal('test-search-index-case7-vector'); + // 12. Run `coll0.listSearchIndexes('test-search-index-case7-vector')` repeatedly every 5 seconds until the following + // condition is satisfied and store the value in a variable `index3`: + // - An index with the `name` of `test-search-index-case7-vector` is present and the index has a field `queryable` with + // a value of `true`. + const [index3] = await waitForIndexes({ + predicate: indexes => indexes.every(index => index.queryable), + indexNames: 'test-search-index-case7-vector' + }); + + // 13. Assert that `index3` has a property `type` whose value is `vectorSearch`. + expect(index3).to.have.property('type', 'vectorSearch'); } - ) - // 07. Assert that the command returns the name of the index: `"test-search-index-case7-explicit"`. - expect(indexName).to.equal('test-search-index-case7-explicit') - // 08. Run `coll0.listSearchIndexes('test-search-index-case7-explicit')` repeatedly every 5 seconds until the following - // condition is satisfied and store the value in a variable `index2`: - - // - An index with the `name` of `test-search-index-case7-explicit` is present and the index has a field `queryable` - // with a value of `true`. - - const [index2] = await waitForIndexes({ - predicate: indexes => indexes.every(index => index.queryable), - indexNames: 'test-search-index-case7-explicit' - }); - // 09. Assert that `index2` has a property `type` whose value is `search`. - expect(index2).to.have.property('type', 'search'); } - { - // 10. Create a new vector search index on `coll0` with the `createSearchIndex` helper. Use the following definition: - // ```typescript - // { - // name: 'test-search-index-case7-vector', - // type: 'vectorSearch', - // definition: { - // "fields": [ - // { - // "type": "vector", - // "path": "plot_embedding", - // "numDimensions": 1536, - // "similarity": "euclidean", - // }, - // ] - // } - // } - // ``` + ); - const indexName = await coll0.createSearchIndex({ - name: 'test-search-index-case7-vector', - type: 'vectorSearch', - definition: { - "fields": [ - { - "type": "vector", - "path": "plot_embedding", - "numDimensions": 1536, - "similarity": "euclidean", - }, - ] - } + it('Case 8: Driver requires explicit type to create a vector search index', async function () { + // 1. Create a collection with the "create" command using a randomly generated name (referred to as `coll0`). + const coll0 = collection; + + // 2. Create a new vector search index on `coll0` with the `createSearchIndex` helper. Use the following definition: + // { + // name: 'test-search-index-case8-error', + // definition: { + // fields: [ + // { + // type: 'vector', + // path: 'plot_embedding', + // numDimensions: 1536, + // similarity: 'euclidean', + // }, + // ] + // } + // } + const definition = { + name: 'test-search-index-case8-error', + definition: { + fields: [ + { + type: 'vector', + path: 'plot_embedding', + numDimensions: 1536, + similarity: 'euclidean' + } + ] } - ) - // 11. Assert that the command returns the name of the index: `"test-search-index-case7-vector"`. - expect(indexName).to.equal("test-search-index-case7-vector"); - // 12. Run `coll0.listSearchIndexes('test-search-index-case7-vector')` repeatedly every 5 seconds until the following - // condition is satisfied and store the value in a variable `index3`: - // - An index with the `name` of `test-search-index-case7-vector` is present and the index has a field `queryable` with - // a value of `true`. - const [index3] = await waitForIndexes({ - predicate: indexes => indexes.every(index => index.queryable), - indexNames: 'test-search-index-case7-vector' - }); + }; + const error = await coll0.createSearchIndex(definition).catch(e => e); - // 13. Assert that `index3` has a property `type` whose value is `vectorSearch`. - expect(index3).to.have.property('type', 'vectorSearch'); - } - { - // 14. Create a new vector search index on `coll0` with the `createSearchIndex` helper. Use the following definition: - // ```typescript - // { - // name: 'test-search-index-case7-error', - // definition: { - // "fields": [ - // { - // "type": "vector", - // "path": "plot_embedding", - // "numDimensions": 1536, - // "similarity": "euclidean", - // }, - // ] - // } - // } - // ``` - const error = await coll0.createSearchIndex({ - name: 'test-search-index-case7-error', - definition: { - "fields": [ - { - "type": "vector", - "path": "plot_embedding", - "numDimensions": 1536, - "similarity": "euclidean", - }, - ] - } - }).catch(e => e) - // 15. Assert that the command throws an exception due to the `mappings` field missing. - expect(error).to.be.instanceOf(MongoServerError).to.match(/mappings/i); - } - }) + // 3. Assert that the command throws an exception containing the string "Attribute mappings missing" due to the `mappings` + // field missing. + expect(error).to.match(/Attribute mappings missing/i); + }); }); });