Skip to content

Commit

Permalink
Make received_at parameter optional and gracefully handle it
Browse files Browse the repository at this point in the history
  • Loading branch information
Nick Campbell committed May 28, 2024
1 parent 1f9482e commit fe3c78b
Show file tree
Hide file tree
Showing 10 changed files with 84 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -141,4 +141,30 @@ describe('Attio.assertRecord', () => {

expect(response.status).toBe(202)
})

it('handles the case where receivedAt is not provided', async () => {
const lackingReceivedAtEvent = createTestEvent({
type: 'track' as const,
traits: {
name: 'Stair car',
number_of_wheels: 4
},
receivedAt: undefined
})

// Can't control the exact timestamp, so only check it starts on the same year-month-day and is ISO8601 formatted
const datePrefix = new Date().toISOString().split('T')[0]

nock('https://api.attio.com')
.put('/v2/batch/records', new RegExp(`"received_at":"${datePrefix}T`))
.reply(202, '')

const [response] = await testDestination.testBatchAction('assertRecord', {
events: [lackingReceivedAtEvent],
mapping,
settings: {}
})

expect(response.status).toBe(202)
})
})

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ const action: ActionDefinition<Settings, Payload> = {
matching_attribute: item.matching_attribute,
multiselect_values: 'append',
values: (item.attributes as Record<string, SimpleValue>) ?? {},
received_at: item.received_at.toString()
received_at: item.received_at?.toString() ?? new Date().toISOString()
}))
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const commonFields: ActionDefinition<Settings>['fields'] = {
label: 'Received at',
description: 'When the event was received.',
type: 'datetime',
required: true,
required: false,
default: {
'@path': '$.receivedAt'
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,4 +224,28 @@ describe('Attio.groupWorkspace', () => {
expect(responses.length).toBe(2)
expect(responses[1].status).toBe(202)
})

it('handles the case where receivedAt is not provided', async () => {
const lackingReceivedAtEvent = createTestEvent({
type: 'group' as const,
traits: {
id: '42',
domain
},
receivedAt: undefined
})

// Can't control the exact timestamp, so only check it starts on the same year-month-day and is ISO8601 formatted
const datePrefix = new Date().toISOString().split('T')[0]

nock('https://api.attio.com')
.put('/v2/batch/records', new RegExp(`"received_at":"${datePrefix}T`))
.reply(202, '')

await testDestination.testBatchAction('groupWorkspace', {
events: [lackingReceivedAtEvent],
mapping,
settings: {}
})
})
})

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,10 @@ const action: ActionDefinition<Settings, Payload> = {
domains: item.domain,
...(item.company_attributes ?? {})
},
received_at: item.received_at.toString()
received_at: item.received_at?.toString() ?? new Date().toISOString()
}
},
received_at: item.received_at.toString()
received_at: item.received_at?.toString() ?? new Date().toISOString()
}))
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,4 +125,29 @@ describe('Attio.identifyUser', () => {
expect(responses.length).toBe(2)
expect(responses[1].status).toBe(202)
})

it('handles the case where receivedAt is not provided', async () => {
const lackingReceivedAtEvent = createTestEvent({
type: 'identify' as const,
userId: '9',
traits: {
name: 'George Oscar Bluth',
email
},
receivedAt: undefined
})

// Can't control the exact timestamp, so only check it starts on the same year-month-day and is ISO8601 formatted
const datePrefix = new Date().toISOString().split('T')[0]

nock('https://api.attio.com')
.put('/v2/batch/records', new RegExp(`"received_at":"${datePrefix}T`))
.reply(202, '')

await testDestination.testBatchAction('identifyUser', {
events: [lackingReceivedAtEvent],
mapping,
settings: {}
})
})
})

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,10 @@ const action: ActionDefinition<Settings, Payload> = {
email_addresses: item.email_address,
...(item.person_attributes ?? {})
},
received_at: item.received_at.toString()
received_at: item.received_at?.toString() ?? new Date().toISOString()
}
},
received_at: item.received_at.toString()
received_at: item.received_at?.toString() ?? new Date().toISOString()
}))
})
}
Expand Down

0 comments on commit fe3c78b

Please sign in to comment.