From d22d5c7c28747b5fb19b4e0827dccaba4f6108f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Keviin=20=C3=85berg=20Kultalahti?= Date: Tue, 30 Mar 2021 10:49:42 +0200 Subject: [PATCH] fix last roles store test --- packages/builder/src/stores/backend/roles.js | 5 +---- .../builder/src/stores/backend/tests/roles.spec.js | 11 ++++++----- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/packages/builder/src/stores/backend/roles.js b/packages/builder/src/stores/backend/roles.js index b927f00cac..a9f8d936f1 100644 --- a/packages/builder/src/stores/backend/roles.js +++ b/packages/builder/src/stores/backend/roles.js @@ -12,10 +12,7 @@ export function createRolesStore() { }, delete: async role => { const response = await api.delete(`/api/roles/${role._id}/${role._rev}`) - update(state => { - state = state.filter(existing => existing._id !== role._id) - return state - }) + update(state => state.filter(existing => existing._id !== role._id)) return response }, save: async role => { diff --git a/packages/builder/src/stores/backend/tests/roles.spec.js b/packages/builder/src/stores/backend/tests/roles.spec.js index 8ecd9c338e..13861f6359 100644 --- a/packages/builder/src/stores/backend/tests/roles.spec.js +++ b/packages/builder/src/stores/backend/tests/roles.spec.js @@ -22,13 +22,14 @@ describe("Roles Store", () => { }) it("deletes a role", async () => { - api.get.mockReturnValue({ json: () => ROLES}) + api.get.mockReturnValueOnce({ json: () => ROLES}) await store.fetch() - - const {_id, _rev} = ROLES[0] + api.delete.mockReturnValue({status: 200, message: `Role deleted.`}) - await store.delete(`/api/roles/${_id}/${_rev}`) + + const updatedRoles = [...ROLES.slice(1)] + await store.delete(ROLES[0]) - expect(get(store)).toEqual(ROLES) + expect(get(store)).toEqual(updatedRoles) }) }) \ No newline at end of file