From 13f7e3b94e6500529f1130a22692757d626c8e8d Mon Sep 17 00:00:00 2001 From: Sai Sankeerth Date: Fri, 9 Aug 2024 10:24:39 +0530 Subject: [PATCH] fix: source transformation integration test generation --- .../testcases/close_crm/group_creation.json | 3 ++- .../testcases/close_crm/lead_deletion.json | 3 ++- .../testcases/close_crm/lead_update.json | 3 ++- ...ject_input_event_with_batched_payload.json | 6 ++++-- ...single_object_input_event_with_no_cid.json | 3 ++- ..._event_with_normal_channel_and_action.json | 3 ++- .../mail_jet_when_no_email_is_present.json | 3 ++- .../testcases/moengage/batch_of_events.json | 4 ++-- .../testdata/testcases/segment/test_0.json | 3 ++- .../testcases/shopify/invalid_topic.json | 2 +- .../shopify/no_query_parameters.json | 2 +- .../testcases/shopify/topic_not_found.json | 2 +- test/integrations/sources/auth0/data.ts | 1 + test/integrations/sources/iterable/data.ts | 5 ++++- test/integrations/sources/mailjet/data.ts | 1 + test/integrations/sources/moengage/data.ts | 2 ++ test/integrations/sources/segment/data.ts | 1 + test/integrations/testTypes.ts | 2 ++ test/scripts/generateJson.ts | 20 +++++++++++++++---- 19 files changed, 50 insertions(+), 19 deletions(-) diff --git a/go/webhook/testcases/testdata/testcases/close_crm/group_creation.json b/go/webhook/testcases/testdata/testcases/close_crm/group_creation.json index 3bb8d60503..24bb4546b4 100644 --- a/go/webhook/testcases/testdata/testcases/close_crm/group_creation.json +++ b/go/webhook/testcases/testdata/testcases/close_crm/group_creation.json @@ -34,7 +34,8 @@ ] }, "previous_data": {} - } + }, + "source": {} }, "headers": { "Content-Type": "application/json" diff --git a/go/webhook/testcases/testdata/testcases/close_crm/lead_deletion.json b/go/webhook/testcases/testdata/testcases/close_crm/lead_deletion.json index 34a36a8da8..3b8a2ce578 100644 --- a/go/webhook/testcases/testdata/testcases/close_crm/lead_deletion.json +++ b/go/webhook/testcases/testdata/testcases/close_crm/lead_deletion.json @@ -43,7 +43,8 @@ "updated_by": "user_123", "created_by": "user_123" } - } + }, + "source": {} }, "headers": { "Content-Type": "application/json" diff --git a/go/webhook/testcases/testdata/testcases/close_crm/lead_update.json b/go/webhook/testcases/testdata/testcases/close_crm/lead_update.json index 38aeba6468..99cdfe061c 100644 --- a/go/webhook/testcases/testdata/testcases/close_crm/lead_update.json +++ b/go/webhook/testcases/testdata/testcases/close_crm/lead_update.json @@ -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" diff --git a/go/webhook/testcases/testdata/testcases/cordial/multiple_object_input_event_with_batched_payload.json b/go/webhook/testcases/testdata/testcases/cordial/multiple_object_input_event_with_batched_payload.json index 6ab438b077..1217608454 100644 --- a/go/webhook/testcases/testdata/testcases/cordial/multiple_object_input_event_with_batched_payload.json +++ b/go/webhook/testcases/testdata/testcases/cordial/multiple_object_input_event_with_batched_payload.json @@ -64,7 +64,8 @@ "product_name": ["wtp ab"], "product_group": ["women"] } - } + }, + "source": {} }, { "contact": { @@ -126,7 +127,8 @@ "product_name": ["wtp ab"], "product_group": ["women"] } - } + }, + "source": {} } ], "headers": { diff --git a/go/webhook/testcases/testdata/testcases/cordial/simple_single_object_input_event_with_no_cid.json b/go/webhook/testcases/testdata/testcases/cordial/simple_single_object_input_event_with_no_cid.json index eac08aea16..5b7f898cb3 100644 --- a/go/webhook/testcases/testdata/testcases/cordial/simple_single_object_input_event_with_no_cid.json +++ b/go/webhook/testcases/testdata/testcases/cordial/simple_single_object_input_event_with_no_cid.json @@ -49,7 +49,8 @@ "title": "Khaki Shirt", "test_key": "value" } - } + }, + "source": {} }, "headers": { "Content-Type": "application/json" diff --git a/go/webhook/testcases/testdata/testcases/cordial/simple_single_object_input_event_with_normal_channel_and_action.json b/go/webhook/testcases/testdata/testcases/cordial/simple_single_object_input_event_with_normal_channel_and_action.json index b7e4cae319..72c76816ec 100644 --- a/go/webhook/testcases/testdata/testcases/cordial/simple_single_object_input_event_with_normal_channel_and_action.json +++ b/go/webhook/testcases/testdata/testcases/cordial/simple_single_object_input_event_with_normal_channel_and_action.json @@ -44,7 +44,8 @@ "title": "Khaki Shirt", "test_key": "value" } - } + }, + "source": {} }, "headers": { "Content-Type": "application/json" diff --git a/go/webhook/testcases/testdata/testcases/mailjet/mail_jet_when_no_email_is_present.json b/go/webhook/testcases/testdata/testcases/mailjet/mail_jet_when_no_email_is_present.json index 301cf0a780..67935f116f 100644 --- a/go/webhook/testcases/testdata/testcases/mailjet/mail_jet_when_no_email_is_present.json +++ b/go/webhook/testcases/testdata/testcases/mailjet/mail_jet_when_no_email_is_present.json @@ -59,5 +59,6 @@ } ], "errQueue": [] - } + }, + "skip": "FIXME" } diff --git a/go/webhook/testcases/testdata/testcases/moengage/batch_of_events.json b/go/webhook/testcases/testdata/testcases/moengage/batch_of_events.json index 76f72961ca..58d4513db2 100644 --- a/go/webhook/testcases/testdata/testcases/moengage/batch_of_events.json +++ b/go/webhook/testcases/testdata/testcases/moengage/batch_of_events.json @@ -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", diff --git a/go/webhook/testcases/testdata/testcases/segment/test_0.json b/go/webhook/testcases/testdata/testcases/segment/test_0.json index d3103126c9..868300e20e 100644 --- a/go/webhook/testcases/testdata/testcases/segment/test_0.json +++ b/go/webhook/testcases/testdata/testcases/segment/test_0.json @@ -246,5 +246,6 @@ } ], "errQueue": [] - } + }, + "skip": "NoAnonID error" } diff --git a/go/webhook/testcases/testdata/testcases/shopify/invalid_topic.json b/go/webhook/testcases/testdata/testcases/shopify/invalid_topic.json index 5e176d4e5b..8439ce36e0 100644 --- a/go/webhook/testcases/testdata/testcases/shopify/invalid_topic.json +++ b/go/webhook/testcases/testdata/testcases/shopify/invalid_topic.json @@ -17,7 +17,7 @@ "output": { "response": { "status": 400, - "body": "Invalid topic in query_parameters" + "body": "Invalid topic in query_parameters\n" }, "queue": [], "errQueue": [ diff --git a/go/webhook/testcases/testdata/testcases/shopify/no_query_parameters.json b/go/webhook/testcases/testdata/testcases/shopify/no_query_parameters.json index 6466693059..1c69d854fd 100644 --- a/go/webhook/testcases/testdata/testcases/shopify/no_query_parameters.json +++ b/go/webhook/testcases/testdata/testcases/shopify/no_query_parameters.json @@ -12,7 +12,7 @@ "output": { "response": { "status": 400, - "body": "Query_parameters is missing" + "body": "Query_parameters is missing\n" }, "queue": [], "errQueue": [{}] diff --git a/go/webhook/testcases/testdata/testcases/shopify/topic_not_found.json b/go/webhook/testcases/testdata/testcases/shopify/topic_not_found.json index bd0e37ab98..5b97996d17 100644 --- a/go/webhook/testcases/testdata/testcases/shopify/topic_not_found.json +++ b/go/webhook/testcases/testdata/testcases/shopify/topic_not_found.json @@ -18,7 +18,7 @@ "output": { "response": { "status": 400, - "body": "Topic not found" + "body": "Topic not found\n" }, "queue": [], "errQueue": [ diff --git a/test/integrations/sources/auth0/data.ts b/test/integrations/sources/auth0/data.ts index daedf1b75d..b012887bc4 100644 --- a/test/integrations/sources/auth0/data.ts +++ b/test/integrations/sources/auth0/data.ts @@ -1508,6 +1508,7 @@ export const data = [ description: 'empty batch', module: 'source', version: 'v0', + skipGo: 'Created this case manually', input: { request: { body: [], diff --git a/test/integrations/sources/iterable/data.ts b/test/integrations/sources/iterable/data.ts index b6fda071e4..8912c83434 100644 --- a/test/integrations/sources/iterable/data.ts +++ b/test/integrations/sources/iterable/data.ts @@ -2216,4 +2216,7 @@ export const data = [ }, }, }, -]; +].map((tc) => ({ + ...tc, + overrideReceivedAt: true, +})); diff --git a/test/integrations/sources/mailjet/data.ts b/test/integrations/sources/mailjet/data.ts index f7f56182c8..2a8f3eaf46 100644 --- a/test/integrations/sources/mailjet/data.ts +++ b/test/integrations/sources/mailjet/data.ts @@ -236,6 +236,7 @@ export const data = [ description: 'MailJet when no email is present', module: 'source', version: 'v0', + skipGo: 'FIXME', input: { request: { body: [ diff --git a/test/integrations/sources/moengage/data.ts b/test/integrations/sources/moengage/data.ts index e8160ae08b..c307959121 100644 --- a/test/integrations/sources/moengage/data.ts +++ b/test/integrations/sources/moengage/data.ts @@ -264,6 +264,8 @@ const data = [ description: 'Batch of events', module: 'source', version: 'v0', + overrideReceivedAt: true, + overrideRequestIP: true, input: { request: { body: [ diff --git a/test/integrations/sources/segment/data.ts b/test/integrations/sources/segment/data.ts index d16176e8f1..8c66abd252 100644 --- a/test/integrations/sources/segment/data.ts +++ b/test/integrations/sources/segment/data.ts @@ -11,6 +11,7 @@ export const data: SrcTestCaseData[] = [ description: 'test-0', module: 'source', version: 'v0', + skipGo: 'NoAnonID error', input: { request: { body: [ diff --git a/test/integrations/testTypes.ts b/test/integrations/testTypes.ts index 3ccc792caf..3c5cf60600 100644 --- a/test/integrations/testTypes.ts +++ b/test/integrations/testTypes.ts @@ -52,6 +52,8 @@ export interface TestCaseData { input: inputType; output: outputType; mock?: mockType[]; + overrideReceivedAt?: string; + overrideRequestIP?: string; mockFns?: (mockAdapter: MockAdapter) => {}; } diff --git a/test/scripts/generateJson.ts b/test/scripts/generateJson.ts index a4a254f8f3..388c81477d 100644 --- a/test/scripts/generateJson.ts +++ b/test/scripts/generateJson.ts @@ -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; } @@ -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 }; } @@ -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'; }