@@ -29,7 +29,6 @@ describe('protect', () => {
29
29
disableTags : false ,
30
30
disableHub : false ,
31
31
} ;
32
- let protectAPI : Protect | undefined ;
33
32
34
33
async function getProtect ( options : ProtectConfig ) : Promise < Protect > {
35
34
const protectAPI : Protect = await protect ( options ) ;
@@ -61,8 +60,6 @@ describe('protect', () => {
61
60
pauseBehavioralData : vi . fn ( ) ,
62
61
resumeBehavioralData : vi . fn ( ) ,
63
62
} ;
64
-
65
- protectAPI = await getProtect ( config ) ;
66
63
} ) ;
67
64
68
65
afterEach ( ( ) => {
@@ -76,90 +73,99 @@ describe('protect', () => {
76
73
} ) ;
77
74
78
75
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 ( ) ;
88
86
} ) ;
89
87
90
88
it ( 'should error on failed signals sdk load' , async ( ) => {
91
- protectAPI = undefined ;
92
89
vi . doUnmock ( './signals-sdk.js' ) ;
93
90
await expect ( protect ( config ) ) . rejects . toThrowError ( 'Failed to load PingOne Signals SDK' ) ;
94
91
} ) ;
95
92
96
93
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 ( ) ;
99
97
expect ( protectMock ) . toHaveBeenCalled ( ) ;
100
98
expect ( window . _pingOneSignals . init ) . toHaveBeenCalledWith ( config ) ;
101
99
} ) ;
102
100
103
101
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 ( ) ;
106
105
expect ( protectMock ) . toHaveBeenCalled ( ) ;
107
106
} ) ;
108
107
109
108
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 ( ) ;
112
112
expect ( protectMock ) . toHaveBeenCalled ( ) ;
113
113
} ) ;
114
114
115
115
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 ( ) ;
118
119
expect ( protectMock ) . toHaveBeenCalled ( ) ;
119
120
} ) ;
120
121
121
122
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 ) ;
124
126
expect ( result ) . toEqual ( false ) ;
125
127
126
128
const secondResult = protectAPI ?. getPauseBehavioralData ( standardPingProtectInitializeStep ) ;
127
129
expect ( secondResult ) . toEqual ( true ) ;
128
130
} ) ;
129
131
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 ) ;
132
135
expect ( result ) . toEqual (
133
136
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
134
137
standardPingProtectInitializeStep ! . payload . callbacks ! [ 0 ] . output [ 0 ] . value ,
135
138
) ;
136
139
137
- const result2 = protectAPI ? .getNodeConfig ( noProtectType ) ;
140
+ const result2 = protectAPI . getNodeConfig ( noProtectType ) ;
138
141
expect ( result2 ) . toBeUndefined ( ) ;
139
142
} ) ;
140
143
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 ) ;
143
147
expect ( result ) . toEqual ( 'initialize' ) ;
144
148
145
- const result2 = protectAPI ? .getProtectType ( standardPingProtectEvaluationStep ) ;
149
+ const result2 = protectAPI . getProtectType ( standardPingProtectEvaluationStep ) ;
146
150
expect ( result2 ) . toEqual ( 'evaluate' ) ;
147
151
148
- const result3 = protectAPI ? .getProtectType ( noProtectType ) ;
152
+ const result3 = protectAPI . getProtectType ( noProtectType ) ;
149
153
expect ( result3 ) . toEqual ( 'none' ) ;
150
154
} ) ;
151
155
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 ) ;
153
158
const step = standardPingProtectEvaluationStep as FRStep ;
154
159
155
- protectAPI ? .setNodeInputValue ( step , 'the value' ) ;
160
+ protectAPI . setNodeInputValue ( step , 'the value' ) ;
156
161
const [ hc ] = step . getCallbacksOfType < HiddenValueCallback > ( CallbackType . HiddenValueCallback ) ;
157
162
158
163
expect ( hc . getInputValue ( ) ) . toEqual ( 'the value' ) ;
159
164
} ) ;
160
165
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!' ) ;
163
169
164
170
const [ , err ] = (
165
171
standardPingProtectEvaluationStep as FRStep
0 commit comments