Skip to content

Commit

Permalink
Fixes unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nick-Ag committed Jul 23, 2024
1 parent b9f0391 commit d7b8c1e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,26 @@ import nock from 'nock'

const requestClient = createRequestClient()
const settings: Settings = {
adAccountId: 'act_123456'
retlAdAccountId: 'act_123456'
}

describe('Facebook Custom Audiences', () => {
describe('retlOnMappingSave hook', () => {
const facebookClient = new FacebookClient(requestClient, settings.adAccountId)
const facebookClient = new FacebookClient(requestClient, settings.retlAdAccountId)
const hookInputs = {
audienceName: 'test-audience'
}

it('should create a custom audience in facebook', async () => {
nock(`${BASE_URL}`)
.post(`/${settings.adAccountId}/customaudiences`, {
.post(`/${settings.retlAdAccountId}/customaudiences`, {
name: hookInputs.audienceName,
subtype: 'CUSTOM',
customer_file_source: 'BOTH_USER_AND_PARTNER_PROVIDED'
})
.reply(201, { id: '123' })

const { data } = await facebookClient.createAudience(hookInputs.audienceName)

expect(data).toEqual({ id: '123' })
await facebookClient.createAudience(hookInputs.audienceName)
})
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,20 @@ const getAudienceUrl = `https://graph.facebook.com/${FACEBOOK_API_VERSION}/`
const createAudienceUrl = `https://graph.facebook.com/${FACEBOOK_API_VERSION}/act_${adAccountId}`

const createAudienceInput = {
settings: {},
settings: {
retlAdAccountId: '123'
},
audienceName: '',
audienceSettings: {
adAccountId: adAccountId,
engageAdAccountId: adAccountId,
audienceDescription: 'We are the Mario Brothers and plumbing is our game.'
}
}
const getAudienceInput = {
externalId: audienceId,
settings: {}
settings: {
retlAdAccountId: '123'
}
}

describe('Facebook Custom Audiences', () => {
Expand All @@ -29,15 +33,15 @@ describe('Facebook Custom Audiences', () => {

it('should fail if no ad account ID is set', async () => {
createAudienceInput.audienceName = 'The Void'
createAudienceInput.audienceSettings.adAccountId = 0
createAudienceInput.audienceSettings.engageAdAccountId = 0
await expect(testDestination.createAudience(createAudienceInput)).rejects.toThrowError(IntegrationError)
})

it('should create a new Facebook Audience', async () => {
nock(createAudienceUrl).post('/customaudiences').reply(200, { id: '88888888888888888' })

createAudienceInput.audienceName = 'The Super Mario Brothers Fans'
createAudienceInput.audienceSettings.adAccountId = adAccountId
createAudienceInput.audienceSettings.engageAdAccountId = adAccountId

const r = await testDestination.createAudience(createAudienceInput)
expect(r).toEqual({ externalId: '88888888888888888' })
Expand Down

0 comments on commit d7b8c1e

Please sign in to comment.