From 11e0d7465a155a7bc7ee57151f98707a9f6efb83 Mon Sep 17 00:00:00 2001 From: Biswajeet Das Date: Tue, 5 Sep 2023 18:06:52 +0530 Subject: [PATCH 1/3] feat: add missing endpoints --- .../integrations/integrations.interface.ts | 1 + .../src/lib/integrations/integrations.spec.ts | 20 ++++++++++++++++++ .../node/src/lib/integrations/integrations.ts | 21 ++++++++++++++----- 3 files changed, 37 insertions(+), 5 deletions(-) diff --git a/packages/node/src/lib/integrations/integrations.interface.ts b/packages/node/src/lib/integrations/integrations.interface.ts index da362206d33..3b9087b20d7 100644 --- a/packages/node/src/lib/integrations/integrations.interface.ts +++ b/packages/node/src/lib/integrations/integrations.interface.ts @@ -8,6 +8,7 @@ export interface IIntegrations { update(integrationId: string, data: IIntegrationsUpdatePayload); delete(integrationId: string); getInAppStatus(); + setIntegrationAsPrimary(integrationId: string); } export interface IIntegrationsPayload extends IIntegrationsUpdatePayload { diff --git a/packages/node/src/lib/integrations/integrations.spec.ts b/packages/node/src/lib/integrations/integrations.spec.ts index 2353d0aeb73..83e62739c2d 100644 --- a/packages/node/src/lib/integrations/integrations.spec.ts +++ b/packages/node/src/lib/integrations/integrations.spec.ts @@ -108,4 +108,24 @@ describe('test use of novus node package - Integrations class', () => { '/integrations/INTEGRATION_ID' ); }); + + test('should set the integration as primary', async () => { + mockedAxios.post.mockResolvedValue({}); + + await novu.integrations.setIntegrationAsPrimary('INTEGRATION_ID'); + + expect(mockedAxios.post).toHaveBeenCalled(); + expect(mockedAxios.post).toHaveBeenCalledWith( + '/integrations/INTEGRATION_ID/set-primary' + ); + }); + + test('should get the in-app status of the integration', async () => { + mockedAxios.post.mockResolvedValue({}); + + await novu.integrations.getInAppStatus(); + + expect(mockedAxios.get).toHaveBeenCalled(); + expect(mockedAxios.get).toHaveBeenCalledWith('/integrations/in-app/status'); + }); }); diff --git a/packages/node/src/lib/integrations/integrations.ts b/packages/node/src/lib/integrations/integrations.ts index cf99b9fdb03..c5675eef2e0 100644 --- a/packages/node/src/lib/integrations/integrations.ts +++ b/packages/node/src/lib/integrations/integrations.ts @@ -1,9 +1,10 @@ +import { ChannelTypeEnum } from '@novu/shared'; +import { WithHttp } from '../novu.interface'; import { IIntegrations, IIntegrationsPayload, IIntegrationsUpdatePayload, } from './integrations.interface'; -import { WithHttp } from '../novu.interface'; export class Integrations extends WithHttp implements IIntegrations { async getAll() { @@ -14,6 +15,10 @@ export class Integrations extends WithHttp implements IIntegrations { return await this.http.get('/integrations/active'); } + async getInAppStatus() { + return await this.http.get('/integrations/in-app/status'); + } + /** * @param {string} providerId - Id of the provider to get status */ @@ -44,14 +49,20 @@ export class Integrations extends WithHttp implements IIntegrations { }); } + /** + * @param {string} integrationId - integrationId of the integration to set it as primary + */ + async setIntegrationAsPrimary(integrationId: string) { + return await this.http.post( + `/integrations/${integrationId}/set-primary`, + {} + ); + } + /** * @param {string} integrationId - integrationId of the integration to delete */ async delete(integrationId: string) { return await this.http.delete(`/integrations/${integrationId}`); } - - async getInAppStatus() { - return await this.http.get('/integrations/in-app/status'); - } } From 0329f4baa2c2ad90211bbb6b4f236309aa91e250 Mon Sep 17 00:00:00 2001 From: Biswajeet Das Date: Tue, 5 Sep 2023 18:51:33 +0530 Subject: [PATCH 2/3] fix: tests --- packages/node/src/lib/integrations/integrations.spec.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/node/src/lib/integrations/integrations.spec.ts b/packages/node/src/lib/integrations/integrations.spec.ts index 83e62739c2d..bc0151eb3ba 100644 --- a/packages/node/src/lib/integrations/integrations.spec.ts +++ b/packages/node/src/lib/integrations/integrations.spec.ts @@ -116,7 +116,8 @@ describe('test use of novus node package - Integrations class', () => { expect(mockedAxios.post).toHaveBeenCalled(); expect(mockedAxios.post).toHaveBeenCalledWith( - '/integrations/INTEGRATION_ID/set-primary' + '/integrations/INTEGRATION_ID/set-primary', + {} ); }); From 40b32dee11f4f1af43d919467a9c9ce223b05e75 Mon Sep 17 00:00:00 2001 From: Biswajeet Das Date: Mon, 11 Sep 2023 13:41:05 +0530 Subject: [PATCH 3/3] feat: added in docs --- packages/node/README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/node/README.md b/packages/node/README.md index 12a5a869892..d0daae5a05a 100644 --- a/packages/node/README.md +++ b/packages/node/README.md @@ -867,6 +867,9 @@ await novu.integrations.delete("integrationId") // get novu in-app status await novu.integrations.getInAppStatus() + +// set an integration as primary +await novu.integrations.setIntegrationAsPrimary("integrationId") ``` ### Feeds