@@ -189,6 +189,121 @@ describe('Rokt Forwarder', () => {
189189 } ) ;
190190 } ) ;
191191
192+ describe ( '#hashedAttributes' , ( ) => {
193+ beforeEach ( ( ) => {
194+ window . Rokt = new MockRoktForwarder ( ) ;
195+ window . mParticle . Rokt = window . Rokt ;
196+ window . mParticle . Rokt . attachKitCalled = false ;
197+ window . mParticle . Rokt . attachKit = async ( kit ) => {
198+ window . mParticle . Rokt . attachKitCalled = true ;
199+ window . mParticle . Rokt . kit = kit ;
200+ Promise . resolve ( ) ;
201+ } ;
202+ window . mParticle . forwarder . launcher = {
203+ hashedAttributes : function ( attributes ) {
204+ window . mParticle . Rokt . hashedAttributesOptions = attributes ;
205+ window . mParticle . Rokt . hashedAttributesCalled = true ;
206+
207+ // Mocking the hashedAttributes method to show that
208+ // the attributes will be transformed by the launcher's
209+ // hashedAttributes method.
210+ return Promise . resolve ( {
211+ 'test-attribute' : 'hashed-value' ,
212+ } ) ;
213+ } ,
214+ } ;
215+ } ) ;
216+
217+ it ( 'should call launcher.hashedAttributes with passed through attributes when fully initialized' , function ( ) {
218+ // Ensure both initialization conditions are met
219+ window . mParticle . forwarder . isInitialized = true ;
220+ window . mParticle . forwarder . launcher = {
221+ hashedAttributes : function ( attributes ) {
222+ window . mParticle . Rokt . hashedAttributesOptions = attributes ;
223+ window . mParticle . Rokt . hashedAttributesCalled = true ;
224+ return {
225+ 'test-attribute' : 'hashed-value' ,
226+ } ;
227+ } ,
228+ } ;
229+
230+ var attributes = {
231+ 'test-attribute' : 'test-value' ,
232+ } ;
233+
234+ window . mParticle . forwarder . hashedAttributes ( attributes ) ;
235+
236+ window . Rokt . hashedAttributesCalled . should . equal ( true ) ;
237+ window . Rokt . hashedAttributesOptions . should . deepEqual ( attributes ) ;
238+ } ) ;
239+
240+ it ( 'should return null when launcher exists but kit is not initialized' , function ( ) {
241+ // Set launcher but ensure isInitialized is false
242+ window . mParticle . forwarder . isInitialized = false ;
243+ window . mParticle . forwarder . launcher = {
244+ hashedAttributes : function ( ) { } ,
245+ } ;
246+
247+ var result = window . mParticle . forwarder . hashedAttributes ( {
248+ 'test-attribute' : 'test-value' ,
249+ } ) ;
250+
251+ ( result === null ) . should . equal ( true ) ;
252+ } ) ;
253+
254+ it ( 'should log an error when called before initialization' , function ( ) {
255+ var errorLogged = false ;
256+ var errorMessage = null ;
257+ window . console . error = function ( message ) {
258+ errorLogged = true ;
259+ errorMessage = message ;
260+ } ;
261+
262+ // Ensure kit is not initialized
263+ window . mParticle . forwarder . isInitialized = false ;
264+ window . mParticle . forwarder . launcher = null ;
265+
266+ window . mParticle . forwarder . hashedAttributes ( {
267+ 'test-attribute' : 'test-value' ,
268+ } ) ;
269+
270+ errorLogged . should . equal ( true ) ;
271+ errorMessage . should . equal ( 'Rokt Kit: Not initialized' ) ;
272+ } ) ;
273+
274+ it ( 'should return null when kit is initialized but launcher is missing' , function ( ) {
275+ // Mock isInitialized but remove launcher
276+ window . mParticle . forwarder . isInitialized = true ;
277+ window . mParticle . forwarder . launcher = null ;
278+
279+ var result = window . mParticle . forwarder . hashedAttributes ( {
280+ 'test-attribute' : 'test-value' ,
281+ } ) ;
282+
283+ ( result === null ) . should . equal ( true ) ;
284+ } ) ;
285+
286+ it ( 'should return hashed attributes from launcher' , async ( ) => {
287+ await window . mParticle . forwarder . init (
288+ {
289+ accountId : '123456' ,
290+ } ,
291+ reportService . cb ,
292+ true ,
293+ null ,
294+ { }
295+ ) ;
296+
297+ const result = await window . mParticle . forwarder . hashedAttributes ( {
298+ 'test-attribute' : 'test-value' ,
299+ } ) ;
300+
301+ result . should . deepEqual ( {
302+ 'test-attribute' : 'hashed-value' ,
303+ } ) ;
304+ } ) ;
305+ } ) ;
306+
192307 describe ( '#selectPlacements' , ( ) => {
193308 beforeEach ( ( ) => {
194309 window . Rokt = new MockRoktForwarder ( ) ;
0 commit comments