Skip to content

Commit afb8784

Browse files
feat(ping_route): fix tests and cleanup
1 parent 51e8a79 commit afb8784

File tree

6 files changed

+64
-47
lines changed

6 files changed

+64
-47
lines changed

nuxt.config.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ export default defineNuxtConfig({
99
},
1010
},
1111

12-
modules: [["@pinia/nuxt", { autoImports: ["defineStore"] }], "@vueuse/nuxt"],
12+
modules: [
13+
["@pinia/nuxt", { autoImports: ["defineStore", "storeToRefs"] }],
14+
"@vueuse/nuxt",
15+
],
1316
imports: {
1417
dirs: ["stores"],
1518
},

stores/viewer.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,23 @@ export const use_viewer_store = defineStore("viewer", {
2121
return "ws"
2222
}
2323
},
24-
port() {
24+
port(state) {
2525
if (use_infra_store().is_cloud) {
2626
return "443"
2727
} else {
28-
return this.default_local_port
28+
return state.default_local_port
2929
}
3030
},
31-
base_url() {
31+
base_url(state) {
3232
const infra_store = use_infra_store()
33-
var viewer_url = `${this.protocol}://${infra_store.domain_name}:${this.port}`
33+
let viewer_url = `${state.protocol}://${infra_store.domain_name}:${state.port}`
3434
if (infra_store.is_cloud) {
3535
if (infra_store.ID == "") {
3636
throw new Error("ID must not be empty in cloud mode")
3737
}
3838
viewer_url += `/${infra_store.ID}/viewer`
3939
}
40+
viewer_url += "/ws"
4041
return viewer_url
4142
},
4243
is_busy(state) {

test/stores/Feedback.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { setActivePinia } from "pinia"
22
import { createTestingPinia } from "@pinia/testing"
33
import { use_feedback_store } from "@/stores/feedback"
4-
import { describe, test, expect, beforeEach } from "vitest"
4+
import { describe, test, expect, expectTypeOf, beforeEach } from "vitest"
55

66
describe("Feedback Store", () => {
77
const pinia = createTestingPinia({

test/stores/Geode.test.js

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -97,34 +97,30 @@ describe("Geode Store", () => {
9797

9898
describe("actions", () => {
9999
describe("do_ping", () => {
100-
// test("request_error", async () => {
101-
// geode_store.base_url = ""
102-
// await geode_store.do_ping()
103-
104-
// expect(geode_store.is_running).toBe(false)
105-
// expect(feedback_store.server_error).toBe(true)
106-
// })
100+
test("request_error", async () => {
101+
geode_store.base_url = ""
102+
geode_store.is_running = true
103+
try {
104+
await geode_store.do_ping()
105+
} catch (e) {
106+
console.log(e)
107+
}
108+
109+
expect(geode_store.is_running).toBe(false)
110+
expect(feedback_store.server_error).toBe(true)
111+
expect(feedback_store.feedbacks.length).toBe(1)
112+
})
107113

108114
test("response", async () => {
109115
geode_store.base_url = ""
110-
111116
registerEndpoint(back_schemas.opengeodeweb_back.ping.$id, {
112117
method: "POST",
113118
handler: () => ({}),
114119
})
115120
await geode_store.do_ping()
116121
expect(geode_store.is_running).toBe(true)
122+
expect(feedback_store.server_error).toBe(false)
117123
})
118-
119-
// test("response_error", async () => {
120-
// geode_store.base_url = ""
121-
// registerEndpoint(back_schemas.opengeodeweb_back.ping.$id, {
122-
// method: "POST",
123-
// handler: () => ({}),
124-
// })
125-
// await geode_store.do_ping()
126-
// expect(geode_store.is_running).toBe(false)
127-
// })
128124
})
129125

130126
describe("start_request", () => {

test/stores/Infra.nuxt.test.js

Lines changed: 37 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { describe, test, expect, beforeEach } from "vitest"
1+
import { describe, test, expect, expectTypeOf, beforeEach } from "vitest"
22
import { registerEndpoint } from "@nuxt/test-utils/runtime"
33
import { setActivePinia } from "pinia"
44
import { createTestingPinia } from "@pinia/testing"
55

6-
describe("Cloud Store", () => {
6+
describe("Infra Store", () => {
77
const pinia = createTestingPinia({
88
stubActions: false,
99
})
@@ -46,6 +46,17 @@ describe("Cloud Store", () => {
4646
expect(infra_store.domain_name).toBe("api.geode-solutions.com")
4747
})
4848
})
49+
50+
describe("lambda_url", () => {
51+
test("test is cloud true", () => {
52+
useRuntimeConfig().public.SITE_BRANCH = "/test"
53+
useRuntimeConfig().public.PROJECT = "/project"
54+
infra_store.is_cloud = true
55+
expect(infra_store.lambda_url).toBe(
56+
"https://api.geode-solutions.com:443/test/project/createbackend",
57+
)
58+
})
59+
})
4960
describe("is_running", () => {
5061
test("test geode false & viewer false", () => {
5162
geode_store.$patch({ is_running: false })
@@ -93,22 +104,28 @@ describe("Cloud Store", () => {
93104
})
94105
})
95106

96-
// describe("actions", () => {
97-
// describe("create_backend", async () => {
98-
// test("test without end-point", async () => {
99-
// expect(geode_store.is_running).toBe(false)
100-
// await infra_store.create_backend()
101-
// expect(geode_store.is_running).toBe(false)
102-
// })
103-
// test("test with end-point", async () => {
104-
// expect(geode_store.is_running).toBe(false)
105-
// registerEndpoint("/createbackend", {
106-
// method: "POST",
107-
// handler: () => ({ ID: "123456" }),
108-
// })
109-
// await infra_store.create_backend()
110-
// await flushPromises()
111-
// })
112-
// })
113-
// })
107+
describe("actions", () => {
108+
describe("create_connexion", async () => {
109+
test("test without end-point", async () => {
110+
await infra_store.create_connexion()
111+
expect(infra_store.is_connexion_launched).toBe(true)
112+
expect(feedback_store.server_error).toBe(true)
113+
})
114+
})
115+
describe("create_backend", async () => {
116+
test("test without end-point", async () => {
117+
await infra_store.create_backend()
118+
expect(geode_store.is_running).toBe(false)
119+
expect(feedback_store.server_error).toBe(true)
120+
})
121+
test("test with end-point", async () => {
122+
registerEndpoint(infra_store.lambda_url, {
123+
method: "POST",
124+
handler: () => ({ ID: "123456" }),
125+
})
126+
await infra_store.create_backend()
127+
expect(geode_store.is_running).toBe(true)
128+
})
129+
})
130+
})
114131
})

test/stores/Viewer.nuxt.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { setActivePinia } from "pinia"
22
import { createTestingPinia } from "@pinia/testing"
3-
import { describe, test, expect, beforeEach } from "vitest"
3+
import { describe, test, expect, expectTypeOf, beforeEach } from "vitest"
44

55
describe("Viewer Store", () => {
66
const pinia = createTestingPinia({
@@ -61,15 +61,15 @@ describe("Viewer Store", () => {
6161
test("test is_cloud false", () => {
6262
infra_store.is_cloud = false
6363
infra_store.domain_name = "localhost"
64-
expect(viewer_store.base_url).toBe("ws://localhost:1234")
64+
expect(viewer_store.base_url).toBe("ws://localhost:1234/ws")
6565
})
6666

6767
test("test is_cloud true", async () => {
6868
infra_store.is_cloud = true
6969
infra_store.ID = "123456"
7070
infra_store.domain_name = "example.com"
7171
expect(viewer_store.base_url).toBe(
72-
"wss://example.com:443/123456/viewer",
72+
"wss://example.com:443/123456/viewer/ws",
7373
)
7474
})
7575

0 commit comments

Comments
 (0)