Skip to content

Commit

Permalink
chore: refactor intercom proxy tests to new component structure
Browse files Browse the repository at this point in the history
  • Loading branch information
mihir-4116 committed Feb 13, 2024
1 parent 33d4d62 commit 6d7c637
Show file tree
Hide file tree
Showing 2 changed files with 174 additions and 91 deletions.
171 changes: 171 additions & 0 deletions test/integrations/destinations/intercom/dataDelivery/business.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
import { ProxyMetdata } from '../../../../../src/types';
import { generateProxyV0Payload, generateProxyV1Payload } from '../../../testUtils';

const commonHeaders = {
'Content-Type': 'application/json',
Authorization: 'Bearer intercomApiKey',
Accept: 'application/json',
'Intercom-Version': '1.4',
};

const createUserPayload = {
email: '[email protected]',
phone: '9876543210',
name: 'Test Name',
signed_up_at: 1601493060,
last_seen_user_agent: 'unknown',
update_last_request_at: true,
user_id: 'test_user_id_1',
custom_attributes: {
anonymousId: '58b21c2d-f8d5-4410-a2d0-b268a26b7e33',
key1: 'value1',
'address.city': 'Kolkata',
'address.state': 'West Bengal',
'originalArray[0].nested_field': 'nested value',
'originalArray[0].tags[0]': 'tag_1',
'originalArray[0].tags[1]': 'tag_2',
'originalArray[0].tags[2]': 'tag_3',
'originalArray[1].nested_field': 'nested value',
'originalArray[1].tags[0]': 'tag_1',
'originalArray[2].nested_field': 'nested value',
},
};

const commonRequestParameters = {
JSON: createUserPayload,
headers: commonHeaders,
};

const proxyMetdata: ProxyMetdata = {
jobId: 1,
attemptNum: 1,
userId: 'dummyUserId',
sourceId: 'dummySourceId',
destinationId: 'dummyDestinationId',
workspaceId: 'dummyWorkspaceId',
secret: {},
dontBatch: false,
};

const metadataArray = [proxyMetdata];

export const testScenariosForV0API = [
{
id: 'intercom_v0_other_scenario_1',
name: 'intercom',
description: '[Proxy v0 API] :: Scenario for testing Request Timeout error from destination',
successCriteria: 'Should return 500 status code with error message',
scenario: 'Business',
feature: 'dataDelivery',
module: 'destination',
version: 'v0',
input: {
request: {
body: generateProxyV0Payload({
...commonRequestParameters,
endpoint: 'https://api.intercom.io/users/test1',
}),
method: 'POST',
},
},
output: {
response: {
status: 500,
body: {
output: {
status: 500,
message:
'[Intercom Response Handler] Request failed for destination intercom with status: 408',
destinationResponse: {
response: {
type: 'error.list',
request_id: '000on04msi4jpk7d3u60',
errors: [
{
code: 'Request Timeout',
message: 'The server would not wait any longer for the client',
},
],
},
status: 408,
},
statTags: {
destType: 'INTERCOM',
errorCategory: 'network',
destinationId: 'default-destinationId',
workspaceId: 'default-workspaceId',
errorType: 'retryable',
feature: 'dataDelivery',
implementation: 'native',
module: 'destination',
},
},
},
},
},
},
];

export const testScenariosForV1API = [
{
id: 'intercom_v1_other_scenario_1',
name: 'intercom',
description: '[Proxy v1 API] :: Scenario for testing Request Timeout error from destination',
successCriteria: 'Should return 500 status code with error message',
scenario: 'Business',
feature: 'dataDelivery',
module: 'destination',
version: 'v1',
input: {
request: {
body: generateProxyV1Payload(
{
...commonRequestParameters,
endpoint: 'https://api.intercom.io/users/test1',
},
metadataArray,
),
method: 'POST',
},
},
output: {
response: {
status: 200,
body: {
output: {
message:
'[Intercom Response Handler] Request failed for destination intercom with status: 408',
response: [
{
error:
'{"type":"error.list","request_id":"000on04msi4jpk7d3u60","errors":[{"code":"Request Timeout","message":"The server would not wait any longer for the client"}]}',
metadata: {
attemptNum: 1,
destinationId: 'dummyDestinationId',
dontBatch: false,
jobId: 1,
secret: {},
sourceId: 'dummySourceId',
userId: 'dummyUserId',
workspaceId: 'dummyWorkspaceId',
},
statusCode: 500,
},
],
statTags: {
destType: 'INTERCOM',
destinationId: 'dummyDestinationId',
errorCategory: 'network',
errorType: 'retryable',
feature: 'dataDelivery',
implementation: 'native',
module: 'destination',
workspaceId: 'dummyWorkspaceId',
},
status: 500,
},
},
},
},
},
];
94 changes: 3 additions & 91 deletions test/integrations/destinations/intercom/dataDelivery/data.ts
Original file line number Diff line number Diff line change
@@ -1,91 +1,3 @@
export const data = [
{
name: 'intercom',
description: 'Test 0',
feature: 'dataDelivery',
module: 'destination',
version: 'v0',
input: {
request: {
body: {
version: '1',
type: 'REST',
method: 'POST',
endpoint: 'https://api.intercom.io/users/test1',
headers: {
'Content-Type': 'application/json',
Authorization: 'Bearer intercomApiKey',
Accept: 'application/json',
'Intercom-Version': '1.4',
},
params: {},
body: {
JSON: {
email: '[email protected]',
phone: '9876543210',
name: 'Test Name',
signed_up_at: 1601493060,
last_seen_user_agent: 'unknown',
update_last_request_at: true,
user_id: 'test_user_id_1',
custom_attributes: {
anonymousId: '58b21c2d-f8d5-4410-a2d0-b268a26b7e33',
key1: 'value1',
'address.city': 'Kolkata',
'address.state': 'West Bengal',
'originalArray[0].nested_field': 'nested value',
'originalArray[0].tags[0]': 'tag_1',
'originalArray[0].tags[1]': 'tag_2',
'originalArray[0].tags[2]': 'tag_3',
'originalArray[1].nested_field': 'nested value',
'originalArray[1].tags[0]': 'tag_1',
'originalArray[2].nested_field': 'nested value',
},
},
XML: {},
JSON_ARRAY: {},
FORM: {},
},
files: {},
userId: '58b21c2d-f8d5-4410-a2d0-b268a26b7e33',
},
method: 'POST',
},
},
output: {
response: {
status: 500,
body: {
output: {
status: 500,
message:
'[Intercom Response Handler] Request failed for destination intercom with status: 408',
destinationResponse: {
response: {
type: 'error.list',
request_id: '000on04msi4jpk7d3u60',
errors: [
{
code: 'Request Timeout',
message: 'The server would not wait any longer for the client',
},
],
},
status: 408,
},
statTags: {
destType: 'INTERCOM',
errorCategory: 'network',
destinationId: 'Non-determininable',
workspaceId: 'Non-determininable',
errorType: 'retryable',
feature: 'dataDelivery',
implementation: 'native',
module: 'destination',
},
},
},
},
},
},
];
import { testScenariosForV0API, testScenariosForV1API } from './business';

export const data = [...testScenariosForV0API, ...testScenariosForV1API];

0 comments on commit 6d7c637

Please sign in to comment.