-
Notifications
You must be signed in to change notification settings - Fork 253
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from StackAdapt/jc/onDelete-handle
(ITE-146) Update Segment Engage Destination to handle onDelete events
- Loading branch information
Showing
6 changed files
with
148 additions
and
324 deletions.
There are no files selected for viewing
97 changes: 97 additions & 0 deletions
97
packages/destination-actions/src/destinations/stackadapt-audiences/__tests__/index.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,97 @@ | ||
import { createTestEvent, createTestIntegration } from '@segment/actions-core' | ||
import nock from 'nock' | ||
import Definition from '../index' | ||
import { GQL_ENDPOINT } from '../functions' | ||
|
||
const testDestination = createTestIntegration(Definition) | ||
|
||
describe('StackAdapt Audiences - Destination Tests', () => { | ||
const mockSettings = { apiKey: 'test-api-key' } | ||
const gqlHostUrl = 'https://api.stackadapt.com' | ||
|
||
afterEach(() => { | ||
nock.cleanAll() | ||
}) | ||
|
||
describe('testAuthentication', () => { | ||
it('should validate authentication inputs', async () => { | ||
nock(GQL_ENDPOINT, { | ||
reqheaders: { | ||
authorization: `Bearer ${mockSettings.apiKey}`, | ||
'content-type': 'application/json' | ||
} | ||
}) | ||
.post('', { | ||
query: /tokenInfo/ | ||
}) | ||
.reply(200, { | ||
data: { | ||
tokenInfo: { | ||
scopesByAdvertiser: { | ||
nodes: [ | ||
{ | ||
advertiser: { name: 'Test Advertiser' }, | ||
scopes: ['WRITE'] | ||
} | ||
] | ||
} | ||
} | ||
} | ||
}) | ||
|
||
await expect(testDestination.testAuthentication(mockSettings)).resolves.not.toThrowError() | ||
}) | ||
|
||
it('should fail if authentication is invalid', async () => { | ||
nock(GQL_ENDPOINT).post('').reply(403, {}) | ||
|
||
await expect(testDestination.testAuthentication(mockSettings)).rejects.toThrowError('403Forbidden') | ||
}) | ||
}) | ||
|
||
describe('onDelete', () => { | ||
it('should delete a user with a given userId', async () => { | ||
const userId = '9999' | ||
const event = createTestEvent({ userId, type: 'identify' }) | ||
|
||
// Mock the GraphQL deleteProfilesWithExternalIds mutation | ||
nock(gqlHostUrl) | ||
.post('/graphql', (body) => { | ||
return body.query.includes('deleteProfilesWithExternalIds') && body.query.includes(userId) | ||
}) | ||
.reply(200, { | ||
data: { deleteProfilesWithExternalIds: { userErrors: [] } } | ||
}) | ||
|
||
const response = await testDestination.onDelete!(event, { | ||
apiKey: 'test-api-key' | ||
}) | ||
|
||
expect(response).toMatchObject({ | ||
data: { deleteProfilesWithExternalIds: { userErrors: [] } } | ||
}) | ||
}) | ||
|
||
it('should throw an error if profile deletion fails with userErrors', async () => { | ||
const userId = '9999' | ||
const event = createTestEvent({ userId, type: 'identify' }) | ||
|
||
// Mock the GraphQL deleteProfilesWithExternalIds mutation with an error | ||
nock(gqlHostUrl) | ||
.post('/graphql') | ||
.reply(200, { | ||
data: { | ||
deleteProfilesWithExternalIds: { | ||
userErrors: [{ message: 'Deletion failed' }] | ||
} | ||
} | ||
}) | ||
|
||
await expect( | ||
testDestination.onDelete!(event, { | ||
apiKey: 'test-api-key' | ||
}) | ||
).rejects.toThrowError('Profile deletion was not successful: Deletion failed') | ||
}) | ||
}) | ||
}) |
182 changes: 0 additions & 182 deletions
182
...on-actions/src/destinations/stackadapt-audiences/deleteProfile/__tests__/onDelete.test.ts
This file was deleted.
Oops, something went wrong.
73 changes: 0 additions & 73 deletions
73
...ages/destination-actions/src/destinations/stackadapt-audiences/deleteProfile/functions.ts
This file was deleted.
Oops, something went wrong.
20 changes: 0 additions & 20 deletions
20
...estination-actions/src/destinations/stackadapt-audiences/deleteProfile/generated-types.ts
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.