@@ -31,6 +31,13 @@ describe(testSuite.testName, () => {
31
31
] ) ;
32
32
} ;
33
33
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
+
34
41
it ( 'copies indices between accounts' , async ( ) => {
35
42
const source = testSuite . makeIndex ( ) ;
36
43
const destination = testSuite
@@ -75,11 +82,8 @@ describe(testSuite.testName, () => {
75
82
76
83
await expect ( accountCopyIndex ( source , destination ) ) . resolves . toBeUndefined ( ) ;
77
84
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 ) ;
83
87
} ) ;
84
88
85
89
it ( 'it bubbles up errors' , async ( ) => {
@@ -91,7 +95,7 @@ describe(testSuite.testName, () => {
91
95
92
96
const addApiKeyResponse = await testSuite
93
97
. makeSearchClient ( 'ALGOLIA_APPLICATION_ID_2' , 'ALGOLIA_ADMIN_KEY_2' )
94
- . addApiKey ( [ 'settings' , 'editSettings' ] , {
98
+ . addApiKey ( [ 'settings' , 'editSettings' , 'search' ] , {
95
99
indexes : [ indexName ] ,
96
100
} )
97
101
. wait ( ) ;
@@ -106,6 +110,13 @@ describe(testSuite.testName, () => {
106
110
status : 400 ,
107
111
} ) ;
108
112
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
+ } ) ;
110
121
} ) ;
111
122
} ) ;
0 commit comments