Skip to content

Commit 927f19b

Browse files
committed
chore(protect): pr revisions
1 parent 0ae6abe commit 927f19b

File tree

2 files changed

+223
-239
lines changed

2 files changed

+223
-239
lines changed

packages/protect/src/lib/protect.test.ts

Lines changed: 40 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ describe('protect', () => {
2929
disableTags: false,
3030
disableHub: false,
3131
};
32-
let protectAPI: Protect | undefined;
3332

3433
async function getProtect(options: ProtectConfig): Promise<Protect> {
3534
const protectAPI: Protect = await protect(options);
@@ -61,8 +60,6 @@ describe('protect', () => {
6160
pauseBehavioralData: vi.fn(),
6261
resumeBehavioralData: vi.fn(),
6362
};
64-
65-
protectAPI = await getProtect(config);
6663
});
6764

6865
afterEach(() => {
@@ -76,90 +73,99 @@ describe('protect', () => {
7673
});
7774

7875
it('should return protect methods', async () => {
79-
expect(protectAPI?.start).toBeDefined();
80-
expect(protectAPI?.getData).toBeDefined();
81-
expect(protectAPI?.pauseBehavioralData).toBeDefined();
82-
expect(protectAPI?.resumeBehavioralData).toBeDefined();
83-
expect(protectAPI?.getPauseBehavioralData).toBeDefined();
84-
expect(protectAPI?.getNodeConfig).toBeDefined();
85-
expect(protectAPI?.getProtectType).toBeDefined();
86-
expect(protectAPI?.setNodeClientError).toBeDefined();
87-
expect(protectAPI?.setNodeInputValue).toBeDefined();
76+
const protectAPI = await getProtect(config);
77+
expect(protectAPI.start).toBeDefined();
78+
expect(protectAPI.getData).toBeDefined();
79+
expect(protectAPI.pauseBehavioralData).toBeDefined();
80+
expect(protectAPI.resumeBehavioralData).toBeDefined();
81+
expect(protectAPI.getPauseBehavioralData).toBeDefined();
82+
expect(protectAPI.getNodeConfig).toBeDefined();
83+
expect(protectAPI.getProtectType).toBeDefined();
84+
expect(protectAPI.setNodeClientError).toBeDefined();
85+
expect(protectAPI.setNodeInputValue).toBeDefined();
8886
});
8987

9088
it('should error on failed signals sdk load', async () => {
91-
protectAPI = undefined;
9289
vi.doUnmock('./signals-sdk.js');
9390
await expect(protect(config)).rejects.toThrowError('Failed to load PingOne Signals SDK');
9491
});
9592

9693
it('should call start', async () => {
97-
const protectMock = protectAPI && vi.spyOn(protectAPI, 'start');
98-
await protectAPI?.start();
94+
const protectAPI = await getProtect(config);
95+
const protectMock = vi.spyOn(protectAPI, 'start');
96+
await protectAPI.start();
9997
expect(protectMock).toHaveBeenCalled();
10098
expect(window._pingOneSignals.init).toHaveBeenCalledWith(config);
10199
});
102100

103101
it('should call getData', async () => {
104-
const protectMock = protectAPI && vi.spyOn(protectAPI, 'getData');
105-
await protectAPI?.getData();
102+
const protectAPI = await getProtect(config);
103+
const protectMock = vi.spyOn(protectAPI, 'getData');
104+
await protectAPI.getData();
106105
expect(protectMock).toHaveBeenCalled();
107106
});
108107

109108
it('should call pauseBehavioralData', async () => {
110-
const protectMock = protectAPI && vi.spyOn(protectAPI, 'pauseBehavioralData');
111-
protectAPI?.pauseBehavioralData();
109+
const protectAPI = await getProtect(config);
110+
const protectMock = vi.spyOn(protectAPI, 'pauseBehavioralData');
111+
protectAPI.pauseBehavioralData();
112112
expect(protectMock).toHaveBeenCalled();
113113
});
114114

115115
it('should call resume behavioralData', async () => {
116-
const protectMock = protectAPI && vi.spyOn(protectAPI, 'resumeBehavioralData');
117-
protectAPI?.resumeBehavioralData();
116+
const protectAPI = await getProtect(config);
117+
const protectMock = vi.spyOn(protectAPI, 'resumeBehavioralData');
118+
protectAPI.resumeBehavioralData();
118119
expect(protectMock).toHaveBeenCalled();
119120
});
120121

121122
describe('should test the marketplace node setup', () => {
122-
it('should test getPauseBehavioralData with marketplace data', () => {
123-
const result = protectAPI?.getPauseBehavioralData(standardPingProtectEvaluationStep);
123+
it('should test getPauseBehavioralData with marketplace data', async () => {
124+
const protectAPI = await getProtect(config);
125+
const result = protectAPI.getPauseBehavioralData(standardPingProtectEvaluationStep);
124126
expect(result).toEqual(false);
125127

126128
const secondResult = protectAPI?.getPauseBehavioralData(standardPingProtectInitializeStep);
127129
expect(secondResult).toEqual(true);
128130
});
129131

130-
it('should get the node config', () => {
131-
const result = protectAPI?.getNodeConfig(standardPingProtectInitializeStep);
132+
it('should get the node config', async () => {
133+
const protectAPI = await getProtect(config);
134+
const result = protectAPI.getNodeConfig(standardPingProtectInitializeStep);
132135
expect(result).toEqual(
133136
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
134137
standardPingProtectInitializeStep!.payload.callbacks![0].output[0].value,
135138
);
136139

137-
const result2 = protectAPI?.getNodeConfig(noProtectType);
140+
const result2 = protectAPI.getNodeConfig(noProtectType);
138141
expect(result2).toBeUndefined();
139142
});
140143

141-
it('should test the getPingProtectType method', () => {
142-
const result = protectAPI?.getProtectType(standardPingProtectInitializeStep);
144+
it('should test the getPingProtectType method', async () => {
145+
const protectAPI = await getProtect(config);
146+
const result = protectAPI.getProtectType(standardPingProtectInitializeStep);
143147
expect(result).toEqual('initialize');
144148

145-
const result2 = protectAPI?.getProtectType(standardPingProtectEvaluationStep);
149+
const result2 = protectAPI.getProtectType(standardPingProtectEvaluationStep);
146150
expect(result2).toEqual('evaluate');
147151

148-
const result3 = protectAPI?.getProtectType(noProtectType);
152+
const result3 = protectAPI.getProtectType(noProtectType);
149153
expect(result3).toEqual('none');
150154
});
151155

152-
it('should set the input with marketplace nodes', () => {
156+
it('should set the input with marketplace nodes', async () => {
157+
const protectAPI = await getProtect(config);
153158
const step = standardPingProtectEvaluationStep as FRStep;
154159

155-
protectAPI?.setNodeInputValue(step, 'the value');
160+
protectAPI.setNodeInputValue(step, 'the value');
156161
const [hc] = step.getCallbacksOfType<HiddenValueCallback>(CallbackType.HiddenValueCallback);
157162

158163
expect(hc.getInputValue()).toEqual('the value');
159164
});
160165

161-
it('should set an error with marketplace nodes', () => {
162-
protectAPI?.setNodeClientError(standardPingProtectEvaluationStep, 'we errored!');
166+
it('should set an error with marketplace nodes', async () => {
167+
const protectAPI = await getProtect(config);
168+
protectAPI.setNodeClientError(standardPingProtectEvaluationStep, 'we errored!');
163169

164170
const [, err] = (
165171
standardPingProtectEvaluationStep as FRStep

0 commit comments

Comments
 (0)