Skip to content

Commit 3851ea3

Browse files
committed
tests(update_tests): use await instead of .then
Signed-off-by: k-kumar-01 <[email protected]>
1 parent 71d490b commit 3851ea3

File tree

1 file changed

+39
-35
lines changed

1 file changed

+39
-35
lines changed

tests/update_tests.ts

Lines changed: 39 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -44,46 +44,50 @@ describe.each([
4444
})
4545

4646
test(`${permission} key: Get one update`, async () => {
47-
const { updateId } = await client
48-
.index(index.uid)
49-
.addDocuments(dataset)
50-
.then((response: EnqueuedUpdate) => {
51-
expect(response).toHaveProperty('updateId', expect.any(Number))
52-
return response
53-
})
54-
await client.index(index.uid).waitForPendingUpdate(updateId)
55-
await client
56-
.index(index.uid)
57-
.getUpdateStatus(updateId)
58-
.then((response: Update) => {
59-
expect(response).toHaveProperty('status', 'processed')
60-
expect(response).toHaveProperty('updateId', expect.any(Number))
61-
expect(response).toHaveProperty('type', expect.any(Object))
62-
expect(response.type).toHaveProperty('name', 'DocumentsAddition')
63-
expect(response.type).toHaveProperty('number', 7)
64-
expect(response).toHaveProperty('duration', expect.any(Number))
65-
expect(response).toHaveProperty('enqueuedAt', expect.any(String))
66-
expect(response).toHaveProperty('processedAt', expect.any(String))
67-
})
47+
try {
48+
const response: EnqueuedUpdate = await client
49+
.index(index.uid)
50+
.addDocuments(dataset)
51+
expect(response).toHaveProperty('updateId', expect.any(Number))
52+
await client.index(index.uid).waitForPendingUpdate(response.updateId)
53+
54+
const stausReponse: Update = await client
55+
.index(index.uid)
56+
.getUpdateStatus(response.updateId)
57+
58+
expect(stausReponse).toHaveProperty('status', 'processed')
59+
expect(stausReponse).toHaveProperty('updateId', expect.any(Number))
60+
expect(stausReponse).toHaveProperty('type', expect.any(Object))
61+
expect(stausReponse.type).toHaveProperty('name', 'DocumentsAddition')
62+
expect(stausReponse.type).toHaveProperty('number', 7)
63+
expect(stausReponse).toHaveProperty('duration', expect.any(Number))
64+
expect(stausReponse).toHaveProperty('enqueuedAt', expect.any(String))
65+
expect(stausReponse).toHaveProperty('processedAt', expect.any(String))
66+
} catch (error) {
67+
throw new Error(error)
68+
}
6869
})
6970

7071
test(`${permission} key: Get all updates`, async () => {
7172
const { updateId } = await client.index(index.uid).addDocuments([{ id: 1 }])
7273
await client.index(index.uid).waitForPendingUpdate(updateId)
73-
await client
74-
.index(index.uid)
75-
.getAllUpdateStatus()
76-
.then((response: Update[]) => {
77-
expect(response.length).toEqual(1)
78-
expect(response[0]).toHaveProperty('status', 'processed')
79-
expect(response[0]).toHaveProperty('updateId', expect.any(Number))
80-
expect(response[0]).toHaveProperty('type', expect.any(Object))
81-
expect(response[0].type).toHaveProperty('name', 'DocumentsAddition')
82-
expect(response[0].type).toHaveProperty('number', 1)
83-
expect(response[0]).toHaveProperty('duration', expect.any(Number))
84-
expect(response[0]).toHaveProperty('enqueuedAt', expect.any(String))
85-
expect(response[0]).toHaveProperty('processedAt', expect.any(String))
86-
})
74+
75+
try {
76+
const response: Update[] = await client
77+
.index(index.uid)
78+
.getAllUpdateStatus()
79+
expect(response.length).toEqual(1)
80+
expect(response[0]).toHaveProperty('status', 'processed')
81+
expect(response[0]).toHaveProperty('updateId', expect.any(Number))
82+
expect(response[0]).toHaveProperty('type', expect.any(Object))
83+
expect(response[0].type).toHaveProperty('name', 'DocumentsAddition')
84+
expect(response[0].type).toHaveProperty('number', 1)
85+
expect(response[0]).toHaveProperty('duration', expect.any(Number))
86+
expect(response[0]).toHaveProperty('enqueuedAt', expect.any(String))
87+
expect(response[0]).toHaveProperty('processedAt', expect.any(String))
88+
} catch (error) {
89+
throw new Error(error)
90+
}
8791
})
8892

8993
test(`${permission} key: Try to get update that does not exist`, async () => {

0 commit comments

Comments
 (0)