|
3 | 3 | * |
4 | 4 | * ping-protect-intitialize-callback.test.ts |
5 | 5 | * |
6 | | - * Copyright (c) 2024 - 2025 Ping Identity Corporation. All rights reserved. |
| 6 | + * Copyright (c) 2024 - 2026 Ping Identity Corporation. All rights reserved. |
7 | 7 | * This software may be modified and distributed under the terms |
8 | 8 | * of the MIT license. See the LICENSE file for details. |
9 | 9 | */ |
@@ -89,6 +89,128 @@ describe('PingOneProtectInitializeCallback', () => { |
89 | 89 | disableHub: false, |
90 | 90 | }); |
91 | 91 | }); |
| 92 | + it('should return signalsInitializationOptions directly when it is a valid plain object', () => { |
| 93 | + const signalsInitializationOptions = { |
| 94 | + agentIdentification: 'false', |
| 95 | + htmlGeoLocation: 'true', |
| 96 | + behavioralDataCollection: 'true', |
| 97 | + universalDeviceIdentification: 'false', |
| 98 | + option1: 'value1', |
| 99 | + disableTags: 'false', |
| 100 | + }; |
| 101 | + |
| 102 | + const callback = new PingOneProtectInitializeCallback({ |
| 103 | + type: callbackType.PingOneProtectInitializeCallback, |
| 104 | + input: [], |
| 105 | + output: [ |
| 106 | + { |
| 107 | + name: 'signalsInitializationOptions', |
| 108 | + value: signalsInitializationOptions, |
| 109 | + }, |
| 110 | + { |
| 111 | + name: 'envId', |
| 112 | + value: 'legacy-env-id-that-should-be-ignored', |
| 113 | + }, |
| 114 | + ], |
| 115 | + }); |
| 116 | + |
| 117 | + const config = callback.getConfig(); |
| 118 | + expect(config).toEqual(signalsInitializationOptions); |
| 119 | + expect(config).not.toHaveProperty('envId'); |
| 120 | + }); |
| 121 | + |
| 122 | + it('should fallback to legacy config when signalsInitializationOptions is an array (invalid)', () => { |
| 123 | + const callback = new PingOneProtectInitializeCallback({ |
| 124 | + type: callbackType.PingOneProtectInitializeCallback, |
| 125 | + input: [], |
| 126 | + output: [ |
| 127 | + { |
| 128 | + name: 'signalsInitializationOptions', |
| 129 | + value: [], |
| 130 | + }, |
| 131 | + { |
| 132 | + name: 'envId', |
| 133 | + value: '02fb4743-189a-4bc7-9d6c-a919edfe6447', |
| 134 | + }, |
| 135 | + ], |
| 136 | + }); |
| 137 | + |
| 138 | + const config = callback.getConfig(); |
| 139 | + expect(config).toMatchObject({ |
| 140 | + envId: '02fb4743-189a-4bc7-9d6c-a919edfe6447', |
| 141 | + behavioralDataCollection: true, |
| 142 | + disableTags: false, |
| 143 | + }); |
| 144 | + }); |
| 145 | + |
| 146 | + it('should fallback to legacy config when signalsInitializationOptions is null (invalid)', () => { |
| 147 | + const callback = new PingOneProtectInitializeCallback({ |
| 148 | + type: callbackType.PingOneProtectInitializeCallback, |
| 149 | + input: [], |
| 150 | + output: [ |
| 151 | + { |
| 152 | + name: 'signalsInitializationOptions', |
| 153 | + value: null, |
| 154 | + }, |
| 155 | + { |
| 156 | + name: 'envId', |
| 157 | + value: '02fb4743-189a-4bc7-9d6c-a919edfe6447', |
| 158 | + }, |
| 159 | + ], |
| 160 | + }); |
| 161 | + |
| 162 | + const config = callback.getConfig(); |
| 163 | + expect(config).toMatchObject({ |
| 164 | + envId: '02fb4743-189a-4bc7-9d6c-a919edfe6447', |
| 165 | + behavioralDataCollection: true, |
| 166 | + disableTags: false, |
| 167 | + }); |
| 168 | + }); |
| 169 | + |
| 170 | + it('should fallback to legacy config when signalsInitializationOptions is a string (invalid)', () => { |
| 171 | + const callback = new PingOneProtectInitializeCallback({ |
| 172 | + type: callbackType.PingOneProtectInitializeCallback, |
| 173 | + input: [], |
| 174 | + output: [ |
| 175 | + { |
| 176 | + name: 'signalsInitializationOptions', |
| 177 | + value: 'somestring', |
| 178 | + }, |
| 179 | + { |
| 180 | + name: 'envId', |
| 181 | + value: '02fb4743-189a-4bc7-9d6c-a919edfe6447', |
| 182 | + }, |
| 183 | + ], |
| 184 | + }); |
| 185 | + |
| 186 | + const config = callback.getConfig(); |
| 187 | + expect(config).toMatchObject({ |
| 188 | + envId: '02fb4743-189a-4bc7-9d6c-a919edfe6447', |
| 189 | + behavioralDataCollection: true, |
| 190 | + disableTags: false, |
| 191 | + }); |
| 192 | + }); |
| 193 | + |
| 194 | + it('should fallback to legacy config when signalsInitializationOptions is missing', () => { |
| 195 | + const callback = new PingOneProtectInitializeCallback({ |
| 196 | + type: callbackType.PingOneProtectInitializeCallback, |
| 197 | + input: [], |
| 198 | + output: [ |
| 199 | + { |
| 200 | + name: 'envId', |
| 201 | + value: '02fb4743-189a-4bc7-9d6c-a919edfe6447', |
| 202 | + }, |
| 203 | + ], |
| 204 | + }); |
| 205 | + |
| 206 | + const config = callback.getConfig(); |
| 207 | + expect(config).toMatchObject({ |
| 208 | + envId: '02fb4743-189a-4bc7-9d6c-a919edfe6447', |
| 209 | + behavioralDataCollection: true, |
| 210 | + disableTags: false, |
| 211 | + }); |
| 212 | + }); |
| 213 | + |
92 | 214 | it('should test the setClientError method', () => { |
93 | 215 | const callback = new PingOneProtectInitializeCallback({ |
94 | 216 | type: callbackType.PingOneProtectInitializeCallback, |
|
0 commit comments