mirror of https://github.com/Budibase/budibase.git
7 changed files with 143 additions and 28 deletions
@ -0,0 +1,80 @@ |
|||||
|
export const SOME_QUERY = { |
||||
|
"datasourceId": "datasource_04b003a7b4a8428eadd3bb2f7eae0255", |
||||
|
"parameters": [], |
||||
|
"fields": { |
||||
|
"headers": {}, |
||||
|
"queryString": "", |
||||
|
"path": "Speakers" |
||||
|
}, |
||||
|
"queryVerb": "read", |
||||
|
"schema": {}, |
||||
|
"name": "Speakers", |
||||
|
"_id": "query_datasource_04b003a7b4a8428eadd3bb2f7eae0255_bcb8ffc6fcbc484e8d63121fc0bf986f", |
||||
|
"_rev": "2-941f8699eb0adf995f8bd59c99203b26", |
||||
|
"readable": true |
||||
|
} |
||||
|
|
||||
|
export const SAVE_QUERY_RESPONSE = { |
||||
|
"datasourceId": "datasource_04b003a7b4a8428eadd3bb2f7eae0255", |
||||
|
"parameters": [], |
||||
|
"fields": { |
||||
|
"headers": {}, |
||||
|
"queryString": "", |
||||
|
"path": "Speakers" |
||||
|
}, |
||||
|
"queryVerb": "read", |
||||
|
"schema": { |
||||
|
"id": { |
||||
|
"name": "id", |
||||
|
"type": "string" |
||||
|
}, |
||||
|
"firstName": { |
||||
|
"name": "firstName", |
||||
|
"type": "string" |
||||
|
}, |
||||
|
"lastName": { |
||||
|
"name": "lastName", |
||||
|
"type": "string" |
||||
|
}, |
||||
|
"fullName": { |
||||
|
"name": "fullName", |
||||
|
"type": "string" |
||||
|
}, |
||||
|
"bio": { |
||||
|
"name": "bio", |
||||
|
"type": "string" |
||||
|
}, |
||||
|
"tagLine": { |
||||
|
"name": "tagLine", |
||||
|
"type": "string" |
||||
|
}, |
||||
|
"profilePicture": { |
||||
|
"name": "profilePicture", |
||||
|
"type": "string" |
||||
|
}, |
||||
|
"sessions": { |
||||
|
"name": "sessions", |
||||
|
"type": "string" |
||||
|
}, |
||||
|
"isTopSpeaker": { |
||||
|
"name": "isTopSpeaker", |
||||
|
"type": "string" |
||||
|
}, |
||||
|
"links": { |
||||
|
"name": "links", |
||||
|
"type": "string" |
||||
|
}, |
||||
|
"questionAnswers": { |
||||
|
"name": "questionAnswers", |
||||
|
"type": "string" |
||||
|
}, |
||||
|
"categories": { |
||||
|
"name": "categories", |
||||
|
"type": "string" |
||||
|
} |
||||
|
}, |
||||
|
"name": "Speakers", |
||||
|
"_id": "query_datasource_04b003a7b4a8428eadd3bb2f7eae0255_bcb8ffc6fcbc484e8d63121fc0bf986f", |
||||
|
"_rev": "3-5a64adef494b1e9c793dc91b51ce73c6", |
||||
|
"readable": true |
||||
|
} |
||||
@ -1,26 +1,57 @@ |
|||||
// import api from 'builderStore/api'
|
import { get } from 'svelte/store' |
||||
|
import api from 'builderStore/api' |
||||
|
|
||||
// jest.mock('builderStore/api');
|
jest.mock('builderStore/api'); |
||||
|
|
||||
// const PERMISSIONS_FOR_RESOURCE = {
|
import { SOME_QUERY, SAVE_QUERY_RESPONSE } from './fixtures/queries' |
||||
// "write": "BASIC",
|
|
||||
// "read": "BASIC"
|
|
||||
// }
|
|
||||
|
|
||||
// import { createQueriesStore } from "../queries"
|
import { createQueriesStore } from "../queries" |
||||
|
import { datasources } from '../datasources' |
||||
|
|
||||
// describe("Queries Store", () => {
|
describe("Queries Store", () => { |
||||
// const store = createQueriesStore()
|
let store = createQueriesStore() |
||||
|
|
||||
// it("fetches permissions for specific resource", async () => {
|
beforeEach(async () => { |
||||
// api.get.mockReturnValueOnce({ json: () => PERMISSIONS_FOR_RESOURCE})
|
api.get.mockReturnValue({ json: () => [SOME_QUERY]}) |
||||
|
await store.init() |
||||
|
}) |
||||
|
|
||||
// const resourceId = "ta_013657543b4043b89dbb17e9d3a4723a"
|
it("Initialises correctly", async () => { |
||||
|
api.get.mockReturnValue({ json: () => [SOME_QUERY]}) |
||||
|
|
||||
|
await store.init() |
||||
|
expect(get(store)).toEqual({ list: [SOME_QUERY], selected: null}) |
||||
|
}) |
||||
|
|
||||
// const permissions = await store.forResource(resourceId)
|
it("fetches all the queries", async () => { |
||||
|
api.get.mockReturnValue({ json: () => [SOME_QUERY]}) |
||||
|
|
||||
// expect(api.get).toBeCalledWith(`/api/permission/${resourceId}`)
|
await store.fetch() |
||||
// expect(permissions).toEqual(PERMISSIONS_FOR_RESOURCE)
|
expect(get(store)).toEqual({ list: [SOME_QUERY], selected: null}) |
||||
|
}) |
||||
// })
|
|
||||
// })
|
it("selects a query and updates selected datasource", async () => { |
||||
|
await store.select(SOME_QUERY) |
||||
|
|
||||
|
expect(get(store).selected).toEqual(SOME_QUERY._id) |
||||
|
expect(get(datasources).selected).toEqual(SOME_QUERY.datasourceId) |
||||
|
}) |
||||
|
|
||||
|
it("saves the datasource, updates the store and returns status message", async () => { |
||||
|
api.post.mockReturnValue({ json: () => SAVE_QUERY_RESPONSE}) |
||||
|
|
||||
|
await store.select(SOME_QUERY.datasourceId, SOME_QUERY) |
||||
|
|
||||
|
expect(get(store).list).toEqual(expect.arrayContaining([SOME_QUERY])) |
||||
|
}) |
||||
|
it("deletes a datasource, updates the store and returns status message", async () => { |
||||
|
api.get.mockReturnValue({ json: () => SOME_QUERY}) |
||||
|
|
||||
|
await store.fetch() |
||||
|
|
||||
|
api.delete.mockReturnValue({status: 200, message: 'Datasource deleted.'}) |
||||
|
|
||||
|
await store.delete(SOME_QUERY) |
||||
|
expect(get(store)).toEqual({ list: [], selected: null}) |
||||
|
}) |
||||
|
}) |
||||
Loading…
Reference in new issue