From a902b49bc5ad9b5c1d292435e0d638d90be7a06a Mon Sep 17 00:00:00 2001 From: Nithin David Thomas <1277421+nithindavid@users.noreply.github.com> Date: Fri, 16 Feb 2024 03:31:27 -0800 Subject: [PATCH] feat: Adds bulk_invite api for onboarding view (#8931) - New API for bulk email invite --- app/javascript/dashboard/api/agents.js | 8 ++++++ .../dashboard/api/specs/agents.spec.js | 25 +++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/app/javascript/dashboard/api/agents.js b/app/javascript/dashboard/api/agents.js index 7cc5e6d0c..cfc6b36ff 100644 --- a/app/javascript/dashboard/api/agents.js +++ b/app/javascript/dashboard/api/agents.js @@ -1,9 +1,17 @@ +/* global axios */ + import ApiClient from './ApiClient'; class Agents extends ApiClient { constructor() { super('agents', { accountScoped: true }); } + + bulkInvite({ emails }) { + return axios.post(`${this.url}/bulk_create`, { + emails, + }); + } } export default new Agents(); diff --git a/app/javascript/dashboard/api/specs/agents.spec.js b/app/javascript/dashboard/api/specs/agents.spec.js index 7cf1bdd0e..20dd36688 100644 --- a/app/javascript/dashboard/api/specs/agents.spec.js +++ b/app/javascript/dashboard/api/specs/agents.spec.js @@ -10,4 +10,29 @@ describe('#AgentAPI', () => { expect(agents).toHaveProperty('update'); expect(agents).toHaveProperty('delete'); }); + + describe('API calls', () => { + const originalAxios = window.axios; + const axiosMock = { + post: jest.fn(() => Promise.resolve()), + }; + + beforeEach(() => { + window.axios = axiosMock; + }); + + afterEach(() => { + window.axios = originalAxios; + }); + + it('#bulkInvite', () => { + agents.bulkInvite({ emails: ['hello@hi.com'] }); + expect(axiosMock.post).toHaveBeenCalledWith( + '/api/v1/agents/bulk_create', + { + emails: ['hello@hi.com'], + } + ); + }); + }); });