Skip to content

Commit bd2374b

Browse files
authored
Remove deleteIfExists method (#1124)
* Change updates to tasks * Complete implementation of asynchronous index CRUD * Add client tests * Add index tests * Add documents test * Improve js doc * Add distinct attributes tests * Add distrinct attributes tests * Remove unused variable from tests * Add dump tests * Add filterable attributes tests * Add ranking rules tests * Add settings tests * Add sortable attr tests * Add stop words * Fix types for Tasks * Add search tests * Finish tests compatibility * Fix tasks issues * Fix tests * Fix task type * Add await in return statement * Fix tests * Fix node12 jest tests * Fix tests environments * Remove obsolete test * Fix tests * Fix document tests * Update update information in readme * Add type check test * Fix types of env * Put back express tests to check for CORS issues * Remove env from typescript type test * Add new keys API * Remove deleteIfExists method * Remove unused variables
1 parent 023c835 commit bd2374b

File tree

3 files changed

+0
-80
lines changed

3 files changed

+0
-80
lines changed

src/lib/indexes.ts

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ import {
3434
SortableAttributes,
3535
SearchableAttributes,
3636
DisplayedAttributes,
37-
ErrorStatusCode,
3837
} from '../types'
3938
import { removeUndefinedFromObject } from './utils'
4039
import { HttpRequests } from './http-requests'
@@ -221,24 +220,6 @@ class Index<T = Record<string, any>> {
221220
return await this.httpRequest.delete(url)
222221
}
223222

224-
/**
225-
* Deletes an index if it already exists.
226-
* @memberof Index
227-
* @method deleteIfExists
228-
* @returns {Promise<boolean>} Promise which resolves to true when index exists and is deleted successfully, otherwise false if it does not exist
229-
*/
230-
async deleteIfExists(): Promise<boolean> {
231-
try {
232-
await this.delete()
233-
return true
234-
} catch (e: any) {
235-
if (e.code === ErrorStatusCode.INDEX_NOT_FOUND) {
236-
return false
237-
}
238-
throw e
239-
}
240-
}
241-
242223
///
243224
/// TASKS
244225
///

tests/client_tests.ts

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -332,35 +332,6 @@ describe.each([{ permission: 'Master' }, { permission: 'Private' }])(
332332
expect(task.status).toEqual('failed')
333333
})
334334

335-
// TODO: skipped because of deleteIfExists
336-
test.skip(`${permission} key: delete index if exists on existing index`, async () => {
337-
const client = await getClient(permission)
338-
const { uid } = await client.createIndex(indexPk.uid)
339-
await client.waitForTask(uid)
340-
341-
const response: boolean = await client.deleteIndexIfExists(indexPk.uid)
342-
expect(response).toBe(true)
343-
344-
await expect(client.getIndex(indexPk.uid)).rejects.toHaveProperty(
345-
'code',
346-
ErrorStatusCode.INDEX_NOT_FOUND
347-
)
348-
})
349-
350-
// TODO: skipped because of deleteIfExists
351-
test.skip(`${permission} key: delete index if exists on index that does not exist`, async () => {
352-
const client = await getClient(permission)
353-
const indexes = await client.getIndexes()
354-
const response: boolean = await client.deleteIndexIfExists('badIndex')
355-
expect(response).toBe(false)
356-
357-
await expect(client.getIndex('badIndex')).rejects.toHaveProperty(
358-
'code',
359-
ErrorStatusCode.INDEX_NOT_FOUND
360-
)
361-
await expect(client.getIndexes()).resolves.toHaveLength(indexes.length)
362-
})
363-
364335
test(`${permission} key: fetch deleted index should fail`, async () => {
365336
const client = await getClient(permission)
366337
const index = client.index(indexPk.uid)

tests/index_tests.ts

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -315,38 +315,6 @@ describe.each([{ permission: 'Master' }, { permission: 'Private' }])(
315315
expect(response).toHaveProperty('isIndexing', false)
316316
expect(response).toHaveProperty('fieldDistribution', {})
317317
})
318-
319-
// TODO: Skipped until discussed
320-
test.skip(`${permission} key: delete if exists when index is present`, async () => {
321-
// const client = await getClient(permission)
322-
// const { uid } = await client.createIndex(indexPk.uid)
323-
// const response: boolean = await index.deleteIfExists()
324-
// expect(response).toBe(true)
325-
// await expect(client.getIndex(indexPk.uid)).rejects.toHaveProperty(
326-
// 'code',
327-
// ErrorStatusCode.INDEX_NOT_FOUND
328-
// )
329-
})
330-
331-
// TODO: Skipped until discussed
332-
test.skip(`${permission} key: delete if exists when index is not present`, async () => {
333-
// const client = await getClient(permission)
334-
// const indexes = await client.getIndexes()
335-
// const index = client.index('badIndex')
336-
// const response: boolean = await index.deleteIfExists()
337-
// expect(response).toBe(false)
338-
// await expect(client.getIndex('badIndex')).rejects.toHaveProperty(
339-
// 'code',
340-
// ErrorStatusCode.INDEX_NOT_FOUND
341-
// )
342-
// await expect(client.getIndexes()).resolves.toHaveLength(indexes.length)
343-
})
344-
345-
// test(`${permission} key: delete if exists error`, async () => {
346-
// const client = await getClient(permission)
347-
// const index = badHostClient.index(indexPk.uid)
348-
// await expect(index.deleteIfExists()).rejects.toThrow()
349-
// })
350318
}
351319
)
352320

0 commit comments

Comments
 (0)