From e4f37b3cdfd81d54b271bccbb1ea6cd6520cce9a Mon Sep 17 00:00:00 2001 From: Antoine SEIN <142824551+asein-sinch@users.noreply.github.com> Date: Thu, 12 Dec 2024 15:06:21 +0100 Subject: [PATCH] purgeSendingQueue returns void --- .../src/mailgun/emails/purgeSendingQueue.ts | 7 +++---- .../mailgun/src/rest/v1/emails/emails-api.jest.fixture.ts | 3 +-- packages/mailgun/src/rest/v1/emails/emails-api.ts | 8 ++------ packages/mailgun/tests/rest/v1/emails/emails-api.test.ts | 6 +++--- packages/mailgun/tests/rest/v1/emails/emails.steps.ts | 4 ++-- 5 files changed, 11 insertions(+), 17 deletions(-) diff --git a/examples/simple-examples/src/mailgun/emails/purgeSendingQueue.ts b/examples/simple-examples/src/mailgun/emails/purgeSendingQueue.ts index 4f42afb..8bece00 100644 --- a/examples/simple-examples/src/mailgun/emails/purgeSendingQueue.ts +++ b/examples/simple-examples/src/mailgun/emails/purgeSendingQueue.ts @@ -1,4 +1,4 @@ -import { getMailgunDomainFromConfig, initMailgunService, printFullResponse } from '../../config'; +import { getMailgunDomainFromConfig, initMailgunService } from '../../config'; (async () => { console.log('*********************'); @@ -8,14 +8,13 @@ import { getMailgunDomainFromConfig, initMailgunService, printFullResponse } fro const domainName = getMailgunDomainFromConfig(); const mailgunService = initMailgunService(); - let response; try { - response = await mailgunService.emails.purgeSendingQueue(domainName, 'https://storage-us-west1.api.mailgun.net'); + await mailgunService.emails.purgeSendingQueue(domainName, 'https://storage-us-west1.api.mailgun.net'); } catch (error) { console.error('Error when trying to purge the sending queue'); throw error; } - printFullResponse(response); + console.log('The sending queue has been purged'); })(); diff --git a/packages/mailgun/src/rest/v1/emails/emails-api.jest.fixture.ts b/packages/mailgun/src/rest/v1/emails/emails-api.jest.fixture.ts index e9ea198..e96d26d 100644 --- a/packages/mailgun/src/rest/v1/emails/emails-api.jest.fixture.ts +++ b/packages/mailgun/src/rest/v1/emails/emails-api.jest.fixture.ts @@ -1,6 +1,5 @@ import { EmailsApi } from './emails-api'; import { - GenericResponse, GetStoredEmailResponse, SendEmailResponse, SendingQueuesStatusResponse, @@ -25,7 +24,7 @@ export class EmailsApiFixture implements Partial> { /** * Fixture associated to function purgeSendingQueue */ - public purgeSendingQueue: jest.Mock, [string, MailgunStorageHostname]> = jest.fn(); + public purgeSendingQueue: jest.Mock, [string, MailgunStorageHostname]> = jest.fn(); /** * Fixture associated to function getSendingQueuesStatus */ diff --git a/packages/mailgun/src/rest/v1/emails/emails-api.ts b/packages/mailgun/src/rest/v1/emails/emails-api.ts index 51f5dee..bcc6804 100644 --- a/packages/mailgun/src/rest/v1/emails/emails-api.ts +++ b/packages/mailgun/src/rest/v1/emails/emails-api.ts @@ -1,5 +1,4 @@ import { - GenericResponse, GenericResponseFromApi, GetStoredEmailResponse, GetStoredEmailResponseFromApi, @@ -9,7 +8,6 @@ import { SendingQueuesStatusResponse, SendingQueuesStatusResponseFromApi, SendMimeEmailRequest, - transformGenericResponseIntoClientResponse, transformGetEmailResponseIntoClientResponse, transformSendEmailRequestIntoApiRequestBody, transformSendEmailResponseIntoClientResponse, @@ -133,7 +131,7 @@ export class EmailsApi extends MailgunDomainApi { public async purgeSendingQueue( domainName: string, storageHostname: MailgunStorageHostname, - ): Promise { + ): Promise { this.client = this.getSinchClient(); const getParams = {}; const headers: { [key: string]: string | undefined } = { @@ -152,14 +150,12 @@ export class EmailsApi extends MailgunDomainApi { ); const url = this.client.prepareUrl(requestOptions.hostname, requestOptions.queryParams); - const apiResponse = await this.client.processCall({ + await this.client.processCall({ url, requestOptions, apiName: this.apiName, operationId: 'purgeSendingQueue', }); - - return transformGenericResponseIntoClientResponse(apiResponse); } /** diff --git a/packages/mailgun/tests/rest/v1/emails/emails-api.test.ts b/packages/mailgun/tests/rest/v1/emails/emails-api.test.ts index 95fb6eb..42ea265 100644 --- a/packages/mailgun/tests/rest/v1/emails/emails-api.test.ts +++ b/packages/mailgun/tests/rest/v1/emails/emails-api.test.ts @@ -5,7 +5,6 @@ import { sendMimeEmailRequest, } from '../../../models/v1/emails/request'; import { - genericResponse, getStoredEmailResponse, sendEmailResponse, sendingQueuesStatusResponse, @@ -78,14 +77,15 @@ describe('EmailsApi', () => { // Given const domainName: string = 'domainName'; const storageHostname: MailgunStorageHostname = 'storageHostname'; + const expectedResponse: void = undefined; // When - fixture.purgeSendingQueue.mockResolvedValue(genericResponse); + fixture.purgeSendingQueue.mockResolvedValue(expectedResponse); emailsApi.purgeSendingQueue = fixture.purgeSendingQueue; const response = await emailsApi.purgeSendingQueue(domainName, storageHostname); // Then - expect(response).toEqual(genericResponse); + expect(response).toEqual(expectedResponse); expect(fixture.purgeSendingQueue).toHaveBeenCalledWith(domainName, storageHostname); }); }); diff --git a/packages/mailgun/tests/rest/v1/emails/emails.steps.ts b/packages/mailgun/tests/rest/v1/emails/emails.steps.ts index 16d543f..3b747da 100644 --- a/packages/mailgun/tests/rest/v1/emails/emails.steps.ts +++ b/packages/mailgun/tests/rest/v1/emails/emails.steps.ts @@ -7,7 +7,7 @@ let sendEmailResponse: Mailgun.SendEmailResponse; let sendMimeEmailResponse: Mailgun.SendEmailResponse; let getEmailResponse: Mailgun.GetStoredEmailResponse; let sendingQueuesStatusResponse: Mailgun.SendingQueuesStatusResponse; -let purgeSendingQueueResponse: Mailgun.GenericResponse; +let purgeSendingQueueResponse: void; const domainName = 'sandbox123.mailgun.org'; Given('the Mailgun service "Emails" is available', () => { @@ -111,5 +111,5 @@ When('I send a request to purge a sending queue', async () => { }); Then('the response indicates the purge has been done', () => { - assert.equal(purgeSendingQueueResponse.message, 'done'); + assert.deepEqual(purgeSendingQueueResponse, {} ); });