@@ -29,7 +29,7 @@ const config: ProtectConfig = {
2929 disableHub : false ,
3030} ;
3131
32- describe ( 'protect (success tests )' , ( ) => {
32+ describe ( 'protect (with successfully loaded signals sdk )' , ( ) => {
3333 beforeAll ( ( ) => {
3434 vi . doMock ( './signals-sdk.js' , ( ) => {
3535 return {
@@ -67,99 +67,117 @@ describe('protect (success tests)', () => {
6767 expect ( protect ) . toBeDefined ( ) ;
6868 } ) ;
6969
70- it ( 'should return protect methods' , async ( ) => {
71- const protectAPI = await protect ( config ) ;
72- expect ( protectAPI ) . toBeDefined ( ) ;
73- assertType < Protect > ( protectAPI ) ;
74- expect ( protectAPI . start ) . toBeDefined ( ) ;
75- expect ( protectAPI . getData ) . toBeDefined ( ) ;
76- expect ( protectAPI . pauseBehavioralData ) . toBeDefined ( ) ;
77- expect ( protectAPI . resumeBehavioralData ) . toBeDefined ( ) ;
78- expect ( protectAPI . getPauseBehavioralData ) . toBeDefined ( ) ;
79- expect ( protectAPI . getNodeConfig ) . toBeDefined ( ) ;
80- expect ( protectAPI . getProtectType ) . toBeDefined ( ) ;
81- expect ( protectAPI . setNodeClientError ) . toBeDefined ( ) ;
82- expect ( protectAPI . setNodeInputValue ) . toBeDefined ( ) ;
70+ it ( 'should return protect methods' , ( ) => {
71+ const protectApi = protect ( config ) ;
72+ expect ( protectApi ) . toBeDefined ( ) ;
73+ assertType < Protect > ( protectApi ) ;
74+ expect ( protectApi . start ) . toBeDefined ( ) ;
75+ expect ( protectApi . getData ) . toBeDefined ( ) ;
76+ expect ( protectApi . pauseBehavioralData ) . toBeDefined ( ) ;
77+ expect ( protectApi . resumeBehavioralData ) . toBeDefined ( ) ;
78+ expect ( protectApi . getPauseBehavioralData ) . toBeDefined ( ) ;
79+ expect ( protectApi . getNodeConfig ) . toBeDefined ( ) ;
80+ expect ( protectApi . getProtectType ) . toBeDefined ( ) ;
81+ expect ( protectApi . setNodeClientError ) . toBeDefined ( ) ;
82+ expect ( protectApi . setNodeInputValue ) . toBeDefined ( ) ;
8383 } ) ;
8484
8585 describe ( 'native node methods' , ( ) => {
8686 it ( 'should call start' , async ( ) => {
87- const protectAPI = await protect ( config ) ;
88- const protectMock = vi . spyOn ( protectAPI , 'start' ) ;
89- await protectAPI . start ( ) ;
87+ const protectApi = protect ( config ) ;
88+ const protectMock = vi . spyOn ( protectApi , 'start' ) ;
89+ await protectApi . start ( ) ;
9090 expect ( protectMock ) . toHaveBeenCalled ( ) ;
9191 expect ( window . _pingOneSignals . init ) . toHaveBeenCalledWith ( config ) ;
9292 } ) ;
9393
9494 it ( 'should call getData' , async ( ) => {
95- const protectAPI = await protect ( config ) ;
96- const protectMock = vi . spyOn ( protectAPI , 'getData' ) ;
97- await protectAPI . getData ( ) ;
95+ const protectApi = protect ( config ) ;
96+ const protectMock = vi . spyOn ( protectApi , 'getData' ) ;
97+ await protectApi . getData ( ) ;
9898 expect ( protectMock ) . toHaveBeenCalled ( ) ;
9999 } ) ;
100100
101- it ( 'should call pauseBehavioralData' , async ( ) => {
102- const protectAPI = await protect ( config ) ;
103- const protectMock = vi . spyOn ( protectAPI , 'pauseBehavioralData' ) ;
104- protectAPI . pauseBehavioralData ( ) ;
101+ it ( 'should call pauseBehavioralData' , ( ) => {
102+ const protectApi = protect ( config ) ;
103+ const protectMock = vi . spyOn ( protectApi , 'pauseBehavioralData' ) ;
104+ protectApi . pauseBehavioralData ( ) ;
105105 expect ( protectMock ) . toHaveBeenCalled ( ) ;
106106 } ) ;
107107
108- it ( 'should call resume behavioralData' , async ( ) => {
109- const protectAPI = await protect ( config ) ;
110- const protectMock = vi . spyOn ( protectAPI , 'resumeBehavioralData' ) ;
111- protectAPI . resumeBehavioralData ( ) ;
108+ it ( 'should call resumeBehavioralData' , ( ) => {
109+ const protectApi = protect ( config ) ;
110+ const protectMock = vi . spyOn ( protectApi , 'resumeBehavioralData' ) ;
111+ protectApi . resumeBehavioralData ( ) ;
112112 expect ( protectMock ) . toHaveBeenCalled ( ) ;
113113 } ) ;
114+
115+ it ( 'getData should error if start has not been called' , async ( ) => {
116+ const protectApi = protect ( config ) ;
117+ const error = await protectApi . getData ( ) ;
118+ expect ( error ) . toEqual ( { error : 'PingOne Signals SDK is not initialized' } ) ;
119+ } ) ;
120+
121+ it ( 'pauseBehavioralData should error if start has not been called' , async ( ) => {
122+ const protectApi = protect ( config ) ;
123+ const error = await protectApi . pauseBehavioralData ( ) ;
124+ expect ( error ) . toEqual ( { error : 'PingOne Signals SDK is not initialized' } ) ;
125+ } ) ;
126+
127+ it ( 'resumeBehavioralData should error if start has not been called' , async ( ) => {
128+ const protectApi = protect ( config ) ;
129+ const error = await protectApi . resumeBehavioralData ( ) ;
130+ expect ( error ) . toEqual ( { error : 'PingOne Signals SDK is not initialized' } ) ;
131+ } ) ;
114132 } ) ;
115133
116134 describe ( 'marketplace node methods' , ( ) => {
117- it ( 'should test getPauseBehavioralData with marketplace data' , async ( ) => {
118- const protectAPI = await protect ( config ) ;
119- const result = protectAPI . getPauseBehavioralData ( standardPingProtectEvaluationStep ) ;
135+ it ( 'should test getPauseBehavioralData with marketplace data' , ( ) => {
136+ const protectApi = protect ( config ) ;
137+ const result = protectApi . getPauseBehavioralData ( standardPingProtectEvaluationStep ) ;
120138 expect ( result ) . toEqual ( false ) ;
121139
122- const secondResult = protectAPI . getPauseBehavioralData ( standardPingProtectInitializeStep ) ;
140+ const secondResult = protectApi . getPauseBehavioralData ( standardPingProtectInitializeStep ) ;
123141 expect ( secondResult ) . toEqual ( true ) ;
124142 } ) ;
125143
126- it ( 'should get the node config' , async ( ) => {
127- const protectAPI = await protect ( config ) ;
128- const result = protectAPI . getNodeConfig ( standardPingProtectInitializeStep ) ;
144+ it ( 'should get the node config' , ( ) => {
145+ const protectApi = protect ( config ) ;
146+ const result = protectApi . getNodeConfig ( standardPingProtectInitializeStep ) ;
129147 expect ( result ) . toEqual (
130148 // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
131149 standardPingProtectInitializeStep ! . payload . callbacks ! [ 0 ] . output [ 0 ] . value ,
132150 ) ;
133151
134- const result2 = protectAPI . getNodeConfig ( noProtectType ) ;
152+ const result2 = protectApi . getNodeConfig ( noProtectType ) ;
135153 expect ( result2 ) . toBeUndefined ( ) ;
136154 } ) ;
137155
138- it ( 'should test the getPingProtectType method' , async ( ) => {
139- const protectAPI = await protect ( config ) ;
140- const result = protectAPI . getProtectType ( standardPingProtectInitializeStep ) ;
156+ it ( 'should test the getPingProtectType method' , ( ) => {
157+ const protectApi = protect ( config ) ;
158+ const result = protectApi . getProtectType ( standardPingProtectInitializeStep ) ;
141159 expect ( result ) . toEqual ( 'initialize' ) ;
142160
143- const result2 = protectAPI . getProtectType ( standardPingProtectEvaluationStep ) ;
161+ const result2 = protectApi . getProtectType ( standardPingProtectEvaluationStep ) ;
144162 expect ( result2 ) . toEqual ( 'evaluate' ) ;
145163
146- const result3 = protectAPI . getProtectType ( noProtectType ) ;
164+ const result3 = protectApi . getProtectType ( noProtectType ) ;
147165 expect ( result3 ) . toEqual ( 'none' ) ;
148166 } ) ;
149167
150- it ( 'should set the input with marketplace nodes' , async ( ) => {
151- const protectAPI = await protect ( config ) ;
168+ it ( 'should set the input with marketplace nodes' , ( ) => {
169+ const protectApi = protect ( config ) ;
152170 const step = standardPingProtectEvaluationStep as FRStep ;
153171
154- protectAPI . setNodeInputValue ( step , 'the value' ) ;
172+ protectApi . setNodeInputValue ( step , 'the value' ) ;
155173 const [ hc ] = step . getCallbacksOfType < HiddenValueCallback > ( CallbackType . HiddenValueCallback ) ;
156174
157175 expect ( hc . getInputValue ( ) ) . toEqual ( 'the value' ) ;
158176 } ) ;
159177
160- it ( 'should set an error with marketplace nodes' , async ( ) => {
161- const protectAPI = await protect ( config ) ;
162- protectAPI . setNodeClientError ( standardPingProtectEvaluationStep , 'we errored!' ) ;
178+ it ( 'should set an error with marketplace nodes' , ( ) => {
179+ const protectApi = protect ( config ) ;
180+ protectApi . setNodeClientError ( standardPingProtectEvaluationStep , 'we errored!' ) ;
163181
164182 const [ , err ] = (
165183 standardPingProtectEvaluationStep as FRStep
@@ -170,16 +188,41 @@ describe('protect (success tests)', () => {
170188 } ) ;
171189} ) ;
172190
173- describe ( 'protect (error tests )' , ( ) => {
191+ describe ( 'protect (with failed signals sdk load )' , ( ) => {
174192 beforeAll ( ( ) => {
175193 vi . doMock ( './signals-sdk.js' , ( ) => {
176194 throw new Error ( 'Failed to load PingOne Signals SDK' ) ;
177195 } ) ;
178196 } ) ;
197+
179198 afterAll ( ( ) => {
180199 vi . doUnmock ( './signals-sdk.js' ) ;
181200 } ) ;
182- it ( 'should error on failed signals sdk load' , async ( ) => {
183- await expect ( protect ( config ) ) . rejects . toThrowError ( 'Failed to load PingOne Signals SDK' ) ;
201+
202+ it ( 'start method should error' , async ( ) => {
203+ const protectApi = protect ( config ) ;
204+ const error = await protectApi . start ( ) ;
205+ await expect ( error ) . toEqual ( { error : 'Failed to load PingOne Signals SDK' } ) ;
206+ } ) ;
207+
208+ it ( 'getData method should error' , async ( ) => {
209+ const protectApi = protect ( config ) ;
210+ await protectApi . start ( ) ;
211+ const error = await protectApi . getData ( ) ;
212+ await expect ( error ) . toEqual ( { error : 'PingOne Signals SDK is not initialized' } ) ;
213+ } ) ;
214+
215+ it ( 'pauseBehavioralData method should error' , async ( ) => {
216+ const protectApi = protect ( config ) ;
217+ await protectApi . start ( ) ;
218+ const error = await protectApi . pauseBehavioralData ( ) ;
219+ await expect ( error ) . toEqual ( { error : 'PingOne Signals SDK is not initialized' } ) ;
220+ } ) ;
221+
222+ it ( 'resumeBehavioralData method should error' , async ( ) => {
223+ const protectApi = protect ( config ) ;
224+ await protectApi . start ( ) ;
225+ const error = await protectApi . resumeBehavioralData ( ) ;
226+ await expect ( error ) . toEqual ( { error : 'PingOne Signals SDK is not initialized' } ) ;
184227 } ) ;
185228} ) ;
0 commit comments