Skip to content
This repository has been archived by the owner on Mar 10, 2024. It is now read-only.

feat: Sequence integration tests #1843

Merged
merged 5 commits into from
Nov 3, 2023
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
2 changes: 2 additions & 0 deletions apps/api/integration-test-environment.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@ const toPipedriveObjectName = {
const toOutreachObjectName = {
contact: 'prospects',
account: 'accounts',
sequence: 'sequences',
};

const toSalesloftObjectName = {
contact: 'people',
account: 'accounts',
sequence: 'cadences',
};

const getDeletePassthroughRequest = (id, objectName, providerName) => {
Expand Down
177 changes: 177 additions & 0 deletions apps/api/routes/engagement/v2/sequence.integration.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
/**
* Tests sequences endpoints
*
* @group integration/engagement/v2/sequences
* @jest-environment ./integration-test-environment
*/

import type {
CreateContactRequest,
CreateContactResponse,
CreateSequenceRequest,
CreateSequenceResponse,
CreateSequenceStateRequest,
CreateSequenceStateResponse,
GetSequenceResponse,
} from '@supaglue/schemas/v2/engagement';

export function getTestContact() {
return {
first_name: `first ${Math.random().toString()}`,
last_name: `last ${Math.random().toString()}`,
job_title: 'job title',
email_addresses: [
{
email_address: `test${Math.random().toString()}@mydomain.com`,
email_address_type: 'primary' as 'primary' | null,
},
],
} satisfies CreateContactRequest['record'];
}

function getTestSequence() {
return {
name: `Test Sequence ${Math.random().toString()}`,
type: 'team',
steps: [
{
type: 'manual_email',
is_reply: false,
template: {
name: 'what is up~!',
subject: 'hello world again',
body: 'Hi there, how are you doing?',
},
},
{
interval_seconds: 86400,
is_reply: true,
type: 'auto_email',
template: {
name: 'what is up~!',
subject: 'hello world again',
body: 'Hi there, how are you doing?',
},
},
{
interval_seconds: 172800,
is_reply: true,
type: 'call',
task_note: 'my call notes',
template: {
name: 'what is up~!',
subject: 'hello world again',
body: 'Hi there, how are you doing?',
},
},
{
interval_seconds: 0,
is_reply: true,
type: 'task',
task_note: 'my task notes',
template: {
name: 'what is up~!',
subject: 'hello world again',
body: 'Hi there, how are you doing?',
},
},
],
} satisfies CreateSequenceRequest['record'];
}

/** Required for sequence state creation. Hard coding as a result */
const OUTREACH_MAILBOX_ID = '3';
const APOLLO_MAILBOX_ID = '651c4cb3520e8800a3808e8a';

describe('sequence', () => {
let testSequence: ReturnType<typeof getTestSequence>;

beforeEach(() => {
testSequence = getTestSequence();
});

test(`Error body`, async () => {
testSequence.steps[0].interval_seconds = 123;
const response = await apiClient.post<CreateSequenceResponse>(
'/engagement/v2/sequences',
{ record: testSequence },
{ headers: { 'x-provider-name': 'salesloft' } }
);
expect(response.status).toEqual(400);
expect(response.data.errors?.[0].title).toMatch('Salesloft only supports intervals in whole days');
});

describe.each(['outreach', 'salesloft', 'apollo'])('%s', (providerName) => {
test(`POST /`, async () => {
const response = await apiClient.post<CreateSequenceResponse>(
'/engagement/v2/sequences',
{ record: testSequence },
{
headers: { 'x-provider-name': providerName },
}
);
expect(response.status).toEqual(201);
expect(response.data.record?.id).toBeTruthy();
addedObjects.push({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this get cleaned up at the end even if there are active contacts on it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image
Yes, it appears so.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Though delete is only supported in outreach api though.

Copy link
Contributor Author

@tonyxiao tonyxiao Nov 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is salesloft

image

And for apollo I don't think there is delete at all, only archive.

id: response.data.record?.id as string,
providerName,
objectName: 'sequence',
});
const getResponse = await apiClient.get<GetSequenceResponse>(
`/engagement/v2/sequences/${response.data.record?.id}`,
{
headers: { 'x-provider-name': providerName },
}
);

expect(getResponse.status).toEqual(200);
expect(getResponse.data.id).toEqual(response.data.record?.id);
expect(getResponse.data.name).toEqual(testSequence.name);
expect(getResponse.data.num_steps).toEqual(testSequence.steps?.length);
expect(getResponse.data.share_type).toEqual('team');

const contactRes = await apiClient.post<CreateContactResponse>(
'/engagement/v2/contacts',
{ record: getTestContact() },
{ headers: { 'x-provider-name': providerName } }
);
expect(contactRes.status).toEqual(201);
expect(contactRes.data.record?.id).toBeTruthy();

addedObjects.push({
id: contactRes.data.record?.id as string,
providerName,
objectName: 'contact',
});

const stateResponse = await apiClient.post<CreateSequenceStateResponse>(
'/engagement/v2/sequence_states',
{
record: {
contact_id: contactRes.data.record!.id,
sequence_id: response.data.record!.id,
mailbox_id:
providerName === 'outreach'
? OUTREACH_MAILBOX_ID
: providerName === 'apollo'
? APOLLO_MAILBOX_ID
: undefined,
} satisfies CreateSequenceStateRequest['record'],
},
{ headers: { 'x-provider-name': providerName } }
);
expect(stateResponse.status).toEqual(201);
expect(stateResponse.data.record?.id).toBeTruthy();

addedObjects.push({
id: stateResponse.data.record?.id as string,
providerName,
objectName: 'sequence_state',
});

// test that the db was updated
const dbSequence = await db.query('SELECT * FROM engagement_sequences WHERE id = $1', [response.data.record?.id]);
expect(dbSequence.rows[0].name).toEqual(testSequence.name);
}, 120000);
});
});
10 changes: 8 additions & 2 deletions packages/core/remotes/impl/salesloft/mappers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,10 @@ describe('Salesloft mapper tests', () => {
"step_groups": [
{
"automated": true,
"automated_settings": undefined,
"automated_settings": {
"delay_time": 0,
"send_type": "after_time_delay",
},
"day": 2,
"due_immediately": false,
"reference_id": 1,
Expand All @@ -267,7 +270,10 @@ describe('Salesloft mapper tests', () => {
},
{
"automated": true,
"automated_settings": undefined,
"automated_settings": {
"delay_time": 0,
"send_type": "after_time_delay",
},
"day": 4,
"due_immediately": false,
"reference_id": 2,
Expand Down
4 changes: 1 addition & 3 deletions packages/core/remotes/impl/salesloft/mappers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -396,9 +396,7 @@ export const toSalesloftCadenceStepImportParams = (step: SequenceStepCreateParam
day,
automated: step.type === 'auto_email',
automated_settings:
step.type === 'auto_email' && delayInMins !== 0
? { send_type: 'after_time_delay', delay_time: delayInMins }
: undefined,
step.type === 'auto_email' ? { send_type: 'after_time_delay', delay_time: delayInMins } : undefined,
tonyxiao marked this conversation as resolved.
Show resolved Hide resolved
due_immediately: false,
steps: cadenceStep ? [cadenceStep] : [],
reference_id: step.order ?? null,
Expand Down