From 6711801f97e3004ffedba3c42ca3454262c8e37d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Keviin=20=C3=85berg=20Kultalahti?= Date: Fri, 26 Mar 2021 15:43:55 +0100 Subject: [PATCH] add some temporary testing files --- packages/builder/package.json | 9 ++--- .../builder/src/stores/backend/datasources.js | 11 ++++--- .../src/stores/backend/tests/database.spec.js | 26 --------------- .../stores/backend/tests/datasources.spec.js | 33 ++++++++++++------- .../stores/backend/tests/integration.spec.js | 0 .../stores/backend/tests/permissions.spec.js | 0 .../src/stores/backend/tests/queries.spec.js | 0 .../src/stores/backend/tests/roles.spec.js | 0 .../src/stores/backend/tests/rows.spec.js | 0 .../src/stores/backend/tests/tables.spec.js | 0 .../src/stores/backend/tests/views.spec.js | 0 11 files changed, 31 insertions(+), 48 deletions(-) delete mode 100644 packages/builder/src/stores/backend/tests/database.spec.js create mode 100644 packages/builder/src/stores/backend/tests/integration.spec.js create mode 100644 packages/builder/src/stores/backend/tests/permissions.spec.js create mode 100644 packages/builder/src/stores/backend/tests/queries.spec.js create mode 100644 packages/builder/src/stores/backend/tests/roles.spec.js create mode 100644 packages/builder/src/stores/backend/tests/rows.spec.js create mode 100644 packages/builder/src/stores/backend/tests/tables.spec.js create mode 100644 packages/builder/src/stores/backend/tests/views.spec.js diff --git a/packages/builder/package.json b/packages/builder/package.json index 586a7fcfe8..15013489d2 100644 --- a/packages/builder/package.json +++ b/packages/builder/package.json @@ -29,18 +29,15 @@ "\\.(css|less|sass|scss)$": "identity-obj-proxy", "components(.*)$": "/src/components$1", "builderStore(.*)$": "/src/builderStore$1", - "stores(.*)$": "/src/stores$1" + "stores(.*)$": "/src/stores$1", + "analytics(.*)$": "/src/analytics$1" }, "moduleFileExtensions": [ "js", "svelte" ], "moduleDirectories": [ - "node_modules", - "builderStore", - "stores", - "constants", - "analytics" + "node_modules" ], "transform": { "^.+js$": "babel-jest", diff --git a/packages/builder/src/stores/backend/datasources.js b/packages/builder/src/stores/backend/datasources.js index 0f30695ea3..6317d32e41 100644 --- a/packages/builder/src/stores/backend/datasources.js +++ b/packages/builder/src/stores/backend/datasources.js @@ -1,17 +1,20 @@ import { writable } from "svelte/store" import { queries } from "./" -import api from "builderStore/api" +import api from "../../builderStore/api" -export function createDatasourcesStore(_api = api) { - const { subscribe, update, set } = writable({ +export const INITIAL_DATASOURCE_VALUES = { list: [], selected: null, - }) + } + +export function createDatasourcesStore(_api = api) { + const { subscribe, update, set } = writable(INITIAL_DATASOURCE_VALUES) return { subscribe, set, update, + init: () => set(INITIAL_DATASOURCE_VALUES), fetch: async () => { const response = await api.get(`/api/datasources`) const json = await response.json() diff --git a/packages/builder/src/stores/backend/tests/database.spec.js b/packages/builder/src/stores/backend/tests/database.spec.js deleted file mode 100644 index ccaf9c0570..0000000000 --- a/packages/builder/src/stores/backend/tests/database.spec.js +++ /dev/null @@ -1,26 +0,0 @@ -import { database } from "../" - -describe("Backend DataSources Store", () => { - - let state; - let unsub; - - beforeEach(() => { - unsub = database.subscribe(s => state = s); - }) - afterEach(() => { - unsub() - }) - - it("initialises correctly", () => { - expect(state.list, []) - }) -}) - -const api = { - post: () => ({}), - get: () => ({}), - patch: () => ({}), - delete: () => ({}), - put: () => ({}), - } \ No newline at end of file diff --git a/packages/builder/src/stores/backend/tests/datasources.spec.js b/packages/builder/src/stores/backend/tests/datasources.spec.js index 02c90d134c..79913c24ac 100644 --- a/packages/builder/src/stores/backend/tests/datasources.spec.js +++ b/packages/builder/src/stores/backend/tests/datasources.spec.js @@ -1,24 +1,33 @@ import { get } from 'svelte/store' +import api from 'builderStore/api' + +jest.mock('builderStore/api'); + import { createDatasourcesStore } from "../datasources" -const mockApi = { - post: () => ({}), - get: () => ({}), - patch: () => ({}), - delete: () => ({}), - put: () => ({}), -} - - describe("Automation Data Object", () => { - let store + let store = createDatasourcesStore() beforeEach(() => { - store = createDatasourcesStore(mockApi) + store.init() }) it("Inits properly", () => { + const value = get(store) - expect(value).toBe(true) + expect(value).toEqual({ list: [], selected: null}) + }) + + it("Fetch returns and updates store", async () => { + api.get.mockReturnValueOnce({ json: () => 'some-cool-value'}) + + store.fetch() + + + + expect(api.get).toBeCalledWith(`/api/datasources`) + + + // expect(get(store)).toEqual({ list: [], selected: null}) }) }) diff --git a/packages/builder/src/stores/backend/tests/integration.spec.js b/packages/builder/src/stores/backend/tests/integration.spec.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/packages/builder/src/stores/backend/tests/permissions.spec.js b/packages/builder/src/stores/backend/tests/permissions.spec.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/packages/builder/src/stores/backend/tests/queries.spec.js b/packages/builder/src/stores/backend/tests/queries.spec.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/packages/builder/src/stores/backend/tests/roles.spec.js b/packages/builder/src/stores/backend/tests/roles.spec.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/packages/builder/src/stores/backend/tests/rows.spec.js b/packages/builder/src/stores/backend/tests/rows.spec.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/packages/builder/src/stores/backend/tests/tables.spec.js b/packages/builder/src/stores/backend/tests/tables.spec.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/packages/builder/src/stores/backend/tests/views.spec.js b/packages/builder/src/stores/backend/tests/views.spec.js new file mode 100644 index 0000000000..e69de29bb2