@nest-yalc-2/api-strategy 2.2.1 → 2.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (30) hide show
  1. package/package.json +10 -2
  2. package/src/__tests__/call-strategy-wrappers.spec.ts +217 -217
  3. package/src/__tests__/context-call.service.spec.ts +52 -52
  4. package/src/__tests__/context-event.service.spec.ts +52 -52
  5. package/src/__tests__/event-strategy-composition.spec.ts +185 -185
  6. package/src/__tests__/header-whitelist.helper.spec.ts +41 -30
  7. package/src/__tests__/http-abstract-call.strategy.spec.ts +17 -17
  8. package/src/__tests__/nest-http-call.strategy.spec.ts +164 -164
  9. package/src/__tests__/nest-local-call.strategy.spec.ts +263 -263
  10. package/src/__tests__/nest-local-event.strategy.spec.ts +55 -55
  11. package/src/__tests__/rabbitmq-event.strategy.spec.ts +220 -220
  12. package/src/__tests__/strategy-selector.provider.spec.ts +182 -182
  13. package/src/context-call.interface.ts +49 -49
  14. package/src/context-call.service.ts +31 -31
  15. package/src/context-event.interface.ts +4 -4
  16. package/src/context-event.service.ts +31 -31
  17. package/src/header-whitelist.helper.ts +12 -12
  18. package/src/index.ts +17 -17
  19. package/src/strategies/composite-event.strategy.ts +76 -76
  20. package/src/strategies/conditional-call.strategy.ts +70 -70
  21. package/src/strategies/conditional-event.strategy.ts +54 -54
  22. package/src/strategies/fallback-call.strategy.ts +67 -67
  23. package/src/strategies/http-abstract-call.strategy.ts +238 -238
  24. package/src/strategies/nest-http-call.strategy.ts +121 -121
  25. package/src/strategies/nest-local-call.strategy.ts +153 -153
  26. package/src/strategies/nest-local-event.strategy.d.ts +1 -1
  27. package/src/strategies/nest-local-event.strategy.ts +42 -42
  28. package/src/strategies/rabbitmq-event.strategy.ts +154 -154
  29. package/src/strategies/shadow-call.strategy.ts +87 -87
  30. package/src/strategy-selector.provider.ts +103 -103
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nest-yalc-2/api-strategy",
3
- "version": "2.2.1",
3
+ "version": "2.2.3",
4
4
  "type": "module",
5
5
  "description": "",
6
6
  "exports": {
@@ -16,8 +16,16 @@
16
16
  "src"
17
17
  ],
18
18
  "dependencies": {
19
- "tslib": "^2.6.3"
19
+ "tslib": "^2.8.1"
20
20
  },
21
+ "keywords": [
22
+ "nestjs",
23
+ "nestjs-yalc",
24
+ "yalc",
25
+ "api-strategy",
26
+ "framework",
27
+ "utility"
28
+ ],
21
29
  "repository": {
22
30
  "type": "git",
23
31
  "url": "git+https://github.com/Nek97/nestjs-yalc.git"
@@ -1,217 +1,217 @@
1
- import { jest, describe, expect, it } from "@jest/globals";
2
- import type { IApiCallStrategy } from "../context-call.interface.js";
3
- import { ConditionalCallStrategy } from "../strategies/conditional-call.strategy.js";
4
- import { FallbackCallStrategy } from "../strategies/fallback-call.strategy.js";
5
- import { ShadowCallStrategy } from "../strategies/shadow-call.strategy.js";
6
-
7
- function callStrategy(overrides: Partial<IApiCallStrategy> = {}) {
8
- return {
9
- call: jest.fn(async () => ({ data: "call" })),
10
- get: jest.fn(async () => ({ data: "get" })),
11
- post: jest.fn(async () => ({ data: "post" })),
12
- ...overrides,
13
- } satisfies IApiCallStrategy;
14
- }
15
-
16
- describe("ConditionalCallStrategy", () => {
17
- it("delegates calls when enabled", async () => {
18
- const target = callStrategy();
19
- const strategy = new ConditionalCallStrategy(target, {
20
- enabled: () => true,
21
- });
22
-
23
- await expect(strategy.call("/items")).resolves.toEqual({ data: "call" });
24
- await expect(strategy.get("/items")).resolves.toEqual({ data: "get" });
25
- await expect(strategy.post("/items")).resolves.toEqual({ data: "post" });
26
- });
27
-
28
- it("delegates calls when no condition is configured", async () => {
29
- const strategy = new ConditionalCallStrategy(callStrategy());
30
-
31
- await expect(strategy.call("/items")).resolves.toEqual({ data: "call" });
32
- });
33
-
34
- it("returns a disabled response when disabled", async () => {
35
- const target = callStrategy();
36
- const strategy = new ConditionalCallStrategy(target, {
37
- enabled: false,
38
- disabledResponse: { data: "disabled" },
39
- });
40
-
41
- await expect(strategy.call("/items")).resolves.toEqual({
42
- data: "disabled",
43
- });
44
- expect(target.call).not.toHaveBeenCalled();
45
- });
46
-
47
- it("throws the default disabled error", async () => {
48
- const strategy = new ConditionalCallStrategy(callStrategy(), {
49
- enabled: false,
50
- });
51
-
52
- await expect(strategy.get("/items")).rejects.toThrow("disabled");
53
- });
54
-
55
- it("throws a custom disabled error", async () => {
56
- const strategy = new ConditionalCallStrategy(callStrategy(), {
57
- enabled: false,
58
- disabledError: () => new Error("custom disabled"),
59
- });
60
-
61
- await expect(strategy.post("/items")).rejects.toThrow("custom disabled");
62
- });
63
-
64
- it("throws a custom disabled error instance", async () => {
65
- const strategy = new ConditionalCallStrategy(callStrategy(), {
66
- enabled: false,
67
- disabledError: new Error("disabled instance"),
68
- });
69
-
70
- await expect(strategy.call("/items")).rejects.toThrow("disabled instance");
71
- });
72
- });
73
-
74
- describe("FallbackCallStrategy", () => {
75
- it("requires at least one strategy", () => {
76
- expect(() => new FallbackCallStrategy([])).toThrow("at least one");
77
- });
78
-
79
- it("falls back to the next strategy after a failure", async () => {
80
- const first = callStrategy({
81
- call: jest.fn(async () => {
82
- throw new Error("primary failed");
83
- }),
84
- });
85
- const second = callStrategy();
86
- const strategy = new FallbackCallStrategy([first, second]);
87
-
88
- await expect(strategy.call("/items")).resolves.toEqual({ data: "call" });
89
- expect(first.call).toHaveBeenCalled();
90
- expect(second.call).toHaveBeenCalled();
91
- });
92
-
93
- it("stops fallback when the predicate rejects it", async () => {
94
- const error = new Error("do not retry");
95
- const strategy = new FallbackCallStrategy(
96
- [
97
- callStrategy({
98
- get: jest.fn(async () => {
99
- throw error;
100
- }),
101
- }),
102
- callStrategy(),
103
- ],
104
- {
105
- shouldFallback: () => false,
106
- }
107
- );
108
-
109
- await expect(strategy.get("/items")).rejects.toThrow(error);
110
- });
111
-
112
- it("throws the last error after all strategies fail", async () => {
113
- const strategy = new FallbackCallStrategy([
114
- callStrategy({
115
- post: jest.fn(async () => {
116
- throw new Error("first failed");
117
- }),
118
- }),
119
- callStrategy({
120
- post: jest.fn(async () => {
121
- throw new Error("last failed");
122
- }),
123
- }),
124
- ]);
125
-
126
- await expect(strategy.post("/items")).rejects.toThrow("last failed");
127
- });
128
- });
129
-
130
- describe("ShadowCallStrategy", () => {
131
- it("requires at least one shadow strategy", () => {
132
- expect(() => new ShadowCallStrategy(callStrategy(), [])).toThrow(
133
- "at least one"
134
- );
135
- });
136
-
137
- it("returns the primary response and triggers shadows", async () => {
138
- const primary = callStrategy();
139
- const shadow = callStrategy();
140
- const strategy = new ShadowCallStrategy(primary, [shadow]);
141
-
142
- await expect(strategy.call("/items")).resolves.toEqual({ data: "call" });
143
- await new Promise((resolve) => setTimeout(resolve, 0));
144
-
145
- expect(primary.call).toHaveBeenCalled();
146
- expect(shadow.call).toHaveBeenCalled();
147
- });
148
-
149
- it("ignores fire-and-forget shadow failures", async () => {
150
- const strategy = new ShadowCallStrategy(callStrategy(), [
151
- callStrategy({
152
- call: jest.fn(async () => {
153
- throw new Error("shadow failed");
154
- }),
155
- }),
156
- ]);
157
-
158
- await expect(strategy.call("/items")).resolves.toEqual({ data: "call" });
159
- await new Promise((resolve) => setTimeout(resolve, 0));
160
- });
161
-
162
- it("throws shadow failures when configured to await and throw", async () => {
163
- const strategy = new ShadowCallStrategy(
164
- callStrategy(),
165
- [
166
- callStrategy({
167
- get: jest.fn(async () => {
168
- throw new Error("shadow failed");
169
- }),
170
- }),
171
- ],
172
- {
173
- awaitShadows: true,
174
- shadowErrorMode: "throw",
175
- }
176
- );
177
-
178
- await expect(strategy.get("/items")).rejects.toThrow("shadow failed");
179
- });
180
-
181
- it("awaits and ignores shadow failures when configured", async () => {
182
- const strategy = new ShadowCallStrategy(
183
- callStrategy(),
184
- [
185
- callStrategy({
186
- post: jest.fn(async () => {
187
- throw new Error("shadow failed");
188
- }),
189
- }),
190
- ],
191
- {
192
- awaitShadows: true,
193
- shadowErrorMode: "ignore",
194
- }
195
- );
196
-
197
- await expect(strategy.post("/items")).resolves.toEqual({ data: "post" });
198
- });
199
-
200
- it("awaits shadows automatically when throw mode is configured", async () => {
201
- const strategy = new ShadowCallStrategy(
202
- callStrategy(),
203
- [
204
- callStrategy({
205
- call: jest.fn(async () => {
206
- throw new Error("shadow failed");
207
- }),
208
- }),
209
- ],
210
- {
211
- shadowErrorMode: "throw",
212
- }
213
- );
214
-
215
- await expect(strategy.call("/items")).rejects.toThrow("shadow failed");
216
- });
217
- });
1
+ import { jest, describe, expect, it } from "@jest/globals";
2
+ import type { IApiCallStrategy } from "../context-call.interface.js";
3
+ import { ConditionalCallStrategy } from "../strategies/conditional-call.strategy.js";
4
+ import { FallbackCallStrategy } from "../strategies/fallback-call.strategy.js";
5
+ import { ShadowCallStrategy } from "../strategies/shadow-call.strategy.js";
6
+
7
+ function callStrategy(overrides: Partial<IApiCallStrategy> = {}) {
8
+ return {
9
+ call: jest.fn(async () => ({ data: "call" })),
10
+ get: jest.fn(async () => ({ data: "get" })),
11
+ post: jest.fn(async () => ({ data: "post" })),
12
+ ...overrides,
13
+ } satisfies IApiCallStrategy;
14
+ }
15
+
16
+ describe("ConditionalCallStrategy", () => {
17
+ it("delegates calls when enabled", async () => {
18
+ const target = callStrategy();
19
+ const strategy = new ConditionalCallStrategy(target, {
20
+ enabled: () => true,
21
+ });
22
+
23
+ await expect(strategy.call("/items")).resolves.toEqual({ data: "call" });
24
+ await expect(strategy.get("/items")).resolves.toEqual({ data: "get" });
25
+ await expect(strategy.post("/items")).resolves.toEqual({ data: "post" });
26
+ });
27
+
28
+ it("delegates calls when no condition is configured", async () => {
29
+ const strategy = new ConditionalCallStrategy(callStrategy());
30
+
31
+ await expect(strategy.call("/items")).resolves.toEqual({ data: "call" });
32
+ });
33
+
34
+ it("returns a disabled response when disabled", async () => {
35
+ const target = callStrategy();
36
+ const strategy = new ConditionalCallStrategy(target, {
37
+ enabled: false,
38
+ disabledResponse: { data: "disabled" },
39
+ });
40
+
41
+ await expect(strategy.call("/items")).resolves.toEqual({
42
+ data: "disabled",
43
+ });
44
+ expect(target.call).not.toHaveBeenCalled();
45
+ });
46
+
47
+ it("throws the default disabled error", async () => {
48
+ const strategy = new ConditionalCallStrategy(callStrategy(), {
49
+ enabled: false,
50
+ });
51
+
52
+ await expect(strategy.get("/items")).rejects.toThrow("disabled");
53
+ });
54
+
55
+ it("throws a custom disabled error", async () => {
56
+ const strategy = new ConditionalCallStrategy(callStrategy(), {
57
+ enabled: false,
58
+ disabledError: () => new Error("custom disabled"),
59
+ });
60
+
61
+ await expect(strategy.post("/items")).rejects.toThrow("custom disabled");
62
+ });
63
+
64
+ it("throws a custom disabled error instance", async () => {
65
+ const strategy = new ConditionalCallStrategy(callStrategy(), {
66
+ enabled: false,
67
+ disabledError: new Error("disabled instance"),
68
+ });
69
+
70
+ await expect(strategy.call("/items")).rejects.toThrow("disabled instance");
71
+ });
72
+ });
73
+
74
+ describe("FallbackCallStrategy", () => {
75
+ it("requires at least one strategy", () => {
76
+ expect(() => new FallbackCallStrategy([])).toThrow("at least one");
77
+ });
78
+
79
+ it("falls back to the next strategy after a failure", async () => {
80
+ const first = callStrategy({
81
+ call: jest.fn(async () => {
82
+ throw new Error("primary failed");
83
+ }),
84
+ });
85
+ const second = callStrategy();
86
+ const strategy = new FallbackCallStrategy([first, second]);
87
+
88
+ await expect(strategy.call("/items")).resolves.toEqual({ data: "call" });
89
+ expect(first.call).toHaveBeenCalled();
90
+ expect(second.call).toHaveBeenCalled();
91
+ });
92
+
93
+ it("stops fallback when the predicate rejects it", async () => {
94
+ const error = new Error("do not retry");
95
+ const strategy = new FallbackCallStrategy(
96
+ [
97
+ callStrategy({
98
+ get: jest.fn(async () => {
99
+ throw error;
100
+ }),
101
+ }),
102
+ callStrategy(),
103
+ ],
104
+ {
105
+ shouldFallback: () => false,
106
+ }
107
+ );
108
+
109
+ await expect(strategy.get("/items")).rejects.toThrow(error);
110
+ });
111
+
112
+ it("throws the last error after all strategies fail", async () => {
113
+ const strategy = new FallbackCallStrategy([
114
+ callStrategy({
115
+ post: jest.fn(async () => {
116
+ throw new Error("first failed");
117
+ }),
118
+ }),
119
+ callStrategy({
120
+ post: jest.fn(async () => {
121
+ throw new Error("last failed");
122
+ }),
123
+ }),
124
+ ]);
125
+
126
+ await expect(strategy.post("/items")).rejects.toThrow("last failed");
127
+ });
128
+ });
129
+
130
+ describe("ShadowCallStrategy", () => {
131
+ it("requires at least one shadow strategy", () => {
132
+ expect(() => new ShadowCallStrategy(callStrategy(), [])).toThrow(
133
+ "at least one"
134
+ );
135
+ });
136
+
137
+ it("returns the primary response and triggers shadows", async () => {
138
+ const primary = callStrategy();
139
+ const shadow = callStrategy();
140
+ const strategy = new ShadowCallStrategy(primary, [shadow]);
141
+
142
+ await expect(strategy.call("/items")).resolves.toEqual({ data: "call" });
143
+ await new Promise((resolve) => setTimeout(resolve, 0));
144
+
145
+ expect(primary.call).toHaveBeenCalled();
146
+ expect(shadow.call).toHaveBeenCalled();
147
+ });
148
+
149
+ it("ignores fire-and-forget shadow failures", async () => {
150
+ const strategy = new ShadowCallStrategy(callStrategy(), [
151
+ callStrategy({
152
+ call: jest.fn(async () => {
153
+ throw new Error("shadow failed");
154
+ }),
155
+ }),
156
+ ]);
157
+
158
+ await expect(strategy.call("/items")).resolves.toEqual({ data: "call" });
159
+ await new Promise((resolve) => setTimeout(resolve, 0));
160
+ });
161
+
162
+ it("throws shadow failures when configured to await and throw", async () => {
163
+ const strategy = new ShadowCallStrategy(
164
+ callStrategy(),
165
+ [
166
+ callStrategy({
167
+ get: jest.fn(async () => {
168
+ throw new Error("shadow failed");
169
+ }),
170
+ }),
171
+ ],
172
+ {
173
+ awaitShadows: true,
174
+ shadowErrorMode: "throw",
175
+ }
176
+ );
177
+
178
+ await expect(strategy.get("/items")).rejects.toThrow("shadow failed");
179
+ });
180
+
181
+ it("awaits and ignores shadow failures when configured", async () => {
182
+ const strategy = new ShadowCallStrategy(
183
+ callStrategy(),
184
+ [
185
+ callStrategy({
186
+ post: jest.fn(async () => {
187
+ throw new Error("shadow failed");
188
+ }),
189
+ }),
190
+ ],
191
+ {
192
+ awaitShadows: true,
193
+ shadowErrorMode: "ignore",
194
+ }
195
+ );
196
+
197
+ await expect(strategy.post("/items")).resolves.toEqual({ data: "post" });
198
+ });
199
+
200
+ it("awaits shadows automatically when throw mode is configured", async () => {
201
+ const strategy = new ShadowCallStrategy(
202
+ callStrategy(),
203
+ [
204
+ callStrategy({
205
+ call: jest.fn(async () => {
206
+ throw new Error("shadow failed");
207
+ }),
208
+ }),
209
+ ],
210
+ {
211
+ shadowErrorMode: "throw",
212
+ }
213
+ );
214
+
215
+ await expect(strategy.call("/items")).rejects.toThrow("shadow failed");
216
+ });
217
+ });
@@ -1,52 +1,52 @@
1
- import {
2
- expect,
3
- jest,
4
- describe,
5
- it,
6
- beforeEach,
7
- beforeAll,
8
- afterAll,
9
- afterEach,
10
- } from '@jest/globals';
11
-
12
- import { createMock } from '@golevelup/ts-jest';
13
- import { HttpAdapterHost } from '@nestjs/common';
14
- import { ContextCallServiceFactory } from '../context-call.service.js';
15
- import { NestLocalCallStrategy } from '../index.js';
16
-
17
- describe('ContextCallServiceFactory', () => {
18
- let httpAdapterHost: HttpAdapterHost;
19
-
20
- beforeEach(() => {
21
- httpAdapterHost = createMock<HttpAdapterHost>();
22
- });
23
-
24
- it('should be defined', () => {
25
- expect(ContextCallServiceFactory).toBeDefined();
26
- });
27
-
28
- it('should return a class', () => {
29
- const ContextCallService = ContextCallServiceFactory(
30
- new NestLocalCallStrategy(httpAdapterHost),
31
- );
32
- expect(ContextCallService).toBeDefined();
33
- });
34
-
35
- it('should return a class that can be instantiated', () => {
36
- const ContextCallService = ContextCallServiceFactory(
37
- new NestLocalCallStrategy(httpAdapterHost),
38
- );
39
- const instance = new ContextCallService();
40
- expect(instance).toBeDefined();
41
- });
42
-
43
- it('should return a class that can set and get a strategy', () => {
44
- const ContextCallService = ContextCallServiceFactory(
45
- new NestLocalCallStrategy(httpAdapterHost),
46
- );
47
- const instance = new ContextCallService();
48
- const strategy = new NestLocalCallStrategy(httpAdapterHost);
49
- instance.setStrategy(strategy);
50
- expect(instance.getStrategy()).toBe(strategy);
51
- });
52
- });
1
+ import {
2
+ expect,
3
+ jest,
4
+ describe,
5
+ it,
6
+ beforeEach,
7
+ beforeAll,
8
+ afterAll,
9
+ afterEach,
10
+ } from '@jest/globals';
11
+
12
+ import { createMock } from '@golevelup/ts-jest';
13
+ import { HttpAdapterHost } from '@nestjs/common';
14
+ import { ContextCallServiceFactory } from '../context-call.service.js';
15
+ import { NestLocalCallStrategy } from '../index.js';
16
+
17
+ describe('ContextCallServiceFactory', () => {
18
+ let httpAdapterHost: HttpAdapterHost;
19
+
20
+ beforeEach(() => {
21
+ httpAdapterHost = createMock<HttpAdapterHost>();
22
+ });
23
+
24
+ it('should be defined', () => {
25
+ expect(ContextCallServiceFactory).toBeDefined();
26
+ });
27
+
28
+ it('should return a class', () => {
29
+ const ContextCallService = ContextCallServiceFactory(
30
+ new NestLocalCallStrategy(httpAdapterHost),
31
+ );
32
+ expect(ContextCallService).toBeDefined();
33
+ });
34
+
35
+ it('should return a class that can be instantiated', () => {
36
+ const ContextCallService = ContextCallServiceFactory(
37
+ new NestLocalCallStrategy(httpAdapterHost),
38
+ );
39
+ const instance = new ContextCallService();
40
+ expect(instance).toBeDefined();
41
+ });
42
+
43
+ it('should return a class that can set and get a strategy', () => {
44
+ const ContextCallService = ContextCallServiceFactory(
45
+ new NestLocalCallStrategy(httpAdapterHost),
46
+ );
47
+ const instance = new ContextCallService();
48
+ const strategy = new NestLocalCallStrategy(httpAdapterHost);
49
+ instance.setStrategy(strategy);
50
+ expect(instance.getStrategy()).toBe(strategy);
51
+ });
52
+ });
@@ -1,52 +1,52 @@
1
- import {
2
- expect,
3
- jest,
4
- describe,
5
- it,
6
- beforeEach,
7
- beforeAll,
8
- afterAll,
9
- afterEach,
10
- } from '@jest/globals';
11
-
12
- import { createMock } from '@golevelup/ts-jest';
13
- import { EventEmitter2 } from '@nestjs/event-emitter';
14
- import { ContextEventServiceFactory } from '../context-event.service.js';
15
- import { NestLocalEventStrategy } from '../index.js';
16
-
17
- describe('ContextEventServiceFactory', () => {
18
- let eventEmitter: EventEmitter2;
19
-
20
- beforeEach(() => {
21
- eventEmitter = createMock<EventEmitter2>();
22
- });
23
-
24
- it('should be defined', () => {
25
- expect(ContextEventServiceFactory).toBeDefined();
26
- });
27
-
28
- it('should return a class', () => {
29
- const ContextCallService = ContextEventServiceFactory(
30
- new NestLocalEventStrategy(eventEmitter),
31
- );
32
- expect(ContextCallService).toBeDefined();
33
- });
34
-
35
- it('should return a class that can be instantiated', () => {
36
- const ContextCallService = ContextEventServiceFactory(
37
- new NestLocalEventStrategy(eventEmitter),
38
- );
39
- const instance = new ContextCallService();
40
- expect(instance).toBeDefined();
41
- });
42
-
43
- it('should return a class that can set and get a strategy', () => {
44
- const ContextCallService = ContextEventServiceFactory(
45
- new NestLocalEventStrategy(eventEmitter),
46
- );
47
- const instance = new ContextCallService();
48
- const strategy = new NestLocalEventStrategy(eventEmitter);
49
- instance.setStrategy(strategy);
50
- expect(instance.getStrategy()).toBe(strategy);
51
- });
52
- });
1
+ import {
2
+ expect,
3
+ jest,
4
+ describe,
5
+ it,
6
+ beforeEach,
7
+ beforeAll,
8
+ afterAll,
9
+ afterEach,
10
+ } from '@jest/globals';
11
+
12
+ import { createMock } from '@golevelup/ts-jest';
13
+ import { EventEmitter2 } from '@nestjs/event-emitter';
14
+ import { ContextEventServiceFactory } from '../context-event.service.js';
15
+ import { NestLocalEventStrategy } from '../index.js';
16
+
17
+ describe('ContextEventServiceFactory', () => {
18
+ let eventEmitter: EventEmitter2;
19
+
20
+ beforeEach(() => {
21
+ eventEmitter = createMock<EventEmitter2>();
22
+ });
23
+
24
+ it('should be defined', () => {
25
+ expect(ContextEventServiceFactory).toBeDefined();
26
+ });
27
+
28
+ it('should return a class', () => {
29
+ const ContextCallService = ContextEventServiceFactory(
30
+ new NestLocalEventStrategy(eventEmitter),
31
+ );
32
+ expect(ContextCallService).toBeDefined();
33
+ });
34
+
35
+ it('should return a class that can be instantiated', () => {
36
+ const ContextCallService = ContextEventServiceFactory(
37
+ new NestLocalEventStrategy(eventEmitter),
38
+ );
39
+ const instance = new ContextCallService();
40
+ expect(instance).toBeDefined();
41
+ });
42
+
43
+ it('should return a class that can set and get a strategy', () => {
44
+ const ContextCallService = ContextEventServiceFactory(
45
+ new NestLocalEventStrategy(eventEmitter),
46
+ );
47
+ const instance = new ContextCallService();
48
+ const strategy = new NestLocalEventStrategy(eventEmitter);
49
+ instance.setStrategy(strategy);
50
+ expect(instance.getStrategy()).toBe(strategy);
51
+ });
52
+ });