Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion app/stores/infra.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@
export const useInfraStore = defineStore("infra", {
state: () => ({
app_mode: getAppMode(),
ID: "",
is_captcha_validated: false,
status: Status.NOT_CREATED,
microservices: [],
}),
getters: {
domain_name() {
if (this.app_mode == appMode.CLOUD) {

Check warning on line 14 in app/stores/infra.js

View workflow job for this annotation

GitHub Actions / test / oxlint

eslint(eqeqeq)

Expected === and instead saw ==
return useRuntimeConfig().public.API_URL
}
return "localhost"
Expand All @@ -29,12 +30,12 @@
const store_name = store.$id
console.log("[INFRA] Registering microservice:", store_name)

if (!this.microservices.find((store) => store.$id === store_name)) {

Check warning on line 33 in app/stores/infra.js

View workflow job for this annotation

GitHub Actions / test / oxlint

eslint-plugin-unicorn(prefer-array-some)

Prefer `.some(…)` over `.find(…)` or `.findLast(…)`.
this.microservices.push(store)
console.log("[INFRA] Microservice registered:", store_name)
}
},
async create_backend() {

Check warning on line 38 in app/stores/infra.js

View workflow job for this annotation

GitHub Actions / test / oxlint

eslint(require-await)

Async function has no 'await' expression.
console.log("[INFRA] Starting create_backend - Mode:", this.app_mode)
console.log(
"[INFRA] Registered microservices:",
Expand All @@ -43,12 +44,12 @@

if (this.status === Status.CREATED) return

return navigator.locks.request("infra.create_backend", async (lock) => {

Check warning on line 47 in app/stores/infra.js

View workflow job for this annotation

GitHub Actions / test / oxlint

eslint(no-unused-vars)

Parameter 'lock' is declared but never used. Unused parameters should start with a '_'.
this.status = Status.CREATING
if (this.status === Status.CREATED) return
console.log("[INFRA] Lock granted for create_backend")

if (this.app_mode == appMode.DESKTOP) {

Check warning on line 52 in app/stores/infra.js

View workflow job for this annotation

GitHub Actions / test / oxlint

eslint(eqeqeq)

Expected === and instead saw ==
console.log("[INFRA] DESKTOP mode - Launching microservices...")
const microservices_with_launch = this.microservices.filter(
(store) => store.launch,
Expand All @@ -62,10 +63,10 @@
microservices_with_launch.forEach((store, index) => {
store.$patch({ default_local_port: ports[index] })
})
} else if (this.app_mode == appMode.CLOUD) {

Check warning on line 66 in app/stores/infra.js

View workflow job for this annotation

GitHub Actions / test / oxlint

eslint(eqeqeq)

Expected === and instead saw ==
console.log("[INFRA] CLOUD mode - Launching lambda...")
const lambdaStore = useLambdaStore()
await lambdaStore.launch()
this.ID = await lambdaStore.launch()
console.log("[INFRA] Lambda launched successfully")
}

Expand All @@ -81,15 +82,15 @@
this.microservices.map((store) => store.$id),
)

const connection_promises = this.microservices.map((store) => {
return store.connect().then(() => {
console.log("[INFRA] Microservice connected:", store.$id)
})
})

Check failure on line 89 in app/stores/infra.js

View workflow job for this annotation

GitHub Actions / test / oxlint

eslint(arrow-body-style)

Unexpected block statement surrounding arrow body; move the returned value immediately after the `=>`.

await Promise.all(connection_promises)
console.log("[INFRA] All microservices connected")
return

Check warning on line 93 in app/stores/infra.js

View workflow job for this annotation

GitHub Actions / test / oxlint

eslint(no-useless-return)

Unnecessary return statement.
},
},
share: {
Expand Down
2 changes: 1 addition & 1 deletion app/stores/lambda.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
import Status from "@ogw_front/utils/status.js"

export const useLambdaStore = defineStore("lambda", {
state: () => ({
status: Status.NOT_CONNECTED,
}),
getters: {
protocol() {
return "https"
},
port() {
return "443"
},
base_url() {
const public_runtime_config = useRuntimeConfig().public
const domain_name = public_runtime_config.API_URL
const url =
this.protocol +
"://" +
domain_name +
":" +
this.port +
public_runtime_config.SITE_BRANCH +
public_runtime_config.PROJECT +
"/createbackend"

Check failure on line 25 in app/stores/lambda.js

View workflow job for this annotation

GitHub Actions / test / oxlint

eslint(prefer-template)

Unexpected string concatenation.
return url
},
is_busy() {
Expand All @@ -30,8 +30,8 @@
},
},
actions: {
async launch() {

Check failure on line 33 in app/stores/lambda.js

View workflow job for this annotation

GitHub Actions / test / oxlint

oxc(no-async-await)

async is not allowed
console.log("[LAMBDA] Launching lambda backend...")

Check failure on line 34 in app/stores/lambda.js

View workflow job for this annotation

GitHub Actions / test / oxlint

eslint(no-console)

Unexpected console statement.
const feedbackStore = useFeedbackStore()

const { data, error } = await useFetch(this.base_url, {
Expand All @@ -41,20 +41,20 @@
if (error.value || !data.value) {
this.status = Status.NOT_CONNECTED
feedbackStore.server_error = true
console.error("[LAMBDA] Failed to launch lambda backend")
console.error("[LAMBDA] Failed to launch lambda backend", error.value)

Check failure on line 44 in app/stores/lambda.js

View workflow job for this annotation

GitHub Actions / test / oxlint

eslint(no-console)

Unexpected console statement.
throw new Error("Failed to launch lambda backend")
}

this.status = Status.CONNECTED
const id = data.value.ID

console.log("[LAMBDA] Lambda launched, ID:", id)

Check failure on line 51 in app/stores/lambda.js

View workflow job for this annotation

GitHub Actions / test / oxlint

eslint(no-console)

Unexpected console statement.
return id
},
async connect() {

Check failure on line 54 in app/stores/lambda.js

View workflow job for this annotation

GitHub Actions / test / oxlint

oxc(no-async-await)

async is not allowed

Check warning on line 54 in app/stores/lambda.js

View workflow job for this annotation

GitHub Actions / test / oxlint

eslint(require-await)

Async function has no 'await' expression.
console.log("[LAMBDA] Lambda connected")

Check failure on line 55 in app/stores/lambda.js

View workflow job for this annotation

GitHub Actions / test / oxlint

eslint(no-console)

Unexpected console statement.
this.status = Status.CONNECTED
return Promise.resolve()

Check warning on line 57 in app/stores/lambda.js

View workflow job for this annotation

GitHub Actions / test / oxlint

eslint-plugin-unicorn(no-useless-promise-resolve-reject)

Prefer `return value` over `return Promise.resolve(value)`.
},
},
share: {
Expand Down
1 change: 0 additions & 1 deletion tests/integration/microservices/back/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,3 @@
# pip-compile --output-file=tests/integration/microservices/back/requirements.txt tests/integration/microservices/back/requirements.in
#

opengeodeweb-back==5.*,>=5.14.0
1 change: 0 additions & 1 deletion tests/integration/microservices/viewer/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,3 @@
# pip-compile --output-file=tests/integration/microservices/viewer/requirements.txt tests/integration/microservices/viewer/requirements.in
#

opengeodeweb-viewer==1.*,>=1.13.1rc1
36 changes: 20 additions & 16 deletions tests/unit/stores/Infra.nuxt.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,276 +29,280 @@
setActivePinia(pinia)
})

describe("Infra Store", () => {
describe("state", () => {
test("initial state", () => {
const infra_store = useInfraStore()
expectTypeOf(infra_store.ID).toBeString()
expectTypeOf(infra_store.is_captcha_validated).toBeBoolean()
expectTypeOf(infra_store.status).toBeString()
})
})
describe("getters", () => {
describe("app_mode", () => {
test("test type", () => {
const infra_store = useInfraStore()
expectTypeOf(infra_store.app_mode).toBeString()
})
})

describe("domain_name", () => {
test("test app_mode BROWSER", () => {
const infra_store = useInfraStore()
infra_store.app_mode = appMode.BROWSER
expect(infra_store.domain_name).toBe("localhost")
})
test("test app_mode DESKTOP", () => {
const infra_store = useInfraStore()
infra_store.app_mode = appMode.DESKTOP
expect(infra_store.domain_name).toBe("localhost")
})
test("test app_mode CLOUD", () => {
const infra_store = useInfraStore()
infra_store.app_mode = appMode.CLOUD
expect(infra_store.domain_name).toBe("api.geode-solutions.com")
})
})

describe("microservices_connected", () => {
test("test no microservices registered", () => {
const infra_store = useInfraStore()
expect(infra_store.microservices_connected).toBe(true)
})
test("test geode false & viewer false", () => {
const infra_store = useInfraStore()
const geodeStore = useGeodeStore()
const viewerStore = useViewerStore()

infra_store.register_microservice(geodeStore, {
request: vi.fn(),
connect: vi.fn(),
launch: vi.fn(),
})
infra_store.register_microservice(viewerStore, {
request: vi.fn(),
connect: vi.fn(),
launch: vi.fn(),
})

geodeStore.$patch({ status: Status.NOT_CONNECTED })
viewerStore.$patch({ status: Status.NOT_CONNECTED })
expect(infra_store.microservices_connected).toBe(false)
})
test("test geode true & viewer false", () => {
const infra_store = useInfraStore()
const geodeStore = useGeodeStore()
const viewerStore = useViewerStore()

infra_store.register_microservice(geodeStore, {
request: vi.fn(),
connect: vi.fn(),
launch: vi.fn(),
})
infra_store.register_microservice(viewerStore, {
request: vi.fn(),
connect: vi.fn(),
launch: vi.fn(),
})

geodeStore.$patch({ status: Status.CONNECTED })
viewerStore.$patch({ status: Status.NOT_CONNECTED })
expect(infra_store.microservices_connected).toBe(false)
})
test("test geode false & viewer true", () => {
const infra_store = useInfraStore()
const geodeStore = useGeodeStore()
const viewerStore = useViewerStore()

infra_store.register_microservice(geodeStore, {
request: vi.fn(),
connect: vi.fn(),
launch: vi.fn(),
})
infra_store.register_microservice(viewerStore, {
request: vi.fn(),
connect: vi.fn(),
launch: vi.fn(),
})

geodeStore.$patch({ status: Status.NOT_CONNECTED })
viewerStore.$patch({ status: Status.CONNECTED })
expect(infra_store.microservices_connected).toBe(false)
})
test("test geode true & viewer true", () => {
const infra_store = useInfraStore()
const geodeStore = useGeodeStore()
const viewerStore = useViewerStore()

infra_store.register_microservice(geodeStore, {
request: vi.fn(),
connect: vi.fn(),
launch: vi.fn(),
})
infra_store.register_microservice(viewerStore, {
request: vi.fn(),
connect: vi.fn(),
launch: vi.fn(),
})

geodeStore.$patch({ status: Status.CONNECTED })
viewerStore.$patch({ status: Status.CONNECTED })
expect(infra_store.microservices_connected).toBe(true)
})
})

describe("microservices_busy", () => {
test("test no microservices registered", () => {
const infra_store = useInfraStore()
expect(infra_store.microservices_busy).toBe(false)
})
test("test geode false & viewer false", () => {
const infra_store = useInfraStore()
const geodeStore = useGeodeStore()
const viewerStore = useViewerStore()

infra_store.register_microservice(geodeStore, {
request: vi.fn(),
connect: vi.fn(),
launch: vi.fn(),
})
infra_store.register_microservice(viewerStore, {
request: vi.fn(),
connect: vi.fn(),
launch: vi.fn(),
})

geodeStore.$patch({ request_counter: 0 })
viewerStore.$patch({ request_counter: 0 })
expect(infra_store.microservices_busy).toBe(false)
})
test("test geode true & viewer false", () => {
const infra_store = useInfraStore()
const geodeStore = useGeodeStore()
const viewerStore = useViewerStore()

infra_store.register_microservice(geodeStore, {
request: vi.fn(),
connect: vi.fn(),
launch: vi.fn(),
})
infra_store.register_microservice(viewerStore, {
request: vi.fn(),
connect: vi.fn(),
launch: vi.fn(),
})

geodeStore.$patch({ request_counter: 1 })
viewerStore.$patch({ request_counter: 0 })
expect(infra_store.microservices_busy).toBe(true)
})
test("test geode false & viewer true", () => {
const infra_store = useInfraStore()
const geodeStore = useGeodeStore()
const viewerStore = useViewerStore()

infra_store.register_microservice(geodeStore, {
request: vi.fn(),
connect: vi.fn(),
launch: vi.fn(),
})
infra_store.register_microservice(viewerStore, {
request: vi.fn(),
connect: vi.fn(),
launch: vi.fn(),
})

geodeStore.$patch({ request_counter: 0 })
viewerStore.$patch({ request_counter: 1 })
expect(infra_store.microservices_busy).toBe(true)
})
test("test geode true & viewer true", () => {
const infra_store = useInfraStore()
const geodeStore = useGeodeStore()
const viewerStore = useViewerStore()

infra_store.register_microservice(geodeStore, {
request: vi.fn(),
connect: vi.fn(),
launch: vi.fn(),
})
infra_store.register_microservice(viewerStore, {
request: vi.fn(),
connect: vi.fn(),
launch: vi.fn(),
})

geodeStore.$patch({ request_counter: 1 })
viewerStore.$patch({ request_counter: 1 })
expect(infra_store.microservices_busy).toBe(true)
})
})
})

describe("actions", () => {
describe("register_microservice", () => {
test("register geode microservice", () => {
const infra_store = useInfraStore()
const geodeStore = useGeodeStore()

infra_store.register_microservice(geodeStore, {
request: vi.fn(),
connect: vi.fn(),
launch: vi.fn(),
})

expect(infra_store.microservices.length).toBe(1)
expect(infra_store.microservices[0].$id).toBe("geode")
})

test("register multiple microservices", () => {
const infra_store = useInfraStore()
const geodeStore = useGeodeStore()
const viewerStore = useViewerStore()

infra_store.register_microservice(geodeStore, {
request: vi.fn(),
connect: vi.fn(),
launch: vi.fn(),
})

infra_store.register_microservice(viewerStore, {
request: vi.fn(),
connect: vi.fn(),
launch: vi.fn(),
})

expect(infra_store.microservices.length).toBe(2)
})
})

describe("create_backend", () => {
test("test without microservices", async () => {
const infra_store = useInfraStore()
infra_store.app_mode = appMode.BROWSER
await infra_store.create_backend()
expect(infra_store.status).toBe(Status.CREATED)
})
// test("test with end-point", async () => {
// const infra_store = useInfraStore()
// const geodeStore = useGeodeStore()
// const viewerStore = useViewerStore()
// const feedback_store = useFeedbackStore()

// registerEndpoint(infra_store.lambda_url, {
// method: "POST",
// handler: () => ({ ID: "123456" }),
// })
// await infra_store.create_backend()
// expect(infra_store.status).toBe(Status.CREATED)
// expect(geodeStore.status).toBe(Status.NOT_CONNECTED)
// expect(viewerStore.status).toBe(Status.NOT_CONNECTED)
// expect(feedback_store.server_error).toBe(true)
// })
test("test with end-point", async () => {
const infra_store = useInfraStore()
const geodeStore = useGeodeStore()
const viewerStore = useViewerStore()
const feedback_store = useFeedbackStore()
const lambdaStore = useLambdaStore()

infra_store.app_mode = appMode.CLOUD
const ID = "123456"
registerEndpoint(lambdaStore.base_url, {
method: "POST",
handler: () => ({ ID }),
})
await infra_store.create_backend()
expect(infra_store.status).toBe(Status.CREATED)
expect(infra_store.ID).toBe(ID)

expect(geodeStore.status).toBe(Status.NOT_CONNECTED)
expect(viewerStore.status).toBe(Status.NOT_CONNECTED)
})
})
})
})

Check warning on line 308 in tests/unit/stores/Infra.nuxt.test.js

View workflow job for this annotation

GitHub Actions / test / oxlint

eslint(max-lines-per-function)

The function has too many lines (277). Maximum allowed is 50.