@queue-it/fastly 3.6.0 → 4.4.3-beta.0

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 (39) hide show
  1. package/README.md +156 -58
  2. package/package.json +23 -16
  3. package/src/contextProvider.ts +175 -0
  4. package/src/fastlyCryptoProvider.ts +8 -0
  5. package/src/helper.ts +11 -0
  6. package/{assembly/sdk → src}/helpers/crypto.ts +338 -340
  7. package/src/index.ts +3 -0
  8. package/src/integrationConfigProvider.ts +199 -0
  9. package/src/requestResponseHandler.ts +200 -0
  10. package/README-INTERNAL.md +0 -21
  11. package/asconfig.json +0 -17
  12. package/assembly/__tests__/CustomerIntegrationDecodingHandler.spec.ts +0 -1086
  13. package/assembly/__tests__/IntegrationConfigHelpersTest.spec.ts +0 -574
  14. package/assembly/__tests__/KnownUserTest.spec.ts +0 -1894
  15. package/assembly/__tests__/Mocks.ts +0 -321
  16. package/assembly/__tests__/QueueParameterHelper.spec.ts +0 -59
  17. package/assembly/__tests__/UserInQueueService.spec.ts +0 -418
  18. package/assembly/__tests__/UserInQueueStateCookieRepository.spec.ts +0 -337
  19. package/assembly/__tests__/as-pect.config.js +0 -57
  20. package/assembly/__tests__/as-pect.d.ts +0 -1
  21. package/assembly/contextProvider.ts +0 -123
  22. package/assembly/helper.ts +0 -23
  23. package/assembly/index.ts +0 -10
  24. package/assembly/integrationConfigProvider.ts +0 -32
  25. package/assembly/requestResponseHandler.ts +0 -92
  26. package/assembly/sdk/HttpContextProvider.ts +0 -24
  27. package/assembly/sdk/IntegrationConfig/CustomerIntegrationDecodingHandler.ts +0 -198
  28. package/assembly/sdk/IntegrationConfig/IntegrationConfigHelpers.ts +0 -232
  29. package/assembly/sdk/IntegrationConfig/IntegrationConfigModel.ts +0 -93
  30. package/assembly/sdk/KnownUser.ts +0 -396
  31. package/assembly/sdk/Models.ts +0 -105
  32. package/assembly/sdk/QueueITHelpers.ts +0 -263
  33. package/assembly/sdk/UserInQueueService.ts +0 -245
  34. package/assembly/sdk/UserInQueueStateCookieRepository.ts +0 -189
  35. package/assembly/sdk/helpers/Date.ts +0 -194
  36. package/assembly/sdk/helpers/Uri.ts +0 -308
  37. package/assembly/tsconfig.json +0 -6
  38. package/index.js +0 -5
  39. package/pipelines/ci.yaml +0 -28
@@ -1,418 +0,0 @@
1
- //@ts-ignore
2
- import {RegExp} from 'assemblyscript-regex'
3
-
4
- import {Utils} from "../sdk/QueueITHelpers";
5
- import {UserInQueueService} from "../sdk/UserInQueueService";
6
- import {StateInfo} from "../sdk/UserInQueueStateCookieRepository";
7
- import {CancelEventConfig, QueueEventConfig} from "../sdk/Models";
8
- import {UserInQueueStateCookieRepositoryMock} from "./Mocks";
9
- import {hashString, hmacString} from '../sdk/helpers/crypto'
10
-
11
- const SDK_VERSION = UserInQueueService.SDK_VERSION;
12
-
13
-
14
- function generateHash(eventId: string,
15
- queueId: string,
16
- timestamp: i64,
17
- extendableCookie: string,
18
- cookieValidityMinutes: i64,
19
- redirectType: string,
20
- secretKey: string): string {
21
- let token = 'e_' + eventId + '~ts_' + timestamp.toString() + '~ce_' + extendableCookie + '~q_' + queueId;
22
- if (cookieValidityMinutes != 0)
23
- token = token + '~cv_' + cookieValidityMinutes.toString();
24
- if (redirectType != null)
25
- token = token + '~rt_' + redirectType;
26
- return token + '~h_' + Utils.generateSHA256Hash(secretKey, token);
27
- }
28
-
29
- const userInQueueStateCookieRepositoryMock = new UserInQueueStateCookieRepositoryMock();
30
- const userInQueueService = new UserInQueueService(userInQueueStateCookieRepositoryMock);
31
- Utils.generateSHA256Hash = hmacString;
32
-
33
- function newConfig(): QueueEventConfig {
34
- return new QueueEventConfig("", "", "", "", false, 0, "", 13);
35
- }
36
-
37
- describe('Crypto', () => {
38
- it('should use hmac-sha256', () => {
39
- let hash = hmacString('4e1db821-a825-49da-acd0-5d376f2068db', 'e_e1~ts_1620389879~ce_True~q_queueId~rt_idle');
40
- let hash2 = hmacString('4e1db821-a825-49da-acd0-5d376f2068db', 'e_e1~ts_1620389879~ce_True~q_queueId~rt_idle');
41
- expect(hash).toBe("c76001c94ec53a3d46c0c9b5939914d1f0f834cdf14acdc224450a0fe9810fe6");
42
- expect(hash2).toBe("c76001c94ec53a3d46c0c9b5939914d1f0f834cdf14acdc224450a0fe9810fe6");
43
- })
44
-
45
- it('should use sha256', () => {
46
- let r = hashString('asdasdasd');
47
- expect(r).toBe('d8a928b2043db77e340b523547bf16cb4aa483f0645fe0a290ed1f20aab76257');
48
- })
49
- });
50
-
51
- describe("UserInQueueService.validateQueueRequest", () => {
52
-
53
- it('ValidState_ExtendableCookie_NoCookieExtensionFromConfig_DoNotRedirectDoNotStoreCookieWithExtension', () => {
54
- userInQueueStateCookieRepositoryMock.reset();
55
- userInQueueStateCookieRepositoryMock.returnThisState = new StateInfo(true, true, "queueId", 0, "idle");
56
-
57
- const eventConfig = new QueueEventConfig("", "", "", "", false, 0, "", 13, "");
58
- eventConfig.eventId = "e1";
59
- eventConfig.queueDomain = "testDomain";
60
- eventConfig.cookieDomain = "testDomain";
61
- eventConfig.cookieValidityMinute = 10;
62
- eventConfig.extendCookieValidity = false;
63
-
64
- const result = userInQueueService.validateQueueRequest("url", "token", eventConfig, "customerid", "key");
65
- expect(result.first!.doRedirect()).toBeFalsy();
66
- expect(result.first!.queueId).toBe('queueId');
67
-
68
- expect(userInQueueStateCookieRepositoryMock.storeCall.keys().length).toBe(0);
69
- expect(userInQueueStateCookieRepositoryMock.getStateCall.get("eventId")).toBe("e1");
70
- expect(userInQueueStateCookieRepositoryMock.getStateCall.get("cookieValidityMinutes")).toBe("10");
71
- expect(userInQueueStateCookieRepositoryMock.getStateCall.get("secretKey")).toBe("key");
72
- expect(userInQueueStateCookieRepositoryMock.getStateCall.get("validateTime")).toBe("true");
73
- });
74
-
75
- it('ValidState_ExtendableCookie_CookieExtensionFromConfig_DoNotRedirectDoStoreCookieWithExtension', () => {
76
- userInQueueStateCookieRepositoryMock.reset();
77
- userInQueueStateCookieRepositoryMock.returnThisState = new StateInfo(true, true, "queueId", 0, "disabled");
78
-
79
- const eventConfig = newConfig();
80
- eventConfig.eventId = "e1";
81
- eventConfig.queueDomain = "testDomain.com";
82
- eventConfig.cookieDomain = "testDomain";
83
- eventConfig.cookieValidityMinute = 10;
84
- eventConfig.extendCookieValidity = true;
85
-
86
- const result = userInQueueService.validateQueueRequest("url", "token", eventConfig, "customerid", "key");
87
-
88
- expect(result.first!.doRedirect()).toBeFalsy();
89
- expect(result.first!.eventId).toBe('e1');
90
- expect(result.first!.queueId).toBe("queueId");
91
-
92
- expect(userInQueueStateCookieRepositoryMock.storeCall.get("eventId")).toBe("e1");
93
- expect(userInQueueStateCookieRepositoryMock.storeCall.get("queueId")).toBe("queueId");
94
- expect(userInQueueStateCookieRepositoryMock.storeCall.get("fixedCookieValidityMinutes")).toBe("0");
95
- expect(userInQueueStateCookieRepositoryMock.storeCall.get("cookieDomain")).toBe("testDomain");
96
- expect(userInQueueStateCookieRepositoryMock.storeCall.get("redirectType")).toBe("disabled");
97
- expect(userInQueueStateCookieRepositoryMock.storeCall.get("secretKey")).toBe("key");
98
- });
99
-
100
- it('ValidState_NoExtendableCookie_DoNotRedirectDoNotStoreCookieWithExtension', () => {
101
- userInQueueStateCookieRepositoryMock.reset();
102
- userInQueueStateCookieRepositoryMock.returnThisState = new StateInfo(true, true, "queueId", 3, "idle");
103
-
104
- const eventConfig = newConfig();
105
- eventConfig.eventId = "e1";
106
- eventConfig.queueDomain = "testDomain";
107
- eventConfig.cookieValidityMinute = 10;
108
- eventConfig.extendCookieValidity = true;
109
-
110
- const result = userInQueueService.validateQueueRequest("url", "token", eventConfig, "customerid", "key");
111
-
112
- expect(result.first!.doRedirect()).toBeFalsy();
113
- expect(result.first!.eventId).toBe('e1');
114
- expect(result.first!.queueId).toBe("queueId");
115
- expect(userInQueueStateCookieRepositoryMock.storeCall.keys().length).toBe(0);
116
- });
117
-
118
- it('NoCookie_TampredToken_RedirectToErrorPageWithHashError_DoNotStoreCookie', () => {
119
- userInQueueStateCookieRepositoryMock.reset();
120
- userInQueueStateCookieRepositoryMock.returnThisState = new StateInfo(false, false, "", 0, "");
121
-
122
- const key = "4e1db821-a825-49da-acd0-5d376f2068db";
123
- const eventConfig = newConfig();
124
- eventConfig.eventId = "e1";
125
- eventConfig.queueDomain = "testDomain.com";
126
- eventConfig.cookieValidityMinute = 10;
127
- eventConfig.extendCookieValidity = true;
128
- eventConfig.version = 11;
129
- eventConfig.actionName = "Queue Action (._~-) &!*|'\"";
130
- const url = "http://test.test.com?b=h";
131
-
132
- let token = generateHash('e1', 'queueId', Utils.getCurrentTime() + 3 * 60, 'False', 0, 'idle', key);
133
- token = token.replace("False", "True");
134
-
135
- const expectedErrorUrl = "https://testDomain.com/error/hash/?c=testCustomer&e=e1" +
136
- "&ver=" + SDK_VERSION
137
- + "&cver=11"
138
- + "&man=Queue%20Action%20%28._~-%29%20%26%21%2a%7C%27%22"
139
- + "&queueittoken=" + token
140
- + "&t=" + Utils.encodeUrl(url);
141
-
142
- const result = userInQueueService.validateQueueRequest(url, token, eventConfig, "testCustomer", key);
143
- const tsPartRx = new RegExp('&ts=[^&]*', 'g')
144
- expect(userInQueueStateCookieRepositoryMock.storeCall.keys().length).toBe(0);
145
- expect(result.first!.doRedirect()).toBeTruthy();
146
- expect(result.first!.eventId).toBe('e1');
147
-
148
- const tsMatch = tsPartRx.exec(result.first!.redirectUrl);
149
- expect(tsMatch).not.toBeNull()
150
-
151
- const tsPart = tsMatch!.matches[0];
152
- const timestamp = I64.parseInt(tsPart.replace("&ts=", ""));
153
- const urlWithoutTimeStamp = result.first!.redirectUrl.replace(tsPart, "");
154
- expect(Utils.getCurrentTime() - timestamp < 100 as bool).toBe(true);
155
- expect(urlWithoutTimeStamp).toBe(expectedErrorUrl, 'redirect url should be an error url');
156
- });
157
-
158
- it('NoCookie_ValidToken_ExtendableCookie_DoNotRedirect_StoreExtendableCookie', () => {
159
- userInQueueStateCookieRepositoryMock.reset();
160
- userInQueueStateCookieRepositoryMock.returnThisState = new StateInfo(false, false, '', 0, '');
161
-
162
- const key = "4e1db821-a825-49da-acd0-5d376f2068db";
163
- const eventConfig = newConfig();
164
- eventConfig.eventId = "e1";
165
- eventConfig.queueDomain = "testDomain.com";
166
- eventConfig.cookieValidityMinute = 10;
167
- eventConfig.cookieDomain = "testDomain";
168
- eventConfig.extendCookieValidity = true;
169
- eventConfig.version = 11;
170
- const url = "http://test.test.com?b=h";
171
-
172
- const token = generateHash('e1', 'queueId', Utils.getCurrentTime() + 3 * 60, 'true', 0, 'queue', key);
173
-
174
- const result = userInQueueService.validateQueueRequest(url, token, eventConfig, "testCustomer", key);
175
-
176
- expect(result.first!.doRedirect()).toBeFalsy('should redirect');
177
- expect(result.first!.eventId).toBe('e1');
178
- expect(result.first!.queueId).toBe('queueId');
179
- expect(result.first!.redirectType).toBe('queue');
180
-
181
- expect(userInQueueStateCookieRepositoryMock.storeCall.get('eventId')).toBe('e1');
182
- expect(userInQueueStateCookieRepositoryMock.storeCall.get('queueId')).toBe('queueId');
183
- expect(userInQueueStateCookieRepositoryMock.storeCall.get('fixedCookieValidityMinutes')).toBe('0');
184
- expect(userInQueueStateCookieRepositoryMock.storeCall.get('cookieDomain')).toBe('testDomain');
185
- expect(userInQueueStateCookieRepositoryMock.storeCall.get('redirectType')).toBe('queue');
186
- expect(userInQueueStateCookieRepositoryMock.storeCall.get('secretKey')).toBe(key);
187
- expect(userInQueueStateCookieRepositoryMock.cancelQueueCookieCall.keys().length).toBe(0);
188
- });
189
-
190
- it('NoCookie_ValidToken_CookieValidityMinuteFromToken_DoNotRedirect_StoreNonExtendableCookie', () => {
191
- userInQueueStateCookieRepositoryMock.reset();
192
- userInQueueStateCookieRepositoryMock.returnThisState = new StateInfo(false, false, '', 0, '');
193
-
194
- const key = "4e1db821-a825-49da-acd0-5d376f2068db";
195
- const eventConfig = newConfig();
196
- eventConfig.eventId = "e1";
197
- eventConfig.queueDomain = "testDomain.com";
198
- eventConfig.cookieValidityMinute = 30;
199
- eventConfig.cookieDomain = "testDomain";
200
- eventConfig.extendCookieValidity = true;
201
- const url = "http://test.test.com?b=h";
202
-
203
- const token = generateHash('e1', 'queueId', Utils.getCurrentTime() + 3 * 60, 'false', 3, 'DirectLink', key);
204
- const result = userInQueueService.validateQueueRequest(url, token, eventConfig, "testCustomer", key);
205
-
206
- expect(result.first!.doRedirect()).toBeFalsy('should not redirect');
207
- expect(result.first!.eventId).toBe('e1');
208
- expect(result.first!.queueId).toBe('queueId');
209
- expect(result.first!.redirectType).toBe('DirectLink');
210
-
211
- expect(userInQueueStateCookieRepositoryMock.storeCall.get('eventId')).toBe('e1');
212
- expect(userInQueueStateCookieRepositoryMock.storeCall.get('queueId')).toBe('queueId');
213
- expect(userInQueueStateCookieRepositoryMock.storeCall.get('fixedCookieValidityMinutes')).toBe('3');
214
- expect(userInQueueStateCookieRepositoryMock.storeCall.get('cookieDomain')).toBe('testDomain');
215
- expect(userInQueueStateCookieRepositoryMock.storeCall.get('redirectType')).toBe('DirectLink');
216
- expect(userInQueueStateCookieRepositoryMock.storeCall.get('secretKey')).toBe(key);
217
- expect(userInQueueStateCookieRepositoryMock.cancelQueueCookieCall.keys().length).toBe(0);
218
- });
219
-
220
- it('NoCookie_NoValidToken_WithoutToken_RedirectToQueue', () => {
221
- userInQueueStateCookieRepositoryMock.reset();
222
- userInQueueStateCookieRepositoryMock.returnThisState = new StateInfo(false, false, '', 0, '');
223
-
224
- const key = "4e1db821-a825-49da-acd0-5d376f2068db";
225
- const eventConfig = newConfig();
226
- eventConfig.eventId = "e1";
227
- eventConfig.queueDomain = "testDomain.com";
228
- eventConfig.cookieValidityMinute = 10;
229
- eventConfig.extendCookieValidity = true;
230
- eventConfig.version = 11;
231
- eventConfig.culture = 'en-US';
232
- eventConfig.layoutName = 'testlayout';
233
-
234
- const url = "http://test.test.com?b=h";
235
- const token = '';
236
-
237
- const expectedRedirectUrl = 'https://testDomain.com/?c=testCustomer&e=e1' +
238
- "&ver=" + SDK_VERSION
239
- + "&cver=11"
240
- + "&man=unspecified"
241
- + "&cid=en-US"
242
- + "&l=testlayout"
243
- + "&t=" + Utils.encodeUrl(url);
244
-
245
- const result = userInQueueService.validateQueueRequest(url, token, eventConfig, "testCustomer", key);
246
-
247
- expect(userInQueueStateCookieRepositoryMock.storeCall.keys().length).toBe(0, 'store should not be called');
248
- expect(result.first!.doRedirect()).toBeTruthy('should redirect');
249
- expect(result.first!.eventId).toBe('e1', 'with WR ID');
250
- expect(result.first!.queueId).toBe('', 'queue id should not be used');
251
- expect(result.first!.redirectUrl).toBe(expectedRedirectUrl, 'should redirect to queue');
252
- });
253
-
254
- it('InValidCookie_WithoutToken_RedirectToQueue_CancelCookie', () => {
255
- userInQueueStateCookieRepositoryMock.reset();
256
- userInQueueStateCookieRepositoryMock.returnThisState = new StateInfo(true, false, '', 0, '');
257
-
258
- const key = "4e1db821-a825-49da-acd0-5d376f2068db";
259
- const eventConfig = newConfig();
260
- eventConfig.eventId = "e1";
261
- eventConfig.queueDomain = "testDomain.com";
262
- eventConfig.cookieValidityMinute = 10;
263
- eventConfig.extendCookieValidity = true;
264
- eventConfig.version = 11;
265
- eventConfig.culture = 'en-US';
266
- eventConfig.layoutName = 'testlayout';
267
-
268
- const url = "http://test.test.com?b=h";
269
- const token = "";
270
-
271
- const expectedRedirectUrl = "https://testDomain.com/?c=testCustomer&e=e1" +
272
- "&ver=" + SDK_VERSION
273
- + "&cver=11"
274
- + "&man=unspecified"
275
- + "&cid=en-US"
276
- + "&l=testlayout"
277
- + "&t=" + Utils.encodeUrl(url);
278
-
279
- const result = userInQueueService.validateQueueRequest(url, token, eventConfig, "testCustomer", key);
280
-
281
- expect(userInQueueStateCookieRepositoryMock.storeCall.keys().length).toBe(0);
282
- expect(result.first!.doRedirect()).toBeTruthy();
283
- expect(result.first!.eventId).toBe('e1');
284
- expect(result.first!.queueId).toBe('');
285
- expect(result.first!.redirectUrl).toBe(expectedRedirectUrl);
286
- expect(userInQueueStateCookieRepositoryMock.cancelQueueCookieCall).toBeTruthy();
287
- });
288
-
289
- it('NoCookie_WithoutToken_RedirectToQueue_NotargetUrl', () => {
290
- userInQueueStateCookieRepositoryMock.reset();
291
- userInQueueStateCookieRepositoryMock.returnThisState = new StateInfo(false, false, '', 0, '');
292
-
293
- const key = "4e1db821-a825-49da-acd0-5d376f2068db";
294
- const eventConfig = newConfig();
295
- eventConfig.eventId = "e1";
296
- eventConfig.queueDomain = "testDomain.com";
297
- eventConfig.cookieValidityMinute = 10;
298
- eventConfig.extendCookieValidity = false;
299
- eventConfig.version = 11;
300
- eventConfig.culture = '';
301
- eventConfig.layoutName = 'testlayout';
302
- const url = "http://test.test.com?b=h";
303
- const token = "";
304
-
305
- const expectedRedirectUrl = "https://testDomain.com/?c=testCustomer&e=e1" +
306
- "&ver=" + SDK_VERSION
307
- + "&cver=" + eventConfig.version.toString()
308
- + "&man=" + 'unspecified'
309
- + "&l=" + eventConfig.layoutName;
310
-
311
- const result = userInQueueService.validateQueueRequest('', token, eventConfig, "testCustomer", key);
312
-
313
- expect(userInQueueStateCookieRepositoryMock.storeCall.keys().length).toBe(0);
314
- expect(result.first!.doRedirect()).toBeTruthy();
315
- expect(result.first!.eventId).toBe('e1');
316
- expect(result.first!.queueId).toBe('');
317
- expect(result.first!.redirectUrl).toBe(expectedRedirectUrl);
318
- });
319
-
320
- it('NoCookie_InValidToken', () => {
321
- userInQueueStateCookieRepositoryMock.reset();
322
- userInQueueStateCookieRepositoryMock.returnThisState = new StateInfo(false, false, '', 0, '');
323
-
324
- const key = "4e1db821-a825-49da-acd0-5d376f2068db";
325
- const eventConfig = newConfig();
326
- eventConfig.eventId = "e1";
327
- eventConfig.queueDomain = "testDomain.com";
328
- eventConfig.cookieValidityMinute = 10;
329
- eventConfig.extendCookieValidity = true;
330
- eventConfig.version = 11;
331
- eventConfig.culture = 'en-US';
332
- eventConfig.layoutName = 'testlayout';
333
- const url = "http://test.test.com?b=h";
334
-
335
- const result = userInQueueService.validateQueueRequest(url, "ts_sasa~cv_adsasa~ce_falwwwse~q_944c1f44-60dd-4e37-aabc-f3e4bb1c8895", eventConfig, "testCustomer", key);
336
-
337
- expect(userInQueueStateCookieRepositoryMock.storeCall.keys().length).toBe(0);
338
- expect(result.first!.doRedirect()).toBeTruthy('should redirect');
339
- expect(result.first!.eventId).toBe('e1');
340
- expect(result.first!.queueId).toBe('');
341
- expect(result.first!.redirectUrl.indexOf("https://testDomain.com/error/hash/?c=testCustomer&e=e1")).toBe(0);
342
-
343
- expect(userInQueueStateCookieRepositoryMock.cancelQueueCookieCall.keys().length).toBe(0);
344
- });
345
-
346
- it('InvalidCookie_InValidToken_CancelCookie', () => {
347
- userInQueueStateCookieRepositoryMock.reset();
348
- userInQueueStateCookieRepositoryMock.returnThisState = new StateInfo(true, false, '', 0, '');
349
-
350
- const key = "4e1db821-a825-49da-acd0-5d376f2068db";
351
- const eventConfig = newConfig();
352
- eventConfig.eventId = 'e1';
353
- eventConfig.queueDomain = "testDomain.com";
354
- eventConfig.cookieValidityMinute = 10;
355
- eventConfig.extendCookieValidity = true;
356
- eventConfig.version = 11;
357
- eventConfig.culture = 'en-US';
358
- eventConfig.layoutName = 'testlayout';
359
-
360
- const url = "http://test.test.com?b=h";
361
-
362
- const resultPair = userInQueueService.validateQueueRequest(url, "ts_sasa~cv_adsasa~ce_falwwwse~q_944c1f44-60dd-4e37-aabc-f3e4bb1c8895", eventConfig, "testCustomer", key);
363
- const result = resultPair.first;
364
-
365
- expect(userInQueueStateCookieRepositoryMock.storeCall.keys().length).toBe(0, 'store should not be called');
366
- expect(result!.doRedirect()).toBeTruthy('should redirect');
367
- expect(result!.eventId).toBe('e1');
368
- expect(result!.queueId).toBe('');
369
- expect(result!.redirectUrl.indexOf("https://testDomain.com/error/hash/?c=testCustomer&e=e1")).toBe(0);
370
-
371
- expect(userInQueueStateCookieRepositoryMock.cancelQueueCookieCall.keys().length > 0).toBeTruthy('cancelQueueCookie should be called');
372
- });
373
-
374
- it('validateCancelRequest', () => {
375
- userInQueueStateCookieRepositoryMock.reset();
376
- userInQueueStateCookieRepositoryMock.returnThisState = new StateInfo(true, true, "queueid", 3, "idle");
377
-
378
- const key = "4e1db821-a825-49da-acd0-5d376f2068db";
379
- const eventConfig = new CancelEventConfig('', '', '', 0);
380
- eventConfig.eventId = "e1";
381
- eventConfig.queueDomain = "testDomain.com";
382
- eventConfig.cookieDomain = "testdomain";
383
- eventConfig.version = 10;
384
- eventConfig.actionName = "Cancel";
385
-
386
- const url = "http://test.test.com?b=h";
387
- let expectedUrl = "https://testDomain.com/cancel/testCustomer/e1/?c=testCustomer&e=e1"
388
- + "&ver=" + SDK_VERSION
389
- + "&cver=" + eventConfig.version.toString()
390
- + "&man=" + eventConfig.actionName
391
- + "&r=" + "http%3A%2F%2Ftest.test.com%3Fb%3Dh";
392
-
393
- const result = userInQueueService.validateCancelRequest(url, eventConfig, "testCustomer", key);
394
-
395
- expect(userInQueueStateCookieRepositoryMock.cancelQueueCookieCall.keys().length).not.toBe(0, 'cancelQueueCookie should be called');
396
- expect(userInQueueStateCookieRepositoryMock.storeCall.keys().length).toBe(0, 'store shouldn`t be called');
397
- expect(result.first!.redirectUrl).toBe(expectedUrl, 'Url should be cancel url');
398
- expect(result.first!.doRedirect()).toBeTruthy('should redirect');
399
- expect(result.first!.eventId).toBe('e1', 'WR ID should match');
400
- expect(result.first!.queueId).toBe('queueid', 'QueueId should match');
401
- expect(result.first!.actionName).toBe('Cancel', 'Action name should be Cancel');
402
- });
403
-
404
- });
405
-
406
- describe('getIgnoreResult', () => {
407
- it('should not redirect with empty request', () => {
408
- userInQueueStateCookieRepositoryMock.reset();
409
-
410
- const result = userInQueueService.getIgnoreResult("");
411
-
412
- expect(result.doRedirect()).toBeFalsy();
413
- expect(result.eventId).toBe("");
414
- expect(result.queueId).toBe("");
415
- expect(result.redirectUrl).toBe("");
416
- expect(result.actionType).toBe("Ignore");
417
- });
418
- });