Skip to content

Commit 780b625

Browse files
feat(microservices status): passing tests
1 parent 5a97467 commit 780b625

File tree

10 files changed

+48
-32
lines changed

10 files changed

+48
-32
lines changed

components/Launcher.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
</template>
2020

2121
<script setup>
22-
import Status from "../utils/status"
22+
import Status from "@/utils/status.js"
2323
2424
const viewer_store = use_viewer_store()
2525
const infra_store = use_infra_store()

components/RemoteRenderingView.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
import vtkRemoteView from "@kitware/vtk.js/Rendering/Misc/RemoteView"
2525
import { useElementSize, useWindowSize } from "@vueuse/core"
2626
import viewer_schemas from "@geode/opengeodeweb-viewer/schemas.json"
27-
import Status from "../utils/status"
27+
import Status from "@/utils/status.js"
2828
2929
const viewer_store = use_viewer_store()
3030
const viewer = ref(null)

composables/run_function_when_infra_created.js renamed to composables/run_function_when_microservices_connected.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1+
import Status from "@/utils/status.js"
2+
13
export function run_function_when_microservices_connected(function_to_run) {
24
const infra_store = use_infra_store()
3-
const { status } = storeToRefs(infra_store)
4-
if (status === Status.CREATED) {
5+
const { microservices_connected } = storeToRefs(infra_store)
6+
if (microservices_connected.value) {
57
function_to_run()
68
} else {
7-
watch(status, (value) => {
8-
if (value === Status.CREATED) {
9+
watch(microservices_connected, (value) => {
10+
if (value) {
911
function_to_run()
1012
}
1113
})

stores/geode.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import back_schemas from "@geode/opengeodeweb-back/schemas.json"
2-
import Status from "@/utils/status"
2+
import Status from "@/utils/status.js"
33

44
export const use_geode_store = defineStore("geode", {
55
state: () => ({

stores/infra.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { useStorage } from "@vueuse/core"
22
import isElectron from "is-electron"
3-
import Status from "../utils/status"
3+
import Status from "@/utils/status.js"
44

55
export const use_infra_store = defineStore("infra", {
66
state: () => ({
@@ -49,12 +49,13 @@ export const use_infra_store = defineStore("infra", {
4949
async create_backend() {
5050
console.log("create_backend", this.status)
5151
if (this.status === Status.CREATED) return
52+
console.log("NAVIGATOR", navigator)
5253
navigator.locks.request("infra.create_backend", async (lock) => {
53-
console.log("create_backend lock", this.status)
54+
console.log("PASSED IN LOCK", this.status)
55+
this.status = Status.CREATING
5456
if (this.status === Status.CREATED) return
5557
console.log("INFRA LOCK GRANTED !", lock)
5658
console.log("INFRA STATUS", this.status)
57-
this.status = Status.CREATING
5859
const geode_store = use_geode_store()
5960
const viewer_store = use_viewer_store()
6061
const feedback_store = use_feedback_store()
@@ -69,13 +70,13 @@ export const use_infra_store = defineStore("infra", {
6970
const { data, error } = await useFetch(this.lambda_url, {
7071
method: "POST",
7172
})
72-
if (data.value !== null) {
73-
this.ID = data.value.ID
74-
localStorage.setItem("ID", data.value.ID)
75-
} else {
73+
if (error.value || !data.value) {
74+
this.status = Status.NOT_CREATED
7675
feedback_store.server_error = true
7776
return
7877
}
78+
this.ID = data.value.ID
79+
localStorage.setItem("ID", data.value.ID)
7980
}
8081
this.status = Status.CREATED
8182
return this.create_connection()

stores/viewer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import _ from "lodash"
22
import vtkWSLinkClient from "@kitware/vtk.js/IO/Core/WSLinkClient"
33
import "@kitware/vtk.js/Rendering/OpenGL/Profiles/Geometry"
44
import schemas from "@geode/opengeodeweb-viewer/schemas.json"
5-
import Status from "../utils/status"
5+
import Status from "@/utils/status.js"
66

77
export const use_viewer_store = defineStore("viewer", {
88
state: () => ({

test/components/FileSelector.nuxt.test.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,6 @@ describe("FileSelector.vue", async () => {
123123
await flushPromises()
124124

125125
const file_uploader = wrapper.findComponent(FileUploader)
126-
console.log("wrapper", wrapper)
127126
expect(wrapper.vm.props.files).toEqual(files)
128127
const upload_files = vi.spyOn(file_uploader.vm, "upload_files")
129128
expect(upload_files).not.toHaveBeenCalled()

test/composables/run_function_when_infra_created.nuxt.test.js renamed to test/composables/run_function_when_microservices_connected.test.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { describe, expect, test, beforeEach, vi } from "vitest"
2-
import { Status } from "../utils/status"
2+
import Status from "@/utils/status.js"
33

4-
describe("run_function_when_infra_created", () => {
4+
describe("run_function_when_microservices_connected", () => {
55
const geode_store = use_geode_store()
66
const viewer_store = use_viewer_store()
77

@@ -14,10 +14,9 @@ describe("run_function_when_infra_created", () => {
1414
console.log("Status.CONNECTED", Status.CONNECTED)
1515
test("microservices connected", async () => {
1616
const spy = vi.spyOn(dumb_obj, "dumb_method")
17+
run_function_when_microservices_connected(dumb_obj.dumb_method)
1718
await geode_store.$patch({ status: Status.CONNECTED })
1819
await viewer_store.$patch({ status: Status.CONNECTED })
19-
20-
await run_function_when_microservices_connected(dumb_obj.dumb_method)
2120
expect(spy).toHaveBeenCalled()
2221
})
2322

test/stores/Infra.nuxt.test.js

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,27 @@
1-
import { describe, test, expect, expectTypeOf, beforeEach } from "vitest"
1+
import { describe, test, expect, expectTypeOf, beforeEach, vi } from "vitest"
22
import { registerEndpoint } from "@nuxt/test-utils/runtime"
33
import { setActivePinia } from "pinia"
44
import { createTestingPinia } from "@pinia/testing"
5-
import Status from "../utils/status"
5+
import Status from "@/utils/status.js"
6+
7+
// Mock navigator.locks API
8+
const mockLockRequest = vi.fn().mockImplementation(async (name, callback) => {
9+
return callback({ name })
10+
})
11+
12+
vi.stubGlobal('navigator', {
13+
...navigator,
14+
locks: {
15+
request: mockLockRequest
16+
}
17+
})
618

719
describe("Infra Store", () => {
20+
// const locksMock = {
21+
// locks: { request: vi.fn() },
22+
// }
23+
// global.navigator = locksMock // here
24+
825
const pinia = createTestingPinia({
926
stubActions: false,
1027
})
@@ -62,6 +79,7 @@ describe("Infra Store", () => {
6279
test("test geode false & viewer false", () => {
6380
geode_store.$patch({ status: Status.NOT_CONNECTED })
6481
viewer_store.$patch({ status: Status.NOT_CONNECTED })
82+
console.log("Status", Status)
6583
expect(infra_store.microservices_connected).toBe(false)
6684
})
6785
test("test geode true & viewer false", () => {
@@ -106,27 +124,24 @@ describe("Infra Store", () => {
106124
})
107125

108126
describe("actions", () => {
109-
describe("create_backend", () => {
110-
test("test without end-point", async () => {
111-
await infra_store.create_backend()
112-
expect(infra_store.status).toBe(Status.NOT_CONNECTED)
113-
expect(feedback_store.server_error).toBe(true)
114-
})
115-
})
116127
describe("create_backend", () => {
117128
test("test without end-point", async () => {
118129
await infra_store.create_backend()
119130
console.log("geode_store.status", geode_store.status)
131+
expect(infra_store.status).toBe(Status.CREATING)
120132
expect(geode_store.status).toBe(Status.NOT_CONNECTED)
121-
expect(feedback_store.server_error).toBe(true)
133+
expect(viewer_store.status).toBe(Status.NOT_CONNECTED)
122134
})
123135
test("test with end-point", async () => {
124136
registerEndpoint(infra_store.lambda_url, {
125137
method: "POST",
126138
handler: () => ({ ID: "123456" }),
127139
})
128140
await infra_store.create_backend()
129-
expect(geode_store.status).toBe(Status.CONNECTED)
141+
expect(infra_store.status).toBe(Status.CREATING)
142+
expect(geode_store.status).toBe(Status.NOT_CONNECTED)
143+
expect(viewer_store.status).toBe(Status.NOT_CONNECTED)
144+
expect(feedback_store.server_error).toBe(false)
130145
})
131146
})
132147
})

utils/status.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ const Status = {
77
CONNECTED: "CONNECTED",
88
}
99

10-
export default { Status }
10+
export default Status

0 commit comments

Comments
 (0)