Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: source transformation integration test generation #3645

Merged
merged 1 commit into from
Aug 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
]
},
"previous_data": {}
}
},
"source": {}
},
"headers": {
"Content-Type": "application/json"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@
"updated_by": "user_123",
"created_by": "user_123"
}
}
},
"source": {}
},
"headers": {
"Content-Type": "application/json"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@
"object_type": "opportunity",
"lead_id": "lead_123"
},
"subscription_id": "whsub_123"
"subscription_id": "whsub_123",
"source": {}
},
"headers": {
"Content-Type": "application/json"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@
"product_name": ["wtp ab"],
"product_group": ["women"]
}
}
},
"source": {}
},
{
"contact": {
Expand Down Expand Up @@ -126,7 +127,8 @@
"product_name": ["wtp ab"],
"product_group": ["women"]
}
}
},
"source": {}
}
],
"headers": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@
"title": "Khaki Shirt",
"test_key": "value"
}
}
},
"source": {}
},
"headers": {
"Content-Type": "application/json"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@
"title": "Khaki Shirt",
"test_key": "value"
}
}
},
"source": {}
},
"headers": {
"Content-Type": "application/json"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,6 @@
}
],
"errQueue": []
}
},
"skip": "FIXME"
}
Original file line number Diff line number Diff line change
Expand Up @@ -376,8 +376,8 @@
"shipping": 4,
"value": 31.98
},
"receivedAt": "2024-03-03T04:48:29.000Z",
"request_ip": "192.0.2.30",
"receivedAt": "2020-10-16T13:40:12.792+05:30",
"request_ip": "[::1]",
"sentAt": "2020-10-16T08:10:12.783Z",
"timestamp": "2020-10-16T13:40:12.791+05:30",
"type": "track",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,5 +246,6 @@
}
],
"errQueue": []
}
},
"skip": "NoAnonID error"
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"output": {
"response": {
"status": 400,
"body": "Invalid topic in query_parameters"
"body": "Invalid topic in query_parameters\n"
},
"queue": [],
"errQueue": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"output": {
"response": {
"status": 400,
"body": "Query_parameters is missing"
"body": "Query_parameters is missing\n"
},
"queue": [],
"errQueue": [{}]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"output": {
"response": {
"status": 400,
"body": "Topic not found"
"body": "Topic not found\n"
},
"queue": [],
"errQueue": [
Expand Down
1 change: 1 addition & 0 deletions test/integrations/sources/auth0/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1508,6 +1508,7 @@ export const data = [
description: 'empty batch',
module: 'source',
version: 'v0',
skipGo: 'Created this case manually',
input: {
request: {
body: [],
Expand Down
5 changes: 4 additions & 1 deletion test/integrations/sources/iterable/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2216,4 +2216,7 @@ export const data = [
},
},
},
];
].map((tc) => ({
...tc,
overrideReceivedAt: true,
}));
1 change: 1 addition & 0 deletions test/integrations/sources/mailjet/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ export const data = [
description: 'MailJet when no email is present',
module: 'source',
version: 'v0',
skipGo: 'FIXME',
input: {
request: {
body: [
Expand Down
2 changes: 2 additions & 0 deletions test/integrations/sources/moengage/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,8 @@ const data = [
description: 'Batch of events',
module: 'source',
version: 'v0',
overrideReceivedAt: true,
overrideRequestIP: true,
input: {
request: {
body: [
Expand Down
1 change: 1 addition & 0 deletions test/integrations/sources/segment/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export const data: SrcTestCaseData[] = [
description: 'test-0',
module: 'source',
version: 'v0',
skipGo: 'NoAnonID error',
input: {
request: {
body: [
Expand Down
2 changes: 2 additions & 0 deletions test/integrations/testTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ export interface TestCaseData {
input: inputType;
output: outputType;
mock?: mockType[];
overrideReceivedAt?: string;
overrideRequestIP?: string;
mockFns?: (mockAdapter: MockAdapter) => {};
}

Expand Down
20 changes: 16 additions & 4 deletions test/scripts/generateJson.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ function getErrorResponse(outputResponse?: responseType) {
const errorResponse = bodyKeys
.map((statusKey) => get(outputResponse, statusKey))
.find(isDefinedAndNotNull);
if (errorResponse) {
return errorResponse + '\n';
}
return errorResponse;
}

Expand All @@ -72,6 +75,9 @@ function getSourceRequestBody(testCase: any, version?: string) {
if (version === 'v0') {
return bodyElement;
}
if (Array.isArray(bodyElement?.event)) {
return bodyElement.event.map((e) => ({ ...e, source: bodyElement.source }));
}
return { ...bodyElement.event, source: bodyElement.source };
}

Expand Down Expand Up @@ -158,11 +164,17 @@ function generateSources(outputFolder: string, options: OptionValues) {
goTest.skip = testCase.skipGo;
}

goTest.output.queue.forEach((queueItem) => {
goTest.output.queue.forEach((queueItem, i) => {
queueItem['receivedAt'] =
testCase.output.response?.body?.[0]?.output?.batch?.[0]?.receivedAt ??
'2024-03-03T04:48:29.000Z';
queueItem['request_ip'] = '192.0.2.30';
testCase?.overrideReceivedAt &&
testCase.output.response?.body?.[0]?.output?.batch?.[i]?.receivedAt
? testCase.output.response?.body?.[0]?.output?.batch?.[i]?.receivedAt
: '2024-03-03T04:48:29.000Z';
queueItem['request_ip'] =
testCase?.overrideRequestIP &&
testCase.output.response?.body?.[0]?.output?.batch?.[i]?.request_ip
? testCase.output.response?.body?.[0]?.output?.batch?.[i]?.request_ip
: '192.0.2.30';
if (!queueItem['messageId']) {
queueItem['messageId'] = '00000000-0000-0000-0000-000000000000';
}
Expand Down
Loading