Skip to content

Commit 8b9980c

Browse files
rethrowing error for CM360 (#3178)
* rethrowing error for CM360 * adding test * adding test for other action * removing throwHttpErrors = false
1 parent d311d19 commit 8b9980c

File tree

3 files changed

+218
-2
lines changed

3 files changed

+218
-2
lines changed

packages/destination-actions/src/destinations/google-campaign-manager-360/conversionAdjustmentUpload/__tests__/index.test.ts

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1072,5 +1072,114 @@ describe('CampaignManager360.conversionAdjustmentUpload', () => {
10721072
})
10731073
).rejects.toThrowError('Conversions over 28 days old may not be updated.')
10741074
})
1075+
1076+
it('throws an 401 response when unauthorized', async () => {
1077+
const tsNow = new Date().toISOString()
1078+
const event = createTestEvent({
1079+
timestamp: tsNow,
1080+
event: 'Test Event',
1081+
context: {
1082+
traits: {
1083+
1084+
phone: '1234567890',
1085+
firstName: 'Daffy',
1086+
lastName: 'Duck',
1087+
streetAddress: '123 Daffy St',
1088+
city: 'Burbank',
1089+
state: 'CA',
1090+
postalCode: '98765',
1091+
countryCode: 'US'
1092+
}
1093+
},
1094+
properties: {
1095+
ordinal: '1',
1096+
quantity: '2',
1097+
value: '100',
1098+
gclid: '54321',
1099+
limitAdTracking: true,
1100+
childDirectedTreatment: true,
1101+
nonPersonalizedAd: true,
1102+
treatmentForUnderage: true
1103+
}
1104+
})
1105+
1106+
delete event.userId
1107+
1108+
nock(`https://dfareporting.googleapis.com/dfareporting/v4/userprofiles/${profileId}/conversions/batchupdate`)
1109+
.post('')
1110+
.reply(401)
1111+
1112+
await expect(
1113+
testDestination.testAction('conversionAdjustmentUpload', {
1114+
event,
1115+
mapping: {
1116+
requiredId: {
1117+
gclid: {
1118+
'@path': '$.properties.gclid'
1119+
}
1120+
},
1121+
timestamp: {
1122+
'@path': '$.timestamp'
1123+
},
1124+
value: {
1125+
'@path': '$.properties.value'
1126+
},
1127+
quantity: {
1128+
'@path': '$.properties.quantity'
1129+
},
1130+
ordinal: {
1131+
'@path': '$.properties.ordinal'
1132+
},
1133+
userDetails: {
1134+
email: {
1135+
'@path': '$.context.traits.email'
1136+
},
1137+
phone: {
1138+
'@path': '$.context.traits.phone'
1139+
},
1140+
firstName: {
1141+
'@path': '$.context.traits.firstName'
1142+
},
1143+
lastName: {
1144+
'@path': '$.context.traits.lastName'
1145+
},
1146+
streetAddress: {
1147+
'@path': '$.context.traits.streetAddress'
1148+
},
1149+
city: {
1150+
'@path': '$.context.traits.city'
1151+
},
1152+
state: {
1153+
'@path': '$.context.traits.state'
1154+
},
1155+
postalCode: {
1156+
'@path': '$.context.traits.postalCode'
1157+
},
1158+
countryCode: {
1159+
'@path': '$.context.traits.countryCode'
1160+
}
1161+
},
1162+
limitAdTracking: {
1163+
'@path': '$.properties.limitAdTracking'
1164+
},
1165+
childDirectedTreatment: {
1166+
'@path': '$.properties.childDirectedTreatment'
1167+
},
1168+
nonPersonalizedAd: {
1169+
'@path': '$.properties.nonPersonalizedAd'
1170+
},
1171+
treatmentForUnderage: {
1172+
'@path': '$.properties.treatmentForUnderage'
1173+
}
1174+
},
1175+
useDefaultMappings: true,
1176+
settings: {
1177+
profileId,
1178+
defaultFloodlightActivityId: floodlightActivityId,
1179+
defaultFloodlightConfigurationId: floodlightConfigurationId
1180+
}
1181+
})
1182+
).rejects.toThrowError('Unauthorized')
1183+
})
10751184
})
10761185
})

packages/destination-actions/src/destinations/google-campaign-manager-360/conversionUpload/__tests__/index.test.ts

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1184,5 +1184,113 @@ describe('Cm360.conversionUpload', () => {
11841184
})
11851185
).rejects.toThrowError('Conversions over 28 days old may not be updated.')
11861186
})
1187+
1188+
it('throws an error when a 401 response is returned', async () => {
1189+
const tsNow = new Date().toISOString()
1190+
1191+
const event = createTestEvent({
1192+
timestamp: tsNow,
1193+
event: 'Test Event',
1194+
context: {
1195+
traits: {
1196+
1197+
phone: '1234567890',
1198+
firstName: 'Daffy',
1199+
lastName: 'Duck',
1200+
streetAddress: '123 Daffy St',
1201+
city: 'Burbank',
1202+
state: 'CA',
1203+
postalCode: '98765',
1204+
countryCode: 'US'
1205+
}
1206+
},
1207+
properties: {
1208+
ordinal: '1',
1209+
quantity: '1',
1210+
value: '123',
1211+
gclid: '54321',
1212+
limitAdTracking: true,
1213+
childDirectedTreatment: true,
1214+
nonPersonalizedAd: true,
1215+
treatmentForUnderage: true
1216+
}
1217+
})
1218+
1219+
nock(`https://dfareporting.googleapis.com/dfareporting/v4/userprofiles/${profileId}/conversions/batchinsert`)
1220+
.post('')
1221+
.reply(401)
1222+
1223+
await expect(
1224+
testDestination.testAction('conversionUpload', {
1225+
event,
1226+
mapping: {
1227+
requiredId: {
1228+
gclid: {
1229+
'@path': '$.properties.gclid'
1230+
}
1231+
},
1232+
timestamp: {
1233+
'@path': '$.timestamp'
1234+
},
1235+
value: {
1236+
'@path': '$.properties.value'
1237+
},
1238+
quantity: {
1239+
'@path': '$.properties.quantity'
1240+
},
1241+
ordinal: {
1242+
'@path': '$.properties.ordinal'
1243+
},
1244+
userDetails: {
1245+
email: {
1246+
'@path': '$.context.traits.email'
1247+
},
1248+
phone: {
1249+
'@path': '$.context.traits.phone'
1250+
},
1251+
firstName: {
1252+
'@path': '$.context.traits.firstName'
1253+
},
1254+
lastName: {
1255+
'@path': '$.context.traits.lastName'
1256+
},
1257+
streetAddress: {
1258+
'@path': '$.context.traits.streetAddress'
1259+
},
1260+
city: {
1261+
'@path': '$.context.traits.city'
1262+
},
1263+
state: {
1264+
'@path': '$.context.traits.state'
1265+
},
1266+
postalCode: {
1267+
'@path': '$.context.traits.postalCode'
1268+
},
1269+
countryCode: {
1270+
'@path': '$.context.traits.countryCode'
1271+
}
1272+
},
1273+
limitAdTracking: {
1274+
'@path': '$.properties.limitAdTracking'
1275+
},
1276+
childDirectedTreatment: {
1277+
'@path': '$.properties.childDirectedTreatment'
1278+
},
1279+
nonPersonalizedAd: {
1280+
'@path': '$.properties.nonPersonalizedAd'
1281+
},
1282+
treatmentForUnderage: {
1283+
'@path': '$.properties.treatmentForUnderage'
1284+
}
1285+
},
1286+
useDefaultMappings: true,
1287+
settings: {
1288+
profileId,
1289+
defaultFloodlightActivityId: floodlightActivityId,
1290+
defaultFloodlightConfigurationId: floodlightConfigurationId
1291+
}
1292+
})
1293+
).rejects.toThrowError('Unauthorized')
1294+
})
11871295
})
11881296
})

packages/destination-actions/src/destinations/google-campaign-manager-360/utils.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,7 @@ export async function send(
4242
'Content-Type': 'application/json',
4343
Host: 'dfareporting.googleapis.com'
4444
},
45-
json,
46-
throwHttpErrors: false
45+
json
4746
}
4847
)
4948

0 commit comments

Comments
 (0)