This repository has been archived by the owner on Mar 10, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 56
feat: Sequence integration tests #1843
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
247d524
feat: Sequence integration tests
tonyxiao e08b7ab
fix: Integration tests
tonyxiao 4dbe9b8
fix: Broken test and PR commets
tonyxiao fe350f3
chore: Adding test for sequence state as well as failing cases
tonyxiao 02c6654
fix: oops skipped test, review your commits yo!
tonyxiao File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
177 changes: 177 additions & 0 deletions
177
apps/api/routes/engagement/v2/sequence.integration.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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({ | ||
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); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it appears so.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is salesloft
And for apollo I don't think there is delete at all, only archive.