Skip to content

Commit 5dbbc0e

Browse files
authored
Change index creation and wait method in tests (#629)
1 parent 7052b74 commit 5dbbc0e

File tree

9 files changed

+101
-119
lines changed

9 files changed

+101
-119
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
"url": "https://github.com/meilisearch/instant-meilisearch.git"
5555
},
5656
"dependencies": {
57-
"meilisearch": "^0.23.0"
57+
"meilisearch": "0.24.0-beta.0"
5858
},
5959
"devDependencies": {
6060
"@babel/cli": "^7.16.0",

tests/configure.attributes-to-retrieve.tests.ts

Lines changed: 51 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@ import { searchClient, dataset, Movies } from './assets/utils'
22

33
describe('Instant MeiliSearch Browser test', () => {
44
beforeAll(async () => {
5-
try {
6-
await searchClient.MeiliSearchClient.deleteIndex('movies')
7-
} catch (e) {
8-
// movies does not exist
9-
}
10-
const moviesUpdate = await searchClient.MeiliSearchClient.index(
5+
const deleteTask = await searchClient.MeiliSearchClient.deleteIndex(
6+
'movies'
7+
)
8+
await searchClient.MeiliSearchClient.waitForTask(deleteTask.uid)
9+
10+
const documentsTask = await searchClient.MeiliSearchClient.index(
1111
'movies'
1212
).addDocuments(dataset)
13-
await searchClient.MeiliSearchClient.index('movies').waitForPendingUpdate(
14-
moviesUpdate.updateId
13+
await searchClient.MeiliSearchClient.index('movies').waitForTask(
14+
documentsTask.uid
1515
)
1616
})
1717

@@ -43,18 +43,14 @@ describe('Instant MeiliSearch Browser test', () => {
4343
},
4444
},
4545
])
46-
const notRetrieved = [
47-
'id',
48-
'overview',
49-
'genres',
50-
'poster',
51-
'release_date',
52-
'title',
53-
]
46+
5447
const hit = <Movies>response.results[0].hits[0]
55-
notRetrieved.map((attribute: string) =>
56-
expect(hit[attribute]).not.toBeDefined()
57-
)
48+
expect(hit.id).not.toBeDefined()
49+
expect(hit.overview).not.toBeDefined()
50+
expect(hit.genres).not.toBeDefined()
51+
expect(hit.poster).not.toBeDefined()
52+
expect(hit.release_date).not.toBeDefined()
53+
expect(hit.title).not.toBeDefined()
5854
})
5955

6056
test('Test attributesToRetrieve on one non existing attribute', async () => {
@@ -67,20 +63,15 @@ describe('Instant MeiliSearch Browser test', () => {
6763
},
6864
},
6965
])
70-
const notRetrieved = [
71-
'id',
72-
'overview',
73-
'genres',
74-
'poster',
75-
'release_date',
76-
'title',
77-
]
66+
7867
const hit = <Movies>response.results[0].hits[0]
79-
notRetrieved.map(
80-
(attribute: string) =>
81-
hit._highlightResult &&
82-
expect(hit._highlightResult[attribute]).toBeDefined()
83-
)
68+
69+
expect(hit._highlightResult?.id).toBeDefined()
70+
expect(hit._highlightResult?.overview).toBeDefined()
71+
expect(hit._highlightResult?.genres).toBeDefined()
72+
expect(hit._highlightResult?.poster).toBeDefined()
73+
expect(hit._highlightResult?.release_date).toBeDefined()
74+
expect(hit._highlightResult?.title).toBeDefined()
8475
})
8576

8677
test('Test attributesToRetrieve on one existing attribute', async () => {
@@ -93,12 +84,14 @@ describe('Instant MeiliSearch Browser test', () => {
9384
},
9485
},
9586
])
96-
const notRetrieved = ['id', 'overview', 'genres', 'poster', 'release_date']
9787
const hit = <Movies>response.results[0].hits[0]
9888
expect(hit.title).toEqual('Ariel')
99-
notRetrieved.map((attribute: string) =>
100-
expect(hit[attribute]).not.toBeDefined()
101-
)
89+
expect(hit.id).not.toBeDefined()
90+
expect(hit.overview).not.toBeDefined()
91+
expect(hit.genres).not.toBeDefined()
92+
expect(hit.poster).not.toBeDefined()
93+
expect(hit.release_date).not.toBeDefined()
94+
expect(hit.title).toBeDefined()
10295
})
10396

10497
test('Test attributesToRetrieve on default value', async () => {
@@ -110,18 +103,24 @@ describe('Instant MeiliSearch Browser test', () => {
110103
},
111104
},
112105
])
113-
const notRetrieved = ['id', 'overview', 'genres', 'poster', 'release_date']
106+
114107
const hit = <Movies>response.results[0].hits[0]
115108
expect(hit.title).toEqual('Ariel')
116109
expect(hit._highlightResult).toBeDefined()
117-
notRetrieved.map((attribute: string) =>
118-
expect(hit[attribute]).toBeDefined()
119-
)
120-
notRetrieved.map(
121-
(attribute: string) =>
122-
hit._highlightResult &&
123-
expect(hit._highlightResult[attribute]).toBeDefined()
124-
)
110+
111+
expect(hit.id).toBeDefined()
112+
expect(hit.overview).toBeDefined()
113+
expect(hit.genres).toBeDefined()
114+
expect(hit.poster).toBeDefined()
115+
expect(hit.release_date).toBeDefined()
116+
expect(hit.title).toBeDefined()
117+
118+
expect(hit._highlightResult?.id).toBeDefined()
119+
expect(hit._highlightResult?.overview).toBeDefined()
120+
expect(hit._highlightResult?.genres).toBeDefined()
121+
expect(hit._highlightResult?.poster).toBeDefined()
122+
expect(hit._highlightResult?.release_date).toBeDefined()
123+
expect(hit._highlightResult?.title).toBeDefined()
125124
})
126125

127126
test('Test attributesToRetrieve on wild card', async () => {
@@ -134,21 +133,14 @@ describe('Instant MeiliSearch Browser test', () => {
134133
},
135134
},
136135
])
137-
const retrieved = [
138-
'id',
139-
'overview',
140-
'genres',
141-
'poster',
142-
'release_date',
143-
'title',
144-
]
136+
145137
const hit = <Movies>response.results[0].hits[0]
146138
expect(hit.title).toEqual('Ariel')
147-
retrieved.map((attribute: string) => expect(hit[attribute]).toBeDefined())
148-
retrieved.map(
149-
(attribute: string) =>
150-
hit._highlightResult &&
151-
expect(hit._highlightResult[attribute]).toBeDefined()
152-
)
139+
expect(hit._highlightResult?.id).toBeDefined()
140+
expect(hit._highlightResult?.overview).toBeDefined()
141+
expect(hit._highlightResult?.genres).toBeDefined()
142+
expect(hit._highlightResult?.poster).toBeDefined()
143+
expect(hit._highlightResult?.release_date).toBeDefined()
144+
expect(hit._highlightResult?.title).toBeDefined()
153145
})
154146
})

tests/facets-distribution.tests.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,18 @@ import { searchClient, dataset } from './assets/utils'
22

33
describe('Instant MeiliSearch Browser test', () => {
44
beforeAll(async () => {
5-
try {
6-
await searchClient.MeiliSearchClient.deleteIndex('movies')
7-
} catch (e) {
8-
// movies does not exist
9-
}
5+
const deleteTask = await searchClient.MeiliSearchClient.deleteIndex(
6+
'movies'
7+
)
8+
await searchClient.MeiliSearchClient.waitForTask(deleteTask.uid)
109
await searchClient.MeiliSearchClient.index(
1110
'movies'
1211
).updateFilterableAttributes(['genres'])
13-
const moviesUpdate = await searchClient.MeiliSearchClient.index(
12+
const documentsTask = await searchClient.MeiliSearchClient.index(
1413
'movies'
1514
).addDocuments(dataset)
16-
await searchClient.MeiliSearchClient.index('movies').waitForPendingUpdate(
17-
moviesUpdate.updateId
15+
await searchClient.MeiliSearchClient.index('movies').waitForTask(
16+
documentsTask.uid
1817
)
1918
})
2019

tests/filter.tests.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,18 @@ import { searchClient, dataset, Movies } from './assets/utils'
22

33
describe('Instant MeiliSearch Browser test', () => {
44
beforeAll(async () => {
5-
try {
6-
await searchClient.MeiliSearchClient.deleteIndex('movies')
7-
} catch (e) {
8-
// movies does not exist
9-
}
5+
const deleteTask = await searchClient.MeiliSearchClient.deleteIndex(
6+
'movies'
7+
)
8+
await searchClient.MeiliSearchClient.waitForTask(deleteTask.uid)
109
await searchClient.MeiliSearchClient.index(
1110
'movies'
1211
).updateFilterableAttributes(['genres', 'title'])
13-
const moviesUpdate = await searchClient.MeiliSearchClient.index(
12+
const documentsTask = await searchClient.MeiliSearchClient.index(
1413
'movies'
1514
).addDocuments(dataset)
16-
await searchClient.MeiliSearchClient.index('movies').waitForPendingUpdate(
17-
moviesUpdate.updateId
15+
await searchClient.MeiliSearchClient.index('movies').waitForTask(
16+
documentsTask.uid
1817
)
1918
})
2019

tests/geosearch.tests.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,21 @@ import { searchClient, geoDataset, City } from './assets/utils'
22

33
describe('Instant MeiliSearch Browser test', () => {
44
beforeAll(async () => {
5-
try {
6-
await searchClient.MeiliSearchClient.deleteIndex('geotest')
7-
} catch (e) {
8-
// geotest does not exist
9-
}
5+
const deleteTask = await searchClient.MeiliSearchClient.deleteIndex(
6+
'geotest'
7+
)
8+
await searchClient.MeiliSearchClient.waitForTask(deleteTask.uid)
109
await searchClient.MeiliSearchClient.index(
1110
'geotest'
1211
).updateFilterableAttributes(['_geo'])
1312
await searchClient.MeiliSearchClient.index(
1413
'geotest'
1514
).updateSortableAttributes(['_geo'])
16-
const geotestUpdate = await searchClient.MeiliSearchClient.index(
15+
const documentsTask = await searchClient.MeiliSearchClient.index(
1716
'geotest'
1817
).addDocuments(geoDataset)
19-
await searchClient.MeiliSearchClient.index('geotest').waitForPendingUpdate(
20-
geotestUpdate.updateId
18+
await searchClient.MeiliSearchClient.index('movies').waitForTask(
19+
documentsTask.uid
2120
)
2221
})
2322

tests/highlight.tests.ts

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,18 @@ import { searchClient, dataset, Movies } from './assets/utils'
22

33
describe('Highlight Browser test', () => {
44
beforeAll(async () => {
5-
try {
6-
await searchClient.MeiliSearchClient.deleteIndex('movies')
7-
} catch (e) {
8-
// movies does not exist
9-
}
10-
const moviesUpdate = await searchClient.MeiliSearchClient.index(
11-
'movies'
12-
).addDocuments(dataset)
13-
const settingsUpdate = await searchClient.MeiliSearchClient.index(
5+
const deleteTask = await searchClient.MeiliSearchClient.deleteIndex(
146
'movies'
15-
).updateFilterableAttributes(['genres']) // if settings update is put before document addition relevancy is impacted
16-
17-
await searchClient.MeiliSearchClient.index('movies').waitForPendingUpdate(
18-
moviesUpdate.updateId
197
)
20-
await searchClient.MeiliSearchClient.index('movies').waitForPendingUpdate(
21-
settingsUpdate.updateId
8+
await searchClient.MeiliSearchClient.waitForTask(deleteTask.uid)
9+
await searchClient.MeiliSearchClient.index(
10+
'movies'
11+
).updateFilterableAttributes(['genres'])
12+
const documentsTask = await searchClient.MeiliSearchClient.index(
13+
'movies'
14+
).addDocuments(dataset)
15+
await searchClient.MeiliSearchClient.index('movies').waitForTask(
16+
documentsTask.uid
2217
)
2318
})
2419

tests/pagination.tests.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,18 @@ import { searchClient, dataset, Movies } from './assets/utils'
33

44
describe('Pagination browser test', () => {
55
beforeAll(async () => {
6-
try {
7-
await searchClient.MeiliSearchClient.deleteIndex('movies')
8-
} catch (e) {
9-
// movies does not exist
10-
}
6+
const deleteTask = await searchClient.MeiliSearchClient.deleteIndex(
7+
'movies'
8+
)
9+
await searchClient.MeiliSearchClient.waitForTask(deleteTask.uid)
1110
await searchClient.MeiliSearchClient.index(
1211
'movies'
1312
).updateFilterableAttributes(['genres'])
14-
const moviesUpdate = await searchClient.MeiliSearchClient.index(
13+
const documentsTask = await searchClient.MeiliSearchClient.index(
1514
'movies'
1615
).addDocuments(dataset)
17-
await searchClient.MeiliSearchClient.index('movies').waitForPendingUpdate(
18-
moviesUpdate.updateId
16+
await searchClient.MeiliSearchClient.index('movies').waitForTask(
17+
documentsTask.uid
1918
)
2019
})
2120

tests/snippets.tests.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,18 @@ import { searchClient, dataset, Movies } from './assets/utils'
22

33
describe('Snippet Browser test', () => {
44
beforeAll(async () => {
5-
try {
6-
await searchClient.MeiliSearchClient.deleteIndex('movies')
7-
} catch (e) {
8-
// movies does not exist
9-
}
5+
const deleteTask = await searchClient.MeiliSearchClient.deleteIndex(
6+
'movies'
7+
)
8+
await searchClient.MeiliSearchClient.waitForTask(deleteTask.uid)
109
await searchClient.MeiliSearchClient.index(
1110
'movies'
1211
).updateFilterableAttributes(['genres'])
13-
const moviesUpdate = await searchClient.MeiliSearchClient.index(
12+
const documentsTask = await searchClient.MeiliSearchClient.index(
1413
'movies'
1514
).addDocuments(dataset)
16-
await searchClient.MeiliSearchClient.index('movies').waitForPendingUpdate(
17-
moviesUpdate.updateId
15+
await searchClient.MeiliSearchClient.index('movies').waitForTask(
16+
documentsTask.uid
1817
)
1918
})
2019

yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5067,10 +5067,10 @@ [email protected]:
50675067
resolved "https://registry.yarnpkg.com/mdn-data/-/mdn-data-2.0.4.tgz#699b3c38ac6f1d728091a64650b65d388502fd5b"
50685068
integrity sha512-iV3XNKw06j5Q7mi6h+9vbx23Tv7JkjEVgKHW4pimwyDGWm0OIQntJJ+u1C6mg6mK1EaTv42XQ7w76yuzH7M2cA==
50695069

5070-
meilisearch@^0.23.0:
5071-
version "0.23.0"
5072-
resolved "https://registry.yarnpkg.com/meilisearch/-/meilisearch-0.23.0.tgz#eed5098bd147c13658c3f92e658df9cbfb9e8953"
5073-
integrity sha512-bLNonPJK2pJz2akjwolcc/Eqnz/GKJ7y1I4Flg4zjL+v0yPFyIGFFdfe0dw93JWFJWj/RbLS2Q6dDTobZQ9Ehg==
5070+
meilisearch@0.24.0-beta.0:
5071+
version "0.24.0-beta.0"
5072+
resolved "https://registry.yarnpkg.com/meilisearch/-/meilisearch-0.24.0-beta.0.tgz#ebbc7c59fe7152c4dc0e9e3002a906f1e7c4a89e"
5073+
integrity sha512-dQDyTPs1e8Zf+LmGv7gEfWPNuv1+3OeFjRCVqSkUsTFEApD2zZtOPstXYSIgksqxyt9XTe38CCQO0m4DVVrP3A==
50745074
dependencies:
50755075
cross-fetch "^3.1.4"
50765076

0 commit comments

Comments
 (0)