From f5492bea6df7d1f3099cdeaadf2b28dd51822711 Mon Sep 17 00:00:00 2001 From: Khaliq Date: Tue, 1 Oct 2024 12:51:51 +0300 Subject: [PATCH] [ext-173] fix tests --- flows.yaml | 8 +- .../{ => EventInvitee}/batchDelete.json | 0 .../{ => EventInvitee}/batchSave.json | 0 .../{ => EventType}/batchDelete.json | 0 .../{ => EventType}/batchSave.json | 0 .../mocks/events/{ => Event}/batchDelete.json | 0 .../mocks/events/{ => Event}/batchSave.json | 0 .../tests/calendly-event-invitees.test.ts | 41 +++--- .../tests/calendly-event-types.test.ts | 41 +++--- .../calendly/tests/calendly-events.test.ts | 41 +++--- .../articles/{ => Article}/batchDelete.json | 0 .../articles/{ => Article}/batchSave.json | 0 .../contacts/{ => Contact}/batchDelete.json | 0 .../contacts/{ => Contact}/batchSave.json | 0 .../{ => Conversation}/batchDelete.json | 0 .../conversations/Conversation/batchSave.json | 117 +++++++++++++++ .../ConversationMessage}/batchDelete.json | 0 .../{ => ConversationMessage}/batchSave.json | 139 ++---------------- .../proxy/conversations/1/conversations.json | 24 +-- .../proxy/conversations/2/conversations.json | 16 +- .../proxy/conversations/3/conversations.json | 20 +-- .../proxy/conversations/4/conversations.json | 12 +- .../proxy/conversations/5/conversations.json | 26 ++-- .../proxy/conversations/6/conversations.json | 12 +- .../proxy/conversations/7/conversations.json | 8 +- .../proxy/conversations/conversations.json | 4 +- integrations/intercom/nango.yaml | 8 +- .../intercom/tests/intercom-articles.test.ts | 38 ++++- .../intercom/tests/intercom-contacts.test.ts | 38 ++++- .../tests/intercom-conversations.test.ts | 38 ++++- .../ContentMetadata}/batchDelete.json | 0 .../{ => ContentMetadata}/batchSave.json | 0 .../tests/notion-content-metadata.test.ts | 41 +++--- .../Account}/batchDelete.json | 0 .../accounts/{ => Account}/batchSave.json | 0 .../Article}/batchDelete.json | 0 .../articles/{ => Article}/batchSave.json | 0 .../Contact}/batchDelete.json | 0 .../contacts/{ => Contact}/batchSave.json | 0 .../{tickets => deals/Deal}/batchDelete.json | 0 .../mocks/deals/{ => Deal}/batchSave.json | 0 .../mocks/tickets/Ticket}/batchDelete.json | 0 .../mocks/tickets/{ => Ticket}/batchSave.json | 0 .../tests/salesforce-accounts.test.ts | 41 +++--- .../tests/salesforce-articles.test.ts | 41 +++--- .../tests/salesforce-contacts.test.ts | 41 +++--- .../salesforce/tests/salesforce-deals.test.ts | 41 +++--- .../tests/salesforce-tickets.test.ts | 41 +++--- .../Account}/batchDelete.json | 0 .../accounts/{ => Account}/batchSave.json | 0 .../Contact}/batchDelete.json | 0 .../contacts/{ => Contact}/batchSave.json | 0 .../Invoice}/batchDelete.json | 0 .../invoices/{ => Invoice}/batchSave.json | 0 .../{payments => items/Item}/batchDelete.json | 0 .../mocks/items/{ => Item}/batchSave.json | 0 .../mocks/payments/Payment/batchDelete.json | 1 + .../payments/{ => Payment}/batchSave.json | 0 integrations/xero/tests/xero-accounts.test.ts | 41 +++--- integrations/xero/tests/xero-contacts.test.ts | 41 +++--- integrations/xero/tests/xero-invoices.test.ts | 41 +++--- integrations/xero/tests/xero-items.test.ts | 41 +++--- integrations/xero/tests/xero-payments.test.ts | 41 +++--- scripts/tests/generate-tests.ts | 4 +- scripts/tests/sync-template.ejs | 41 +++--- vitest.setup.ts | 12 +- 66 files changed, 648 insertions(+), 492 deletions(-) rename integrations/calendly/mocks/event-invitees/{ => EventInvitee}/batchDelete.json (100%) rename integrations/calendly/mocks/event-invitees/{ => EventInvitee}/batchSave.json (100%) rename integrations/calendly/mocks/event-types/{ => EventType}/batchDelete.json (100%) rename integrations/calendly/mocks/event-types/{ => EventType}/batchSave.json (100%) rename integrations/calendly/mocks/events/{ => Event}/batchDelete.json (100%) rename integrations/calendly/mocks/events/{ => Event}/batchSave.json (100%) rename integrations/intercom/mocks/articles/{ => Article}/batchDelete.json (100%) rename integrations/intercom/mocks/articles/{ => Article}/batchSave.json (100%) rename integrations/intercom/mocks/contacts/{ => Contact}/batchDelete.json (100%) rename integrations/intercom/mocks/contacts/{ => Contact}/batchSave.json (100%) rename integrations/intercom/mocks/conversations/{ => Conversation}/batchDelete.json (100%) create mode 100644 integrations/intercom/mocks/conversations/Conversation/batchSave.json rename integrations/{notion/mocks/content-metadata => intercom/mocks/conversations/ConversationMessage}/batchDelete.json (100%) rename integrations/intercom/mocks/conversations/{ => ConversationMessage}/batchSave.json (71%) rename integrations/{salesforce/mocks/accounts => notion/mocks/content-metadata/ContentMetadata}/batchDelete.json (100%) rename integrations/notion/mocks/content-metadata/{ => ContentMetadata}/batchSave.json (100%) rename integrations/salesforce/mocks/{articles => accounts/Account}/batchDelete.json (100%) rename integrations/salesforce/mocks/accounts/{ => Account}/batchSave.json (100%) rename integrations/salesforce/mocks/{contacts => articles/Article}/batchDelete.json (100%) rename integrations/salesforce/mocks/articles/{ => Article}/batchSave.json (100%) rename integrations/salesforce/mocks/{deals => contacts/Contact}/batchDelete.json (100%) rename integrations/salesforce/mocks/contacts/{ => Contact}/batchSave.json (100%) rename integrations/salesforce/mocks/{tickets => deals/Deal}/batchDelete.json (100%) rename integrations/salesforce/mocks/deals/{ => Deal}/batchSave.json (100%) rename integrations/{xero/mocks/accounts => salesforce/mocks/tickets/Ticket}/batchDelete.json (100%) rename integrations/salesforce/mocks/tickets/{ => Ticket}/batchSave.json (100%) rename integrations/xero/mocks/{contacts => accounts/Account}/batchDelete.json (100%) rename integrations/xero/mocks/accounts/{ => Account}/batchSave.json (100%) rename integrations/xero/mocks/{invoices => contacts/Contact}/batchDelete.json (100%) rename integrations/xero/mocks/contacts/{ => Contact}/batchSave.json (100%) rename integrations/xero/mocks/{items => invoices/Invoice}/batchDelete.json (100%) rename integrations/xero/mocks/invoices/{ => Invoice}/batchSave.json (100%) rename integrations/xero/mocks/{payments => items/Item}/batchDelete.json (100%) rename integrations/xero/mocks/items/{ => Item}/batchSave.json (100%) create mode 100644 integrations/xero/mocks/payments/Payment/batchDelete.json rename integrations/xero/mocks/payments/{ => Payment}/batchSave.json (100%) diff --git a/flows.yaml b/flows.yaml index aa4e7404..8d993e4c 100644 --- a/flows.yaml +++ b/flows.yaml @@ -2389,8 +2389,8 @@ integrations: sync_type: incremental version: 1.0.0 endpoint: - - GET /intercom/conversations - - GET /intercom/conversations-message + - GET /conversations + - GET /conversation-messages contacts: runs: every 6 hours description: | @@ -2399,7 +2399,7 @@ integrations: sync_type: full track_deletes: true version: 1.0.0 - endpoint: GET /intercom/contacts + endpoint: GET /contacts articles: runs: every 6 hours description: | @@ -2408,7 +2408,7 @@ integrations: sync_type: full track_deletes: true version: 1.0.0 - endpoint: GET /intercom/articles + endpoint: GET /articles models: Contact: id: string diff --git a/integrations/calendly/mocks/event-invitees/batchDelete.json b/integrations/calendly/mocks/event-invitees/EventInvitee/batchDelete.json similarity index 100% rename from integrations/calendly/mocks/event-invitees/batchDelete.json rename to integrations/calendly/mocks/event-invitees/EventInvitee/batchDelete.json diff --git a/integrations/calendly/mocks/event-invitees/batchSave.json b/integrations/calendly/mocks/event-invitees/EventInvitee/batchSave.json similarity index 100% rename from integrations/calendly/mocks/event-invitees/batchSave.json rename to integrations/calendly/mocks/event-invitees/EventInvitee/batchSave.json diff --git a/integrations/calendly/mocks/event-types/batchDelete.json b/integrations/calendly/mocks/event-types/EventType/batchDelete.json similarity index 100% rename from integrations/calendly/mocks/event-types/batchDelete.json rename to integrations/calendly/mocks/event-types/EventType/batchDelete.json diff --git a/integrations/calendly/mocks/event-types/batchSave.json b/integrations/calendly/mocks/event-types/EventType/batchSave.json similarity index 100% rename from integrations/calendly/mocks/event-types/batchSave.json rename to integrations/calendly/mocks/event-types/EventType/batchSave.json diff --git a/integrations/calendly/mocks/events/batchDelete.json b/integrations/calendly/mocks/events/Event/batchDelete.json similarity index 100% rename from integrations/calendly/mocks/events/batchDelete.json rename to integrations/calendly/mocks/events/Event/batchDelete.json diff --git a/integrations/calendly/mocks/events/batchSave.json b/integrations/calendly/mocks/events/Event/batchSave.json similarity index 100% rename from integrations/calendly/mocks/events/batchSave.json rename to integrations/calendly/mocks/events/Event/batchSave.json diff --git a/integrations/calendly/tests/calendly-event-invitees.test.ts b/integrations/calendly/tests/calendly-event-invitees.test.ts index b542655c..8026ba3e 100644 --- a/integrations/calendly/tests/calendly-event-invitees.test.ts +++ b/integrations/calendly/tests/calendly-event-invitees.test.ts @@ -1,5 +1,4 @@ import { vi, expect, it, describe } from "vitest"; -import type { NangoSync } from "../models.js"; import fetchData from "../syncs/event-invitees.js"; @@ -10,39 +9,45 @@ describe("calendly event-invitees tests", () => { Model: "EventInvitee" }); + const models = "EventInvitee".split(','); const batchSaveSpy = vi.spyOn(nangoMock, 'batchSave'); it("should get, map correctly the data and batchSave the result", async () => { await fetchData(nangoMock); - const batchSaveData = await nangoMock.getBatchSaveData(); + for (const model of models) { + const batchSaveData = await nangoMock.getBatchSaveData(model); - const totalCalls = batchSaveSpy.mock.calls.length; + const totalCalls = batchSaveSpy.mock.calls.length; - if (totalCalls > 1) { - const splitSize = Math.ceil(batchSaveData.length / totalCalls); + if (totalCalls > models.length) { + const splitSize = Math.ceil(batchSaveData.length / totalCalls); - const splitBatchSaveData = []; - for (let i = 0; i < totalCalls; i++) { - const chunk = batchSaveData.slice(i * splitSize, (i + 1) * splitSize); - splitBatchSaveData.push(chunk); - } + const splitBatchSaveData = []; + for (let i = 0; i < totalCalls; i++) { + const chunk = batchSaveData.slice(i * splitSize, (i + 1) * splitSize); + splitBatchSaveData.push(chunk); + } - splitBatchSaveData.forEach((data, index) => { - expect(batchSaveSpy?.mock.calls[index][0]).toEqual(data); - }); + splitBatchSaveData.forEach((data, index) => { + // @ts-ignore + expect(batchSaveSpy?.mock.calls[index][0]).toEqual(data); + }); - } else { - expect(nangoMock.batchSave).toHaveBeenCalledWith(batchSaveData, "EventInvitee"); + } else { + expect(nangoMock.batchSave).toHaveBeenCalledWith(batchSaveData, model); + } } }); it('should get, map correctly the data and batchDelete the result', async () => { await fetchData(nangoMock); - const batchDeleteData = await nangoMock.getBatchDeleteData(); - if (batchDeleteData && batchDeleteData.length > 0) { - expect(nangoMock.batchDelete).toHaveBeenCalledWith(batchDeleteData, "EventInvitee"); + for (const model of models) { + const batchDeleteData = await nangoMock.getBatchDeleteData(model); + if (batchDeleteData && batchDeleteData.length > 0) { + expect(nangoMock.batchDelete).toHaveBeenCalledWith(batchDeleteData, model); + } } }); }); diff --git a/integrations/calendly/tests/calendly-event-types.test.ts b/integrations/calendly/tests/calendly-event-types.test.ts index f6d5c461..2009a8e5 100644 --- a/integrations/calendly/tests/calendly-event-types.test.ts +++ b/integrations/calendly/tests/calendly-event-types.test.ts @@ -1,5 +1,4 @@ import { vi, expect, it, describe } from "vitest"; -import type { NangoSync } from "../models.js"; import fetchData from "../syncs/event-types.js"; @@ -10,39 +9,45 @@ describe("calendly event-types tests", () => { Model: "EventType" }); + const models = "EventType".split(','); const batchSaveSpy = vi.spyOn(nangoMock, 'batchSave'); it("should get, map correctly the data and batchSave the result", async () => { await fetchData(nangoMock); - const batchSaveData = await nangoMock.getBatchSaveData(); + for (const model of models) { + const batchSaveData = await nangoMock.getBatchSaveData(model); - const totalCalls = batchSaveSpy.mock.calls.length; + const totalCalls = batchSaveSpy.mock.calls.length; - if (totalCalls > 1) { - const splitSize = Math.ceil(batchSaveData.length / totalCalls); + if (totalCalls > models.length) { + const splitSize = Math.ceil(batchSaveData.length / totalCalls); - const splitBatchSaveData = []; - for (let i = 0; i < totalCalls; i++) { - const chunk = batchSaveData.slice(i * splitSize, (i + 1) * splitSize); - splitBatchSaveData.push(chunk); - } + const splitBatchSaveData = []; + for (let i = 0; i < totalCalls; i++) { + const chunk = batchSaveData.slice(i * splitSize, (i + 1) * splitSize); + splitBatchSaveData.push(chunk); + } - splitBatchSaveData.forEach((data, index) => { - expect(batchSaveSpy?.mock.calls[index][0]).toEqual(data); - }); + splitBatchSaveData.forEach((data, index) => { + // @ts-ignore + expect(batchSaveSpy?.mock.calls[index][0]).toEqual(data); + }); - } else { - expect(nangoMock.batchSave).toHaveBeenCalledWith(batchSaveData, "EventType"); + } else { + expect(nangoMock.batchSave).toHaveBeenCalledWith(batchSaveData, model); + } } }); it('should get, map correctly the data and batchDelete the result', async () => { await fetchData(nangoMock); - const batchDeleteData = await nangoMock.getBatchDeleteData(); - if (batchDeleteData && batchDeleteData.length > 0) { - expect(nangoMock.batchDelete).toHaveBeenCalledWith(batchDeleteData, "EventType"); + for (const model of models) { + const batchDeleteData = await nangoMock.getBatchDeleteData(model); + if (batchDeleteData && batchDeleteData.length > 0) { + expect(nangoMock.batchDelete).toHaveBeenCalledWith(batchDeleteData, model); + } } }); }); diff --git a/integrations/calendly/tests/calendly-events.test.ts b/integrations/calendly/tests/calendly-events.test.ts index 63e6b155..772560ab 100644 --- a/integrations/calendly/tests/calendly-events.test.ts +++ b/integrations/calendly/tests/calendly-events.test.ts @@ -1,5 +1,4 @@ import { vi, expect, it, describe } from "vitest"; -import type { NangoSync } from "../models.js"; import fetchData from "../syncs/events.js"; @@ -10,39 +9,45 @@ describe("calendly events tests", () => { Model: "Event" }); + const models = "Event".split(','); const batchSaveSpy = vi.spyOn(nangoMock, 'batchSave'); it("should get, map correctly the data and batchSave the result", async () => { await fetchData(nangoMock); - const batchSaveData = await nangoMock.getBatchSaveData(); + for (const model of models) { + const batchSaveData = await nangoMock.getBatchSaveData(model); - const totalCalls = batchSaveSpy.mock.calls.length; + const totalCalls = batchSaveSpy.mock.calls.length; - if (totalCalls > 1) { - const splitSize = Math.ceil(batchSaveData.length / totalCalls); + if (totalCalls > models.length) { + const splitSize = Math.ceil(batchSaveData.length / totalCalls); - const splitBatchSaveData = []; - for (let i = 0; i < totalCalls; i++) { - const chunk = batchSaveData.slice(i * splitSize, (i + 1) * splitSize); - splitBatchSaveData.push(chunk); - } + const splitBatchSaveData = []; + for (let i = 0; i < totalCalls; i++) { + const chunk = batchSaveData.slice(i * splitSize, (i + 1) * splitSize); + splitBatchSaveData.push(chunk); + } - splitBatchSaveData.forEach((data, index) => { - expect(batchSaveSpy?.mock.calls[index][0]).toEqual(data); - }); + splitBatchSaveData.forEach((data, index) => { + // @ts-ignore + expect(batchSaveSpy?.mock.calls[index][0]).toEqual(data); + }); - } else { - expect(nangoMock.batchSave).toHaveBeenCalledWith(batchSaveData, "Event"); + } else { + expect(nangoMock.batchSave).toHaveBeenCalledWith(batchSaveData, model); + } } }); it('should get, map correctly the data and batchDelete the result', async () => { await fetchData(nangoMock); - const batchDeleteData = await nangoMock.getBatchDeleteData(); - if (batchDeleteData && batchDeleteData.length > 0) { - expect(nangoMock.batchDelete).toHaveBeenCalledWith(batchDeleteData, "Event"); + for (const model of models) { + const batchDeleteData = await nangoMock.getBatchDeleteData(model); + if (batchDeleteData && batchDeleteData.length > 0) { + expect(nangoMock.batchDelete).toHaveBeenCalledWith(batchDeleteData, model); + } } }); }); diff --git a/integrations/intercom/mocks/articles/batchDelete.json b/integrations/intercom/mocks/articles/Article/batchDelete.json similarity index 100% rename from integrations/intercom/mocks/articles/batchDelete.json rename to integrations/intercom/mocks/articles/Article/batchDelete.json diff --git a/integrations/intercom/mocks/articles/batchSave.json b/integrations/intercom/mocks/articles/Article/batchSave.json similarity index 100% rename from integrations/intercom/mocks/articles/batchSave.json rename to integrations/intercom/mocks/articles/Article/batchSave.json diff --git a/integrations/intercom/mocks/contacts/batchDelete.json b/integrations/intercom/mocks/contacts/Contact/batchDelete.json similarity index 100% rename from integrations/intercom/mocks/contacts/batchDelete.json rename to integrations/intercom/mocks/contacts/Contact/batchDelete.json diff --git a/integrations/intercom/mocks/contacts/batchSave.json b/integrations/intercom/mocks/contacts/Contact/batchSave.json similarity index 100% rename from integrations/intercom/mocks/contacts/batchSave.json rename to integrations/intercom/mocks/contacts/Contact/batchSave.json diff --git a/integrations/intercom/mocks/conversations/batchDelete.json b/integrations/intercom/mocks/conversations/Conversation/batchDelete.json similarity index 100% rename from integrations/intercom/mocks/conversations/batchDelete.json rename to integrations/intercom/mocks/conversations/Conversation/batchDelete.json diff --git a/integrations/intercom/mocks/conversations/Conversation/batchSave.json b/integrations/intercom/mocks/conversations/Conversation/batchSave.json new file mode 100644 index 00000000..21b71162 --- /dev/null +++ b/integrations/intercom/mocks/conversations/Conversation/batchSave.json @@ -0,0 +1,117 @@ +[ + { + "id": "7", + "created_at": "2024-09-30T23:13:05.000Z", + "updated_at": "2024-09-30T23:13:06.000Z", + "waiting_since": null, + "snoozed_until": null, + "title": null, + "contacts": [ + { + "contact_id": "66f7ee5ea9e2c41564b4c362" + } + ], + "state": "open", + "open": true, + "read": false, + "priority": "not_priority" + }, + { + "id": "6", + "created_at": "2024-09-28T11:54:21.000Z", + "updated_at": "2024-09-28T11:54:24.000Z", + "waiting_since": "2024-09-28T11:54:23.000Z", + "snoozed_until": null, + "title": null, + "contacts": [ + { + "contact_id": "66f7ee5ea9e2c41564b4c362" + } + ], + "state": "open", + "open": true, + "read": true, + "priority": "not_priority" + }, + { + "id": "5", + "created_at": "2024-09-28T11:54:18.000Z", + "updated_at": "2024-09-28T11:54:21.000Z", + "waiting_since": null, + "snoozed_until": null, + "title": null, + "contacts": [ + { + "contact_id": "66f7ee5ea9e2c41564b4c362" + } + ], + "state": "open", + "open": true, + "read": true, + "priority": "not_priority" + }, + { + "id": "3", + "created_at": "2024-09-28T11:54:12.000Z", + "updated_at": "2024-09-28T11:54:17.000Z", + "waiting_since": null, + "snoozed_until": null, + "title": null, + "contacts": [ + { + "contact_id": "66f7ee5ea9e2c41564b4c362" + } + ], + "state": "open", + "open": true, + "read": true, + "priority": "not_priority" + }, + { + "id": "4", + "created_at": "2024-09-28T11:54:14.000Z", + "updated_at": "2024-09-28T11:54:17.000Z", + "waiting_since": null, + "snoozed_until": null, + "title": null, + "contacts": [ + { + "contact_id": "66f7ee5ea9e2c41564b4c362" + } + ], + "state": "open", + "open": true, + "read": false, + "priority": "not_priority" + }, + { + "id": "1", + "created_at": "2024-09-28T11:54:06.000Z", + "updated_at": "2024-09-28T11:54:12.000Z", + "waiting_since": null, + "snoozed_until": null, + "title": null, + "contacts": [ + { + "contact_id": "66f7ee5ea9e2c41564b4c362" + } + ], + "state": "open", + "open": true, + "read": true, + "priority": "not_priority" + }, + { + "id": "2", + "created_at": "2024-09-28T11:54:08.000Z", + "updated_at": "2024-09-28T11:54:12.000Z", + "waiting_since": null, + "snoozed_until": null, + "title": null, + "contacts": [], + "state": "open", + "open": true, + "read": false, + "priority": "not_priority" + } +] diff --git a/integrations/notion/mocks/content-metadata/batchDelete.json b/integrations/intercom/mocks/conversations/ConversationMessage/batchDelete.json similarity index 100% rename from integrations/notion/mocks/content-metadata/batchDelete.json rename to integrations/intercom/mocks/conversations/ConversationMessage/batchDelete.json diff --git a/integrations/intercom/mocks/conversations/batchSave.json b/integrations/intercom/mocks/conversations/ConversationMessage/batchSave.json similarity index 71% rename from integrations/intercom/mocks/conversations/batchSave.json rename to integrations/intercom/mocks/conversations/ConversationMessage/batchSave.json index 12a21ffc..c62a1cab 100644 --- a/integrations/intercom/mocks/conversations/batchSave.json +++ b/integrations/intercom/mocks/conversations/ConversationMessage/batchSave.json @@ -1,119 +1,4 @@ [ - { - "id": "7", - "created_at": "2024-09-30T23:13:05.000Z", - "updated_at": "2024-09-30T23:13:06.000Z", - "waiting_since": null, - "snoozed_until": null, - "title": null, - "contacts": [ - { - "contact_id": "66f7ee5ea9e2c41564b4c362" - } - ], - "state": "open", - "open": true, - "read": false, - "priority": "not_priority" - }, - { - "id": "6", - "created_at": "2024-09-28T11:54:21.000Z", - "updated_at": "2024-09-28T11:54:24.000Z", - "waiting_since": "2024-09-28T11:54:23.000Z", - "snoozed_until": null, - "title": null, - "contacts": [ - { - "contact_id": "66f7ee5ea9e2c41564b4c362" - } - ], - "state": "open", - "open": true, - "read": true, - "priority": "not_priority" - }, - { - "id": "5", - "created_at": "2024-09-28T11:54:18.000Z", - "updated_at": "2024-09-28T11:54:21.000Z", - "waiting_since": null, - "snoozed_until": null, - "title": null, - "contacts": [ - { - "contact_id": "66f7ee5ea9e2c41564b4c362" - } - ], - "state": "open", - "open": true, - "read": true, - "priority": "not_priority" - }, - { - "id": "3", - "created_at": "2024-09-28T11:54:12.000Z", - "updated_at": "2024-09-28T11:54:17.000Z", - "waiting_since": null, - "snoozed_until": null, - "title": null, - "contacts": [ - { - "contact_id": "66f7ee5ea9e2c41564b4c362" - } - ], - "state": "open", - "open": true, - "read": true, - "priority": "not_priority" - }, - { - "id": "4", - "created_at": "2024-09-28T11:54:14.000Z", - "updated_at": "2024-09-28T11:54:17.000Z", - "waiting_since": null, - "snoozed_until": null, - "title": null, - "contacts": [ - { - "contact_id": "66f7ee5ea9e2c41564b4c362" - } - ], - "state": "open", - "open": true, - "read": false, - "priority": "not_priority" - }, - { - "id": "1", - "created_at": "2024-09-28T11:54:06.000Z", - "updated_at": "2024-09-28T11:54:12.000Z", - "waiting_since": null, - "snoozed_until": null, - "title": null, - "contacts": [ - { - "contact_id": "66f7ee5ea9e2c41564b4c362" - } - ], - "state": "open", - "open": true, - "read": true, - "priority": "not_priority" - }, - { - "id": "2", - "created_at": "2024-09-28T11:54:08.000Z", - "updated_at": "2024-09-28T11:54:12.000Z", - "waiting_since": null, - "snoozed_until": null, - "title": null, - "contacts": [], - "state": "open", - "open": true, - "read": false, - "priority": "not_priority" - }, { "id": "125299165", "conversation_id": "7", @@ -123,7 +8,7 @@ "updated_at": "2024-09-30T23:13:06.000Z", "author": { "type": "admin", - "name": "Mock Test", + "name": "Kelvin Wari", "id": "7803408" } }, @@ -149,7 +34,7 @@ "updated_at": "2024-09-28T11:54:22.000Z", "author": { "type": "admin", - "name": "Mock Test", + "name": "Kelvin Wari", "id": "7803408" } }, @@ -175,7 +60,7 @@ "updated_at": "2024-09-28T11:54:23.000Z", "author": { "type": "admin", - "name": "Mock Test", + "name": "Kelvin Wari", "id": "7803408" } }, @@ -208,13 +93,13 @@ { "id": "24", "conversation_id": "5", - "body": "[Image \"customer_ticket_example.png?expires=1727750700&signature=21c97acbb22ced63976fa17d2dcc1f4580039c1a141bcbbf7e4889766e07f0d5&req=fSAlF8h8n4BYFb4f3HP0gIoXin1XyoIcWiFf7hD8nErwbPgBnaYMer9M1V2c%0AqgKkJSl6Eo20hsL0%2Fg%3D%3D%0A\"] ℹ️ This is an example of a customer ticket. Customer tickets help you solve complex issues without losing context. Use them to collect the info you need up-front, update your customers in real-time, and track progress.", + "body": "[Image \"customer_ticket_example.png?expires=1727777700&signature=71b5e65d434e685a661705b5ebab52302788ea9096cf7b5b4cd43c49880b42b2&req=fSAlF8h8n4BYFb4f3HP0gIoXin1VzYIcWiFf7hD8nErIB6w%2BF0%2BkzjORPRPP%0A6oZFukzKaTfte%2FF9yg%3D%3D%0A\"] ℹ️ This is an example of a customer ticket. Customer tickets help you solve complex issues without losing context. Use them to collect the info you need up-front, update your customers in real-time, and track progress.", "type": "note", "created_at": "2024-09-28T11:54:18.000Z", "updated_at": "2024-09-28T11:54:18.000Z", "author": { "type": "admin", - "name": "Mock Test", + "name": "Kelvin Wari", "id": "7803408" } }, @@ -240,7 +125,7 @@ "updated_at": "2024-09-28T11:54:19.000Z", "author": { "type": "admin", - "name": "Mock Test", + "name": "Kelvin Wari", "id": "7803408" } }, @@ -266,7 +151,7 @@ "updated_at": "2024-09-28T11:54:13.000Z", "author": { "type": "admin", - "name": "Mock Test", + "name": "Kelvin Wari", "id": "7803408" } }, @@ -292,7 +177,7 @@ "updated_at": "2024-09-28T11:54:14.000Z", "author": { "type": "admin", - "name": "Mock Test", + "name": "Kelvin Wari", "id": "7803408" } }, @@ -318,7 +203,7 @@ "updated_at": "2024-09-28T11:54:17.000Z", "author": { "type": "admin", - "name": "Mock Test", + "name": "Kelvin Wari", "id": "7803408" } }, @@ -344,7 +229,7 @@ "updated_at": "2024-09-28T11:54:07.000Z", "author": { "type": "admin", - "name": "Mock Test", + "name": "Kelvin Wari", "id": "7803408" } }, @@ -370,7 +255,7 @@ "updated_at": "2024-09-28T11:54:08.000Z", "author": { "type": "admin", - "name": "Mock Test", + "name": "Kelvin Wari", "id": "7803408" } }, @@ -396,7 +281,7 @@ "updated_at": "2024-09-28T11:54:12.000Z", "author": { "type": "admin", - "name": "Mock Test", + "name": "Kelvin Wari", "id": "7803408" } } diff --git a/integrations/intercom/mocks/nango/get/proxy/conversations/1/conversations.json b/integrations/intercom/mocks/nango/get/proxy/conversations/1/conversations.json index f25c0bc3..ba351b80 100644 --- a/integrations/intercom/mocks/nango/get/proxy/conversations/1/conversations.json +++ b/integrations/intercom/mocks/nango/get/proxy/conversations/1/conversations.json @@ -102,8 +102,8 @@ "author": { "id": "7803408", "type": "admin", - "name": "Mock Test", - "email": "mock@nango.dev" + "name": "Kelvin Wari", + "email": "kelvin@nango.dev" }, "attachments": [], "external_id": null, @@ -121,8 +121,8 @@ "author": { "id": "7803408", "type": "admin", - "name": "Mock Test", - "email": "mock@nango.dev" + "name": "Kelvin Wari", + "email": "kelvin@nango.dev" }, "attachments": [], "external_id": null, @@ -159,8 +159,8 @@ "author": { "id": "7803408", "type": "admin", - "name": "Mock Test", - "email": "mock@nango.dev" + "name": "Kelvin Wari", + "email": "kelvin@nango.dev" }, "attachments": [], "external_id": null, @@ -197,8 +197,8 @@ "author": { "id": "7803408", "type": "admin", - "name": "Mock Test", - "email": "mock@nango.dev" + "name": "Kelvin Wari", + "email": "kelvin@nango.dev" }, "attachments": [], "external_id": null, @@ -216,8 +216,8 @@ "author": { "id": "7803408", "type": "admin", - "name": "Mock Test", - "email": "mock@nango.dev" + "name": "Kelvin Wari", + "email": "kelvin@nango.dev" }, "attachments": [], "external_id": null, @@ -238,8 +238,8 @@ "author": { "id": "7803408", "type": "admin", - "name": "Mock Test", - "email": "mock@nango.dev" + "name": "Kelvin Wari", + "email": "kelvin@nango.dev" }, "attachments": [], "external_id": null, diff --git a/integrations/intercom/mocks/nango/get/proxy/conversations/2/conversations.json b/integrations/intercom/mocks/nango/get/proxy/conversations/2/conversations.json index f58c97b8..1daf5deb 100644 --- a/integrations/intercom/mocks/nango/get/proxy/conversations/2/conversations.json +++ b/integrations/intercom/mocks/nango/get/proxy/conversations/2/conversations.json @@ -130,8 +130,8 @@ "author": { "id": "7803408", "type": "admin", - "name": "Mock Test", - "email": "mock@nango.dev" + "name": "Kelvin Wari", + "email": "kelvin@nango.dev" }, "attachments": [], "external_id": null, @@ -152,8 +152,8 @@ "author": { "id": "7803408", "type": "admin", - "name": "Mock Test", - "email": "mock@nango.dev" + "name": "Kelvin Wari", + "email": "kelvin@nango.dev" }, "attachments": [], "external_id": null, @@ -171,8 +171,8 @@ "author": { "id": "7803408", "type": "admin", - "name": "Mock Test", - "email": "mock@nango.dev" + "name": "Kelvin Wari", + "email": "kelvin@nango.dev" }, "attachments": [], "external_id": null, @@ -193,8 +193,8 @@ "author": { "id": "7803408", "type": "admin", - "name": "Mock Test", - "email": "mock@nango.dev" + "name": "Kelvin Wari", + "email": "kelvin@nango.dev" }, "attachments": [], "external_id": null, diff --git a/integrations/intercom/mocks/nango/get/proxy/conversations/3/conversations.json b/integrations/intercom/mocks/nango/get/proxy/conversations/3/conversations.json index b97d6281..766d3bf0 100644 --- a/integrations/intercom/mocks/nango/get/proxy/conversations/3/conversations.json +++ b/integrations/intercom/mocks/nango/get/proxy/conversations/3/conversations.json @@ -102,8 +102,8 @@ "author": { "id": "7803408", "type": "admin", - "name": "Mock Test", - "email": "mock@nango.dev" + "name": "Kelvin Wari", + "email": "kelvin@nango.dev" }, "attachments": [], "external_id": null, @@ -121,8 +121,8 @@ "author": { "id": "7803408", "type": "admin", - "name": "Mock Test", - "email": "mock@nango.dev" + "name": "Kelvin Wari", + "email": "kelvin@nango.dev" }, "attachments": [], "external_id": null, @@ -159,8 +159,8 @@ "author": { "id": "7803408", "type": "admin", - "name": "Mock Test", - "email": "mock@nango.dev" + "name": "Kelvin Wari", + "email": "kelvin@nango.dev" }, "attachments": [], "external_id": null, @@ -197,8 +197,8 @@ "author": { "id": "7803408", "type": "admin", - "name": "Mock Test", - "email": "mock@nango.dev" + "name": "Kelvin Wari", + "email": "kelvin@nango.dev" }, "attachments": [], "external_id": null, @@ -219,8 +219,8 @@ "author": { "id": "7803408", "type": "admin", - "name": "Mock Test", - "email": "mock@nango.dev" + "name": "Kelvin Wari", + "email": "kelvin@nango.dev" }, "attachments": [], "external_id": null, diff --git a/integrations/intercom/mocks/nango/get/proxy/conversations/4/conversations.json b/integrations/intercom/mocks/nango/get/proxy/conversations/4/conversations.json index 94fca9d8..b23bb6da 100644 --- a/integrations/intercom/mocks/nango/get/proxy/conversations/4/conversations.json +++ b/integrations/intercom/mocks/nango/get/proxy/conversations/4/conversations.json @@ -127,8 +127,8 @@ "author": { "id": "7803408", "type": "admin", - "name": "Mock Test", - "email": "mock@nango.dev" + "name": "Kelvin Wari", + "email": "kelvin@nango.dev" }, "attachments": [], "external_id": null, @@ -149,8 +149,8 @@ "author": { "id": "7803408", "type": "admin", - "name": "Mock Test", - "email": "mock@nango.dev" + "name": "Kelvin Wari", + "email": "kelvin@nango.dev" }, "attachments": [], "external_id": null, @@ -171,8 +171,8 @@ "author": { "id": "7803408", "type": "admin", - "name": "Mock Test", - "email": "mock@nango.dev" + "name": "Kelvin Wari", + "email": "kelvin@nango.dev" }, "attachments": [], "external_id": null, diff --git a/integrations/intercom/mocks/nango/get/proxy/conversations/5/conversations.json b/integrations/intercom/mocks/nango/get/proxy/conversations/5/conversations.json index 969b07bc..51190392 100644 --- a/integrations/intercom/mocks/nango/get/proxy/conversations/5/conversations.json +++ b/integrations/intercom/mocks/nango/get/proxy/conversations/5/conversations.json @@ -134,8 +134,8 @@ "author": { "id": "7803408", "type": "admin", - "name": "Mock Test", - "email": "mock@nango.dev" + "name": "Kelvin Wari", + "email": "kelvin@nango.dev" }, "attachments": [], "external_id": null, @@ -145,7 +145,7 @@ "type": "conversation_part", "id": "24", "part_type": "note", - "body": "[Image \"customer_ticket_example.png?expires=1727750700&signature=21c97acbb22ced63976fa17d2dcc1f4580039c1a141bcbbf7e4889766e07f0d5&req=fSAlF8h8n4BYFb4f3HP0gIoXin1XyoIcWiFf7hD8nErwbPgBnaYMer9M1V2c%0AqgKkJSl6Eo20hsL0%2Fg%3D%3D%0A\"] ℹ️ This is an example of a customer ticket. Customer tickets help you solve complex issues without losing context. Use them to collect the info you need up-front, update your customers in real-time, and track progress.", + "body": "[Image \"customer_ticket_example.png?expires=1727777700&signature=71b5e65d434e685a661705b5ebab52302788ea9096cf7b5b4cd43c49880b42b2&req=fSAlF8h8n4BYFb4f3HP0gIoXin1VzYIcWiFf7hD8nErIB6w%2BF0%2BkzjORPRPP%0A6oZFukzKaTfte%2FF9yg%3D%3D%0A\"] ℹ️ This is an example of a customer ticket. Customer tickets help you solve complex issues without losing context. Use them to collect the info you need up-front, update your customers in real-time, and track progress.", "created_at": 1727524458, "updated_at": 1727524458, "notified_at": 1727524458, @@ -153,8 +153,8 @@ "author": { "id": "7803408", "type": "admin", - "name": "Mock Test", - "email": "mock@nango.dev" + "name": "Kelvin Wari", + "email": "kelvin@nango.dev" }, "attachments": [], "external_id": null, @@ -191,8 +191,8 @@ "author": { "id": "7803408", "type": "admin", - "name": "Mock Test", - "email": "mock@nango.dev" + "name": "Kelvin Wari", + "email": "kelvin@nango.dev" }, "attachments": [], "external_id": null, @@ -210,8 +210,8 @@ "author": { "id": "7803408", "type": "admin", - "name": "Mock Test", - "email": "mock@nango.dev" + "name": "Kelvin Wari", + "email": "kelvin@nango.dev" }, "attachments": [], "external_id": null, @@ -251,8 +251,8 @@ "author": { "id": "7803408", "type": "admin", - "name": "Mock Test", - "email": "mock@nango.dev" + "name": "Kelvin Wari", + "email": "kelvin@nango.dev" }, "attachments": [], "external_id": null, @@ -270,8 +270,8 @@ "author": { "id": "7803408", "type": "admin", - "name": "Mock Test", - "email": "mock@nango.dev" + "name": "Kelvin Wari", + "email": "kelvin@nango.dev" }, "attachments": [], "external_id": null, diff --git a/integrations/intercom/mocks/nango/get/proxy/conversations/6/conversations.json b/integrations/intercom/mocks/nango/get/proxy/conversations/6/conversations.json index 56266cf0..ef1725fc 100644 --- a/integrations/intercom/mocks/nango/get/proxy/conversations/6/conversations.json +++ b/integrations/intercom/mocks/nango/get/proxy/conversations/6/conversations.json @@ -102,8 +102,8 @@ "author": { "id": "7803408", "type": "admin", - "name": "Mock Test", - "email": "mock@nango.dev" + "name": "Kelvin Wari", + "email": "kelvin@nango.dev" }, "attachments": [], "external_id": null, @@ -121,8 +121,8 @@ "author": { "id": "7803408", "type": "admin", - "name": "Mock Test", - "email": "mock@nango.dev" + "name": "Kelvin Wari", + "email": "kelvin@nango.dev" }, "attachments": [], "external_id": null, @@ -159,8 +159,8 @@ "author": { "id": "7803408", "type": "admin", - "name": "Mock Test", - "email": "mock@nango.dev" + "name": "Kelvin Wari", + "email": "kelvin@nango.dev" }, "attachments": [], "external_id": null, diff --git a/integrations/intercom/mocks/nango/get/proxy/conversations/7/conversations.json b/integrations/intercom/mocks/nango/get/proxy/conversations/7/conversations.json index 91583b4f..49bcb9aa 100644 --- a/integrations/intercom/mocks/nango/get/proxy/conversations/7/conversations.json +++ b/integrations/intercom/mocks/nango/get/proxy/conversations/7/conversations.json @@ -14,8 +14,8 @@ "author": { "type": "admin", "id": "7803408", - "name": "Mock Test", - "email": "mock@nango.dev" + "name": "Kelvin Wari", + "email": "kelvin@nango.dev" }, "attachments": [], "url": null, @@ -117,8 +117,8 @@ "author": { "id": "7803408", "type": "admin", - "name": "Mock Test", - "email": "mock@nango.dev" + "name": "Kelvin Wari", + "email": "kelvin@nango.dev" }, "attachments": [], "external_id": null, diff --git a/integrations/intercom/mocks/nango/get/proxy/conversations/conversations.json b/integrations/intercom/mocks/nango/get/proxy/conversations/conversations.json index 94496951..ea95ac8b 100644 --- a/integrations/intercom/mocks/nango/get/proxy/conversations/conversations.json +++ b/integrations/intercom/mocks/nango/get/proxy/conversations/conversations.json @@ -24,8 +24,8 @@ "author": { "type": "admin", "id": "7803408", - "name": "Mock Test", - "email": "mock@nango.dev" + "name": "Kelvin Wari", + "email": "kelvin@nango.dev" }, "attachments": [], "url": null, diff --git a/integrations/intercom/nango.yaml b/integrations/intercom/nango.yaml index a9e613a6..9bb0d748 100644 --- a/integrations/intercom/nango.yaml +++ b/integrations/intercom/nango.yaml @@ -11,8 +11,8 @@ integrations: sync_type: incremental version: 1.0.0 endpoint: - - GET /intercom/conversations - - GET /intercom/conversations-message + - GET /conversations + - GET /conversation-messages contacts: runs: every 6 hours description: | @@ -21,7 +21,7 @@ integrations: sync_type: full track_deletes: true version: 1.0.0 - endpoint: GET /intercom/contacts + endpoint: GET /contacts articles: runs: every 6 hours description: | @@ -30,7 +30,7 @@ integrations: sync_type: full track_deletes: true version: 1.0.0 - endpoint: GET /intercom/articles + endpoint: GET /articles models: Contact: id: string diff --git a/integrations/intercom/tests/intercom-articles.test.ts b/integrations/intercom/tests/intercom-articles.test.ts index f498d656..b9409375 100644 --- a/integrations/intercom/tests/intercom-articles.test.ts +++ b/integrations/intercom/tests/intercom-articles.test.ts @@ -1,5 +1,4 @@ import { vi, expect, it, describe } from "vitest"; -import type { NangoSync } from "../models.js"; import fetchData from "../syncs/articles.js"; @@ -9,19 +8,46 @@ describe("intercom articles tests", () => { name: "articles", Model: "Article" }); + + const models = "Article".split(','); + const batchSaveSpy = vi.spyOn(nangoMock, 'batchSave'); + it("should get, map correctly the data and batchSave the result", async () => { await fetchData(nangoMock); - const batchSaveData = await nangoMock.getBatchSaveData(); - expect(nangoMock.batchSave).toHaveBeenCalledWith(batchSaveData, "Article"); + for (const model of models) { + const batchSaveData = await nangoMock.getBatchSaveData(model); + + const totalCalls = batchSaveSpy.mock.calls.length; + + if (totalCalls > models.length) { + const splitSize = Math.ceil(batchSaveData.length / totalCalls); + + const splitBatchSaveData = []; + for (let i = 0; i < totalCalls; i++) { + const chunk = batchSaveData.slice(i * splitSize, (i + 1) * splitSize); + splitBatchSaveData.push(chunk); + } + + splitBatchSaveData.forEach((data, index) => { + // @ts-ignore + expect(batchSaveSpy?.mock.calls[index][0]).toEqual(data); + }); + + } else { + expect(nangoMock.batchSave).toHaveBeenCalledWith(batchSaveData, model); + } + } }); it('should get, map correctly the data and batchDelete the result', async () => { await fetchData(nangoMock); - const batchDeleteData = await nangoMock.getBatchDeleteData(); - if (batchDeleteData && batchDeleteData.length > 0) { - expect(nangoMock.batchDelete).toHaveBeenCalledWith(batchDeleteData, "Article"); + for (const model of models) { + const batchDeleteData = await nangoMock.getBatchDeleteData(model); + if (batchDeleteData && batchDeleteData.length > 0) { + expect(nangoMock.batchDelete).toHaveBeenCalledWith(batchDeleteData, model); + } } }); }); diff --git a/integrations/intercom/tests/intercom-contacts.test.ts b/integrations/intercom/tests/intercom-contacts.test.ts index ab27f796..bf79e144 100644 --- a/integrations/intercom/tests/intercom-contacts.test.ts +++ b/integrations/intercom/tests/intercom-contacts.test.ts @@ -1,5 +1,4 @@ import { vi, expect, it, describe } from "vitest"; -import type { NangoSync } from "../models.js"; import fetchData from "../syncs/contacts.js"; @@ -9,19 +8,46 @@ describe("intercom contacts tests", () => { name: "contacts", Model: "Contact" }); + + const models = "Contact".split(','); + const batchSaveSpy = vi.spyOn(nangoMock, 'batchSave'); + it("should get, map correctly the data and batchSave the result", async () => { await fetchData(nangoMock); - const batchSaveData = await nangoMock.getBatchSaveData(); - expect(nangoMock.batchSave).toHaveBeenCalledWith(batchSaveData, "Contact"); + for (const model of models) { + const batchSaveData = await nangoMock.getBatchSaveData(model); + + const totalCalls = batchSaveSpy.mock.calls.length; + + if (totalCalls > models.length) { + const splitSize = Math.ceil(batchSaveData.length / totalCalls); + + const splitBatchSaveData = []; + for (let i = 0; i < totalCalls; i++) { + const chunk = batchSaveData.slice(i * splitSize, (i + 1) * splitSize); + splitBatchSaveData.push(chunk); + } + + splitBatchSaveData.forEach((data, index) => { + // @ts-ignore + expect(batchSaveSpy?.mock.calls[index][0]).toEqual(data); + }); + + } else { + expect(nangoMock.batchSave).toHaveBeenCalledWith(batchSaveData, model); + } + } }); it('should get, map correctly the data and batchDelete the result', async () => { await fetchData(nangoMock); - const batchDeleteData = await nangoMock.getBatchDeleteData(); - if (batchDeleteData && batchDeleteData.length > 0) { - expect(nangoMock.batchDelete).toHaveBeenCalledWith(batchDeleteData, "Contact"); + for (const model of models) { + const batchDeleteData = await nangoMock.getBatchDeleteData(model); + if (batchDeleteData && batchDeleteData.length > 0) { + expect(nangoMock.batchDelete).toHaveBeenCalledWith(batchDeleteData, model); + } } }); }); diff --git a/integrations/intercom/tests/intercom-conversations.test.ts b/integrations/intercom/tests/intercom-conversations.test.ts index 70156f42..90cc04e3 100644 --- a/integrations/intercom/tests/intercom-conversations.test.ts +++ b/integrations/intercom/tests/intercom-conversations.test.ts @@ -1,5 +1,4 @@ import { vi, expect, it, describe } from "vitest"; -import type { NangoSync } from "../models.js"; import fetchData from "../syncs/conversations.js"; @@ -9,19 +8,46 @@ describe("intercom conversations tests", () => { name: "conversations", Model: "Conversation,ConversationMessage" }); + + const models = "Conversation,ConversationMessage".split(','); + const batchSaveSpy = vi.spyOn(nangoMock, 'batchSave'); + it("should get, map correctly the data and batchSave the result", async () => { await fetchData(nangoMock); - const batchSaveData = await nangoMock.getBatchSaveData(); - expect(nangoMock.batchSave).toHaveBeenCalledWith(batchSaveData, "Conversation,ConversationMessage"); + for (const model of models) { + const batchSaveData = await nangoMock.getBatchSaveData(model); + + const totalCalls = batchSaveSpy.mock.calls.length; + + if (totalCalls > models.length) { + const splitSize = Math.ceil(batchSaveData.length / totalCalls); + + const splitBatchSaveData = []; + for (let i = 0; i < totalCalls; i++) { + const chunk = batchSaveData.slice(i * splitSize, (i + 1) * splitSize); + splitBatchSaveData.push(chunk); + } + + splitBatchSaveData.forEach((data, index) => { + // @ts-ignore + expect(batchSaveSpy?.mock.calls[index][0]).toEqual(data); + }); + + } else { + expect(nangoMock.batchSave).toHaveBeenCalledWith(batchSaveData, model); + } + } }); it('should get, map correctly the data and batchDelete the result', async () => { await fetchData(nangoMock); - const batchDeleteData = await nangoMock.getBatchDeleteData(); - if (batchDeleteData && batchDeleteData.length > 0) { - expect(nangoMock.batchDelete).toHaveBeenCalledWith(batchDeleteData, "Conversation,ConversationMessage"); + for (const model of models) { + const batchDeleteData = await nangoMock.getBatchDeleteData(model); + if (batchDeleteData && batchDeleteData.length > 0) { + expect(nangoMock.batchDelete).toHaveBeenCalledWith(batchDeleteData, model); + } } }); }); diff --git a/integrations/salesforce/mocks/accounts/batchDelete.json b/integrations/notion/mocks/content-metadata/ContentMetadata/batchDelete.json similarity index 100% rename from integrations/salesforce/mocks/accounts/batchDelete.json rename to integrations/notion/mocks/content-metadata/ContentMetadata/batchDelete.json diff --git a/integrations/notion/mocks/content-metadata/batchSave.json b/integrations/notion/mocks/content-metadata/ContentMetadata/batchSave.json similarity index 100% rename from integrations/notion/mocks/content-metadata/batchSave.json rename to integrations/notion/mocks/content-metadata/ContentMetadata/batchSave.json diff --git a/integrations/notion/tests/notion-content-metadata.test.ts b/integrations/notion/tests/notion-content-metadata.test.ts index acfb8e73..5e10418f 100644 --- a/integrations/notion/tests/notion-content-metadata.test.ts +++ b/integrations/notion/tests/notion-content-metadata.test.ts @@ -1,5 +1,4 @@ import { vi, expect, it, describe } from "vitest"; -import type { NangoSync } from "../models.js"; import fetchData from "../syncs/content-metadata.js"; @@ -10,39 +9,45 @@ describe("notion content-metadata tests", () => { Model: "ContentMetadata" }); + const models = "ContentMetadata".split(','); const batchSaveSpy = vi.spyOn(nangoMock, 'batchSave'); it("should get, map correctly the data and batchSave the result", async () => { await fetchData(nangoMock); - const batchSaveData = await nangoMock.getBatchSaveData(); + for (const model of models) { + const batchSaveData = await nangoMock.getBatchSaveData(model); - const totalCalls = batchSaveSpy.mock.calls.length; + const totalCalls = batchSaveSpy.mock.calls.length; - if (totalCalls > 1) { - const splitSize = Math.ceil(batchSaveData.length / totalCalls); + if (totalCalls > models.length) { + const splitSize = Math.ceil(batchSaveData.length / totalCalls); - const splitBatchSaveData = []; - for (let i = 0; i < totalCalls; i++) { - const chunk = batchSaveData.slice(i * splitSize, (i + 1) * splitSize); - splitBatchSaveData.push(chunk); - } + const splitBatchSaveData = []; + for (let i = 0; i < totalCalls; i++) { + const chunk = batchSaveData.slice(i * splitSize, (i + 1) * splitSize); + splitBatchSaveData.push(chunk); + } - splitBatchSaveData.forEach((data, index) => { - expect(batchSaveSpy?.mock.calls[index][0]).toEqual(data); - }); + splitBatchSaveData.forEach((data, index) => { + // @ts-ignore + expect(batchSaveSpy?.mock.calls[index][0]).toEqual(data); + }); - } else { - expect(nangoMock.batchSave).toHaveBeenCalledWith(batchSaveData, "ContentMetadata"); + } else { + expect(nangoMock.batchSave).toHaveBeenCalledWith(batchSaveData, model); + } } }); it('should get, map correctly the data and batchDelete the result', async () => { await fetchData(nangoMock); - const batchDeleteData = await nangoMock.getBatchDeleteData(); - if (batchDeleteData && batchDeleteData.length > 0) { - expect(nangoMock.batchDelete).toHaveBeenCalledWith(batchDeleteData, "ContentMetadata"); + for (const model of models) { + const batchDeleteData = await nangoMock.getBatchDeleteData(model); + if (batchDeleteData && batchDeleteData.length > 0) { + expect(nangoMock.batchDelete).toHaveBeenCalledWith(batchDeleteData, model); + } } }); }); diff --git a/integrations/salesforce/mocks/articles/batchDelete.json b/integrations/salesforce/mocks/accounts/Account/batchDelete.json similarity index 100% rename from integrations/salesforce/mocks/articles/batchDelete.json rename to integrations/salesforce/mocks/accounts/Account/batchDelete.json diff --git a/integrations/salesforce/mocks/accounts/batchSave.json b/integrations/salesforce/mocks/accounts/Account/batchSave.json similarity index 100% rename from integrations/salesforce/mocks/accounts/batchSave.json rename to integrations/salesforce/mocks/accounts/Account/batchSave.json diff --git a/integrations/salesforce/mocks/contacts/batchDelete.json b/integrations/salesforce/mocks/articles/Article/batchDelete.json similarity index 100% rename from integrations/salesforce/mocks/contacts/batchDelete.json rename to integrations/salesforce/mocks/articles/Article/batchDelete.json diff --git a/integrations/salesforce/mocks/articles/batchSave.json b/integrations/salesforce/mocks/articles/Article/batchSave.json similarity index 100% rename from integrations/salesforce/mocks/articles/batchSave.json rename to integrations/salesforce/mocks/articles/Article/batchSave.json diff --git a/integrations/salesforce/mocks/deals/batchDelete.json b/integrations/salesforce/mocks/contacts/Contact/batchDelete.json similarity index 100% rename from integrations/salesforce/mocks/deals/batchDelete.json rename to integrations/salesforce/mocks/contacts/Contact/batchDelete.json diff --git a/integrations/salesforce/mocks/contacts/batchSave.json b/integrations/salesforce/mocks/contacts/Contact/batchSave.json similarity index 100% rename from integrations/salesforce/mocks/contacts/batchSave.json rename to integrations/salesforce/mocks/contacts/Contact/batchSave.json diff --git a/integrations/salesforce/mocks/tickets/batchDelete.json b/integrations/salesforce/mocks/deals/Deal/batchDelete.json similarity index 100% rename from integrations/salesforce/mocks/tickets/batchDelete.json rename to integrations/salesforce/mocks/deals/Deal/batchDelete.json diff --git a/integrations/salesforce/mocks/deals/batchSave.json b/integrations/salesforce/mocks/deals/Deal/batchSave.json similarity index 100% rename from integrations/salesforce/mocks/deals/batchSave.json rename to integrations/salesforce/mocks/deals/Deal/batchSave.json diff --git a/integrations/xero/mocks/accounts/batchDelete.json b/integrations/salesforce/mocks/tickets/Ticket/batchDelete.json similarity index 100% rename from integrations/xero/mocks/accounts/batchDelete.json rename to integrations/salesforce/mocks/tickets/Ticket/batchDelete.json diff --git a/integrations/salesforce/mocks/tickets/batchSave.json b/integrations/salesforce/mocks/tickets/Ticket/batchSave.json similarity index 100% rename from integrations/salesforce/mocks/tickets/batchSave.json rename to integrations/salesforce/mocks/tickets/Ticket/batchSave.json diff --git a/integrations/salesforce/tests/salesforce-accounts.test.ts b/integrations/salesforce/tests/salesforce-accounts.test.ts index e39eb523..7e87f25d 100644 --- a/integrations/salesforce/tests/salesforce-accounts.test.ts +++ b/integrations/salesforce/tests/salesforce-accounts.test.ts @@ -1,5 +1,4 @@ import { vi, expect, it, describe } from "vitest"; -import type { NangoSync } from "../models.js"; import fetchData from "../syncs/accounts.js"; @@ -10,39 +9,45 @@ describe("salesforce accounts tests", () => { Model: "Account" }); + const models = "Account".split(','); const batchSaveSpy = vi.spyOn(nangoMock, 'batchSave'); it("should get, map correctly the data and batchSave the result", async () => { await fetchData(nangoMock); - const batchSaveData = await nangoMock.getBatchSaveData(); + for (const model of models) { + const batchSaveData = await nangoMock.getBatchSaveData(model); - const totalCalls = batchSaveSpy.mock.calls.length; + const totalCalls = batchSaveSpy.mock.calls.length; - if (totalCalls > 1) { - const splitSize = Math.ceil(batchSaveData.length / totalCalls); + if (totalCalls > models.length) { + const splitSize = Math.ceil(batchSaveData.length / totalCalls); - const splitBatchSaveData = []; - for (let i = 0; i < totalCalls; i++) { - const chunk = batchSaveData.slice(i * splitSize, (i + 1) * splitSize); - splitBatchSaveData.push(chunk); - } + const splitBatchSaveData = []; + for (let i = 0; i < totalCalls; i++) { + const chunk = batchSaveData.slice(i * splitSize, (i + 1) * splitSize); + splitBatchSaveData.push(chunk); + } - splitBatchSaveData.forEach((data, index) => { - expect(batchSaveSpy?.mock.calls[index][0]).toEqual(data); - }); + splitBatchSaveData.forEach((data, index) => { + // @ts-ignore + expect(batchSaveSpy?.mock.calls[index][0]).toEqual(data); + }); - } else { - expect(nangoMock.batchSave).toHaveBeenCalledWith(batchSaveData, "Account"); + } else { + expect(nangoMock.batchSave).toHaveBeenCalledWith(batchSaveData, model); + } } }); it('should get, map correctly the data and batchDelete the result', async () => { await fetchData(nangoMock); - const batchDeleteData = await nangoMock.getBatchDeleteData(); - if (batchDeleteData && batchDeleteData.length > 0) { - expect(nangoMock.batchDelete).toHaveBeenCalledWith(batchDeleteData, "Account"); + for (const model of models) { + const batchDeleteData = await nangoMock.getBatchDeleteData(model); + if (batchDeleteData && batchDeleteData.length > 0) { + expect(nangoMock.batchDelete).toHaveBeenCalledWith(batchDeleteData, model); + } } }); }); diff --git a/integrations/salesforce/tests/salesforce-articles.test.ts b/integrations/salesforce/tests/salesforce-articles.test.ts index ed2ecf89..91f7d0b7 100644 --- a/integrations/salesforce/tests/salesforce-articles.test.ts +++ b/integrations/salesforce/tests/salesforce-articles.test.ts @@ -1,5 +1,4 @@ import { vi, expect, it, describe } from "vitest"; -import type { NangoSync } from "../models.js"; import fetchData from "../syncs/articles.js"; @@ -10,39 +9,45 @@ describe("salesforce articles tests", () => { Model: "Article" }); + const models = "Article".split(','); const batchSaveSpy = vi.spyOn(nangoMock, 'batchSave'); it("should get, map correctly the data and batchSave the result", async () => { await fetchData(nangoMock); - const batchSaveData = await nangoMock.getBatchSaveData(); + for (const model of models) { + const batchSaveData = await nangoMock.getBatchSaveData(model); - const totalCalls = batchSaveSpy.mock.calls.length; + const totalCalls = batchSaveSpy.mock.calls.length; - if (totalCalls > 1) { - const splitSize = Math.ceil(batchSaveData.length / totalCalls); + if (totalCalls > models.length) { + const splitSize = Math.ceil(batchSaveData.length / totalCalls); - const splitBatchSaveData = []; - for (let i = 0; i < totalCalls; i++) { - const chunk = batchSaveData.slice(i * splitSize, (i + 1) * splitSize); - splitBatchSaveData.push(chunk); - } + const splitBatchSaveData = []; + for (let i = 0; i < totalCalls; i++) { + const chunk = batchSaveData.slice(i * splitSize, (i + 1) * splitSize); + splitBatchSaveData.push(chunk); + } - splitBatchSaveData.forEach((data, index) => { - expect(batchSaveSpy?.mock.calls[index][0]).toEqual(data); - }); + splitBatchSaveData.forEach((data, index) => { + // @ts-ignore + expect(batchSaveSpy?.mock.calls[index][0]).toEqual(data); + }); - } else { - expect(nangoMock.batchSave).toHaveBeenCalledWith(batchSaveData, "Article"); + } else { + expect(nangoMock.batchSave).toHaveBeenCalledWith(batchSaveData, model); + } } }); it('should get, map correctly the data and batchDelete the result', async () => { await fetchData(nangoMock); - const batchDeleteData = await nangoMock.getBatchDeleteData(); - if (batchDeleteData && batchDeleteData.length > 0) { - expect(nangoMock.batchDelete).toHaveBeenCalledWith(batchDeleteData, "Article"); + for (const model of models) { + const batchDeleteData = await nangoMock.getBatchDeleteData(model); + if (batchDeleteData && batchDeleteData.length > 0) { + expect(nangoMock.batchDelete).toHaveBeenCalledWith(batchDeleteData, model); + } } }); }); diff --git a/integrations/salesforce/tests/salesforce-contacts.test.ts b/integrations/salesforce/tests/salesforce-contacts.test.ts index 833e5538..d25e7297 100644 --- a/integrations/salesforce/tests/salesforce-contacts.test.ts +++ b/integrations/salesforce/tests/salesforce-contacts.test.ts @@ -1,5 +1,4 @@ import { vi, expect, it, describe } from "vitest"; -import type { NangoSync } from "../models.js"; import fetchData from "../syncs/contacts.js"; @@ -10,39 +9,45 @@ describe("salesforce contacts tests", () => { Model: "Contact" }); + const models = "Contact".split(','); const batchSaveSpy = vi.spyOn(nangoMock, 'batchSave'); it("should get, map correctly the data and batchSave the result", async () => { await fetchData(nangoMock); - const batchSaveData = await nangoMock.getBatchSaveData(); + for (const model of models) { + const batchSaveData = await nangoMock.getBatchSaveData(model); - const totalCalls = batchSaveSpy.mock.calls.length; + const totalCalls = batchSaveSpy.mock.calls.length; - if (totalCalls > 1) { - const splitSize = Math.ceil(batchSaveData.length / totalCalls); + if (totalCalls > models.length) { + const splitSize = Math.ceil(batchSaveData.length / totalCalls); - const splitBatchSaveData = []; - for (let i = 0; i < totalCalls; i++) { - const chunk = batchSaveData.slice(i * splitSize, (i + 1) * splitSize); - splitBatchSaveData.push(chunk); - } + const splitBatchSaveData = []; + for (let i = 0; i < totalCalls; i++) { + const chunk = batchSaveData.slice(i * splitSize, (i + 1) * splitSize); + splitBatchSaveData.push(chunk); + } - splitBatchSaveData.forEach((data, index) => { - expect(batchSaveSpy?.mock.calls[index][0]).toEqual(data); - }); + splitBatchSaveData.forEach((data, index) => { + // @ts-ignore + expect(batchSaveSpy?.mock.calls[index][0]).toEqual(data); + }); - } else { - expect(nangoMock.batchSave).toHaveBeenCalledWith(batchSaveData, "Contact"); + } else { + expect(nangoMock.batchSave).toHaveBeenCalledWith(batchSaveData, model); + } } }); it('should get, map correctly the data and batchDelete the result', async () => { await fetchData(nangoMock); - const batchDeleteData = await nangoMock.getBatchDeleteData(); - if (batchDeleteData && batchDeleteData.length > 0) { - expect(nangoMock.batchDelete).toHaveBeenCalledWith(batchDeleteData, "Contact"); + for (const model of models) { + const batchDeleteData = await nangoMock.getBatchDeleteData(model); + if (batchDeleteData && batchDeleteData.length > 0) { + expect(nangoMock.batchDelete).toHaveBeenCalledWith(batchDeleteData, model); + } } }); }); diff --git a/integrations/salesforce/tests/salesforce-deals.test.ts b/integrations/salesforce/tests/salesforce-deals.test.ts index d96ace7b..1857ffd1 100644 --- a/integrations/salesforce/tests/salesforce-deals.test.ts +++ b/integrations/salesforce/tests/salesforce-deals.test.ts @@ -1,5 +1,4 @@ import { vi, expect, it, describe } from "vitest"; -import type { NangoSync } from "../models.js"; import fetchData from "../syncs/deals.js"; @@ -10,39 +9,45 @@ describe("salesforce deals tests", () => { Model: "Deal" }); + const models = "Deal".split(','); const batchSaveSpy = vi.spyOn(nangoMock, 'batchSave'); it("should get, map correctly the data and batchSave the result", async () => { await fetchData(nangoMock); - const batchSaveData = await nangoMock.getBatchSaveData(); + for (const model of models) { + const batchSaveData = await nangoMock.getBatchSaveData(model); - const totalCalls = batchSaveSpy.mock.calls.length; + const totalCalls = batchSaveSpy.mock.calls.length; - if (totalCalls > 1) { - const splitSize = Math.ceil(batchSaveData.length / totalCalls); + if (totalCalls > models.length) { + const splitSize = Math.ceil(batchSaveData.length / totalCalls); - const splitBatchSaveData = []; - for (let i = 0; i < totalCalls; i++) { - const chunk = batchSaveData.slice(i * splitSize, (i + 1) * splitSize); - splitBatchSaveData.push(chunk); - } + const splitBatchSaveData = []; + for (let i = 0; i < totalCalls; i++) { + const chunk = batchSaveData.slice(i * splitSize, (i + 1) * splitSize); + splitBatchSaveData.push(chunk); + } - splitBatchSaveData.forEach((data, index) => { - expect(batchSaveSpy?.mock.calls[index][0]).toEqual(data); - }); + splitBatchSaveData.forEach((data, index) => { + // @ts-ignore + expect(batchSaveSpy?.mock.calls[index][0]).toEqual(data); + }); - } else { - expect(nangoMock.batchSave).toHaveBeenCalledWith(batchSaveData, "Deal"); + } else { + expect(nangoMock.batchSave).toHaveBeenCalledWith(batchSaveData, model); + } } }); it('should get, map correctly the data and batchDelete the result', async () => { await fetchData(nangoMock); - const batchDeleteData = await nangoMock.getBatchDeleteData(); - if (batchDeleteData && batchDeleteData.length > 0) { - expect(nangoMock.batchDelete).toHaveBeenCalledWith(batchDeleteData, "Deal"); + for (const model of models) { + const batchDeleteData = await nangoMock.getBatchDeleteData(model); + if (batchDeleteData && batchDeleteData.length > 0) { + expect(nangoMock.batchDelete).toHaveBeenCalledWith(batchDeleteData, model); + } } }); }); diff --git a/integrations/salesforce/tests/salesforce-tickets.test.ts b/integrations/salesforce/tests/salesforce-tickets.test.ts index c12eb6bb..afb9047b 100644 --- a/integrations/salesforce/tests/salesforce-tickets.test.ts +++ b/integrations/salesforce/tests/salesforce-tickets.test.ts @@ -1,5 +1,4 @@ import { vi, expect, it, describe } from "vitest"; -import type { NangoSync } from "../models.js"; import fetchData from "../syncs/tickets.js"; @@ -10,39 +9,45 @@ describe("salesforce tickets tests", () => { Model: "Ticket" }); + const models = "Ticket".split(','); const batchSaveSpy = vi.spyOn(nangoMock, 'batchSave'); it("should get, map correctly the data and batchSave the result", async () => { await fetchData(nangoMock); - const batchSaveData = await nangoMock.getBatchSaveData(); + for (const model of models) { + const batchSaveData = await nangoMock.getBatchSaveData(model); - const totalCalls = batchSaveSpy.mock.calls.length; + const totalCalls = batchSaveSpy.mock.calls.length; - if (totalCalls > 1) { - const splitSize = Math.ceil(batchSaveData.length / totalCalls); + if (totalCalls > models.length) { + const splitSize = Math.ceil(batchSaveData.length / totalCalls); - const splitBatchSaveData = []; - for (let i = 0; i < totalCalls; i++) { - const chunk = batchSaveData.slice(i * splitSize, (i + 1) * splitSize); - splitBatchSaveData.push(chunk); - } + const splitBatchSaveData = []; + for (let i = 0; i < totalCalls; i++) { + const chunk = batchSaveData.slice(i * splitSize, (i + 1) * splitSize); + splitBatchSaveData.push(chunk); + } - splitBatchSaveData.forEach((data, index) => { - expect(batchSaveSpy?.mock.calls[index][0]).toEqual(data); - }); + splitBatchSaveData.forEach((data, index) => { + // @ts-ignore + expect(batchSaveSpy?.mock.calls[index][0]).toEqual(data); + }); - } else { - expect(nangoMock.batchSave).toHaveBeenCalledWith(batchSaveData, "Ticket"); + } else { + expect(nangoMock.batchSave).toHaveBeenCalledWith(batchSaveData, model); + } } }); it('should get, map correctly the data and batchDelete the result', async () => { await fetchData(nangoMock); - const batchDeleteData = await nangoMock.getBatchDeleteData(); - if (batchDeleteData && batchDeleteData.length > 0) { - expect(nangoMock.batchDelete).toHaveBeenCalledWith(batchDeleteData, "Ticket"); + for (const model of models) { + const batchDeleteData = await nangoMock.getBatchDeleteData(model); + if (batchDeleteData && batchDeleteData.length > 0) { + expect(nangoMock.batchDelete).toHaveBeenCalledWith(batchDeleteData, model); + } } }); }); diff --git a/integrations/xero/mocks/contacts/batchDelete.json b/integrations/xero/mocks/accounts/Account/batchDelete.json similarity index 100% rename from integrations/xero/mocks/contacts/batchDelete.json rename to integrations/xero/mocks/accounts/Account/batchDelete.json diff --git a/integrations/xero/mocks/accounts/batchSave.json b/integrations/xero/mocks/accounts/Account/batchSave.json similarity index 100% rename from integrations/xero/mocks/accounts/batchSave.json rename to integrations/xero/mocks/accounts/Account/batchSave.json diff --git a/integrations/xero/mocks/invoices/batchDelete.json b/integrations/xero/mocks/contacts/Contact/batchDelete.json similarity index 100% rename from integrations/xero/mocks/invoices/batchDelete.json rename to integrations/xero/mocks/contacts/Contact/batchDelete.json diff --git a/integrations/xero/mocks/contacts/batchSave.json b/integrations/xero/mocks/contacts/Contact/batchSave.json similarity index 100% rename from integrations/xero/mocks/contacts/batchSave.json rename to integrations/xero/mocks/contacts/Contact/batchSave.json diff --git a/integrations/xero/mocks/items/batchDelete.json b/integrations/xero/mocks/invoices/Invoice/batchDelete.json similarity index 100% rename from integrations/xero/mocks/items/batchDelete.json rename to integrations/xero/mocks/invoices/Invoice/batchDelete.json diff --git a/integrations/xero/mocks/invoices/batchSave.json b/integrations/xero/mocks/invoices/Invoice/batchSave.json similarity index 100% rename from integrations/xero/mocks/invoices/batchSave.json rename to integrations/xero/mocks/invoices/Invoice/batchSave.json diff --git a/integrations/xero/mocks/payments/batchDelete.json b/integrations/xero/mocks/items/Item/batchDelete.json similarity index 100% rename from integrations/xero/mocks/payments/batchDelete.json rename to integrations/xero/mocks/items/Item/batchDelete.json diff --git a/integrations/xero/mocks/items/batchSave.json b/integrations/xero/mocks/items/Item/batchSave.json similarity index 100% rename from integrations/xero/mocks/items/batchSave.json rename to integrations/xero/mocks/items/Item/batchSave.json diff --git a/integrations/xero/mocks/payments/Payment/batchDelete.json b/integrations/xero/mocks/payments/Payment/batchDelete.json new file mode 100644 index 00000000..fe51488c --- /dev/null +++ b/integrations/xero/mocks/payments/Payment/batchDelete.json @@ -0,0 +1 @@ +[] diff --git a/integrations/xero/mocks/payments/batchSave.json b/integrations/xero/mocks/payments/Payment/batchSave.json similarity index 100% rename from integrations/xero/mocks/payments/batchSave.json rename to integrations/xero/mocks/payments/Payment/batchSave.json diff --git a/integrations/xero/tests/xero-accounts.test.ts b/integrations/xero/tests/xero-accounts.test.ts index 5bc36b09..694353a5 100644 --- a/integrations/xero/tests/xero-accounts.test.ts +++ b/integrations/xero/tests/xero-accounts.test.ts @@ -1,5 +1,4 @@ import { vi, expect, it, describe } from "vitest"; -import type { NangoSync } from "../models.js"; import fetchData from "../syncs/accounts.js"; @@ -10,39 +9,45 @@ describe("xero accounts tests", () => { Model: "Account" }); + const models = "Account".split(','); const batchSaveSpy = vi.spyOn(nangoMock, 'batchSave'); it("should get, map correctly the data and batchSave the result", async () => { await fetchData(nangoMock); - const batchSaveData = await nangoMock.getBatchSaveData(); + for (const model of models) { + const batchSaveData = await nangoMock.getBatchSaveData(model); - const totalCalls = batchSaveSpy.mock.calls.length; + const totalCalls = batchSaveSpy.mock.calls.length; - if (totalCalls > 1) { - const splitSize = Math.ceil(batchSaveData.length / totalCalls); + if (totalCalls > models.length) { + const splitSize = Math.ceil(batchSaveData.length / totalCalls); - const splitBatchSaveData = []; - for (let i = 0; i < totalCalls; i++) { - const chunk = batchSaveData.slice(i * splitSize, (i + 1) * splitSize); - splitBatchSaveData.push(chunk); - } + const splitBatchSaveData = []; + for (let i = 0; i < totalCalls; i++) { + const chunk = batchSaveData.slice(i * splitSize, (i + 1) * splitSize); + splitBatchSaveData.push(chunk); + } - splitBatchSaveData.forEach((data, index) => { - expect(batchSaveSpy?.mock.calls[index][0]).toEqual(data); - }); + splitBatchSaveData.forEach((data, index) => { + // @ts-ignore + expect(batchSaveSpy?.mock.calls[index][0]).toEqual(data); + }); - } else { - expect(nangoMock.batchSave).toHaveBeenCalledWith(batchSaveData, "Account"); + } else { + expect(nangoMock.batchSave).toHaveBeenCalledWith(batchSaveData, model); + } } }); it('should get, map correctly the data and batchDelete the result', async () => { await fetchData(nangoMock); - const batchDeleteData = await nangoMock.getBatchDeleteData(); - if (batchDeleteData && batchDeleteData.length > 0) { - expect(nangoMock.batchDelete).toHaveBeenCalledWith(batchDeleteData, "Account"); + for (const model of models) { + const batchDeleteData = await nangoMock.getBatchDeleteData(model); + if (batchDeleteData && batchDeleteData.length > 0) { + expect(nangoMock.batchDelete).toHaveBeenCalledWith(batchDeleteData, model); + } } }); }); diff --git a/integrations/xero/tests/xero-contacts.test.ts b/integrations/xero/tests/xero-contacts.test.ts index db363363..77336f5a 100644 --- a/integrations/xero/tests/xero-contacts.test.ts +++ b/integrations/xero/tests/xero-contacts.test.ts @@ -1,5 +1,4 @@ import { vi, expect, it, describe } from "vitest"; -import type { NangoSync } from "../models.js"; import fetchData from "../syncs/contacts.js"; @@ -10,39 +9,45 @@ describe("xero contacts tests", () => { Model: "Contact" }); + const models = "Contact".split(','); const batchSaveSpy = vi.spyOn(nangoMock, 'batchSave'); it("should get, map correctly the data and batchSave the result", async () => { await fetchData(nangoMock); - const batchSaveData = await nangoMock.getBatchSaveData(); + for (const model of models) { + const batchSaveData = await nangoMock.getBatchSaveData(model); - const totalCalls = batchSaveSpy.mock.calls.length; + const totalCalls = batchSaveSpy.mock.calls.length; - if (totalCalls > 1) { - const splitSize = Math.ceil(batchSaveData.length / totalCalls); + if (totalCalls > models.length) { + const splitSize = Math.ceil(batchSaveData.length / totalCalls); - const splitBatchSaveData = []; - for (let i = 0; i < totalCalls; i++) { - const chunk = batchSaveData.slice(i * splitSize, (i + 1) * splitSize); - splitBatchSaveData.push(chunk); - } + const splitBatchSaveData = []; + for (let i = 0; i < totalCalls; i++) { + const chunk = batchSaveData.slice(i * splitSize, (i + 1) * splitSize); + splitBatchSaveData.push(chunk); + } - splitBatchSaveData.forEach((data, index) => { - expect(batchSaveSpy?.mock.calls[index][0]).toEqual(data); - }); + splitBatchSaveData.forEach((data, index) => { + // @ts-ignore + expect(batchSaveSpy?.mock.calls[index][0]).toEqual(data); + }); - } else { - expect(nangoMock.batchSave).toHaveBeenCalledWith(batchSaveData, "Contact"); + } else { + expect(nangoMock.batchSave).toHaveBeenCalledWith(batchSaveData, model); + } } }); it('should get, map correctly the data and batchDelete the result', async () => { await fetchData(nangoMock); - const batchDeleteData = await nangoMock.getBatchDeleteData(); - if (batchDeleteData && batchDeleteData.length > 0) { - expect(nangoMock.batchDelete).toHaveBeenCalledWith(batchDeleteData, "Contact"); + for (const model of models) { + const batchDeleteData = await nangoMock.getBatchDeleteData(model); + if (batchDeleteData && batchDeleteData.length > 0) { + expect(nangoMock.batchDelete).toHaveBeenCalledWith(batchDeleteData, model); + } } }); }); diff --git a/integrations/xero/tests/xero-invoices.test.ts b/integrations/xero/tests/xero-invoices.test.ts index 7b3a4d15..268ed3ba 100644 --- a/integrations/xero/tests/xero-invoices.test.ts +++ b/integrations/xero/tests/xero-invoices.test.ts @@ -1,5 +1,4 @@ import { vi, expect, it, describe } from "vitest"; -import type { NangoSync } from "../models.js"; import fetchData from "../syncs/invoices.js"; @@ -10,39 +9,45 @@ describe("xero invoices tests", () => { Model: "Invoice" }); + const models = "Invoice".split(','); const batchSaveSpy = vi.spyOn(nangoMock, 'batchSave'); it("should get, map correctly the data and batchSave the result", async () => { await fetchData(nangoMock); - const batchSaveData = await nangoMock.getBatchSaveData(); + for (const model of models) { + const batchSaveData = await nangoMock.getBatchSaveData(model); - const totalCalls = batchSaveSpy.mock.calls.length; + const totalCalls = batchSaveSpy.mock.calls.length; - if (totalCalls > 1) { - const splitSize = Math.ceil(batchSaveData.length / totalCalls); + if (totalCalls > models.length) { + const splitSize = Math.ceil(batchSaveData.length / totalCalls); - const splitBatchSaveData = []; - for (let i = 0; i < totalCalls; i++) { - const chunk = batchSaveData.slice(i * splitSize, (i + 1) * splitSize); - splitBatchSaveData.push(chunk); - } + const splitBatchSaveData = []; + for (let i = 0; i < totalCalls; i++) { + const chunk = batchSaveData.slice(i * splitSize, (i + 1) * splitSize); + splitBatchSaveData.push(chunk); + } - splitBatchSaveData.forEach((data, index) => { - expect(batchSaveSpy?.mock.calls[index][0]).toEqual(data); - }); + splitBatchSaveData.forEach((data, index) => { + // @ts-ignore + expect(batchSaveSpy?.mock.calls[index][0]).toEqual(data); + }); - } else { - expect(nangoMock.batchSave).toHaveBeenCalledWith(batchSaveData, "Invoice"); + } else { + expect(nangoMock.batchSave).toHaveBeenCalledWith(batchSaveData, model); + } } }); it('should get, map correctly the data and batchDelete the result', async () => { await fetchData(nangoMock); - const batchDeleteData = await nangoMock.getBatchDeleteData(); - if (batchDeleteData && batchDeleteData.length > 0) { - expect(nangoMock.batchDelete).toHaveBeenCalledWith(batchDeleteData, "Invoice"); + for (const model of models) { + const batchDeleteData = await nangoMock.getBatchDeleteData(model); + if (batchDeleteData && batchDeleteData.length > 0) { + expect(nangoMock.batchDelete).toHaveBeenCalledWith(batchDeleteData, model); + } } }); }); diff --git a/integrations/xero/tests/xero-items.test.ts b/integrations/xero/tests/xero-items.test.ts index 400d1fbe..8e48e212 100644 --- a/integrations/xero/tests/xero-items.test.ts +++ b/integrations/xero/tests/xero-items.test.ts @@ -1,5 +1,4 @@ import { vi, expect, it, describe } from "vitest"; -import type { NangoSync } from "../models.js"; import fetchData from "../syncs/items.js"; @@ -10,39 +9,45 @@ describe("xero items tests", () => { Model: "Item" }); + const models = "Item".split(','); const batchSaveSpy = vi.spyOn(nangoMock, 'batchSave'); it("should get, map correctly the data and batchSave the result", async () => { await fetchData(nangoMock); - const batchSaveData = await nangoMock.getBatchSaveData(); + for (const model of models) { + const batchSaveData = await nangoMock.getBatchSaveData(model); - const totalCalls = batchSaveSpy.mock.calls.length; + const totalCalls = batchSaveSpy.mock.calls.length; - if (totalCalls > 1) { - const splitSize = Math.ceil(batchSaveData.length / totalCalls); + if (totalCalls > models.length) { + const splitSize = Math.ceil(batchSaveData.length / totalCalls); - const splitBatchSaveData = []; - for (let i = 0; i < totalCalls; i++) { - const chunk = batchSaveData.slice(i * splitSize, (i + 1) * splitSize); - splitBatchSaveData.push(chunk); - } + const splitBatchSaveData = []; + for (let i = 0; i < totalCalls; i++) { + const chunk = batchSaveData.slice(i * splitSize, (i + 1) * splitSize); + splitBatchSaveData.push(chunk); + } - splitBatchSaveData.forEach((data, index) => { - expect(batchSaveSpy?.mock.calls[index][0]).toEqual(data); - }); + splitBatchSaveData.forEach((data, index) => { + // @ts-ignore + expect(batchSaveSpy?.mock.calls[index][0]).toEqual(data); + }); - } else { - expect(nangoMock.batchSave).toHaveBeenCalledWith(batchSaveData, "Item"); + } else { + expect(nangoMock.batchSave).toHaveBeenCalledWith(batchSaveData, model); + } } }); it('should get, map correctly the data and batchDelete the result', async () => { await fetchData(nangoMock); - const batchDeleteData = await nangoMock.getBatchDeleteData(); - if (batchDeleteData && batchDeleteData.length > 0) { - expect(nangoMock.batchDelete).toHaveBeenCalledWith(batchDeleteData, "Item"); + for (const model of models) { + const batchDeleteData = await nangoMock.getBatchDeleteData(model); + if (batchDeleteData && batchDeleteData.length > 0) { + expect(nangoMock.batchDelete).toHaveBeenCalledWith(batchDeleteData, model); + } } }); }); diff --git a/integrations/xero/tests/xero-payments.test.ts b/integrations/xero/tests/xero-payments.test.ts index 00295d20..d37573d4 100644 --- a/integrations/xero/tests/xero-payments.test.ts +++ b/integrations/xero/tests/xero-payments.test.ts @@ -1,5 +1,4 @@ import { vi, expect, it, describe } from "vitest"; -import type { NangoSync } from "../models.js"; import fetchData from "../syncs/payments.js"; @@ -10,39 +9,45 @@ describe("xero payments tests", () => { Model: "Payment" }); + const models = "Payment".split(','); const batchSaveSpy = vi.spyOn(nangoMock, 'batchSave'); it("should get, map correctly the data and batchSave the result", async () => { await fetchData(nangoMock); - const batchSaveData = await nangoMock.getBatchSaveData(); + for (const model of models) { + const batchSaveData = await nangoMock.getBatchSaveData(model); - const totalCalls = batchSaveSpy.mock.calls.length; + const totalCalls = batchSaveSpy.mock.calls.length; - if (totalCalls > 1) { - const splitSize = Math.ceil(batchSaveData.length / totalCalls); + if (totalCalls > models.length) { + const splitSize = Math.ceil(batchSaveData.length / totalCalls); - const splitBatchSaveData = []; - for (let i = 0; i < totalCalls; i++) { - const chunk = batchSaveData.slice(i * splitSize, (i + 1) * splitSize); - splitBatchSaveData.push(chunk); - } + const splitBatchSaveData = []; + for (let i = 0; i < totalCalls; i++) { + const chunk = batchSaveData.slice(i * splitSize, (i + 1) * splitSize); + splitBatchSaveData.push(chunk); + } - splitBatchSaveData.forEach((data, index) => { - expect(batchSaveSpy?.mock.calls[index][0]).toEqual(data); - }); + splitBatchSaveData.forEach((data, index) => { + // @ts-ignore + expect(batchSaveSpy?.mock.calls[index][0]).toEqual(data); + }); - } else { - expect(nangoMock.batchSave).toHaveBeenCalledWith(batchSaveData, "Payment"); + } else { + expect(nangoMock.batchSave).toHaveBeenCalledWith(batchSaveData, model); + } } }); it('should get, map correctly the data and batchDelete the result', async () => { await fetchData(nangoMock); - const batchDeleteData = await nangoMock.getBatchDeleteData(); - if (batchDeleteData && batchDeleteData.length > 0) { - expect(nangoMock.batchDelete).toHaveBeenCalledWith(batchDeleteData, "Payment"); + for (const model of models) { + const batchDeleteData = await nangoMock.getBatchDeleteData(model); + if (batchDeleteData && batchDeleteData.length > 0) { + expect(nangoMock.batchDelete).toHaveBeenCalledWith(batchDeleteData, model); + } } }); }); diff --git a/scripts/tests/generate-tests.ts b/scripts/tests/generate-tests.ts index 2732d4e8..c81813ff 100644 --- a/scripts/tests/generate-tests.ts +++ b/scripts/tests/generate-tests.ts @@ -20,11 +20,11 @@ for (const integration in integrations) { } } -function generateSyncTest(integration: string, syncName: string, modelName: string) { +function generateSyncTest(integration: string, syncName: string, modelName: string | string[]) { const data: { integration: string; syncName: string; - modelName: string; + modelName: string | string[]; } = { integration, syncName, diff --git a/scripts/tests/sync-template.ejs b/scripts/tests/sync-template.ejs index 52a16915..5b13f41a 100644 --- a/scripts/tests/sync-template.ejs +++ b/scripts/tests/sync-template.ejs @@ -1,5 +1,4 @@ import { vi, expect, it, describe } from "vitest"; -import type { NangoSync } from "../models.js"; import fetchData from "../syncs/<%= syncName %>.js"; @@ -10,39 +9,45 @@ describe("<%= integration %> <%= syncName %> tests", () => { Model: "<%= modelName %>" }); + const models = "<%= modelName %>".split(','); const batchSaveSpy = vi.spyOn(nangoMock, 'batchSave'); it("should get, map correctly the data and batchSave the result", async () => { await fetchData(nangoMock); - const batchSaveData = await nangoMock.getBatchSaveData(); + for (const model of models) { + const batchSaveData = await nangoMock.getBatchSaveData(model); - const totalCalls = batchSaveSpy.mock.calls.length; + const totalCalls = batchSaveSpy.mock.calls.length; - if (totalCalls > 1) { - const splitSize = Math.ceil(batchSaveData.length / totalCalls); + if (totalCalls > models.length) { + const splitSize = Math.ceil(batchSaveData.length / totalCalls); - const splitBatchSaveData = []; - for (let i = 0; i < totalCalls; i++) { - const chunk = batchSaveData.slice(i * splitSize, (i + 1) * splitSize); - splitBatchSaveData.push(chunk); - } + const splitBatchSaveData = []; + for (let i = 0; i < totalCalls; i++) { + const chunk = batchSaveData.slice(i * splitSize, (i + 1) * splitSize); + splitBatchSaveData.push(chunk); + } - splitBatchSaveData.forEach((data, index) => { - expect(batchSaveSpy?.mock.calls[index][0]).toEqual(data); - }); + splitBatchSaveData.forEach((data, index) => { + // @ts-ignore + expect(batchSaveSpy?.mock.calls[index][0]).toEqual(data); + }); - } else { - expect(nangoMock.batchSave).toHaveBeenCalledWith(batchSaveData, "<%= modelName %>"); + } else { + expect(nangoMock.batchSave).toHaveBeenCalledWith(batchSaveData, model); + } } }); it('should get, map correctly the data and batchDelete the result', async () => { await fetchData(nangoMock); - const batchDeleteData = await nangoMock.getBatchDeleteData(); - if (batchDeleteData && batchDeleteData.length > 0) { - expect(nangoMock.batchDelete).toHaveBeenCalledWith(batchDeleteData, "<%= modelName %>"); + for (const model of models) { + const batchDeleteData = await nangoMock.getBatchDeleteData(model); + if (batchDeleteData && batchDeleteData.length > 0) { + expect(nangoMock.batchDelete).toHaveBeenCalledWith(batchDeleteData, model); + } } }); }); diff --git a/vitest.setup.ts b/vitest.setup.ts index 35a4a5af..10d7688e 100644 --- a/vitest.setup.ts +++ b/vitest.setup.ts @@ -26,8 +26,8 @@ export class NangoSyncMock { this.dirname = dirname; this.name = name; this.Model = Model; - this.batchSave = vi.fn(this.getBatchSaveData.bind(this)); - this.batchDelete = vi.fn(this.getBatchDeleteData.bind(this)); + this.batchSave = vi.fn(); + this.batchDelete = vi.fn(); this.getConnection = vi.fn(this.getConnectionData.bind(this)); this.getMetadata = vi.fn(this.getMetadataData.bind(this)); this.paginate = vi.fn(this.getProxyPaginateData.bind(this)); @@ -50,13 +50,13 @@ export class NangoSyncMock { } } - private async getBatchSaveData() { - const data = await this.getMockFile(`${this.name}/batchSave`); + public async getBatchSaveData(modelName: string) { + const data = await this.getMockFile(`${this.name}/${modelName}/batchSave`); return data; } - private async getBatchDeleteData() { - const data = await this.getMockFile(`${this.name}/batchDelete`); + public async getBatchDeleteData(modelName: string) { + const data = await this.getMockFile(`${this.name}/${modelName}/batchDelete`); return data; }