diff --git a/packages/builder/src/stores/backend/permissions.js b/packages/builder/src/stores/backend/permissions.js index 6669ef3270..f947bcce81 100644 --- a/packages/builder/src/stores/backend/permissions.js +++ b/packages/builder/src/stores/backend/permissions.js @@ -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 - }, } } diff --git a/packages/builder/src/stores/backend/tests/datasources.spec.js b/packages/builder/src/stores/backend/tests/datasources.spec.js index 5eb7e8cd05..c70104f74d 100644 --- a/packages/builder/src/stores/backend/tests/datasources.spec.js +++ b/packages/builder/src/stores/backend/tests/datasources.spec.js @@ -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) diff --git a/packages/builder/src/stores/backend/tests/integration.spec.js b/packages/builder/src/stores/backend/tests/integration.spec.js deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/packages/builder/src/stores/backend/tests/permissions.spec.js b/packages/builder/src/stores/backend/tests/permissions.spec.js index e69de29bb2..54938c3c6f 100644 --- a/packages/builder/src/stores/backend/tests/permissions.spec.js +++ b/packages/builder/src/stores/backend/tests/permissions.spec.js @@ -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) + + }) +}) \ No newline at end of file