Skip to content

Commit 08d5398

Browse files
Decouple placement sandbox option from global options
1 parent 2b418c2 commit 08d5398

2 files changed

Lines changed: 11 additions & 123 deletions

File tree

src/roktManager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ export default class RoktManager {
162162

163163
try {
164164
const { attributes } = options;
165-
const sandboxValue = attributes?.sandbox ?? this.sandbox;
165+
const sandboxValue = attributes?.sandbox || null;
166166
const mappedAttributes = this.mapPlacementAttributes(attributes, this.placementAttributesMapping);
167167

168168
// Get current user identities

test/jest/roktManager.spec.ts

Lines changed: 10 additions & 122 deletions
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ describe('RoktManager', () => {
458458
expect(kit.selectPlacements).toHaveBeenCalledWith(options);
459459
});
460460

461-
it('should pass through the correct attributes to kit.launcher.selectPlacements', () => {
461+
it('should pass through the correct attributes to kit.selectPlacements', () => {
462462
const kit: IRoktKit = {
463463
launcher: {
464464
selectPlacements: jest.fn(),
@@ -497,77 +497,35 @@ describe('RoktManager', () => {
497497
expect(kit.launcher.selectPlacements).toHaveBeenCalledWith(options);
498498
});
499499

500-
it('should set sandbox to true in placement attributes when initialized as true', () => {
500+
it('should pass sandbox flag as an attribute through to kit.selectPlacements', ()=> {
501501
const kit: IRoktKit = {
502502
launcher: {
503503
selectPlacements: jest.fn(),
504504
hashAttributes: jest.fn()
505505
},
506506
filters: undefined,
507507
filteredUser: undefined,
508-
userAttributes: undefined,
509508
selectPlacements: jest.fn(),
510-
hashAttributes: jest.fn(),
511509
setExtensionData: jest.fn(),
510+
hashAttributes: jest.fn(),
511+
userAttributes: undefined,
512512
};
513513

514514
roktManager.attachKit(kit);
515-
roktManager['sandbox'] = true;
516515

517516
const options: IRoktSelectPlacementsOptions = {
518-
attributes: {
519-
customAttr: 'value'
520-
}
521-
};
522-
523-
roktManager.selectPlacements(options);
524-
525-
const expectedOptions = {
526517
attributes: {
527518
customAttr: 'value',
528-
'sandbox': true
529-
}
530-
};
531-
532-
expect(kit.selectPlacements).toHaveBeenCalledWith(expectedOptions);
533-
});
534-
535-
it('should set sandbox to false in placement attributes when initialized as false', () => {
536-
const kit: IRoktKit = {
537-
launcher: {
538-
selectPlacements: jest.fn(),
539-
hashAttributes: jest.fn()
519+
sandbox: true
540520
},
541-
filters: undefined,
542-
filteredUser: undefined,
543-
userAttributes: undefined,
544-
selectPlacements: jest.fn(),
545-
hashAttributes: jest.fn(),
546-
setExtensionData: jest.fn(),
547-
};
548-
549-
roktManager.attachKit(kit);
550-
roktManager['sandbox'] = false;
551-
552-
const options: IRoktSelectPlacementsOptions = {
553-
attributes: {
554-
customAttr: 'value'
555-
}
521+
identifier: 'test-identifier'
556522
};
557523

558524
roktManager.selectPlacements(options);
559-
560-
const expectedOptions = {
561-
attributes: {
562-
customAttr: 'value',
563-
'sandbox': false
564-
}
565-
};
566-
567-
expect(kit.selectPlacements).toHaveBeenCalledWith(expectedOptions);
525+
expect(kit.selectPlacements).toHaveBeenCalledWith(options);
568526
});
569527

570-
it('should override sandbox to false in placement attributes when initialized as true', () => {
528+
it('should NOT override global sandbox in placement attributes when initialized as true', () => {
571529
const kit: IRoktKit = {
572530
launcher: {
573531
selectPlacements: jest.fn(),
@@ -593,81 +551,11 @@ describe('RoktManager', () => {
593551

594552
roktManager.selectPlacements(options);
595553

596-
const expectedOptions = {
597-
attributes: {
598-
customAttr: 'value',
599-
sandbox: false
600-
}
601-
};
602-
603-
expect(kit.selectPlacements).toHaveBeenCalledWith(expectedOptions);
604-
});
605-
606-
it('should preserve other option properties when adding sandbox', () => {
607-
const kit: IRoktKit = {
608-
launcher: {
609-
selectPlacements: jest.fn(),
610-
hashAttributes: jest.fn()
611-
},
612-
filters: undefined,
613-
filteredUser: undefined,
614-
hashAttributes: jest.fn(),
615-
selectPlacements: jest.fn(),
616-
setExtensionData: jest.fn(),
617-
userAttributes: undefined,
618-
};
619-
620-
roktManager.attachKit(kit);
621-
roktManager['sandbox'] = true;
622-
623-
const options: IRoktSelectPlacementsOptions = {
624-
attributes: {
625-
customAttr: 'value'
626-
},
627-
identifier: 'test-identifier'
628-
};
629-
630-
roktManager.selectPlacements(options);
631-
632-
const expectedOptions = {
633-
attributes: {
634-
customAttr: 'value',
635-
'sandbox': true
636-
},
637-
identifier: 'test-identifier'
638-
};
639-
640-
expect(kit.selectPlacements).toHaveBeenCalledWith(expectedOptions);
641-
});
642-
643-
it('should not add sandbox when sandbox is null', () => {
644-
const kit: IRoktKit = {
645-
launcher: {
646-
selectPlacements: jest.fn(),
647-
hashAttributes: jest.fn()
648-
},
649-
filters: undefined,
650-
filteredUser: undefined,
651-
hashAttributes: jest.fn(),
652-
selectPlacements: jest.fn(),
653-
setExtensionData: jest.fn(),
654-
userAttributes: undefined,
655-
};
656-
657-
roktManager.attachKit(kit);
658-
// Not initializing sandbox, so it remains null
659-
660-
const options: IRoktSelectPlacementsOptions = {
661-
attributes: {
662-
customAttr: 'value'
663-
}
664-
};
665-
666-
roktManager.selectPlacements(options);
554+
expect(roktManager['sandbox']).toBeTruthy();
667555
expect(kit.selectPlacements).toHaveBeenCalledWith(options);
668556
});
669557

670-
it('should set sandbox in placement attributes when not initialized', () => {
558+
it('should set sandbox in placement attributes when not initialized globally', () => {
671559
const kit: IRoktKit = {
672560
launcher: {
673561
selectPlacements: jest.fn(),

0 commit comments

Comments
 (0)