diff --git a/packages/destination-actions/src/destinations/attio/assertRecord/__tests__/index.test.ts b/packages/destination-actions/src/destinations/attio/assertRecord/__tests__/index.test.ts index 6338b6ae9b..3356afaea8 100644 --- a/packages/destination-actions/src/destinations/attio/assertRecord/__tests__/index.test.ts +++ b/packages/destination-actions/src/destinations/attio/assertRecord/__tests__/index.test.ts @@ -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) + }) }) diff --git a/packages/destination-actions/src/destinations/attio/assertRecord/generated-types.ts b/packages/destination-actions/src/destinations/attio/assertRecord/generated-types.ts index 2725423d10..56e2b78b8c 100644 --- a/packages/destination-actions/src/destinations/attio/assertRecord/generated-types.ts +++ b/packages/destination-actions/src/destinations/attio/assertRecord/generated-types.ts @@ -26,5 +26,5 @@ export interface Payload { /** * When the event was received. */ - received_at: string | number + received_at?: string | number } diff --git a/packages/destination-actions/src/destinations/attio/assertRecord/index.ts b/packages/destination-actions/src/destinations/attio/assertRecord/index.ts index f8f69a908b..b784e77ba1 100644 --- a/packages/destination-actions/src/destinations/attio/assertRecord/index.ts +++ b/packages/destination-actions/src/destinations/attio/assertRecord/index.ts @@ -97,7 +97,7 @@ const action: ActionDefinition = { matching_attribute: item.matching_attribute, multiselect_values: 'append', values: (item.attributes as Record) ?? {}, - received_at: item.received_at.toString() + received_at: item.received_at?.toString() ?? new Date().toISOString() })) }) } diff --git a/packages/destination-actions/src/destinations/attio/common-fields.ts b/packages/destination-actions/src/destinations/attio/common-fields.ts index bdbff47547..73674cb64f 100644 --- a/packages/destination-actions/src/destinations/attio/common-fields.ts +++ b/packages/destination-actions/src/destinations/attio/common-fields.ts @@ -24,7 +24,7 @@ export const commonFields: ActionDefinition['fields'] = { label: 'Received at', description: 'When the event was received.', type: 'datetime', - required: true, + required: false, default: { '@path': '$.receivedAt' } diff --git a/packages/destination-actions/src/destinations/attio/groupWorkspace/__tests__/index.test.ts b/packages/destination-actions/src/destinations/attio/groupWorkspace/__tests__/index.test.ts index a3cdd4e451..c285576a35 100644 --- a/packages/destination-actions/src/destinations/attio/groupWorkspace/__tests__/index.test.ts +++ b/packages/destination-actions/src/destinations/attio/groupWorkspace/__tests__/index.test.ts @@ -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: {} + }) + }) }) diff --git a/packages/destination-actions/src/destinations/attio/groupWorkspace/generated-types.ts b/packages/destination-actions/src/destinations/attio/groupWorkspace/generated-types.ts index 60ab260dd2..e5014806b0 100644 --- a/packages/destination-actions/src/destinations/attio/groupWorkspace/generated-types.ts +++ b/packages/destination-actions/src/destinations/attio/groupWorkspace/generated-types.ts @@ -36,5 +36,5 @@ export interface Payload { /** * When the event was received. */ - received_at: string | number + received_at?: string | number } diff --git a/packages/destination-actions/src/destinations/attio/groupWorkspace/index.ts b/packages/destination-actions/src/destinations/attio/groupWorkspace/index.ts index 79c9c26e27..f02f0d19cf 100644 --- a/packages/destination-actions/src/destinations/attio/groupWorkspace/index.ts +++ b/packages/destination-actions/src/destinations/attio/groupWorkspace/index.ts @@ -128,10 +128,10 @@ const action: ActionDefinition = { 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() })) }) } diff --git a/packages/destination-actions/src/destinations/attio/identifyUser/__tests__/index.test.ts b/packages/destination-actions/src/destinations/attio/identifyUser/__tests__/index.test.ts index 6aac56c4b8..0376a41b97 100644 --- a/packages/destination-actions/src/destinations/attio/identifyUser/__tests__/index.test.ts +++ b/packages/destination-actions/src/destinations/attio/identifyUser/__tests__/index.test.ts @@ -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: {} + }) + }) }) diff --git a/packages/destination-actions/src/destinations/attio/identifyUser/generated-types.ts b/packages/destination-actions/src/destinations/attio/identifyUser/generated-types.ts index 4d380f30af..54f895f86b 100644 --- a/packages/destination-actions/src/destinations/attio/identifyUser/generated-types.ts +++ b/packages/destination-actions/src/destinations/attio/identifyUser/generated-types.ts @@ -32,5 +32,5 @@ export interface Payload { /** * When the event was received. */ - received_at: string | number + received_at?: string | number } diff --git a/packages/destination-actions/src/destinations/attio/identifyUser/index.ts b/packages/destination-actions/src/destinations/attio/identifyUser/index.ts index 749a66d333..683c8917b2 100644 --- a/packages/destination-actions/src/destinations/attio/identifyUser/index.ts +++ b/packages/destination-actions/src/destinations/attio/identifyUser/index.ts @@ -112,10 +112,10 @@ const action: ActionDefinition = { 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() })) }) }