Skip to content

Commit 173854f

Browse files
fix(tests): this scoped and hardcoded base_url in tests
1 parent e73323e commit 173854f

File tree

2 files changed

+71
-93
lines changed

2 files changed

+71
-93
lines changed

stores/geode.js

Lines changed: 25 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,18 @@ export const use_geode_store = defineStore("geode", {
1010
protocol() {
1111
if (use_infra_store().is_cloud) {
1212
return "https"
13-
} else {
14-
return "http"
1513
}
14+
return "http"
1615
},
17-
port() {
16+
port(state) {
1817
if (use_infra_store().is_cloud) {
1918
return "443"
20-
} else {
21-
return this.default_local_port
2219
}
20+
return state.default_local_port
2321
},
2422
base_url() {
2523
const infra_store = use_infra_store()
26-
var geode_url = `${this.protocol}://${infra_store.domain_name}:${this.port}`
24+
let geode_url = `${this.protocol}://${infra_store.domain_name}:${this.port}`
2725
if (infra_store.is_cloud) {
2826
if (infra_store.ID == "") {
2927
throw new Error("ID must not be empty in cloud mode")
@@ -32,8 +30,8 @@ export const use_geode_store = defineStore("geode", {
3230
}
3331
return geode_url
3432
},
35-
is_busy() {
36-
return this.request_counter > 0
33+
is_busy(state) {
34+
return state.request_counter > 0
3735
},
3836
},
3937
actions: {
@@ -44,32 +42,26 @@ export const use_geode_store = defineStore("geode", {
4442
}
4543
}, 10 * 1000)
4644
},
47-
async do_ping() {
45+
do_ping() {
46+
const geode_store = this
4847
const feedback_store = use_feedback_store()
49-
return new Promise((resolve, reject) => {
50-
useFetch(back_schemas.opengeodeweb_back.ping.$id, {
51-
baseURL: this.base_url,
52-
method: back_schemas.opengeodeweb_back.ping.methods[0],
53-
async onRequestError({ error }) {
54-
console.log("onRequestError", error)
55-
feedback_store.$patch({ server_error: true })
56-
this.is_running = false
57-
reject()
58-
},
59-
60-
async onResponse({ response }) {
61-
if (response.ok) {
62-
console.log("onResponse", response)
63-
resolve()
64-
}
65-
},
66-
async onResponseError({ response }) {
67-
console.log("onResponseError", response)
68-
feedback_store.$patch({ server_error: true })
69-
this.is_running = false
70-
reject()
71-
},
72-
})
48+
return useFetch(back_schemas.opengeodeweb_back.ping.$id, {
49+
baseURL: this.base_url,
50+
method: back_schemas.opengeodeweb_back.ping.methods[0],
51+
onRequestError({ error }) {
52+
feedback_store.server_error = true
53+
geode_store.is_running = false
54+
},
55+
onResponse({ response }) {
56+
if (response.ok) {
57+
feedback_store.server_error = false
58+
geode_store.is_running = true
59+
}
60+
},
61+
onResponseError({ response }) {
62+
feedback_store.server_error = true
63+
geode_store.is_running = false
64+
},
7365
})
7466
},
7567
start_request() {

test/stores/Geode.nuxt.test.js

Lines changed: 46 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { describe, test, expect, expectTypeOf, beforeEach, vi } from "vitest"
44
import { registerEndpoint } from "@nuxt/test-utils/runtime"
55
import back_schemas from "@geode/opengeodeweb-back/schemas.json"
66

7-
describe("Geode Store", () => {
7+
describe("Geode Store", async () => {
88
const pinia = createTestingPinia({
99
stubActions: false,
1010
})
@@ -52,33 +52,40 @@ describe("Geode Store", () => {
5252

5353
test("test override default_local_port", () => {
5454
infra_store.is_cloud = false
55-
geode_store.default_local_port = "8080"
56-
expect(geode_store.port).toBe("8080")
55+
geode_store.default_local_port = "12"
56+
expect(geode_store.port).toBe("12")
5757
})
5858
})
5959

6060
describe("base_url", () => {
61-
// test("test is_cloud false", () => {
62-
// infra_store.is_cloud = false
63-
// infra_store.domain_name = "localhost"
64-
// expect(geode_store.base_url).toBe("http://localhost:5000")
65-
// })
66-
// test("test is_cloud true", async () => {
67-
// infra_store.is_cloud = true
68-
// infra_store.ID = "123456"
69-
// infra_store.domain_name = "example.com"
70-
// expect(geode_store.base_url).toBe(
71-
// "https://example.com:443/123456/geode",
72-
// )
73-
// })
74-
// test("test is_cloud true, ID empty", async () => {
75-
// infra_store.is_cloud = true
76-
// infra_store.ID = ""
77-
// infra_store.domain_name = "example.com"
78-
// expect(() => geode_store.base_url).toThrowError(
79-
// "ID must not be empty in cloud mode",
80-
// )
81-
// })
61+
test("test is_cloud false", () => {
62+
console.log("is_cloud")
63+
infra_store.is_cloud = false
64+
console.log("is_cloud")
65+
infra_store.domain_name = "localhost"
66+
console.log("is_cloud")
67+
const url = geode_store.port
68+
console.log("port", url)
69+
const url2 = geode_store.base_url
70+
console.log("base_url", url2)
71+
expect(geode_store.base_url).toBe("http://localhost:5000")
72+
})
73+
test("test is_cloud true", async () => {
74+
infra_store.is_cloud = true
75+
infra_store.ID = "123456"
76+
infra_store.domain_name = "example.com"
77+
expect(geode_store.base_url).toBe(
78+
"https://example.com:443/123456/geode",
79+
)
80+
})
81+
test("test is_cloud true, ID empty", async () => {
82+
infra_store.is_cloud = true
83+
infra_store.ID = ""
84+
infra_store.domain_name = "example.com"
85+
expect(() => geode_store.base_url).toThrowError(
86+
"ID must not be empty in cloud mode",
87+
)
88+
})
8289
})
8390

8491
describe("is_busy", () => {
@@ -93,51 +100,30 @@ describe("Geode Store", () => {
93100
})
94101
})
95102

96-
describe("actions", () => {
97-
describe("do_ping", () => {
98-
99-
// beforeEach(() => {
100-
// infra_store.$reset()
101-
// geode_store.$reset()
102-
// feedback_store.$reset()
103-
// })
104-
105-
106-
geode_store.base_url = ""
103+
describe("actions", async () => {
104+
describe("do_ping", async () => {
107105
const getFakeCall = vi.fn()
108106
registerEndpoint(back_schemas.opengeodeweb_back.ping.$id, getFakeCall)
109107

110-
// test("request_error", async () => {
111-
// geode_store.base_url = ""
112-
// getFakeCall.mockImplementation(() => {
113-
// throw createError({
114-
// status: 404,
115-
// })
116-
// })
117-
118-
// await geode_store.do_ping()
119-
// expect(geode_store.is_running).toBe(false)
120-
// expect(feedback_store.server_error).toBe(true)
121-
// })
122-
123108
test("response", async () => {
124109
geode_store.base_url = ""
125-
getFakeCall.mockImplementation(() => ({ test: 123 }));
110+
getFakeCall.mockImplementation(() => ({}))
126111
await geode_store.do_ping()
127112
expect(geode_store.is_running).toBe(true)
128113
expect(feedback_store.server_error).toBe(false)
129114
})
130-
// test("response_error", async () => {
131-
// geode_store.base_url = ""
132-
// getFakeCall.mockImplementation(() => {
133-
// throw createError({
134-
// status: 500,
135-
// })
136-
// })
137-
// await geode_store.do_ping()
138-
// expect(geode_store.is_running).toBe(false)
139-
// expect(feedback_store.server_error).toBe(true)
140-
// })
115+
test("response_error", async () => {
116+
geode_store.base_url = ""
117+
getFakeCall.mockImplementation(() => {
118+
throw createError({
119+
status: 500,
120+
})
121+
})
122+
123+
await geode_store.do_ping()
124+
expect(geode_store.is_running).toBe(false)
125+
expect(feedback_store.server_error).toBe(true)
126+
})
141127
})
142128

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

0 commit comments

Comments
 (0)