forked from tsai/budibase
3 changed files with 71 additions and 2 deletions
@ -0,0 +1,32 @@ |
|||
export const ROLES = [ |
|||
{ |
|||
"name": "Test", |
|||
"permissionId": "admin", |
|||
"inherits": "ADMIN", |
|||
"_id": "role_04681b7e71914a0aa53e09a5bea3584f", |
|||
"_rev": "1-179c71ea61d7fd987306b84b6d64b00e" |
|||
}, |
|||
{ |
|||
"_id": "ADMIN", |
|||
"name": "Admin", |
|||
"permissionId": "admin", |
|||
"inherits": "POWER" |
|||
}, |
|||
{ |
|||
"_id": "POWER", |
|||
"name": "Power", |
|||
"permissionId": "power", |
|||
"inherits": "BASIC" |
|||
}, |
|||
{ |
|||
"_id": "BASIC", |
|||
"name": "Basic", |
|||
"permissionId": "write", |
|||
"inherits": "PUBLIC" |
|||
}, |
|||
{ |
|||
"_id": "PUBLIC", |
|||
"name": "Public", |
|||
"permissionId": "public" |
|||
} |
|||
] |
|||
@ -0,0 +1,34 @@ |
|||
import { get } from 'svelte/store' |
|||
import api from 'builderStore/api' |
|||
|
|||
jest.mock('builderStore/api'); |
|||
|
|||
import { createRolesStore } from "../roles" |
|||
import { ROLES } from './fixtures/roles' |
|||
|
|||
describe("Roles Store", () => { |
|||
let store = createRolesStore() |
|||
|
|||
beforeEach( async() => { |
|||
store = createRolesStore() |
|||
}) |
|||
|
|||
it("fetches roles from backend", async () => { |
|||
api.get.mockReturnValue({ json: () => ROLES}) |
|||
await store.fetch() |
|||
|
|||
expect(api.get).toBeCalledWith("/api/roles") |
|||
expect(get(store)).toEqual(ROLES) |
|||
}) |
|||
|
|||
it("deletes a role", async () => { |
|||
api.get.mockReturnValue({ 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}`) |
|||
|
|||
expect(get(store)).toEqual(ROLES) |
|||
}) |
|||
}) |
|||
Loading…
Reference in new issue