Skip to content
This repository was archived by the owner on Nov 21, 2020. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions src/__tests__/integrationMutations.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -470,17 +470,27 @@ describe('mutations', () => {

spy.mockImplementation(() => Promise.resolve({ erxesApiIds: [integration1._id] }));

const response = await graphqlRequest(mutation, 'integrationsRemoveAccount', { _id: 'accountId' });
const firstResponse = await graphqlRequest(mutation, 'integrationsRemoveAccount', { _id: 'accountId' });

try {
await graphqlRequest(mutation, 'integrationsRemoveAccount', { _id: 'accountId' });
} catch (e) {
expect(e[0].message).toBeDefined();
}

expect(response).toBe('success');
expect(firstResponse).toBe('success');

spy.mockRestore();

const spy1 = jest.spyOn(messageBroker, 'sendRPCMessage');

spy1.mockImplementation(() => Promise.resolve({ erxesApiIds: [] }));

const secondResponse = await graphqlRequest(mutation, 'integrationsRemoveAccount', { _id: 'accountId' });

expect(secondResponse).toBe('success');

spy1.mockRestore();
});

test('Send mail', async () => {
Expand Down
4 changes: 4 additions & 0 deletions src/data/resolvers/mutations/integrations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,10 @@ const integrationMutations = {
try {
const { erxesApiIds } = await sendRPCMessage({ action: 'remove-account', data: { _id } });

if (erxesApiIds.length === 0) {
return 'success';
}

for (const id of erxesApiIds) {
await Integrations.removeIntegration(id);
}
Expand Down