-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[DEV-2016] Connect cognito event to active campaign (#1253)
* connect add contant to AC * update and delete * Add test and refactor handlers * Refactor get user from cognito * Fix active campaing client * Update packages/active-campaign-client/src/__tests__/helpers/deleteContact.test.ts Co-authored-by: marcobottaro <[email protected]> * Update packages/active-campaign-client/src/__tests__/helpers/updateContact.test.ts Co-authored-by: marcobottaro <[email protected]> * Update packages/active-campaign-client/src/__tests__/helpers/listUsersCommandOutputToUser.test.ts Co-authored-by: marcobottaro <[email protected]> * Update packages/active-campaign-client/.env.example Co-authored-by: marcobottaro <[email protected]> * Unify AC integration tests * Merge tests * Add changeset --------- Co-authored-by: t <[email protected]> Co-authored-by: tommaso1 <[email protected]> Co-authored-by: marcobottaro <[email protected]>
- Loading branch information
1 parent
7fe96a6
commit c6a3f41
Showing
26 changed files
with
1,500 additions
and
261 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"active-campaign-client": minor | ||
--- | ||
|
||
Refactor active campaign pacakge and create index file |
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,3 +1,5 @@ | ||
AC_BASE_URL=your_account_url | ||
AC_API_KEY=your_api_key | ||
SENDER_URL=localhost:3000 | ||
AWS_REGION="region" | ||
AWS_USER_POOL_ID="region_DFWF81fRa" |
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
43 changes: 43 additions & 0 deletions
43
packages/active-campaign-client/src/__tests__/contact_flow.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,43 @@ | ||
import { addContact } from '../helpers/addContact'; | ||
import { deleteContact } from '../helpers/deleteContact'; | ||
import { updateContact } from '../helpers/updateContact'; | ||
import { User } from '../types/user'; | ||
|
||
const user: User = { | ||
username: '466e0280-9061-7007-c3e0-beb6be672f68', | ||
email: `test@example${new Date().getTime()}e.com`, | ||
given_name: 'Giovanni', | ||
family_name: 'Doe', | ||
'custom:mailinglist_accepted': 'true', | ||
'custom:company_type': 'Test Co', | ||
'custom:job_role': 'Developer', | ||
}; | ||
|
||
// remove .skip to run the test, be aware it does a real API call so it will create, update and delete a contact in the active campaign account | ||
// NB: this test is not idempotent and it must run in this order | ||
describe.skip('Active campaign integration contact flow', () => { | ||
it('should create a contact successfully', async () => { | ||
const response = await addContact(user); | ||
expect(response.statusCode).toBe(200); | ||
}); | ||
|
||
it('should update a contact successfully', async () => { | ||
const updatedUser: User = { | ||
...user, | ||
email: `test@example${new Date().getTime()}e.com`, | ||
given_name: 'new given_name', | ||
family_name: 'new family_name', | ||
'custom:mailinglist_accepted': 'true', | ||
'custom:company_type': 'new company_type', | ||
'custom:job_role': 'new job_role', | ||
}; | ||
|
||
const response = await updateContact(updatedUser); | ||
expect(response.statusCode).toBe(200); | ||
}); | ||
|
||
it('should delete a contact successfully', async () => { | ||
const response = await deleteContact(user.username); | ||
expect(response.statusCode).toBe(200); | ||
}); | ||
}); |
5 changes: 0 additions & 5 deletions
5
packages/active-campaign-client/src/__tests__/empty-test.test.ts
This file was deleted.
Oops, something went wrong.
39 changes: 0 additions & 39 deletions
39
packages/active-campaign-client/src/__tests__/handlers/addContact.test.ts
This file was deleted.
Oops, something went wrong.
34 changes: 0 additions & 34 deletions
34
packages/active-campaign-client/src/__tests__/handlers/deleteContact.test.ts
This file was deleted.
Oops, something went wrong.
39 changes: 0 additions & 39 deletions
39
packages/active-campaign-client/src/__tests__/handlers/updateContact.test.ts
This file was deleted.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
...src/__tests__/handlers/createList.test.ts → .../src/__tests__/helpers/createList.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
2 changes: 1 addition & 1 deletion
2
...src/__tests__/handlers/deleteList.test.ts → .../src/__tests__/helpers/deleteList.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
82 changes: 82 additions & 0 deletions
82
packages/active-campaign-client/src/__tests__/helpers/listUsersCommandOutputToUser.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,82 @@ | ||
import { ListUsersCommandOutput } from '@aws-sdk/client-cognito-identity-provider'; | ||
import { listUsersCommandOutputToUser } from '../../helpers/listUsersCommandOutputToUser'; | ||
import { User } from '../../types/user'; | ||
|
||
const listUsersCommandOutput: ListUsersCommandOutput = { | ||
$metadata: { | ||
httpStatusCode: 200, | ||
requestId: 'c67ec280-799a-40d6-b398-2a2b31aefbbd', | ||
attempts: 1, | ||
totalRetryDelay: 0, | ||
}, | ||
Users: [ | ||
{ | ||
Attributes: [ | ||
{ | ||
Name: 'email', | ||
Value: '[email protected]', | ||
}, | ||
{ | ||
Name: 'email_verified', | ||
Value: 'true', | ||
}, | ||
{ | ||
Name: 'family_name', | ||
Value: 'Doe', | ||
}, | ||
{ | ||
Name: 'given_name', | ||
Value: 'Giovanni', | ||
}, | ||
{ | ||
Name: 'custom:mailinglist_accepted', | ||
Value: 'true', | ||
}, | ||
{ | ||
Name: 'custom:user_preferences', | ||
Value: | ||
'{"subscribedWebinarSlugs":["comunicazioni-a-valore-legale","nuove-api-io","live","cooming-soon","test","always-live","PagoPA-multe"]}', | ||
}, | ||
{ | ||
Name: 'custom:company_type', | ||
Value: 'gestore-di-pubblico-servizio', | ||
}, | ||
{ | ||
Name: 'custom:job_role', | ||
Value: 'Developer', | ||
}, | ||
{ | ||
Name: 'custom:privacy_accepted', | ||
Value: 'true', | ||
}, | ||
{ | ||
Name: 'sub', | ||
Value: 'c67ec280-799a-40d6-b398-2a2b31aefbbd', | ||
}, | ||
], | ||
Enabled: true, | ||
UserStatus: 'CONFIRMED', | ||
Username: 'c67ec280-799a-40d6-b398-2a2b31aefbbd', | ||
}, | ||
], | ||
}; | ||
|
||
describe('addContact handler', () => { | ||
it('should properly convert ListUsersCommandOutput to User', async () => { | ||
const user = listUsersCommandOutputToUser(listUsersCommandOutput); | ||
const expectedUser: User = { | ||
username: 'c67ec280-799a-40d6-b398-2a2b31aefbbd', | ||
email: '[email protected]', | ||
given_name: 'Giovanni', | ||
family_name: 'Doe', | ||
'custom:mailinglist_accepted': 'true', | ||
'custom:company_type': 'gestore-di-pubblico-servizio', | ||
'custom:job_role': 'Developer', | ||
}; | ||
expect(user).toBeDefined(); | ||
Object.keys(expectedUser).forEach((value) => { | ||
const key = value as keyof User; | ||
expect(user![key]).toBe(expectedUser[key]); | ||
}); | ||
}); | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { CognitoIdentityProviderClient } from '@aws-sdk/client-cognito-identity-provider'; | ||
|
||
export const cognitoClient = new CognitoIdentityProviderClient({ | ||
region: process.env.AWS_REGION, | ||
}); |
52 changes: 0 additions & 52 deletions
52
packages/active-campaign-client/src/handlers/addContact.ts
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.