adds test for permissions store
This commit is contained in:
parent
f8475bfdc2
commit
58546754b8
|
@ -3,27 +3,15 @@ import api from "builderStore/api"
|
|||
|
||||
|
||||
export function createPermissionStore() {
|
||||
const { subscribe, set } = writable([])
|
||||
const { subscribe } = writable([])
|
||||
|
||||
return {
|
||||
subscribe,
|
||||
fetchLevels: async () => {
|
||||
const response = await api.get("/api/permission/levels")
|
||||
const json = await response.json()
|
||||
set(json)
|
||||
},
|
||||
forResource: async resourceId => {
|
||||
const response = await api.get(`/api/permission/${resourceId}`)
|
||||
const json = await response.json()
|
||||
return json
|
||||
},
|
||||
save: async ({ role, resource, level }) => {
|
||||
const response = await api.post(
|
||||
`/api/permission/${role}/${resource}/${level}`
|
||||
)
|
||||
const json = await response.json()
|
||||
return json
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -32,12 +32,11 @@ const SAVE_DATASOURCE = {
|
|||
import { createDatasourcesStore } from "../datasources"
|
||||
import { queries } from '../queries'
|
||||
|
||||
describe("Automation Data Object", () => {
|
||||
describe("Datasources Store", () => {
|
||||
let store = createDatasourcesStore()
|
||||
|
||||
beforeEach(() => {
|
||||
api.get.mockReturnValueOnce({ json: () => SOME_DATASOURCE})
|
||||
api.delete.mockReturnValueOnce({status: 200, message: 'Datasource deleted.'})
|
||||
store.init()
|
||||
})
|
||||
|
||||
|
@ -81,6 +80,8 @@ describe("Automation Data Object", () => {
|
|||
expect(value.list).toEqual(expect.arrayContaining([SAVE_DATASOURCE]))
|
||||
})
|
||||
it("deletes a datasource, updates the store and returns status message", async () => {
|
||||
api.delete.mockReturnValueOnce({status: 200, message: 'Datasource deleted.'})
|
||||
|
||||
await store.fetch()
|
||||
await store.delete(SOME_DATASOURCE[0])
|
||||
const value = await get(store)
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
import api from 'builderStore/api'
|
||||
|
||||
jest.mock('builderStore/api');
|
||||
|
||||
const PERMISSIONS_FOR_RESOURCE = {
|
||||
"write": "BASIC",
|
||||
"read": "BASIC"
|
||||
}
|
||||
|
||||
import { createPermissionStore } from "../permissions"
|
||||
|
||||
describe("Permissions Store", () => {
|
||||
const store = createPermissionStore()
|
||||
|
||||
it("fetches permissions for specific resource", async () => {
|
||||
api.get.mockReturnValueOnce({ json: () => PERMISSIONS_FOR_RESOURCE})
|
||||
|
||||
const resourceId = "ta_013657543b4043b89dbb17e9d3a4723a"
|
||||
|
||||
const permissions = await store.forResource(resourceId)
|
||||
|
||||
expect(api.get).toBeCalledWith(`/api/permission/${resourceId}`)
|
||||
expect(permissions).toEqual(PERMISSIONS_FOR_RESOURCE)
|
||||
|
||||
})
|
||||
})
|
Loading…
Reference in New Issue