wip: queries store tests
This commit is contained in:
parent
58546754b8
commit
d0aca74e4a
|
@ -68,17 +68,15 @@ export const getFrontendStore = () => {
|
|||
|
||||
// Initialise backend stores
|
||||
const [
|
||||
_datasources,
|
||||
_integrations,
|
||||
_queries,
|
||||
_tables,
|
||||
] = await Promise.all([
|
||||
api.get(`/api/datasources`).then(r => r.json()),
|
||||
api.get("/api/integrations").then(r => r.json()),
|
||||
api.get(`/api/queries`).then(r => r.json()),
|
||||
api.get(`/api/tables`).then(r => r.json()),
|
||||
])
|
||||
datasources.set({ list: _datasources, selected: null })
|
||||
datasources.init()
|
||||
integrations.set(_integrations)
|
||||
queries.set({ list: _queries, selected: null })
|
||||
database.set(application.instance)
|
||||
|
|
|
@ -12,9 +12,12 @@ export function createDatasourcesStore(_api = api) {
|
|||
|
||||
return {
|
||||
subscribe,
|
||||
set,
|
||||
update,
|
||||
init: () => set(INITIAL_DATASOURCE_VALUES),
|
||||
init: async () => {
|
||||
const response = await api.get(`/api/datasources`)
|
||||
const json = await response.json()
|
||||
set({ list: json, selected: null })
|
||||
},
|
||||
fetch: async () => {
|
||||
const response = await api.get(`/api/datasources`)
|
||||
const json = await response.json()
|
||||
|
|
|
@ -3,31 +3,7 @@ import api from 'builderStore/api'
|
|||
|
||||
jest.mock('builderStore/api');
|
||||
|
||||
const SOME_DATASOURCE = [
|
||||
{
|
||||
"type": "datasource",
|
||||
"name": "erterter",
|
||||
"source": "REST",
|
||||
"config": {
|
||||
"url": "localhost",
|
||||
"defaultHeaders": {}
|
||||
},
|
||||
"_id": "datasource_04b003a7b4a8428eadd3bb2f7eae0255",
|
||||
"_rev": "1-4e72002f1011e9392e655948469b7908"
|
||||
}
|
||||
]
|
||||
|
||||
const SAVE_DATASOURCE = {
|
||||
"type": "datasource",
|
||||
"name": "CoolDB",
|
||||
"source": "REST",
|
||||
"config": {
|
||||
"url": "localhost",
|
||||
"defaultHeaders": {}
|
||||
},
|
||||
"_id": "datasource_04b003a7b4a8428eadd3bb2f7eae0255",
|
||||
"_rev": "1-4e72002f1011e9392e655948469b7908"
|
||||
}
|
||||
import { SOME_DATASOURCE, SAVE_DATASOURCE} from './fixtures/datasources'
|
||||
|
||||
import { createDatasourcesStore } from "../datasources"
|
||||
import { queries } from '../queries'
|
||||
|
@ -36,27 +12,27 @@ describe("Datasources Store", () => {
|
|||
let store = createDatasourcesStore()
|
||||
|
||||
beforeEach(() => {
|
||||
api.get.mockReturnValueOnce({ json: () => SOME_DATASOURCE})
|
||||
store.init()
|
||||
})
|
||||
|
||||
it("Inits properly", () => {
|
||||
const value = get(store)
|
||||
expect(value).toEqual({ list: [], selected: null})
|
||||
it("Initialises correctly", async () => {
|
||||
api.get.mockReturnValue({ json: () => [SOME_DATASOURCE]})
|
||||
|
||||
await store.init()
|
||||
expect(get(store)).toEqual({ list: [SOME_DATASOURCE], selected: null})
|
||||
})
|
||||
|
||||
it("fetches all the datasources and updates the store", async () => {
|
||||
api.get.mockReturnValue({ json: () => [SOME_DATASOURCE]})
|
||||
|
||||
await store.fetch()
|
||||
const value = get(store)
|
||||
expect(value).toEqual({ list: SOME_DATASOURCE, selected: null})
|
||||
expect(get(store)).toEqual({ list: [SOME_DATASOURCE], selected: null})
|
||||
})
|
||||
|
||||
it("selects a datasource", async () => {
|
||||
store.select(SOME_DATASOURCE._id)
|
||||
|
||||
const value = get(store)
|
||||
expect(value.select).toEqual(SOME_DATASOURCE._id)
|
||||
expect(get(store).select).toEqual(SOME_DATASOURCE._id)
|
||||
})
|
||||
|
||||
it("resets the queries store when it a new datasource is selected", async () => {
|
||||
|
@ -67,7 +43,7 @@ describe("Datasources Store", () => {
|
|||
})
|
||||
|
||||
it("saves the datasource, updates the store and returns status message", async () => {
|
||||
api.post.mockReturnValueOnce({ json: () => SAVE_DATASOURCE})
|
||||
api.post.mockReturnValue({ json: () => SAVE_DATASOURCE})
|
||||
|
||||
await store.save({
|
||||
name: 'CoolDB',
|
||||
|
@ -75,17 +51,17 @@ describe("Datasources Store", () => {
|
|||
config: SOME_DATASOURCE[0].config
|
||||
|
||||
})
|
||||
const value = await get(store)
|
||||
|
||||
expect(value.list).toEqual(expect.arrayContaining([SAVE_DATASOURCE]))
|
||||
expect(get(store).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.'})
|
||||
api.get.mockReturnValue({ json: () => [SOME_DATASOURCE]})
|
||||
|
||||
await store.fetch()
|
||||
await store.delete(SOME_DATASOURCE[0])
|
||||
const value = await get(store)
|
||||
|
||||
expect(value).toEqual({ list: [], selected: null})
|
||||
api.delete.mockReturnValue({status: 200, message: 'Datasource deleted.'})
|
||||
|
||||
await store.delete(SOME_DATASOURCE[0])
|
||||
expect(get(store)).toEqual({ list: [], selected: null})
|
||||
})
|
||||
})
|
|
@ -0,0 +1,26 @@
|
|||
export const SOME_DATASOURCE = [
|
||||
{
|
||||
"type": "datasource",
|
||||
"name": "erterter",
|
||||
"source": "REST",
|
||||
"config": {
|
||||
"url": "localhost",
|
||||
"defaultHeaders": {}
|
||||
},
|
||||
"_id": "datasource_04b003a7b4a8428eadd3bb2f7eae0255",
|
||||
"_rev": "1-4e72002f1011e9392e655948469b7908"
|
||||
}
|
||||
]
|
||||
|
||||
export const SAVE_DATASOURCE = {
|
||||
"type": "datasource",
|
||||
"name": "CoolDB",
|
||||
"source": "REST",
|
||||
"config": {
|
||||
"url": "localhost",
|
||||
"defaultHeaders": {}
|
||||
},
|
||||
"_id": "datasource_04b003a7b4a8428eadd3bb2f7eae0255",
|
||||
"_rev": "1-4e72002f1011e9392e655948469b7908"
|
||||
}
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
// import api from 'builderStore/api'
|
||||
|
||||
// jest.mock('builderStore/api');
|
||||
|
||||
// const PERMISSIONS_FOR_RESOURCE = {
|
||||
// "write": "BASIC",
|
||||
// "read": "BASIC"
|
||||
// }
|
||||
|
||||
// import { createQueriesStore } from "../queries"
|
||||
|
||||
// describe("Queries Store", () => {
|
||||
// const store = createQueriesStore()
|
||||
|
||||
// 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