Skip to content

Commit 72244d3

Browse files
committed
clean up roktManager test
1 parent 797df46 commit 72244d3

1 file changed

Lines changed: 55 additions & 167 deletions

File tree

test/jest/roktManager.spec.ts

Lines changed: 55 additions & 167 deletions
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,7 @@ describe('RoktManager', () => {
593593
attributes: {
594594
mapped_key: 'test_value', // This key should be mapped
595595
other_attr: 'other_value' // This key should remain unchanged
596-
},
596+
}
597597
};
598598

599599
expect(kit.selectPlacements).toHaveBeenCalledWith(expectedMappedOptions);
@@ -658,9 +658,7 @@ describe('RoktManager', () => {
658658
} as IRoktSelectPlacementsOptions;
659659

660660
roktManager.selectPlacements(options);
661-
expect(kit.selectPlacements).toHaveBeenCalledWith({
662-
attributes: {},
663-
});
661+
expect(kit.selectPlacements).toHaveBeenCalledWith(options);
664662
});
665663

666664
it('should call kit.selectPlacements with passed in attributes', async () => {
@@ -692,15 +690,7 @@ describe('RoktManager', () => {
692690
};
693691

694692
await roktManager.selectPlacements(options);
695-
expect(kit.selectPlacements).toHaveBeenCalledWith({
696-
attributes: {
697-
age: 25,
698-
score: 100.5,
699-
isSubscribed: true,
700-
isActive: false,
701-
interests: 'sports,music,books'
702-
},
703-
});
693+
expect(kit.selectPlacements).toHaveBeenCalledWith(options);
704694
});
705695

706696
it('should queue the selectPlacements method if no launcher or kit is attached', () => {
@@ -762,9 +752,7 @@ describe('RoktManager', () => {
762752

763753
expect(roktManager['kit']).not.toBeNull();
764754
expect(roktManager['messageQueue'].size).toBe(0);
765-
expect(kit.selectPlacements).toHaveBeenCalledWith({
766-
attributes: {},
767-
});
755+
expect(kit.selectPlacements).toHaveBeenCalledWith(options);
768756
expect(result).toEqual(expectedResult);
769757
});
770758

@@ -804,19 +792,9 @@ describe('RoktManager', () => {
804792
}
805793
};
806794

807-
const expectedOptions = {
808-
attributes: {
809-
age: 25,
810-
score: 100.5,
811-
isSubscribed: true,
812-
isActive: false,
813-
interests: 'sports,music,books'
814-
},
815-
};
816-
817795
roktManager.selectPlacements(options);
818-
expect(kit.selectPlacements).toHaveBeenCalledWith(expectedOptions);
819-
expect(kit.launcher.selectPlacements).toHaveBeenCalledWith(expectedOptions);
796+
expect(kit.selectPlacements).toHaveBeenCalledWith(options);
797+
expect(kit.launcher.selectPlacements).toHaveBeenCalledWith(options);
820798
});
821799

822800
it('should pass sandbox flag as an attribute through to kit.selectPlacements', () => {
@@ -846,13 +824,7 @@ describe('RoktManager', () => {
846824
};
847825

848826
roktManager.selectPlacements(options);
849-
expect(kit.selectPlacements).toHaveBeenCalledWith({
850-
attributes: {
851-
customAttr: 'value',
852-
sandbox: true
853-
},
854-
identifier: 'test-identifier',
855-
});
827+
expect(kit.selectPlacements).toHaveBeenCalledWith(options);
856828
});
857829

858830
it('should NOT override global sandbox in placement attributes when initialized as true', () => {
@@ -884,12 +856,7 @@ describe('RoktManager', () => {
884856
roktManager.selectPlacements(options);
885857

886858
expect(roktManager['sandbox']).toBeTruthy();
887-
expect(kit.selectPlacements).toHaveBeenCalledWith({
888-
attributes: {
889-
customAttr: 'value',
890-
sandbox: false
891-
},
892-
});
859+
expect(kit.selectPlacements).toHaveBeenCalledWith(options);
893860
});
894861

895862
it('should set sandbox in placement attributes when not initialized globally', () => {
@@ -920,13 +887,7 @@ describe('RoktManager', () => {
920887
};
921888

922889
roktManager.selectPlacements(options);
923-
expect(kit.selectPlacements).toHaveBeenCalledWith({
924-
attributes: {
925-
customAttr: 'value',
926-
sandbox: true
927-
},
928-
identifier: 'test-identifier',
929-
});
890+
expect(kit.selectPlacements).toHaveBeenCalledWith(options);
930891
});
931892

932893
it('should pass mapped attributes to kit.launcher.selectPlacements', () => {
@@ -971,7 +932,7 @@ describe('RoktManager', () => {
971932
firstname: 'John',
972933
lastname: 'Doe',
973934
score: 42,
974-
},
935+
}
975936
};
976937

977938
roktManager.selectPlacements(options);
@@ -1004,117 +965,7 @@ describe('RoktManager', () => {
1004965
};
1005966

1006967
roktManager.selectPlacements(options);
1007-
expect(kit.selectPlacements).toHaveBeenCalledWith({
1008-
attributes: {
1009-
'f.name': 'John',
1010-
'last_name': 'Doe',
1011-
'score': 42,
1012-
'age': 25,
1013-
},
1014-
});
1015-
});
1016-
1017-
it('should log developer passed attributes via verbose logger', async () => {
1018-
const kit: Partial<IRoktKit> = {
1019-
launcher: {
1020-
selectPlacements: jest.fn(),
1021-
hashAttributes: jest.fn(),
1022-
use: jest.fn(),
1023-
},
1024-
hashAttributes: jest.fn(),
1025-
selectPlacements: jest.fn().mockResolvedValue({}),
1026-
setExtensionData: jest.fn(),
1027-
use: jest.fn(),
1028-
};
1029-
1030-
roktManager.kit = kit as IRoktKit;
1031-
roktManager['placementAttributesMapping'] = [];
1032-
1033-
const mockIdentity = {
1034-
getCurrentUser: jest.fn().mockReturnValue({
1035-
getUserIdentities: () => ({
1036-
userIdentities: {}
1037-
}),
1038-
setUserAttributes: jest.fn()
1039-
}),
1040-
identify: jest.fn()
1041-
} as unknown as SDKIdentityApi;
1042-
1043-
roktManager['identityService'] = mockIdentity;
1044-
1045-
const options: IRoktSelectPlacementsOptions = {
1046-
attributes: {
1047-
'customAttr': 'value',
1048-
}
1049-
};
1050-
1051-
await roktManager.selectPlacements(options);
1052-
1053-
expect(mockMPInstance.Logger.verbose).toHaveBeenCalledWith(
1054-
'MParticle.Rokt selectPlacements called with attributes: {"customAttr":"value"}'
1055-
);
1056-
expect(kit.selectPlacements).toHaveBeenCalledWith({
1057-
attributes: {
1058-
'customAttr': 'value',
1059-
}
1060-
});
1061-
});
1062-
1063-
it('should log original attributes even after mapping', async () => {
1064-
const kit: Partial<IRoktKit> = {
1065-
launcher: {
1066-
selectPlacements: jest.fn(),
1067-
hashAttributes: jest.fn(),
1068-
use: jest.fn(),
1069-
},
1070-
hashAttributes: jest.fn(),
1071-
selectPlacements: jest.fn().mockResolvedValue({}),
1072-
setExtensionData: jest.fn(),
1073-
use: jest.fn(),
1074-
};
1075-
1076-
roktManager.kit = kit as IRoktKit;
1077-
roktManager['placementAttributesMapping'] = [
1078-
{
1079-
jsmap: null,
1080-
map: 'f.name',
1081-
maptype: 'UserAttributeClass.Name',
1082-
value: 'firstname'
1083-
}
1084-
];
1085-
1086-
const mockIdentity = {
1087-
getCurrentUser: jest.fn().mockReturnValue({
1088-
getUserIdentities: () => ({
1089-
userIdentities: {}
1090-
}),
1091-
setUserAttributes: jest.fn()
1092-
}),
1093-
identify: jest.fn()
1094-
} as unknown as SDKIdentityApi;
1095-
1096-
roktManager['identityService'] = mockIdentity;
1097-
1098-
const options: IRoktSelectPlacementsOptions = {
1099-
attributes: {
1100-
'f.name': 'John',
1101-
'userId': 'user123',
1102-
}
1103-
};
1104-
1105-
await roktManager.selectPlacements(options);
1106-
1107-
1108-
expect(mockMPInstance.Logger.verbose).toHaveBeenCalledWith(
1109-
'MParticle.Rokt selectPlacements called with attributes: {"f.name":"John","userId":"user123"}'
1110-
);
1111-
1112-
expect(kit.selectPlacements).toHaveBeenCalledWith({
1113-
attributes: {
1114-
'firstname': 'John',
1115-
'userId': 'user123',
1116-
}
1117-
});
968+
expect(kit.selectPlacements).toHaveBeenCalledWith(options);
1118969
});
1119970

1120971
it('should set the mapped attributes on the current user via setUserAttributes', async () => {
@@ -1204,13 +1055,7 @@ describe('RoktManager', () => {
12041055
};
12051056

12061057
await roktManager.selectPlacements(options);
1207-
expect(kit.selectPlacements).toHaveBeenCalledWith({
1208-
attributes: {
1209-
'email': 'test@example.com',
1210-
'sandbox': true
1211-
},
1212-
});
1213-
1058+
expect(kit.selectPlacements).toHaveBeenCalledWith(options);
12141059
expect(setUserAttributesSpy).not.toHaveBeenCalledWith({
12151060
sandbox: true
12161061
});
@@ -1735,6 +1580,49 @@ describe('RoktManager', () => {
17351580
// Verify selectPlacements was still called
17361581
expect(kit.selectPlacements).toHaveBeenCalled();
17371582
});
1583+
1584+
it('should log developer passed attributes via verbose logger', async () => {
1585+
const kit: Partial<IRoktKit> = {
1586+
launcher: {
1587+
selectPlacements: jest.fn(),
1588+
hashAttributes: jest.fn(),
1589+
use: jest.fn(),
1590+
},
1591+
hashAttributes: jest.fn(),
1592+
selectPlacements: jest.fn().mockResolvedValue({}),
1593+
setExtensionData: jest.fn(),
1594+
use: jest.fn(),
1595+
};
1596+
1597+
roktManager.kit = kit as IRoktKit;
1598+
1599+
const mockIdentity = {
1600+
getCurrentUser: jest.fn().mockReturnValue({
1601+
getUserIdentities: () => ({
1602+
userIdentities: {
1603+
email: 'test@example.com'
1604+
}
1605+
}),
1606+
setUserAttributes: jest.fn()
1607+
}),
1608+
identify: jest.fn()
1609+
} as unknown as SDKIdentityApi;
1610+
1611+
roktManager['identityService'] = mockIdentity;
1612+
1613+
const options: IRoktSelectPlacementsOptions = {
1614+
attributes: {
1615+
email: 'test@example.com',
1616+
customAttr: 'value',
1617+
}
1618+
};
1619+
1620+
await roktManager.selectPlacements(options);
1621+
1622+
expect(mockMPInstance.Logger.verbose).toHaveBeenCalledWith(
1623+
'MParticle.Rokt selectPlacements called with attributes: {"email":"test@example.com","customAttr":"value"}'
1624+
);
1625+
});
17381626
});
17391627

17401628
describe('#setExtensionData', () => {

0 commit comments

Comments
 (0)