@shopgate/pwa-core 7.31.5 → 7.31.6
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.
- package/package.json +1 -1
- package/classes/AppCommand/spec.js +0 -265
- package/classes/Bridge/spec.js +0 -24
- package/classes/BrightnessRequest/spec.js +0 -111
- package/classes/Conditioner/spec.js +0 -75
- package/classes/DevServerBridge/spec.js +0 -232
- package/classes/ErrorManager/spec.js +0 -244
- package/classes/PipelineDependencies/spec.js +0 -48
- package/classes/PipelineManager/spec.js +0 -737
- package/classes/PipelineRequest/spec.js +0 -333
- package/classes/RequestManager/spec.js +0 -203
package/package.json
CHANGED
|
@@ -1,265 +0,0 @@
|
|
|
1
|
-
import { hasSGJavaScriptBridge } from "../../helpers";
|
|
2
|
-
import { defaultClientInformation } from "../../helpers/version";
|
|
3
|
-
import AppCommand from "./index";
|
|
4
|
-
jest.unmock("./index.js");
|
|
5
|
-
|
|
6
|
-
// Mocks for the logger.
|
|
7
|
-
const mockedLoggerError = jest.fn();
|
|
8
|
-
const mockedLoggerWarn = jest.fn();
|
|
9
|
-
jest.mock("../../helpers", () => ({
|
|
10
|
-
logger: {
|
|
11
|
-
error: (...args) => {
|
|
12
|
-
mockedLoggerError.apply(void 0, args);
|
|
13
|
-
},
|
|
14
|
-
warn: (...args) => {
|
|
15
|
-
mockedLoggerWarn.apply(void 0, args);
|
|
16
|
-
},
|
|
17
|
-
log: () => {}
|
|
18
|
-
},
|
|
19
|
-
hasSGJavaScriptBridge: jest.fn().mockReturnValue(false),
|
|
20
|
-
useBrowserConnector: () => false
|
|
21
|
-
}));
|
|
22
|
-
const mockedLogGroup = jest.fn();
|
|
23
|
-
// eslint-disable-next-line extra-rules/potential-point-free
|
|
24
|
-
jest.mock("../../helpers/logGroup", () => function logGroup(...args) {
|
|
25
|
-
mockedLogGroup.apply(void 0, args);
|
|
26
|
-
});
|
|
27
|
-
let mockedBridgeDispatch = jest.fn();
|
|
28
|
-
|
|
29
|
-
/* eslint-disable class-methods-use-this */
|
|
30
|
-
jest.mock("../DevServerBridge", () => {
|
|
31
|
-
let DevServerBridge = /*#__PURE__*/function () {
|
|
32
|
-
function DevServerBridge() {}
|
|
33
|
-
var _proto = DevServerBridge.prototype;
|
|
34
|
-
_proto.dispatchCommandsForVersion = function dispatchCommandsForVersion(...args) {
|
|
35
|
-
return mockedBridgeDispatch.apply(void 0, args);
|
|
36
|
-
};
|
|
37
|
-
return DevServerBridge;
|
|
38
|
-
}();
|
|
39
|
-
return {
|
|
40
|
-
__esModule: true,
|
|
41
|
-
default: DevServerBridge
|
|
42
|
-
};
|
|
43
|
-
});
|
|
44
|
-
/* eslint-enable class-methods-use-this */
|
|
45
|
-
|
|
46
|
-
// Mock of the client information web storage.
|
|
47
|
-
let mockedClientInformation = null;
|
|
48
|
-
jest.mock("../../commands/getWebStorageEntry", () => jest.fn().mockImplementation(() => ({
|
|
49
|
-
then(cb) {
|
|
50
|
-
cb({
|
|
51
|
-
value: mockedClientInformation
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
})));
|
|
55
|
-
const defaultLibVersion = defaultClientInformation.libVersion;
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* Updates the mocked client information.
|
|
59
|
-
* @param {string} libVersion The libVersion.
|
|
60
|
-
*/
|
|
61
|
-
const setClientInformation = (libVersion = defaultLibVersion) => {
|
|
62
|
-
mockedClientInformation = {
|
|
63
|
-
libVersion
|
|
64
|
-
};
|
|
65
|
-
};
|
|
66
|
-
describe('AppCommand', () => {
|
|
67
|
-
let instance;
|
|
68
|
-
beforeEach(() => {
|
|
69
|
-
setClientInformation();
|
|
70
|
-
mockedLoggerError.mockClear();
|
|
71
|
-
mockedLoggerWarn.mockClear();
|
|
72
|
-
mockedLogGroup.mockClear();
|
|
73
|
-
mockedBridgeDispatch.mockClear();
|
|
74
|
-
instance = new AppCommand(true, true);
|
|
75
|
-
});
|
|
76
|
-
describe('.constructor()', () => {
|
|
77
|
-
it('should construct as expected without parameters', () => {
|
|
78
|
-
instance = new AppCommand();
|
|
79
|
-
expect(instance.log).toBe(true);
|
|
80
|
-
expect(instance.checkLibVersion).toBe(false);
|
|
81
|
-
});
|
|
82
|
-
it('should construct as expected when the SGJavaScriptBridge was detected', () => {
|
|
83
|
-
hasSGJavaScriptBridge.mockReturnValueOnce(true);
|
|
84
|
-
instance = new AppCommand();
|
|
85
|
-
expect(instance.log).toBe(true);
|
|
86
|
-
expect(instance.checkLibVersion).toBe(true);
|
|
87
|
-
});
|
|
88
|
-
it('should construct as expected when log parameter is false', () => {
|
|
89
|
-
instance = new AppCommand(false, true);
|
|
90
|
-
expect(instance.log).toBe(false);
|
|
91
|
-
expect(instance.checkLibVersion).toBe(true);
|
|
92
|
-
});
|
|
93
|
-
});
|
|
94
|
-
describe('.setCommandName()', () => {
|
|
95
|
-
it('should set a valid value', () => {
|
|
96
|
-
const value = 'sendPipelineRequest';
|
|
97
|
-
const command = instance.setCommandName(value);
|
|
98
|
-
expect(command).toEqual(instance);
|
|
99
|
-
expect(command.name).toEqual(value);
|
|
100
|
-
});
|
|
101
|
-
it('should not set an invalid value', () => {
|
|
102
|
-
const initial = instance.name;
|
|
103
|
-
const command = instance.setCommandName(17.3);
|
|
104
|
-
expect(command).toEqual(instance);
|
|
105
|
-
expect(command.name).toEqual(initial);
|
|
106
|
-
expect(mockedLoggerError).toHaveBeenCalledTimes(1);
|
|
107
|
-
});
|
|
108
|
-
});
|
|
109
|
-
describe('.setCommandParams()', () => {
|
|
110
|
-
it('should set a valid value', () => {
|
|
111
|
-
const value = {
|
|
112
|
-
paramOne: 'foo',
|
|
113
|
-
paramTwo: 1337
|
|
114
|
-
};
|
|
115
|
-
const command = instance.setCommandParams(value);
|
|
116
|
-
expect(command).toEqual(instance);
|
|
117
|
-
expect(command.params).toEqual(value);
|
|
118
|
-
});
|
|
119
|
-
it('should not set an invalid value', () => {
|
|
120
|
-
const initial = instance.params;
|
|
121
|
-
const command = instance.setCommandParams('sendPipelineRequest');
|
|
122
|
-
expect(command).toEqual(instance);
|
|
123
|
-
expect(command.params).toEqual(initial);
|
|
124
|
-
expect(mockedLoggerError).toHaveBeenCalledTimes(1);
|
|
125
|
-
});
|
|
126
|
-
});
|
|
127
|
-
describe('.setLibVersion()', () => {
|
|
128
|
-
it('should set a valid value', () => {
|
|
129
|
-
const value = '17.2';
|
|
130
|
-
const command = instance.setLibVersion(value);
|
|
131
|
-
expect(command).toEqual(instance);
|
|
132
|
-
expect(command.libVersion).toEqual(value);
|
|
133
|
-
});
|
|
134
|
-
it('should not set an invalid value', () => {
|
|
135
|
-
const initial = instance.libVersion;
|
|
136
|
-
const command = instance.setLibVersion('sendPipelineRequest');
|
|
137
|
-
expect(command).toEqual(instance);
|
|
138
|
-
expect(command.libVersion).toEqual(initial);
|
|
139
|
-
expect(mockedLoggerError).toHaveBeenCalledTimes(1);
|
|
140
|
-
});
|
|
141
|
-
});
|
|
142
|
-
describe('.logCommand', () => {
|
|
143
|
-
it('should log a command', () => {
|
|
144
|
-
instance.setCommandName('openPage');
|
|
145
|
-
const command = instance.logCommand();
|
|
146
|
-
expect(command).toEqual(instance);
|
|
147
|
-
expect(mockedLogGroup).toHaveBeenCalledTimes(1);
|
|
148
|
-
});
|
|
149
|
-
it('should not log a command when logging is turned off', () => {
|
|
150
|
-
instance = new AppCommand(false);
|
|
151
|
-
instance.setCommandName('openPage');
|
|
152
|
-
const command = instance.logCommand();
|
|
153
|
-
expect(command).toEqual(instance);
|
|
154
|
-
expect(mockedLogGroup).toHaveBeenCalledTimes(0);
|
|
155
|
-
});
|
|
156
|
-
it('should not log a command when it is blacklisted', () => {
|
|
157
|
-
instance.setCommandName('sendPipelineRequest');
|
|
158
|
-
const command = instance.logCommand();
|
|
159
|
-
expect(command).toEqual(instance);
|
|
160
|
-
expect(mockedLogGroup).toHaveBeenCalledTimes(0);
|
|
161
|
-
});
|
|
162
|
-
});
|
|
163
|
-
describe('.buildCommand()', () => {
|
|
164
|
-
it('should build a command when name and params are set', () => {
|
|
165
|
-
const name = 'sendPipelineRequest';
|
|
166
|
-
const params = {
|
|
167
|
-
paramOne: 'foo',
|
|
168
|
-
paramTwo: 1337
|
|
169
|
-
};
|
|
170
|
-
const expected = {
|
|
171
|
-
c: name,
|
|
172
|
-
p: params
|
|
173
|
-
};
|
|
174
|
-
instance.setCommandName(name);
|
|
175
|
-
instance.setCommandParams(params);
|
|
176
|
-
const result = instance.buildCommand();
|
|
177
|
-
expect(result).toEqual(expected);
|
|
178
|
-
});
|
|
179
|
-
it('should build a command when only the name is set', () => {
|
|
180
|
-
const name = 'sendPipelineRequest';
|
|
181
|
-
const expected = {
|
|
182
|
-
c: name
|
|
183
|
-
};
|
|
184
|
-
instance.setCommandName(name);
|
|
185
|
-
const result = instance.buildCommand();
|
|
186
|
-
expect(result).toEqual(expected);
|
|
187
|
-
});
|
|
188
|
-
it('should not build a command when no name is set', () => {
|
|
189
|
-
const params = {
|
|
190
|
-
paramOne: 'foo',
|
|
191
|
-
paramTwo: 1337
|
|
192
|
-
};
|
|
193
|
-
instance.setCommandParams(params);
|
|
194
|
-
const result = instance.buildCommand();
|
|
195
|
-
expect(result).toEqual(null);
|
|
196
|
-
});
|
|
197
|
-
});
|
|
198
|
-
describe('.dispatch()', () => {
|
|
199
|
-
it('should dispatch as expected', async () => {
|
|
200
|
-
const name = 'sendPipelineRequest';
|
|
201
|
-
instance.setCommandName(name);
|
|
202
|
-
const result = await instance.dispatch();
|
|
203
|
-
expect(result).toBe(true);
|
|
204
|
-
expect(mockedBridgeDispatch).toHaveBeenCalledTimes(1);
|
|
205
|
-
expect(mockedBridgeDispatch.mock.calls[0][0][0].c).toBe(name);
|
|
206
|
-
expect(mockedBridgeDispatch.mock.calls[0][1]).toBe(defaultLibVersion);
|
|
207
|
-
expect(mockedLoggerError).toHaveBeenCalledTimes(0);
|
|
208
|
-
expect(mockedLoggerWarn).toHaveBeenCalledTimes(0);
|
|
209
|
-
});
|
|
210
|
-
it('should set the params if passed to dispatch', async () => {
|
|
211
|
-
const params = {
|
|
212
|
-
paramOne: 'foo',
|
|
213
|
-
paramTwo: 1337
|
|
214
|
-
};
|
|
215
|
-
instance.setCommandName('sendPipelineRequest');
|
|
216
|
-
const result = await instance.dispatch(params);
|
|
217
|
-
expect(result).toBe(true);
|
|
218
|
-
expect(mockedBridgeDispatch).toHaveBeenCalledTimes(1);
|
|
219
|
-
expect(mockedBridgeDispatch.mock.calls[0][0][0].p).toEqual(params);
|
|
220
|
-
expect(mockedLoggerError).toHaveBeenCalledTimes(0);
|
|
221
|
-
expect(mockedLoggerWarn).toHaveBeenCalledTimes(0);
|
|
222
|
-
});
|
|
223
|
-
it('should not dispatch when no command was set up', async () => {
|
|
224
|
-
const result = await instance.dispatch();
|
|
225
|
-
expect(result).toBe(false);
|
|
226
|
-
expect(mockedBridgeDispatch).toHaveBeenCalledTimes(0);
|
|
227
|
-
expect(mockedLoggerError).toHaveBeenCalledTimes(1);
|
|
228
|
-
expect(mockedLoggerWarn).toHaveBeenCalledTimes(0);
|
|
229
|
-
});
|
|
230
|
-
it('should not dispatch when the command is not supported by the app', async () => {
|
|
231
|
-
const libVersion = (Number.parseFloat(defaultLibVersion) + 1).toFixed(1);
|
|
232
|
-
instance.setCommandName('sendPipelineRequest');
|
|
233
|
-
instance.setLibVersion(libVersion);
|
|
234
|
-
const result = await instance.dispatch();
|
|
235
|
-
expect(result).toBe(false);
|
|
236
|
-
expect(mockedBridgeDispatch).toHaveBeenCalledTimes(0);
|
|
237
|
-
expect(mockedLoggerError).toHaveBeenCalledTimes(0);
|
|
238
|
-
expect(mockedLoggerWarn).toHaveBeenCalledTimes(1);
|
|
239
|
-
});
|
|
240
|
-
it('should dispatch when the command is not supported by the app but the check is off', async () => {
|
|
241
|
-
const libVersion = (Number.parseFloat(defaultLibVersion) + 1).toFixed(1);
|
|
242
|
-
instance = new AppCommand(true, false);
|
|
243
|
-
instance.setCommandName('sendPipelineRequest');
|
|
244
|
-
instance.setLibVersion(libVersion);
|
|
245
|
-
const result = await instance.dispatch();
|
|
246
|
-
expect(result).toBe(true);
|
|
247
|
-
expect(mockedBridgeDispatch.mock.calls[0][1]).toBe(libVersion);
|
|
248
|
-
expect(mockedBridgeDispatch).toHaveBeenCalledTimes(1);
|
|
249
|
-
expect(mockedLoggerError).toHaveBeenCalledTimes(0);
|
|
250
|
-
expect(mockedLoggerWarn).toHaveBeenCalledTimes(0);
|
|
251
|
-
});
|
|
252
|
-
it('should handle errors during bridge dispatch', async () => {
|
|
253
|
-
mockedBridgeDispatch = jest.fn().mockImplementation(() => {
|
|
254
|
-
throw new Error();
|
|
255
|
-
});
|
|
256
|
-
const name = 'sendPipelineRequest';
|
|
257
|
-
instance.setCommandName(name);
|
|
258
|
-
const result = await instance.dispatch();
|
|
259
|
-
expect(result).toBe(false);
|
|
260
|
-
expect(mockedBridgeDispatch).toHaveBeenCalledTimes(1);
|
|
261
|
-
expect(mockedLoggerError).toHaveBeenCalledTimes(1);
|
|
262
|
-
expect(mockedLoggerWarn).toHaveBeenCalledTimes(0);
|
|
263
|
-
});
|
|
264
|
-
});
|
|
265
|
-
});
|
package/classes/Bridge/spec.js
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { useBrowserConnector, hasSGJavaScriptBridge } from "../../helpers";
|
|
2
|
-
import Bridge from "./index";
|
|
3
|
-
import BrowserConnector from "../BrowserConnector";
|
|
4
|
-
import DevServerBridge from "../DevServerBridge";
|
|
5
|
-
jest.mock("../../helpers", () => ({
|
|
6
|
-
...jest.requireActual("../../helpers"),
|
|
7
|
-
useBrowserConnector: jest.fn(),
|
|
8
|
-
hasSGJavaScriptBridge: jest.fn()
|
|
9
|
-
}));
|
|
10
|
-
describe('Bridge', () => {
|
|
11
|
-
let bridge;
|
|
12
|
-
it('should use the BrowserConnector', () => {
|
|
13
|
-
useBrowserConnector.mockReturnValueOnce(true);
|
|
14
|
-
hasSGJavaScriptBridge.mockReturnValueOnce(false);
|
|
15
|
-
bridge = new Bridge();
|
|
16
|
-
expect(bridge.bridge instanceof BrowserConnector).toBe(true);
|
|
17
|
-
});
|
|
18
|
-
it('should use the DevServerBridge', () => {
|
|
19
|
-
useBrowserConnector.mockReturnValueOnce(false);
|
|
20
|
-
hasSGJavaScriptBridge.mockReturnValueOnce(false);
|
|
21
|
-
bridge = new Bridge();
|
|
22
|
-
expect(bridge.bridge instanceof DevServerBridge).toBe(true);
|
|
23
|
-
});
|
|
24
|
-
});
|
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
/* eslint-disable import/named */
|
|
2
|
-
import { mockedSetCommandName, mockedSetLibVersion, mockedDispatch, triggerDispatchError } from "../AppCommand";
|
|
3
|
-
/* eslint-enable import/named */
|
|
4
|
-
|
|
5
|
-
const mockedAddCallback = jest.fn();
|
|
6
|
-
jest.mock("../Event", () => ({
|
|
7
|
-
addCallback: (...args) => {
|
|
8
|
-
mockedAddCallback.apply(void 0, args);
|
|
9
|
-
}
|
|
10
|
-
}));
|
|
11
|
-
jest.mock("../AppCommand");
|
|
12
|
-
const mockedLoggerError = jest.fn();
|
|
13
|
-
jest.mock("../../helpers", () => ({
|
|
14
|
-
logger: {
|
|
15
|
-
error: (...args) => {
|
|
16
|
-
mockedLoggerError.apply(void 0, args);
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
}));
|
|
20
|
-
describe('BrightnessRequest', () => {
|
|
21
|
-
/* eslint-disable global-require */
|
|
22
|
-
const brightnessRequest = require("./index").default;
|
|
23
|
-
const {
|
|
24
|
-
BrightnessRequest
|
|
25
|
-
} = require("./index");
|
|
26
|
-
/* eslint-enable global-require */
|
|
27
|
-
|
|
28
|
-
beforeEach(() => {
|
|
29
|
-
mockedLoggerError.mockClear();
|
|
30
|
-
mockedAddCallback.mockClear();
|
|
31
|
-
mockedSetCommandName.mockClear();
|
|
32
|
-
mockedSetLibVersion.mockClear();
|
|
33
|
-
mockedDispatch.mockClear();
|
|
34
|
-
|
|
35
|
-
// Reset the queue for each test
|
|
36
|
-
brightnessRequest.responseQueue = [];
|
|
37
|
-
});
|
|
38
|
-
it('should export an already instantiated class', () => {
|
|
39
|
-
expect(brightnessRequest).toBeInstanceOf(BrightnessRequest);
|
|
40
|
-
expect(brightnessRequest.responseQueue).toEqual([]);
|
|
41
|
-
});
|
|
42
|
-
it('should dispatch a command and prepare a handler for response', async () => {
|
|
43
|
-
brightnessRequest.dispatch().then(result => {
|
|
44
|
-
expect(mockedSetCommandName).toHaveBeenCalled();
|
|
45
|
-
expect(mockedSetCommandName).toHaveBeenLastCalledWith('getCurrentBrightness');
|
|
46
|
-
expect(mockedSetLibVersion).toHaveBeenCalledTimes(1);
|
|
47
|
-
expect(mockedSetLibVersion).toHaveBeenLastCalledWith('17.0');
|
|
48
|
-
expect(mockedDispatch).toHaveBeenCalledTimes(1);
|
|
49
|
-
expect(brightnessRequest.responseQueue).toHaveLength(0);
|
|
50
|
-
expect(result).toBe(100);
|
|
51
|
-
});
|
|
52
|
-
await brightnessRequest.handleResponse({
|
|
53
|
-
brightness: 100
|
|
54
|
-
});
|
|
55
|
-
});
|
|
56
|
-
it('should handle two parallel requests as expected', async () => {
|
|
57
|
-
// Prepare two requests
|
|
58
|
-
const requestOne = brightnessRequest.dispatch();
|
|
59
|
-
const requestTwo = brightnessRequest.dispatch();
|
|
60
|
-
|
|
61
|
-
// Check if the queue looks like expected
|
|
62
|
-
expect(brightnessRequest.responseQueue).toHaveLength(2);
|
|
63
|
-
requestOne.then(result => {
|
|
64
|
-
expect(brightnessRequest.responseQueue).toHaveLength(1);
|
|
65
|
-
expect(result).toBe(100);
|
|
66
|
-
});
|
|
67
|
-
requestTwo.then(result => {
|
|
68
|
-
expect(brightnessRequest.responseQueue).toHaveLength(0);
|
|
69
|
-
expect(result).toBe(80);
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
// Simulate incoming of the first event
|
|
73
|
-
await brightnessRequest.handleResponse({
|
|
74
|
-
brightness: 100
|
|
75
|
-
});
|
|
76
|
-
await brightnessRequest.handleResponse({
|
|
77
|
-
brightness: 80
|
|
78
|
-
});
|
|
79
|
-
});
|
|
80
|
-
it('should reject a promise when response is not valid', done => {
|
|
81
|
-
const assertError = new Error('Did not reject');
|
|
82
|
-
brightnessRequest.dispatch().then(() => {
|
|
83
|
-
throw assertError;
|
|
84
|
-
}).catch(e => {
|
|
85
|
-
expect(e).not.toBe(assertError);
|
|
86
|
-
done();
|
|
87
|
-
});
|
|
88
|
-
brightnessRequest.handleResponse({
|
|
89
|
-
brightnessFFOFOF: 100
|
|
90
|
-
});
|
|
91
|
-
});
|
|
92
|
-
it('should reject a promise when the command dispatch failed', async () => {
|
|
93
|
-
// Configure the AppCommand mock to respolve with an error.
|
|
94
|
-
triggerDispatchError();
|
|
95
|
-
try {
|
|
96
|
-
await brightnessRequest.dispatch();
|
|
97
|
-
} catch (e) {
|
|
98
|
-
expect(e).toBeInstanceOf(Error);
|
|
99
|
-
expect(e.message).toContain('getCurrentBrightness');
|
|
100
|
-
expect(brightnessRequest.responseQueue).toHaveLength(0);
|
|
101
|
-
expect(mockedDispatch).toHaveBeenCalledTimes(1);
|
|
102
|
-
}
|
|
103
|
-
});
|
|
104
|
-
it('should handle incoming events which did not have a dispatch', () => {
|
|
105
|
-
const result = brightnessRequest.handleResponse({
|
|
106
|
-
brightness: 100
|
|
107
|
-
});
|
|
108
|
-
expect(result).toBe(undefined);
|
|
109
|
-
expect(mockedLoggerError).toHaveBeenCalledTimes(1);
|
|
110
|
-
});
|
|
111
|
-
});
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import Conditioner from "./index";
|
|
2
|
-
import { logger } from "../../helpers";
|
|
3
|
-
jest.mock("../../helpers", () => ({
|
|
4
|
-
logger: {
|
|
5
|
-
warn: jest.fn()
|
|
6
|
-
}
|
|
7
|
-
}));
|
|
8
|
-
describe('Conditioner', () => {
|
|
9
|
-
let conditioner;
|
|
10
|
-
let cond1;
|
|
11
|
-
let cond2;
|
|
12
|
-
let cond3;
|
|
13
|
-
beforeEach(() => {
|
|
14
|
-
jest.clearAllMocks();
|
|
15
|
-
conditioner = new Conditioner();
|
|
16
|
-
cond1 = jest.fn().mockReturnValue(true);
|
|
17
|
-
cond2 = jest.fn().mockReturnValue(true);
|
|
18
|
-
cond3 = jest.fn().mockReturnValue(true);
|
|
19
|
-
});
|
|
20
|
-
it('should fail on first sorted condition', async () => {
|
|
21
|
-
cond3.mockReturnValue(false);
|
|
22
|
-
conditioner.addConditioner(1, cond1);
|
|
23
|
-
conditioner.addConditioner(2, cond2, -1);
|
|
24
|
-
conditioner.addConditioner(3, cond3, -2);
|
|
25
|
-
expect(await conditioner.check()).toBeFalsy();
|
|
26
|
-
expect(cond3).toBeCalledTimes(1);
|
|
27
|
-
expect(cond1).toBeCalledTimes(0);
|
|
28
|
-
expect(cond2).toBeCalledTimes(0);
|
|
29
|
-
expect(logger.warn).toBeCalledTimes(1);
|
|
30
|
-
});
|
|
31
|
-
it('should fail on first promisified sorted condition', async () => {
|
|
32
|
-
expect.assertions(5);
|
|
33
|
-
cond3.mockResolvedValue(false);
|
|
34
|
-
conditioner.addConditioner(1, cond1);
|
|
35
|
-
conditioner.addConditioner(2, cond2, -1);
|
|
36
|
-
conditioner.addConditioner(2, cond3, -2);
|
|
37
|
-
expect(await conditioner.check()).toBeFalsy();
|
|
38
|
-
expect(cond3).toBeCalledTimes(1);
|
|
39
|
-
expect(cond1).toBeCalledTimes(0);
|
|
40
|
-
expect(cond2).toBeCalledTimes(0);
|
|
41
|
-
expect(logger.warn).toBeCalledTimes(1);
|
|
42
|
-
});
|
|
43
|
-
it('should fail on second promisified sorted condition', async () => {
|
|
44
|
-
expect.assertions(5);
|
|
45
|
-
cond3.mockResolvedValue(false);
|
|
46
|
-
conditioner.addConditioner(1, cond1);
|
|
47
|
-
conditioner.addConditioner(2, cond2, -10);
|
|
48
|
-
conditioner.addConditioner(2, cond3, -2);
|
|
49
|
-
expect(await conditioner.check()).toBeFalsy();
|
|
50
|
-
expect(cond3).toBeCalledTimes(1);
|
|
51
|
-
expect(cond1).toBeCalledTimes(0);
|
|
52
|
-
expect(cond2).toBeCalledTimes(0);
|
|
53
|
-
expect(logger.warn).toBeCalledTimes(1);
|
|
54
|
-
});
|
|
55
|
-
it('should resolve true', async () => {
|
|
56
|
-
conditioner.addConditioner(1, cond1);
|
|
57
|
-
conditioner.addConditioner(2, cond2);
|
|
58
|
-
conditioner.addConditioner(3, cond3);
|
|
59
|
-
expect(await conditioner.check()).toBeTruthy();
|
|
60
|
-
expect(cond1).toBeCalledTimes(1);
|
|
61
|
-
expect(cond2).toBeCalledTimes(1);
|
|
62
|
-
expect(cond3).toBeCalledTimes(1);
|
|
63
|
-
expect(logger.warn).toBeCalledTimes(0);
|
|
64
|
-
});
|
|
65
|
-
it('should return cloned conditioner', async () => {
|
|
66
|
-
conditioner.addConditioner('one', cond1);
|
|
67
|
-
conditioner.addConditioner('two', cond2);
|
|
68
|
-
const newConditioner = conditioner.without('one');
|
|
69
|
-
expect(newConditioner).not.toBe(conditioner);
|
|
70
|
-
expect(newConditioner.conditions).not.toBe(conditioner.conditions);
|
|
71
|
-
expect(newConditioner.conditions.has('one')).toBeFalsy();
|
|
72
|
-
expect(newConditioner.conditions.has('two')).toBeTruthy();
|
|
73
|
-
expect(logger.warn).toBeCalledTimes(0);
|
|
74
|
-
});
|
|
75
|
-
});
|