Skip to content

Commit

Permalink
purgeSendingQueue returns void
Browse files Browse the repository at this point in the history
  • Loading branch information
asein-sinch committed Dec 12, 2024
1 parent caa680c commit e4f37b3
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getMailgunDomainFromConfig, initMailgunService, printFullResponse } from '../../config';
import { getMailgunDomainFromConfig, initMailgunService } from '../../config';

(async () => {
console.log('*********************');
Expand All @@ -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');

})();
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { EmailsApi } from './emails-api';
import {
GenericResponse,
GetStoredEmailResponse,
SendEmailResponse,
SendingQueuesStatusResponse,
Expand All @@ -25,7 +24,7 @@ export class EmailsApiFixture implements Partial<Readonly<EmailsApi>> {
/**
* Fixture associated to function purgeSendingQueue
*/
public purgeSendingQueue: jest.Mock<Promise<GenericResponse>, [string, MailgunStorageHostname]> = jest.fn();
public purgeSendingQueue: jest.Mock<Promise<void>, [string, MailgunStorageHostname]> = jest.fn();
/**
* Fixture associated to function getSendingQueuesStatus
*/
Expand Down
8 changes: 2 additions & 6 deletions packages/mailgun/src/rest/v1/emails/emails-api.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {
GenericResponse,
GenericResponseFromApi,
GetStoredEmailResponse,
GetStoredEmailResponseFromApi,
Expand All @@ -9,7 +8,6 @@ import {
SendingQueuesStatusResponse,
SendingQueuesStatusResponseFromApi,
SendMimeEmailRequest,
transformGenericResponseIntoClientResponse,
transformGetEmailResponseIntoClientResponse,
transformSendEmailRequestIntoApiRequestBody,
transformSendEmailResponseIntoClientResponse,
Expand Down Expand Up @@ -133,7 +131,7 @@ export class EmailsApi extends MailgunDomainApi {
public async purgeSendingQueue(
domainName: string,
storageHostname: MailgunStorageHostname,
): Promise<GenericResponse> {
): Promise<void> {
this.client = this.getSinchClient();
const getParams = {};
const headers: { [key: string]: string | undefined } = {
Expand All @@ -152,14 +150,12 @@ export class EmailsApi extends MailgunDomainApi {
);
const url = this.client.prepareUrl(requestOptions.hostname, requestOptions.queryParams);

const apiResponse = await this.client.processCall<GenericResponseFromApi>({
await this.client.processCall<GenericResponseFromApi>({
url,
requestOptions,
apiName: this.apiName,
operationId: 'purgeSendingQueue',
});

return transformGenericResponseIntoClientResponse(apiResponse);
}

/**
Expand Down
6 changes: 3 additions & 3 deletions packages/mailgun/tests/rest/v1/emails/emails-api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
sendMimeEmailRequest,
} from '../../../models/v1/emails/request';
import {
genericResponse,
getStoredEmailResponse,
sendEmailResponse,
sendingQueuesStatusResponse,
Expand Down Expand Up @@ -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);
});
});
Expand Down
4 changes: 2 additions & 2 deletions packages/mailgun/tests/rest/v1/emails/emails.steps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down Expand Up @@ -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, {} );
});

0 comments on commit e4f37b3

Please sign in to comment.