Skip to content

Commit

Permalink
test: add tests for notes endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
joscha committed Aug 13, 2024
1 parent 61c2267 commit 1c771e5
Show file tree
Hide file tree
Showing 7 changed files with 179 additions and 64 deletions.
5 changes: 5 additions & 0 deletions src/v1/notes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,11 @@ export class Notes {
/**
* Updates an existing person with `note_id` with the supplied parameters.
*
* *Caveats:*
* - You cannot update the content of a note that has mentions.
* - You also cannot update the content of a note associated with an email.
* - You cannot update the type of a note.
*
* @example
* ```typescript
* const updatedNote = await affinity.notes.update({
Expand Down
64 changes: 0 additions & 64 deletions src/v1/tests/__snapshots__/list_entries_test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -65,70 +65,6 @@ snapshot[`list_entries > can get all 1`] = `
]
`;

snapshot[`list_entries > can get a page 1`] = `
{
list_entries: [
{
created_at: 2024-05-23T12:27:41.625Z,
creator_id: 54576635,
entity: {
emails: [
"[email protected]",
"[email protected]",
],
first_name: "Fridel",
id: 170614434,
last_name: "Test",
primary_email: "[email protected]",
type: 0,
},
entity_id: 170614434,
entity_type: 0,
id: 158330673,
list_id: 247888,
},
],
next_page_token: "eyJwYXJhbXMiOnsibGlzdF9pZCI6IjI0Nzg4OCJ9LCJwYWdlX3NpemUiOjEsIm9mZnNldCI6MX0",
}
`;

snapshot[`list_entries > can get a following page 1`] = `
{
list_entries: [
{
created_at: 2024-05-23T12:27:09.733Z,
creator_id: 54576635,
entity: {
emails: [
"[email protected]",
"[email protected]",
"[email protected]",
"[email protected]",
"[email protected]",
],
first_name: "Joscha",
id: 54576635,
last_name: "Feth",
primary_email: "[email protected]",
type: 1,
},
entity_id: 54576635,
entity_type: 0,
id: 158330666,
list_id: 247888,
},
],
next_page_token: "eyJwYXJhbXMiOnsibGlzdF9pZCI6IjI0Nzg4OCJ9LCJwYWdlX3NpemUiOjEsIm9mZnNldCI6M30",
}
`;

snapshot[`list_entries > can deal with a last empty page 1`] = `
{
list_entries: [],
next_page_token: null,
}
`;

snapshot[`page 1 of entries 1`] = `
[
{
Expand Down
71 changes: 71 additions & 0 deletions src/v1/tests/__snapshots__/notes_test.ts.snap
Original file line number Diff line number Diff line change
@@ -1,5 +1,28 @@
export const snapshot = {};

snapshot[`notes > can get a specific note 1`] = `
{
associated_person_ids: [],
content: "This is an **important** note",
created_at: 2021-01-01T00:00:00.000Z,
creator_id: 54576635,
id: 20423470,
interaction_id: null,
interaction_person_ids: [],
interaction_type: null,
is_meeting: false,
mentioned_person_ids: [],
opportunity_ids: [],
organization_ids: [
297551634,
],
parent_id: null,
person_ids: [],
type: 2,
updated_at: null,
}
`;

snapshot[`notes > can list all notes 1`] = `
{
next_page_token: null,
Expand Down Expand Up @@ -111,3 +134,51 @@ snapshot[`page 2 of notes 1`] = `
`;

snapshot[`page 3 of notes 1`] = `[]`;

snapshot[`notes > can create a new note 1`] = `
{
associated_person_ids: [],
content: "This is an **important** note",
created_at: 2021-01-01T07:00:00.000Z,
creator_id: 54576635,
id: 20423147,
interaction_id: null,
interaction_person_ids: [],
interaction_type: null,
is_meeting: false,
mentioned_person_ids: [],
opportunity_ids: [],
organization_ids: [
297551634,
],
parent_id: null,
person_ids: [],
type: 2,
updated_at: null,
}
`;

snapshot[`notes > can update a note 1`] = `
{
associated_person_ids: [],
content: "This is a <strong>super important</strong> note",
created_at: 2024-08-13T14:03:12.601Z,
creator_id: 54576635,
id: 20423147,
interaction_id: null,
interaction_person_ids: [],
interaction_type: null,
is_meeting: false,
mentioned_person_ids: [],
opportunity_ids: [],
organization_ids: [
297551634,
],
parent_id: null,
person_ids: [],
type: 0,
updated_at: 2024-08-13T14:10:29.868Z,
}
`;

snapshot[`notes > can delete a note 1`] = `true`;
18 changes: 18 additions & 0 deletions src/v1/tests/fixtures/notes/create.raw.response.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"id": 20423147,
"creator_id": 54576635,
"person_ids": [],
"associated_person_ids": [],
"interaction_person_ids": [],
"interaction_id": null,
"interaction_type": null,
"is_meeting": false,
"mentioned_person_ids": [],
"organization_ids": [297551634],
"opportunity_ids": [],
"parent_id": null,
"content": "This is an **important** note",
"type": 2,
"created_at": "2021-01-01T00:00:00.000-07:00",
"updated_at": null
}
18 changes: 18 additions & 0 deletions src/v1/tests/fixtures/notes/get.raw.response.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"id": 20423470,
"creator_id": 54576635,
"person_ids": [],
"associated_person_ids": [],
"interaction_person_ids": [],
"interaction_id": null,
"interaction_type": null,
"is_meeting": false,
"mentioned_person_ids": [],
"organization_ids": [297551634],
"opportunity_ids": [],
"parent_id": null,
"content": "This is an **important** note",
"type": 2,
"created_at": "2021-01-01T00:00:00.000Z",
"updated_at": null
}
18 changes: 18 additions & 0 deletions src/v1/tests/fixtures/notes/update.raw.response.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"id": 20423147,
"creator_id": 54576635,
"person_ids": [],
"associated_person_ids": [],
"interaction_person_ids": [],
"interaction_id": null,
"interaction_type": null,
"is_meeting": false,
"mentioned_person_ids": [],
"organization_ids": [297551634],
"opportunity_ids": [],
"parent_id": null,
"content": "This is a <strong>super important</strong> note",
"type": 0,
"created_at": "2024-08-13T07:03:12.601-07:00",
"updated_at": "2024-08-13T07:10:29.868-07:00"
}
49 changes: 49 additions & 0 deletions src/v1/tests/notes_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import { notesUrl } from '../urls.ts'
import { apiKey, isLiveRun } from './env.ts'
import { getRawFixture } from './get_raw_fixture.ts'
import { mockPagingFromAllEndpoint } from './mock_paging_from_all_endpoint.ts'
import type { CreateNoteRequest } from '../notes.ts'
import { NoteType } from '../notes.ts'

describe('notes', () => {
let mock: MockAdapter
Expand All @@ -23,6 +25,16 @@ describe('notes', () => {
mock?.reset()
})

it('can get a specific note', async (t) => {
const note_id = 20423470
mock?.onGet(notesUrl(note_id)).reply(
200,
await getRawFixture('notes/get.raw.response.json'),
)
const res = await affinity.notes.get({ note_id })
await assertSnapshot(t, res)
})

it('can list all notes', async (t) => {
mock?.onGet(notesUrl()).reply(
200,
Expand Down Expand Up @@ -57,4 +69,41 @@ describe('notes', () => {
})
}
})

it('can create a new note', async (t) => {
const data: CreateNoteRequest = {
organization_ids: [297551634],
content: 'This is an <strong>important</strong> note',
type: NoteType.HTML,
created_at: new Date('2021-01-01T00:00:00Z'),
}
mock?.onPost(notesUrl()).reply(
201,
await getRawFixture('notes/create.raw.response.json'),
)
const res = await affinity.notes.create(data)
await assertSnapshot(t, res)
})

it('can update a note', async (t) => {
const data = {
note_id: 20423298,
content: 'This is a <strong>super super important</strong> note',
}
mock?.onPut(notesUrl(data.note_id)).reply(
200,
await getRawFixture('notes/update.raw.response.json'),
)
const res = await affinity.notes.update(data)
await assertSnapshot(t, res)
})

it('can delete a note', async (t) => {
const note_id = 20423298
mock?.onDelete(notesUrl(note_id)).reply(200, {
success: true,
})
const res = await affinity.notes.delete({ note_id })
await assertSnapshot(t, res)
})
})

0 comments on commit 1c771e5

Please sign in to comment.