adds test for permissions store
This commit is contained in:
parent
29a032d908
commit
ab0ce42245
|
@ -3,27 +3,15 @@ import api from "builderStore/api"
|
||||||
|
|
||||||
|
|
||||||
export function createPermissionStore() {
|
export function createPermissionStore() {
|
||||||
const { subscribe, set } = writable([])
|
const { subscribe } = writable([])
|
||||||
|
|
||||||
return {
|
return {
|
||||||
subscribe,
|
subscribe,
|
||||||
fetchLevels: async () => {
|
|
||||||
const response = await api.get("/api/permission/levels")
|
|
||||||
const json = await response.json()
|
|
||||||
set(json)
|
|
||||||
},
|
|
||||||
forResource: async resourceId => {
|
forResource: async resourceId => {
|
||||||
const response = await api.get(`/api/permission/${resourceId}`)
|
const response = await api.get(`/api/permission/${resourceId}`)
|
||||||
const json = await response.json()
|
const json = await response.json()
|
||||||
return 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 { createDatasourcesStore } from "../datasources"
|
||||||
import { queries } from '../queries'
|
import { queries } from '../queries'
|
||||||
|
|
||||||
describe("Automation Data Object", () => {
|
describe("Datasources Store", () => {
|
||||||
let store = createDatasourcesStore()
|
let store = createDatasourcesStore()
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
api.get.mockReturnValueOnce({ json: () => SOME_DATASOURCE})
|
api.get.mockReturnValueOnce({ json: () => SOME_DATASOURCE})
|
||||||
api.delete.mockReturnValueOnce({status: 200, message: 'Datasource deleted.'})
|
|
||||||
store.init()
|
store.init()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -81,6 +80,8 @@ describe("Automation Data Object", () => {
|
||||||
expect(value.list).toEqual(expect.arrayContaining([SAVE_DATASOURCE]))
|
expect(value.list).toEqual(expect.arrayContaining([SAVE_DATASOURCE]))
|
||||||
})
|
})
|
||||||
it("deletes a datasource, updates the store and returns status message", async () => {
|
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.fetch()
|
||||||
await store.delete(SOME_DATASOURCE[0])
|
await store.delete(SOME_DATASOURCE[0])
|
||||||
const value = await get(store)
|
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