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
17 changes: 6 additions & 11 deletions src/__tests__/integrationMutations.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -429,26 +429,21 @@ describe('mutations', () => {
`;

const integration1 = await integrationFactory();
const integration2 = await integrationFactory();

const spy1 = jest.spyOn(messageBroker, 'sendRPCMessage');
spy1.mockImplementation(() => Promise.resolve({ erxesApiIds: [integration1._id] }));

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

expect(response).toBe('success');
const spy = jest.spyOn(messageBroker, 'sendRPCMessage');

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

const spy = jest.spyOn(messageBroker, 'sendRPCMessage');
spy.mockImplementation(() => Promise.resolve({ erxesApiIds: [integration2._id] }));
const response = await graphqlRequest(mutation, 'integrationsRemoveAccount', { _id: 'accountId' });

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

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

spy.mockRestore();
});

Expand Down
17 changes: 11 additions & 6 deletions src/data/resolvers/mutations/integrations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,13 +212,18 @@ const integrationMutations = {
* Delete an account
*/
async integrationsRemoveAccount(_root, { _id }: { _id: string }) {
const { erxesApiIds } = await sendRPCMessage({ action: 'remove-account', data: { _id } });
try {
const { erxesApiIds } = await sendRPCMessage({ action: 'remove-account', data: { _id } });

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

return 'success';
return 'success';
} catch (e) {
debugExternalApi(e);
throw e;
}
},

/**
Expand All @@ -240,7 +245,7 @@ const integrationMutations = {
});
} catch (e) {
debugExternalApi(e);
throw new Error(e);
throw e;
}

const customerIds = await Customers.find({ primaryEmail: { $in: doc.to } }).distinct('_id');
Expand Down
2 changes: 1 addition & 1 deletion src/messageBroker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const sendRPCMessage = async (message): Promise<any> => {
if (res.status === 'success') {
resolve(res.data);
} else {
reject(res.errorMessage);
reject(new Error(res.errorMessage));
}

channel.deleteQueue(q.queue);
Expand Down