fix last roles store test

This commit is contained in:
Keviin Åberg Kultalahti 2021-03-30 10:49:42 +02:00
parent dd21ee2386
commit d22d5c7c28
2 changed files with 7 additions and 9 deletions

View File

@ -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 => {

View File

@ -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)
})
})