-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathrun_function_when_microservices_connected.nuxt.test.js
More file actions
57 lines (50 loc) · 1.94 KB
/
Copy pathrun_function_when_microservices_connected.nuxt.test.js
File metadata and controls
57 lines (50 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// Third party imports
import { beforeEach, describe, expect, test, vi } from "vitest";
import { flushPromises } from "@vue/test-utils";
// Local imports
import { Status } from "@ogw_front/utils/status";
import { runFunctionWhenMicroservicesConnected } from "@ogw_front/composables/run_function_when_microservices_connected";
import { setupActivePinia } from "@ogw_tests/utils";
import { useBackStore } from "@ogw_front/stores/back";
import { useInfraStore } from "@ogw_front/stores/infra";
import { useViewerStore } from "@ogw_front/stores/viewer";
const dumb_obj = { dumb_method: () => true };
let infraStore = undefined;
let backStore = undefined;
let viewerStore = undefined;
describe("when_microservices_connected_run_function", () => {
beforeEach(() => {
setupActivePinia();
infraStore = useInfraStore();
backStore = useBackStore();
viewerStore = useViewerStore();
// Register microservices in infra store
infraStore.register_microservice(backStore, {
request: vi.fn(),
connect: vi.fn(),
launch: vi.fn(),
});
infraStore.register_microservice(viewerStore, {
request: vi.fn(),
connect: vi.fn(),
launch: vi.fn(),
});
backStore.$patch({ status: Status.NOT_CONNECTED });
viewerStore.$patch({ status: Status.NOT_CONNECTED });
});
test("microservices not connected", () => {
const spy = vi.spyOn(dumb_obj, "dumb_method");
runFunctionWhenMicroservicesConnected(dumb_obj.dumb_method);
backStore.$patch({ status: Status.NOT_CONNECTED });
viewerStore.$patch({ status: Status.NOT_CONNECTED });
expect(spy).not.toHaveBeenCalled();
});
test("microservices connected", async () => {
const spy = vi.spyOn(dumb_obj, "dumb_method");
runFunctionWhenMicroservicesConnected(dumb_obj.dumb_method);
backStore.$patch({ status: Status.CONNECTED });
viewerStore.$patch({ status: Status.CONNECTED });
await flushPromises();
expect(spy).toHaveBeenCalledWith();
});
});