Skip to content

Commit 921c0bc

Browse files
committed
test: run if server support scope search feature
1 parent 9b556b8 commit 921c0bc

1 file changed

Lines changed: 67 additions & 61 deletions

File tree

tests/http-client/tests/waitFor/waitForDocumentsInSearchIndex.spec.ts

Lines changed: 67 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -15,77 +15,83 @@
1515
*/
1616
import { describe } from 'vitest';
1717

18+
import { ServerFeatures } from '@cbjsdev/http-client';
1819
import { waitForDocumentsInSearchIndex } from '@cbjsdev/http-client/dist/src/waitFor/waitForDocumentsInSearchIndex.js';
1920
import { getRandomId } from '@cbjsdev/shared';
2021
import { createCouchbaseTest } from '@cbjsdev/vitest';
2122

23+
import { serverSupportsFeatures } from '../../utils/serverFeature.js';
2224
import getIndexDefinition from './getIndexDefinition.js';
2325

24-
describe('waitForDocumentsInSearchIndex', { timeout: 100_000 }, async () => {
25-
const test = await createCouchbaseTest();
26+
describe.runIf(serverSupportsFeatures(ServerFeatures.ScopeSearchIndexManagement))(
27+
'waitForDocumentsInSearchIndex',
28+
{ timeout: 100_000 },
29+
async () => {
30+
const test = await createCouchbaseTest();
2631

27-
test(
28-
'should return once the document are found',
29-
async ({
30-
expect,
31-
useScopedSearchIndex,
32-
useDocumentKey,
33-
useScope,
34-
useCollection,
35-
serverTestContext,
36-
apiConfig,
37-
}) => {
38-
const scopeName = await useScope();
39-
const collectionName = await useCollection({ scopeName });
32+
test(
33+
'should return once the document are found',
34+
async ({
35+
expect,
36+
useScopedSearchIndex,
37+
useDocumentKey,
38+
useScope,
39+
useCollection,
40+
serverTestContext,
41+
apiConfig,
42+
}) => {
43+
const scopeName = await useScope();
44+
const collectionName = await useCollection({ scopeName });
4045

41-
const searchIndexName = `searchIndex` + getRandomId();
42-
const def = getIndexDefinition(searchIndexName, {
43-
bucket: serverTestContext.bucket.name,
44-
scope: scopeName,
45-
collection: collectionName,
46-
});
46+
const searchIndexName = `searchIndex` + getRandomId();
47+
const def = getIndexDefinition(searchIndexName, {
48+
bucket: serverTestContext.bucket.name,
49+
scope: scopeName,
50+
collection: collectionName,
51+
});
4752

48-
const indexName = await useScopedSearchIndex(
49-
{
50-
bucketName: serverTestContext.bucket.name,
51-
scopeName,
52-
collectionName,
53-
...def,
54-
},
55-
{ waitSearchIndexTimeout: 100_000, awaitMutations: true }
56-
);
53+
const indexName = await useScopedSearchIndex(
54+
{
55+
bucketName: serverTestContext.bucket.name,
56+
scopeName,
57+
collectionName,
58+
...def,
59+
},
60+
{ waitSearchIndexTimeout: 100_000, awaitMutations: true }
61+
);
5762

58-
const testDocKey = useDocumentKey();
59-
const testDocBody = {
60-
title: 'Couchbase',
61-
tagline: 'No Equal - The Cloud database for modern applications',
62-
description:
63-
'Couchbase is a NoSQL, distributed database focused on performances at scale.',
64-
};
63+
const testDocKey = useDocumentKey();
64+
const testDocBody = {
65+
title: 'Couchbase',
66+
tagline: 'No Equal - The Cloud database for modern applications',
67+
description:
68+
'Couchbase is a NoSQL, distributed database focused on performances at scale.',
69+
};
6570

66-
const testDocKey2 = useDocumentKey();
67-
const testDocBody2 = {
68-
title: 'Magma',
69-
description: 'The latest storage engine from Couchbase.',
70-
};
71+
const testDocKey2 = useDocumentKey();
72+
const testDocBody2 = {
73+
title: 'Magma',
74+
description: 'The latest storage engine from Couchbase.',
75+
};
7176

72-
const collection = serverTestContext.bucket
73-
.scope(scopeName)
74-
.collection(collectionName);
75-
await collection.insert(testDocKey, testDocBody);
76-
await collection.insert(testDocKey2, testDocBody2);
77+
const collection = serverTestContext.bucket
78+
.scope(scopeName)
79+
.collection(collectionName);
80+
await collection.insert(testDocKey, testDocBody);
81+
await collection.insert(testDocKey2, testDocBody2);
7782

78-
await waitForDocumentsInSearchIndex(
79-
apiConfig,
80-
{
81-
bucket: serverTestContext.bucket.name,
82-
scope: scopeName,
83-
index: indexName,
84-
},
85-
[testDocKey, testDocKey2],
86-
{ timeout: 60_000 }
87-
);
88-
},
89-
{ timeout: 100_000 }
90-
);
91-
});
83+
await waitForDocumentsInSearchIndex(
84+
apiConfig,
85+
{
86+
bucket: serverTestContext.bucket.name,
87+
scope: scopeName,
88+
index: indexName,
89+
},
90+
[testDocKey, testDocKey2],
91+
{ timeout: 60_000 }
92+
);
93+
},
94+
{ timeout: 100_000 }
95+
);
96+
}
97+
);

0 commit comments

Comments
 (0)