fixes queries and datasource tests
This commit is contained in:
parent
b90e37ba64
commit
d1b7620215
|
@ -69,16 +69,14 @@ export const getFrontendStore = () => {
|
||||||
// Initialise backend stores
|
// Initialise backend stores
|
||||||
const [
|
const [
|
||||||
_integrations,
|
_integrations,
|
||||||
_queries,
|
|
||||||
_tables,
|
_tables,
|
||||||
] = await Promise.all([
|
] = await Promise.all([
|
||||||
api.get("/api/integrations").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()),
|
api.get(`/api/tables`).then(r => r.json()),
|
||||||
])
|
])
|
||||||
datasources.init()
|
datasources.init()
|
||||||
integrations.set(_integrations)
|
integrations.set(_integrations)
|
||||||
queries.set({ list: _queries, selected: null })
|
queries.init()
|
||||||
database.set(application.instance)
|
database.set(application.instance)
|
||||||
tables.set({
|
tables.set({
|
||||||
list: _tables,
|
list: _tables,
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
import IntegrationQueryEditor from "components/integration/index.svelte"
|
import IntegrationQueryEditor from "components/integration/index.svelte"
|
||||||
import ExternalDataSourceTable from "components/backend/DataTable/ExternalDataSourceTable.svelte"
|
import ExternalDataSourceTable from "components/backend/DataTable/ExternalDataSourceTable.svelte"
|
||||||
import ParameterBuilder from "components/integration/QueryParameterBuilder.svelte"
|
import ParameterBuilder from "components/integration/QueryParameterBuilder.svelte"
|
||||||
import { datasources, integrations } from 'stores/backend/'
|
import { datasources, integrations, queries } from 'stores/backend/'
|
||||||
|
|
||||||
const PREVIEW_HEADINGS = [
|
const PREVIEW_HEADINGS = [
|
||||||
{
|
{
|
||||||
|
|
|
@ -10,6 +10,11 @@ export function createQueriesStore() {
|
||||||
subscribe,
|
subscribe,
|
||||||
set,
|
set,
|
||||||
update,
|
update,
|
||||||
|
init: async () => {
|
||||||
|
const response = await api.get(`/api/queries`)
|
||||||
|
const json = await response.json()
|
||||||
|
set({ list: json, selected: null })
|
||||||
|
},
|
||||||
fetch: async () => {
|
fetch: async () => {
|
||||||
const response = await api.get(`/api/queries`)
|
const response = await api.get(`/api/queries`)
|
||||||
const json = await response.json()
|
const json = await response.json()
|
||||||
|
@ -54,7 +59,7 @@ export function createQueriesStore() {
|
||||||
datasources.update(state => ({ ...state, selected: query.datasourceId }))
|
datasources.update(state => ({ ...state, selected: query.datasourceId }))
|
||||||
},
|
},
|
||||||
delete: async query => {
|
delete: async query => {
|
||||||
await api.delete(`/api/queries/${query._id}/${query._rev}`)
|
const response = await api.delete(`/api/queries/${query._id}/${query._rev}`)
|
||||||
update(state => {
|
update(state => {
|
||||||
state.list = state.list.filter(existing => existing._id !== query._id)
|
state.list = state.list.filter(existing => existing._id !== query._id)
|
||||||
if (state.selected === query._id) {
|
if (state.selected === query._id) {
|
||||||
|
@ -63,6 +68,7 @@ export function createQueriesStore() {
|
||||||
|
|
||||||
return state
|
return state
|
||||||
})
|
})
|
||||||
|
console.log(response)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,8 +11,9 @@ import { queries } from '../queries'
|
||||||
describe("Datasources Store", () => {
|
describe("Datasources Store", () => {
|
||||||
let store = createDatasourcesStore()
|
let store = createDatasourcesStore()
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(async () => {
|
||||||
store.init()
|
api.get.mockReturnValue({ json: () => [SOME_DATASOURCE]})
|
||||||
|
await store.init()
|
||||||
})
|
})
|
||||||
|
|
||||||
it("Initialises correctly", async () => {
|
it("Initialises correctly", async () => {
|
||||||
|
@ -35,9 +36,9 @@ describe("Datasources Store", () => {
|
||||||
expect(get(store).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 () => {
|
it("resets the queries store when new datasource is selected", async () => {
|
||||||
|
|
||||||
store.select(SOME_DATASOURCE._id)
|
await store.select(SOME_DATASOURCE._id)
|
||||||
const queriesValue = get(queries)
|
const queriesValue = get(queries)
|
||||||
expect(queriesValue.selected).toEqual(null)
|
expect(queriesValue.selected).toEqual(null)
|
||||||
})
|
})
|
||||||
|
|
|
@ -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
|
||||||
|
}
|
|
@ -21,6 +21,5 @@ describe("Permissions Store", () => {
|
||||||
|
|
||||||
expect(api.get).toBeCalledWith(`/api/permission/${resourceId}`)
|
expect(api.get).toBeCalledWith(`/api/permission/${resourceId}`)
|
||||||
expect(permissions).toEqual(PERMISSIONS_FOR_RESOURCE)
|
expect(permissions).toEqual(PERMISSIONS_FOR_RESOURCE)
|
||||||
|
|
||||||
})
|
})
|
||||||
})
|
})
|
|
@ -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]})
|
||||||
|
|
||||||
// const permissions = await store.forResource(resourceId)
|
await store.init()
|
||||||
|
expect(get(store)).toEqual({ list: [SOME_QUERY], selected: null})
|
||||||
|
})
|
||||||
|
|
||||||
// expect(api.get).toBeCalledWith(`/api/permission/${resourceId}`)
|
it("fetches all the queries", async () => {
|
||||||
// expect(permissions).toEqual(PERMISSIONS_FOR_RESOURCE)
|
api.get.mockReturnValue({ json: () => [SOME_QUERY]})
|
||||||
|
|
||||||
// })
|
await store.fetch()
|
||||||
// })
|
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