Skip to content

Commit 7f8c058

Browse files
🤖 Merge PR DefinitelyTyped#73573 Add tests and definitions for subscriber by @alexs-mparticle
1 parent 8ec5a54 commit 7f8c058

File tree

2 files changed

+94
-1
lines changed

2 files changed

+94
-1
lines changed

‎types/mparticle__web-sdk/index.d.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export interface RoktPlacementEvent<T = void> {
2525
}
2626

2727
export interface RoktSubscriber<T> {
28-
subscribe(handler: T): RoktUnsubscriber;
28+
subscribe(handler: (value: T) => void): RoktUnsubscriber;
2929
}
3030

3131
export interface RoktUnsubscriber {

‎types/mparticle__web-sdk/test/mparticle__web-sdk-instance-tests.ts‎

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -723,3 +723,96 @@ const firstSeenTime: number = user5.getFirstSeenTime();
723723
user5.getCart().add(product1, true);
724724
user5.getCart().remove(product1, true);
725725
user5.getCart().clear();
726+
727+
mParticle.Rokt.selectPlacements({
728+
attributes: {
729+
'foo': 'bar',
730+
'fizz': 'buzz',
731+
},
732+
}).then(selection => {
733+
// Test event subscription patterns
734+
selection.on('PLACEMENT_INTERACTIVE').subscribe(() => {
735+
console.log('Placement interaction');
736+
});
737+
738+
selection.on('PLACEMENT_COMPLETED').subscribe(event => {
739+
console.log('Placement completed', event);
740+
console.log('Event details:', event.body, event.event, event.placement);
741+
});
742+
743+
// Test unsubscription
744+
const unsubscriber = selection.on('PLACEMENT_READY').subscribe(event => {
745+
console.log('Placement ready:', event.placement.id);
746+
});
747+
unsubscriber.unsubscribe();
748+
749+
// Test selection methods
750+
selection.ready().then(() => {
751+
console.log('Selection is ready');
752+
});
753+
754+
selection.send('custom_event', { data: 'test' });
755+
756+
selection.setAttributes({
757+
'dynamic_attr': 'updated_value',
758+
'user_segment': 'premium'
759+
});
760+
761+
// Test getting individual placements
762+
selection.getPlacements().then(placements => {
763+
placements.forEach(placement => {
764+
console.log('Placement ID:', placement.id);
765+
console.log('Placement element:', placement.element);
766+
767+
// Test placement-specific events
768+
placement.on('PLACEMENT_RENDERED').subscribe(event => {
769+
console.log('Placement rendered:', event);
770+
});
771+
772+
// Test placement methods
773+
placement.ready().then(() => {
774+
console.log(`Placement ${placement.id} is ready`);
775+
});
776+
777+
placement.send('placement_event', { custom: 'data' });
778+
779+
// Test placement close events
780+
placement.onClose().then(() => {
781+
console.log(`Placement ${placement.id} was closed`);
782+
});
783+
784+
// Test manual close
785+
placement.close().then(() => {
786+
console.log(`Placement ${placement.id} closed programmatically`);
787+
});
788+
});
789+
});
790+
791+
// Test selection close
792+
selection.close();
793+
});
794+
795+
// Test other Rokt methods
796+
mParticle.Rokt.hashAttributes({
797+
798+
userId: '12345',
799+
segment: 'premium'
800+
}).then(hashedAttrs => {
801+
console.log('Hashed attributes:', hashedAttrs);
802+
});
803+
804+
mParticle.Rokt.setExtensionData({
805+
'analytics': { sessionId: 'abc123' },
806+
'personalization': { variant: 'A' }
807+
});
808+
809+
// Test with identifier
810+
mParticle.Rokt.selectPlacements({
811+
attributes: {
812+
'placement_type': 'checkout',
813+
'cart_value': 150.00
814+
},
815+
identifier: 'checkout-flow-2024',
816+
}).then(selection => {
817+
console.log('Selection with identifier created', selection);
818+
});

0 commit comments

Comments
 (0)