-
Notifications
You must be signed in to change notification settings - Fork 50
Expand file tree
/
Copy pathping-protect.test.ts
More file actions
122 lines (102 loc) · 4.41 KB
/
ping-protect.test.ts
File metadata and controls
122 lines (102 loc) · 4.41 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/**
*
* Copyright (c) 2024 - 2026 Ping Identity Corporation. All right reserved.
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
*
**/
import { vi, expect, describe, it } from 'vitest';
import { PIProtect } from './ping-protect.js';
import {
noProtectType,
standardPingProtectEvaluationStep,
standardPingProtectInitializeStep,
} from './ping-protect.mock.data.js';
import { CallbackType, HiddenValueCallback } from '@forgerock/javascript-sdk';
describe('PIProtect', () => {
it('should be defined', () => {
expect(PIProtect).toBeDefined();
expect(PIProtect.start).toBeDefined();
expect(PIProtect.getData).toBeDefined();
expect(PIProtect.pauseBehavioralData).toBeDefined();
expect(PIProtect.resumeBehavioralData).toBeDefined();
});
it('should call start', async () => {
const protectMock = vi.spyOn(PIProtect, 'start');
const config = {
envId: '12345',
consoleLogEnabled: true,
deviceAttributesToIgnore: ['userAgent'],
customHost: 'https://example.com',
lazyMetadata: false,
behavioralDataCollection: true,
deviceKeyRsyncIntervals: 14,
enableTrust: false,
disableTags: false,
disableHub: false,
};
await PIProtect.start(config);
expect(protectMock).toHaveBeenCalledWith(config);
});
it('should resume behavioralData when behavioralDataCollection is string true', async () => {
await PIProtect.start({ envId: '12345', behavioralDataCollection: false });
const resumeSpy = vi.spyOn(window._pingOneSignals, 'resumeBehavioralData');
await PIProtect.start({ envId: '12345', behavioralDataCollection: 'true' });
expect(resumeSpy).toHaveBeenCalledTimes(1);
});
it('should not resume behavioralData when behavioralDataCollection is string false', async () => {
await PIProtect.start({ envId: '12345', behavioralDataCollection: false });
const resumeSpy = vi.spyOn(window._pingOneSignals, 'resumeBehavioralData');
await PIProtect.start({ envId: '12345', behavioralDataCollection: 'false' });
expect(resumeSpy).not.toHaveBeenCalled();
});
it('should call pause behavioralData', () => {
const protectMock = vi.spyOn(PIProtect, 'pauseBehavioralData');
PIProtect.pauseBehavioralData();
expect(protectMock).toHaveBeenCalled();
});
it('should call resume behavioralData', () => {
const protectMock = vi.spyOn(PIProtect, 'resumeBehavioralData');
PIProtect.resumeBehavioralData();
expect(protectMock).toHaveBeenCalled();
});
describe('should test the marketplace node setup', () => {
it('should test getPauseBehavioralData with marketplace data', () => {
const result = PIProtect.getPauseBehavioralData(standardPingProtectEvaluationStep);
expect(result).toEqual(false);
const secondResult = PIProtect.getPauseBehavioralData(standardPingProtectInitializeStep);
expect(secondResult).toEqual(true);
});
it('should test the getPingProtectType method', () => {
const result = PIProtect.getPingProtectType(standardPingProtectInitializeStep);
expect(result).toEqual('initialize');
const result2 = PIProtect.getPingProtectType(standardPingProtectEvaluationStep);
expect(result2).toEqual('evaluate');
const result3 = PIProtect.getPingProtectType(noProtectType);
expect(result3).toEqual('none');
});
it('should setNodeInputValue', () => {
const step = standardPingProtectEvaluationStep;
PIProtect.setNodeInputValue(step, 'the value');
const [hc] = step.getCallbacksOfType<HiddenValueCallback>(CallbackType.HiddenValueCallback);
expect(hc.getInputValue()).toEqual('the value');
});
});
it('should get the node config', () => {
const result = PIProtect.getNodeConfig(standardPingProtectInitializeStep);
expect(result).toEqual(
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
standardPingProtectInitializeStep!.payload.callbacks![0].output[0].value,
);
const result2 = PIProtect.getNodeConfig(noProtectType);
expect(result2).toBeUndefined();
});
it('should set an error with marketplace nodes', () => {
PIProtect.setNodeClientError(standardPingProtectEvaluationStep, 'we errored!');
const [, err] = standardPingProtectEvaluationStep.getCallbacksOfType<HiddenValueCallback>(
CallbackType.HiddenValueCallback,
);
expect(err.getInputValue()).toBe('we errored!');
});
});