Skip to content

Commit

Permalink
fix: add validation for type in google pubsub (#3578)
Browse files Browse the repository at this point in the history
  • Loading branch information
ItsSudip authored Jul 19, 2024
1 parent f840d54 commit 1bef212
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/v0/destinations/googlepubsub/util.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const { ConfigurationAuthError } = require('@rudderstack/integrations-lib');
const {
getHashFromArray,
getValueFromMessage,
Expand All @@ -18,6 +19,10 @@ const getTopic = (event) => {
const { eventToTopicMap } = destination.Config;
const hashMap = getHashFromArray(eventToTopicMap, 'from', 'to');

if (!message.type) {
throw new ConfigurationAuthError('type is required for event');
}

return (
(message.event ? hashMap[message.event.toLowerCase()] : null) ||
hashMap[message.type.toLowerCase()] ||
Expand Down
68 changes: 68 additions & 0 deletions test/integrations/destinations/googlepubsub/processor/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1314,4 +1314,72 @@ export const data = [
},
},
},
{
name: 'googlepubsub',
description: 'Test 13',
feature: 'processor',
module: 'destination',
version: 'v0',
input: {
request: {
body: [
{
message: {
sentAt: '2020-08-28T15:11:56.167Z',
category: 'Food',
messageId:
'node-cfc5fb7ec83b82bc29e16336a11331e2-0ba97212-0f6e-44cd-a0f1-c20b8b7a7cba',
anonymousId: 'abcdeeeeeeeexxxx111',
originalTimestamp: '2020-08-28T15:11:56.162Z',
name: 'Pizza',
_metadata: {
nodeVersion: '10.22.0',
},
},
destination: {
Config: {
credentials: 'abc',
eventToTopicMap: [
{
from: 'track',
to: 'Test-Topic',
},
{
from: '*',
to: 'test',
},
],
eventToAttributesMap: [
{
from: 'track',
to: 'properties.nestedObject.this',
},
],
},
},
},
],
},
},
output: {
response: {
status: 200,
body: [
{
error: 'type is required for event',
statTags: {
destType: 'GOOGLEPUBSUB',
errorCategory: 'dataValidation',
errorType: 'configuration',
feature: 'processor',
implementation: 'native',
meta: 'accessTokenExpired',
module: 'destination',
},
statusCode: 400,
},
],
},
},
},
];

0 comments on commit 1bef212

Please sign in to comment.