Skip to content

Commit dd7a966

Browse files
nunomaduroHaroenv
andcommitted
fix(account-client-copy): fixes flacky tests
Co-Authored-By: Haroen Viaene <[email protected]>
1 parent c13d728 commit dd7a966

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

packages/client-account/src/__tests__/integration/account-copy-index.test.ts

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,13 @@ describe(testSuite.testName, () => {
3131
]);
3232
};
3333

34+
const waitForIndexCreated = (destination: ReturnType<typeof testSuite.makeIndex>) =>
35+
createRetryablePromise(async retry => {
36+
const exists = await destination.exists();
37+
38+
return exists ? Promise.resolve() : retry();
39+
});
40+
3441
it('copies indices between accounts', async () => {
3542
const source = testSuite.makeIndex();
3643
const destination = testSuite
@@ -75,11 +82,8 @@ describe(testSuite.testName, () => {
7582

7683
await expect(accountCopyIndex(source, destination)).resolves.toBeUndefined();
7784

78-
await createRetryablePromise(async retry => {
79-
const exists = await destination.exists();
80-
81-
return exists ? Promise.resolve() : retry();
82-
});
85+
await waitForIndexCreated(destination);
86+
await expect(destination.exists()).resolves.toEqual(true);
8387
});
8488

8589
it('it bubbles up errors', async () => {
@@ -91,7 +95,7 @@ describe(testSuite.testName, () => {
9195

9296
const addApiKeyResponse = await testSuite
9397
.makeSearchClient('ALGOLIA_APPLICATION_ID_2', 'ALGOLIA_ADMIN_KEY_2')
94-
.addApiKey(['settings', 'editSettings'], {
98+
.addApiKey(['settings', 'editSettings', 'search'], {
9599
indexes: [indexName],
96100
})
97101
.wait();
@@ -106,6 +110,13 @@ describe(testSuite.testName, () => {
106110
status: 400,
107111
});
108112

109-
await expect(destination.exists()).resolves.toBe(false);
113+
// At this point, we should have created the index. But it should
114+
// be empty because we only have set settings on it.
115+
await waitForIndexCreated(destination);
116+
117+
await expect(destination.search('')).resolves.toMatchObject({
118+
nbHits: 0,
119+
hits: [],
120+
});
110121
});
111122
});

0 commit comments

Comments
 (0)