Skip to content

Commit

Permalink
fix: persons ednpoint; dates search
Browse files Browse the repository at this point in the history
  • Loading branch information
joscha committed Jul 26, 2024
1 parent ce34b20 commit 00475a5
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 23 deletions.
45 changes: 45 additions & 0 deletions src/v1/tests/__snapshots__/persons_test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,51 @@ snapshot[`persons > can search for persons 1`] = `
}
`;

snapshot[`persons > can search for persons with the appropriate dates 1`] = `
{
persons: [
{
emails: [
"[email protected]",
],
first_name: "Joscha",
id: 12345678,
interaction_dates: {
first_email_date: 2021-05-31T16:00:37.000Z,
first_event_date: 2021-05-20T06:30:00.000Z,
last_chat_message_date: null,
last_email_date: 2022-05-12T08:01:31.000Z,
last_event_date: 2022-07-08T07:00:00.000Z,
last_interaction_date: 2022-07-08T07:00:00.000Z,
next_event_date: null,
},
interactions: {
first_email: {
date: 2021-05-31T16:00:37.000Z,
},
first_event: {
date: 2021-05-20T06:30:00.000Z,
},
last_chat_message: null,
last_email: {
date: 2022-05-12T08:01:31.000Z,
},
last_event: {
date: 2022-07-08T07:00:00.000Z,
},
last_interaction: {
date: 2022-07-08T07:00:00.000Z,
},
next_event: null,
},
last_name: "Feth",
primary_email: "[email protected]",
type: 0,
},
],
}
`;

snapshot[`persons > can create a new person 1`] = `
{
emails: [
Expand Down
30 changes: 30 additions & 0 deletions src/v1/tests/fixtures/persons/search_with_dates.raw.response.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"persons": [
{
"id": 12345678,
"type": 0,
"first_name": "Joscha",
"last_name": "Feth",
"primary_email": "[email protected]",
"emails": ["[email protected]"],
"interaction_dates": {
"first_email_date": "2021-05-31T09:00:37.000-07:00",
"first_event_date": "2021-05-19T23:30:00.000-07:00",
"last_email_date": "2022-05-12T01:01:31.000-07:00",
"last_event_date": "2022-07-08T00:00:00.000-07:00",
"last_chat_message_date": null,
"last_interaction_date": "2022-07-08T00:00:00.000-07:00",
"next_event_date": null
},
"interactions": {
"first_email": { "date": "2021-05-31T09:00:37.000-07:00" },
"last_email": { "date": "2022-05-12T01:01:31.000-07:00" },
"first_event": { "date": "2021-05-19T23:30:00.000-07:00" },
"next_event": null,
"last_event": { "date": "2022-07-08T00:00:00.000-07:00" },
"last_chat_message": null,
"last_interaction": { "date": "2022-07-08T00:00:00.000-07:00" }
}
}
]
}
2 changes: 2 additions & 0 deletions src/v1/tests/organizations_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,13 @@ describe('organizations', () => {
const request: SearchOrganizationsRequest = {
min_first_email_date: myDate,
term: 'affinity',
with_interaction_dates: true,
}
mock?.onGet(organizationsUrl(), {
params: {
term: request.term,
min_first_email_date: myDate.toISOString(),
with_interaction_dates: true,
},
}).reply(
200,
Expand Down
38 changes: 20 additions & 18 deletions src/v1/tests/persons_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,24 +43,26 @@ describe('persons', () => {
await assertSnapshot(t, res)
})

// it('can search for persons with the appropriate dates', async (t) => {
// const myDate = new Date(1717428411010)
// const request: SearchPersonsRequest = {
// min_first_email_date: myDate,
// term: 'joscha',
// }
// mock?.onGet(personsUrl(), {
// params: {
// term: request.term,
// min_first_email_date: myDate.toISOString(),
// },
// }).reply(
// 200,
// await getRawFixture('persons/search.raw.response.json'),
// )
// const res = await affinity.persons.search(request)
// await assertSnapshot(t, res)
// })
it('can search for persons with the appropriate dates', async (t) => {
const myDate = new Date(0)
const request: SearchPersonsRequest = {
min_first_email_date: myDate,
term: 'Joscha',
with_interaction_dates: true,
}
mock?.onGet(personsUrl(), {
params: {
term: request.term,
min_first_email_date: myDate.toISOString(),
with_interaction_dates: true,
},
}).reply(
200,
await getRawFixture('persons/search_with_dates.raw.response.json'),
)
const res = await affinity.persons.search(request)
await assertSnapshot(t, res)
})

it('can create a new person', async (t) => {
const data = {
Expand Down
18 changes: 13 additions & 5 deletions src/v1/transform_interaction_date_response_raw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,25 @@ export function transformInteractionDateResponseRaw<
if (interaction_dates) {
dates.interaction_dates = Object.fromEntries(
Object.entries(interaction_dates).map(
([key, value]) => [key, new Date(value)],
([key, value]) => [
key,
value ? new Date(value) : null,
],
),
) as Record<InteractionDateKey, Date>
}
if (interactions) {
dates.interactions = Object.fromEntries(
Object.entries(interactions).map(
([key, value]) => [key, {
...value,
date: new Date(value.date),
}],
([key, value]) => [
key,
value
? {
...value,
date: new Date(value.date),
}
: null,
],
),
) as Record<InteractionType, InteractionDate>
}
Expand Down

0 comments on commit 00475a5

Please sign in to comment.