-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor getStoredEmail related models
- Loading branch information
1 parent
fa3c9b9
commit 415148c
Showing
11 changed files
with
53 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
packages/mailgun/src/models/v1/emails/response/get-email-response/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
export type { GetEmailResponse, MessageHeaders } from './get-email-response'; | ||
export type { GetStoredEmailResponse, MessageHeaders } from './get-stored-email-response'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import { Mailgun } from '../../../../../src'; | ||
|
||
export const getEmailResponseFromApi: Mailgun.GetEmailResponseFromApi = { | ||
export const getStoredEmailResponseFromApi: Mailgun.GetStoredEmailResponseFromApi = { | ||
'X-Mailgun-Deliver-By': new Date('Wed, 06 Jun 2024 07:40:00 +0000'), | ||
subject: '"Mailgun is awesome"', | ||
Subject: '"Mailgun is awesome"', | ||
|
@@ -17,7 +17,7 @@ export const getEmailResponseFromApi: Mailgun.GetEmailResponseFromApi = { | |
['Subject', '"Mailgun is awesome"'], | ||
['From', '[email protected]'], | ||
['To', '[email protected], [email protected]'], | ||
['X-Mailgun-Deliver-By', 'Wed, 06 Jun 2024 07:40:00 +0000'], | ||
['X-Mailgun-Deliver-By', new Date('Wed, 06 Jun 2024 07:40:00 +0000')], | ||
['Message-Id', '<[email protected]>'], | ||
['Content-Transfer-Encoding', '7bit'], | ||
['Content-Type', 'text/html; charset=ascii'], | ||
|
@@ -30,19 +30,23 @@ export const getEmailResponseFromApi: Mailgun.GetEmailResponseFromApi = { | |
'Mime-Version': '1.0', | ||
}; | ||
|
||
export const getEmailResponse: Mailgun.GetEmailResponse = { | ||
contentTransferEncoding: '7bit', | ||
contentType: 'text/html; charset=ascii', | ||
messageId: '<[email protected]>', | ||
mimeVersion: '1.0', | ||
to: '[email protected], [email protected]', | ||
deliveryTime: new Date('Wed, 06 Jun 2024 07:40:00 +0000'), | ||
export const getStoredEmailResponse: Mailgun.GetStoredEmailResponse = { | ||
sender: '[email protected]', | ||
recipients: '[email protected], [email protected]', | ||
from: '[email protected]', | ||
subject: '"Mailgun is awesome"', | ||
bodyHtml: '<html>This is some html</html>', | ||
bodyPlain: 'This is some html', | ||
messageHeaders: { | ||
'Content-Transfer-Encoding': '7bit', | ||
'Content-Type': 'text/html; charset=ascii', | ||
'From': '[email protected]', | ||
'Message-Id': '<[email protected]>', | ||
'Mime-Version': '1.0', | ||
'Subject': '"Mailgun is awesome"', | ||
'To': '[email protected], [email protected]', | ||
'X-Mailgun-Deliver-By': new Date('Wed, 06 Jun 2024 07:40:00 +0000'), | ||
}, | ||
strippedHtml: '<html>This is some html</html>', | ||
strippedText: 'This is some html', | ||
strippedSignature: 'This is a signature', | ||
|
6 changes: 3 additions & 3 deletions
6
...mails/response/get-email-response.test.ts → ...esponse/get-stored-email-response.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
import { | ||
transformGetEmailResponseIntoClientResponse, | ||
} from '../../../../../src/models'; | ||
import { getEmailResponse, getEmailResponseFromApi } from './get-email-response.models'; | ||
import { getStoredEmailResponse, getStoredEmailResponseFromApi } from './get-stored-email-response.models'; | ||
|
||
describe('GetEmailResponse', () => { | ||
|
||
it('should convert an API object into a client object', () => { | ||
const transformedResponse = transformGetEmailResponseIntoClientResponse(getEmailResponseFromApi); | ||
expect(transformedResponse).toEqual(getEmailResponse); | ||
const transformedResponse = transformGetEmailResponseIntoClientResponse(getStoredEmailResponseFromApi); | ||
expect(transformedResponse).toEqual(getStoredEmailResponse); | ||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
export * from './bad-request.models'; | ||
export * from './email-not-found.models'; | ||
export * from './generic-response.models'; | ||
export * from './get-email-response.models'; | ||
export * from './get-stored-email-response.models'; | ||
export * from './send-email-response.models'; | ||
export * from './sending-queues-status-response.models'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ import * as assert from 'assert'; | |
let emailsApi: EmailsApi; | ||
let sendEmailResponse: Mailgun.SendEmailResponse; | ||
let sendMimeEmailResponse: Mailgun.SendEmailResponse; | ||
let getEmailResponse: Mailgun.GetEmailResponse; | ||
let getEmailResponse: Mailgun.GetStoredEmailResponse; | ||
let sendingQueuesStatusResponse: Mailgun.SendingQueuesStatusResponse; | ||
let purgeDomainQueuesResponse: Mailgun.GenericResponse; | ||
const domainName = 'sandbox123.mailgun.org'; | ||
|
@@ -67,12 +67,11 @@ Then('the sendMimeEmail response contains information about the email', () => { | |
}); | ||
|
||
When('I send a request to retrieve a stored email', async () => { | ||
getEmailResponse = await emailsApi.getEmail(domainName, 'storageKey'); | ||
getEmailResponse = await emailsApi.getStoredEmail(domainName, 'storageKey'); | ||
}); | ||
|
||
Then('the getEmail response contains the email details', () => { | ||
assert.equal(getEmailResponse.from, '[email protected]'); | ||
assert.equal(getEmailResponse.to, '%recipient%'); | ||
assert.equal(getEmailResponse.subject, 'Hello from mailgun'); | ||
assert.equal(getEmailResponse.recipients, '[email protected]'); | ||
assert.equal(getEmailResponse.strippedHtml, | ||
|
@@ -82,11 +81,16 @@ Then('the getEmail response contains the email details', () => { | |
assert.equal(getEmailResponse.bodyHtml, | ||
'<h1>Hello %recipient.name%</h1><span style="color:blue">This is an HTML email</span>'); | ||
assert.equal(getEmailResponse.bodyPlain, 'Message text only'); | ||
assert.deepEqual(getEmailResponse.deliveryTime, new Date('Thu, 06 Jun 2024 07:40:00 +0000')); | ||
assert.equal(getEmailResponse.contentType, | ||
'multipart/alternative; boundary="44eea75a00c7df3bdd541c89727faec0ce8d5b09663245a35789d6b264c6"'); | ||
assert.equal(getEmailResponse.contentTransferEncoding, undefined); | ||
assert.equal(getEmailResponse.mimeVersion, '1.0'); | ||
const expectedMessageHeaders: Mailgun.MessageHeaders = { | ||
'Content-Type': 'multipart/alternative; boundary="44eea75a00c7df3bdd541c89727faec0ce8d5b09663245a35789d6b264c6"', | ||
'Message-Id': '<[email protected]>', | ||
'Mime-Version': '1.0', | ||
'X-Mailgun-Deliver-By': new Date('Thu, 06 Jun 2024 07:40:00 +0000'), | ||
From: '[email protected]', | ||
Subject: 'Hello from mailgun', | ||
To: '%recipient%', | ||
}; | ||
assert.deepEqual(getEmailResponse.messageHeaders, expectedMessageHeaders); | ||
}); | ||
|
||
When('I send a request to get the sending queue status', async () => { | ||
|