Skip to content

Commit

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

(async () => {
console.log('********************');
console.log('* PurgeDomainQueue *');
console.log('********************');
console.log('*********************');
console.log('* PurgeSendingQueue *');
console.log('*********************');

const domainName = getMailgunDomainFromConfig();

const mailgunService = initMailgunService();
let response;
try {
response = await mailgunService.emails.purgeDomainQueue(domainName, 'https://storage-us-west1.api.mailgun.net');
response = await mailgunService.emails.purgeSendingQueue(domainName, 'https://storage-us-west1.api.mailgun.net');
} catch (error) {
console.error('Error when trying to purge the domain queue');
console.error('Error when trying to purge the sending queue');
throw error;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ export class EmailsApiFixture implements Partial<Readonly<EmailsApi>> {
*/
public getStoredEmail: jest.Mock<Promise<GetStoredEmailResponse>, [string, string]> = jest.fn();
/**
* Fixture associated to function purgeDomainQueue
* Fixture associated to function purgeSendingQueue
*/
public purgeDomainQueue: jest.Mock<Promise<GenericResponse>, [string, MailgunStorageHostname]> = jest.fn();
public purgeSendingQueue: jest.Mock<Promise<GenericResponse>, [string, MailgunStorageHostname]> = jest.fn();
/**
* Fixture associated to function getSendingQueuesStatus
*/
Expand Down
4 changes: 2 additions & 2 deletions packages/mailgun/src/rest/v1/emails/emails-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ export class EmailsApi extends MailgunDomainApi {
* @param { string } domainName - The name of the domain you want to delete envelope from
* @param { MailgunStorageHostname } storageHostname - The storage hostname to be purged
*/
public async purgeDomainQueue(
public async purgeSendingQueue(
domainName: string,
storageHostname: MailgunStorageHostname,
): Promise<GenericResponse> {
Expand All @@ -156,7 +156,7 @@ export class EmailsApi extends MailgunDomainApi {
url,
requestOptions,
apiName: this.apiName,
operationId: 'purgeDomainQueue',
operationId: 'purgeSendingQueue',
});

return transformGenericResponseIntoClientResponse(apiResponse);
Expand Down
12 changes: 6 additions & 6 deletions packages/mailgun/tests/rest/v1/emails/emails-api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,20 +73,20 @@ describe('EmailsApi', () => {
});
});

describe('purgeDomainQueues', () => {
it('should make a DELETE request to purge the domain queues', async () => {
describe('purgeSendingQueue', () => {
it('should make a DELETE request to purge a sending queue', async () => {
// Given
const domainName: string = 'domainName';
const storageHostname: MailgunStorageHostname = 'storageHostname';

// When
fixture.purgeDomainQueue.mockResolvedValue(genericResponse);
emailsApi.purgeDomainQueue = fixture.purgeDomainQueue;
const response = await emailsApi.purgeDomainQueue(domainName, storageHostname);
fixture.purgeSendingQueue.mockResolvedValue(genericResponse);
emailsApi.purgeSendingQueue = fixture.purgeSendingQueue;
const response = await emailsApi.purgeSendingQueue(domainName, storageHostname);

// Then
expect(response).toEqual(genericResponse);
expect(fixture.purgeDomainQueue).toHaveBeenCalledWith(domainName, storageHostname);
expect(fixture.purgeSendingQueue).toHaveBeenCalledWith(domainName, storageHostname);
});
});

Expand Down
8 changes: 4 additions & 4 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 purgeDomainQueuesResponse: Mailgun.GenericResponse;
let purgeSendingQueueResponse: Mailgun.GenericResponse;
const domainName = 'sandbox123.mailgun.org';

Given('the Mailgun service "Emails" is available', () => {
Expand Down Expand Up @@ -106,10 +106,10 @@ Then('the response contains the sending queues status', () => {
assert.equal(sendingQueuesStatusResponse.scheduled.disabled?.reason, '');
});

When('I send a request to purge the domain queues', async () => {
purgeDomainQueuesResponse = await emailsApi.purgeDomainQueue(domainName, 'http://localhost:3021');
When('I send a request to purge a sending queue', async () => {
purgeSendingQueueResponse = await emailsApi.purgeSendingQueue(domainName, 'http://localhost:3021');
});

Then('the response indicates the purge has been done', () => {
assert.equal(purgeDomainQueuesResponse.message, 'done');
assert.equal(purgeSendingQueueResponse.message, 'done');
});

0 comments on commit caa680c

Please sign in to comment.