diff --git a/x-pack/plugins/task_manager/server/lib/delete_task_if_it_exists.test.ts b/x-pack/plugins/task_manager/server/lib/delete_task_if_it_exists.test.ts index 2896ebcdf4b4e..fbbf22a003ef6 100644 --- a/x-pack/plugins/task_manager/server/lib/delete_task_if_it_exists.test.ts +++ b/x-pack/plugins/task_manager/server/lib/delete_task_if_it_exists.test.ts @@ -5,40 +5,40 @@ */ import uuid from 'uuid'; -import { taskManagerMock } from '../../../task_manager/server/mocks'; import { SavedObjectsErrorHelpers } from '../../../../../src/core/server'; import { deleteTaskIfItExists } from './delete_task_if_it_exists'; +import { taskStoreMock } from '../task_store.mock'; describe('deleteTaskIfItExists', () => { test('removes the task by its ID', async () => { - const tm = taskManagerMock.createStart(); + const ts = taskStoreMock.create({}); const id = uuid.v4(); - expect(await deleteTaskIfItExists(tm.remove, id)).toBe(undefined); + expect(await deleteTaskIfItExists(ts, id)).toBe(undefined); - expect(tm.remove).toHaveBeenCalledWith(id); + expect(ts.remove).toHaveBeenCalledWith(id); }); test('handles 404 errors caused by the task not existing', async () => { - const tm = taskManagerMock.createStart(); + const ts = taskStoreMock.create({}); const id = uuid.v4(); - tm.remove.mockRejectedValue(SavedObjectsErrorHelpers.createGenericNotFoundError('task', id)); + ts.remove.mockRejectedValue(SavedObjectsErrorHelpers.createGenericNotFoundError('task', id)); - expect(await deleteTaskIfItExists(tm.remove, id)).toBe(undefined); + expect(await deleteTaskIfItExists(ts, id)).toBe(undefined); - expect(tm.remove).toHaveBeenCalledWith(id); + expect(ts.remove).toHaveBeenCalledWith(id); }); test('throws if any other errro is caused by task removal', async () => { - const tm = taskManagerMock.createStart(); + const ts = taskStoreMock.create({}); const id = uuid.v4(); const error = SavedObjectsErrorHelpers.createInvalidVersionError(uuid.v4()); - tm.remove.mockRejectedValue(error); + ts.remove.mockRejectedValue(error); - expect(deleteTaskIfItExists(tm.remove, id)).rejects.toBe(error); + expect(deleteTaskIfItExists(ts, id)).rejects.toBe(error); - expect(tm.remove).toHaveBeenCalledWith(id); + expect(ts.remove).toHaveBeenCalledWith(id); }); }); diff --git a/x-pack/plugins/task_manager/server/lib/delete_task_if_it_exists.ts b/x-pack/plugins/task_manager/server/lib/delete_task_if_it_exists.ts index a84061b863e78..65e6da6d6d479 100644 --- a/x-pack/plugins/task_manager/server/lib/delete_task_if_it_exists.ts +++ b/x-pack/plugins/task_manager/server/lib/delete_task_if_it_exists.ts @@ -3,15 +3,12 @@ * or more contributor license agreements. Licensed under the Elastic License; * you may not use this file except in compliance with the Elastic License. */ -import { TaskManagerStartContract } from '../'; import { SavedObjectsErrorHelpers } from '../../../../../src/core/server'; +import { TaskStore } from '../task_store'; -export async function deleteTaskIfItExists( - removeFn: TaskManagerStartContract['remove'], - taskId: string -) { +export async function deleteTaskIfItExists(taskStore: TaskStore, taskId: string) { try { - await removeFn(taskId); + await taskStore.remove(taskId); } catch (err) { if (!SavedObjectsErrorHelpers.isNotFoundError(err)) { throw err; diff --git a/x-pack/plugins/task_manager/server/plugin.ts b/x-pack/plugins/task_manager/server/plugin.ts index ddabef39c5a8a..14fd7cc8f2a37 100644 --- a/x-pack/plugins/task_manager/server/plugin.ts +++ b/x-pack/plugins/task_manager/server/plugin.ts @@ -159,7 +159,7 @@ export class TaskManagerPlugin fetch: (opts: SearchOpts): Promise => taskStore.fetch(opts), get: (id: string) => taskStore.get(id), remove: (id: string) => taskStore.remove(id), - deleteTaskIfItExists: (id: string) => deleteTaskIfItExists(taskStore.remove, id), + deleteTaskIfItExists: (id: string) => deleteTaskIfItExists(taskStore, id), schedule: (...args) => taskScheduling.schedule(...args), ensureScheduled: (...args) => taskScheduling.ensureScheduled(...args), runNow: (...args) => taskScheduling.runNow(...args),