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