-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Restructure SDK #51
Open
narekhovhannisyan
wants to merge
29
commits into
main
Choose a base branch
from
restructure-sdk
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Restructure SDK #51
Changes from 23 commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
b96f604
types: add bulk and sandbox flags to mailtrap
narekhovhannisyan 36a9df3
api: move testing send method to client
narekhovhannisyan 0b49830
api: drop bulk
narekhovhannisyan ef8e1b9
lib: refactor MailtrapClient to incapsulate bulk, sandbox send fnality
narekhovhannisyan dbd5fc6
config: add bulk sandbox incompatible message
narekhovhannisyan e8d764b
test: drop moved functionality from Testing
narekhovhannisyan 6f3dcd5
test: drop Bulk
narekhovhannisyan ce67277
test: cover new mailtrap client functionality with units
narekhovhannisyan e53b1c0
examples: fix mailtrap imports in testing
narekhovhannisyan 13fc15d
examples: fix mailtrap imports in general
narekhovhannisyan 10046b8
examples: update bulk sending example
narekhovhannisyan a5d4d20
docs: update Readme file, remove missing testing api notice
narekhovhannisyan 50c8c56
types: drop sending from additional fields
narekhovhannisyan 10f73e5
lib: drop switchable client
narekhovhannisyan a8b56bc
test: drop transport sandbox switch
narekhovhannisyan f24a304
examples: update transport sample
narekhovhannisyan b57bcfe
.github: configure codeql
narekhovhannisyan 9d00310
.github: configure codeql tests path
narekhovhannisyan 88e2acf
.github: add newline at the end of codeql config
narekhovhannisyan c2f1f89
.github: update codeql config to ignore all files in tests
narekhovhannisyan 16abea3
.github: drop codeql from test workflow
narekhovhannisyan 96d79a9
.github: tune codeql config
narekhovhannisyan f764542
WIP
vittorius 7584350
.github: update codeql config path
narekhovhannisyan 51c959c
test: drop commented code from mailtrap client
narekhovhannisyan 7968a07
docs: move info on previous releases to the end of README
narekhovhannisyan 49e099d
lib: separate host detection logic from send method
narekhovhannisyan eed53c6
examples: init transport samples, send testing mail sample
narekhovhannisyan b03961e
examples: fix missing comma in transport
narekhovhannisyan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
paths: | ||
- 'src' | ||
paths-ignore: | ||
- 'src/__tests__/**/*.js' | ||
- 'src/__tests__/**/*.ts' | ||
- 'src/__tests__/**/*.jsx' | ||
- 'src/__tests__/**/*.tsx' |
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
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
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 was deleted.
Oops, something went wrong.
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,151 +1,19 @@ | ||
import axios from "axios"; | ||
import AxiosMockAdapter from "axios-mock-adapter"; | ||
|
||
import Testing from "../../../lib/api/Testing"; | ||
import handleSendingError from "../../../lib/axios-logger"; | ||
|
||
import CONFIG from "../../../config"; | ||
import MailtrapError from "../../../lib/MailtrapError"; | ||
|
||
const { CLIENT_SETTINGS } = CONFIG; | ||
const { TESTING_ENDPOINT } = CLIENT_SETTINGS; | ||
|
||
describe("lib/api/Testing: ", () => { | ||
let mock: AxiosMockAdapter; | ||
const testInboxId = 100; | ||
const testingAPI = new Testing(axios, testInboxId); | ||
|
||
describe("class Testing(): ", () => { | ||
describe("init: ", () => { | ||
it("initalizes with all necessary params.", () => { | ||
expect(testingAPI).toHaveProperty("send"); | ||
expect(testingAPI).toHaveProperty("projects"); | ||
expect(testingAPI).toHaveProperty("inboxes"); | ||
expect(testingAPI).toHaveProperty("messages"); | ||
expect(testingAPI).toHaveProperty("attachments"); | ||
}); | ||
}); | ||
|
||
beforeAll(() => { | ||
/** | ||
* Init Axios interceptors for handling response.data, errors. | ||
*/ | ||
axios.interceptors.response.use( | ||
(response) => response.data, | ||
handleSendingError | ||
); | ||
mock = new AxiosMockAdapter(axios); | ||
}); | ||
|
||
afterEach(() => { | ||
mock.reset(); | ||
}); | ||
|
||
describe("send(): ", () => { | ||
it("successfully sends email.", async () => { | ||
const endpoint = `${TESTING_ENDPOINT}/api/send/${testInboxId}`; | ||
const expectedResponseData = { | ||
success: true, | ||
message_ids: ["0c7fd939-02cf-11ed-88c2-0a58a9feac02"], | ||
}; | ||
mock.onPost(endpoint).reply(200, expectedResponseData); | ||
|
||
const emailData = { | ||
from: { | ||
email: "sender.mock@email.com", | ||
name: "sender", | ||
}, | ||
to: [ | ||
{ | ||
email: "recipient.mock@email.com", | ||
name: "recipient", | ||
}, | ||
], | ||
subject: "mock-subject", | ||
text: "Mock text", | ||
html: "<div>Mock text</div>", | ||
}; | ||
|
||
const result = await testingAPI.send(emailData); | ||
|
||
expect(mock.history.post[0].url).toEqual(endpoint); | ||
expect(mock.history.post[0].data).toEqual(JSON.stringify(emailData)); | ||
expect(result).toEqual(expectedResponseData); | ||
}); | ||
|
||
it("handles an API error.", async () => { | ||
const responseData = { | ||
success: false, | ||
errors: ["mock-error-1", "mock-error-2"], | ||
}; | ||
|
||
const endpoint = `${TESTING_ENDPOINT}/api/send/${testInboxId}`; | ||
|
||
mock.onPost(endpoint).reply(400, responseData); | ||
|
||
const emailData = { | ||
from: { | ||
email: "sender.mock@email.com", | ||
name: "sender", | ||
}, | ||
to: [ | ||
{ | ||
email: "recipient.mock@email.com", | ||
name: "recipient", | ||
}, | ||
], | ||
subject: "mock-subject", | ||
text: "Mock text", | ||
html: "<div>Mock text</div>", | ||
}; | ||
|
||
const expectedErrorMessage = responseData.errors.join(","); | ||
|
||
expect.assertions(3); | ||
|
||
try { | ||
await testingAPI.send(emailData); | ||
} catch (error) { | ||
expect(mock.history.post[0].url).toEqual(endpoint); | ||
expect(mock.history.post[0].data).toEqual(JSON.stringify(emailData)); | ||
|
||
if (error instanceof Error) { | ||
expect(error.message).toEqual(expectedErrorMessage); | ||
} | ||
} | ||
}); | ||
|
||
it("handles an HTTP transport error.", async () => { | ||
const emailData = { | ||
from: { | ||
email: "sender.mock@email.com", | ||
name: "sender", | ||
}, | ||
to: [ | ||
{ | ||
email: "recipient.mock@email.com", | ||
name: "recipient", | ||
}, | ||
], | ||
subject: "mock-subject", | ||
text: "Mock text", | ||
html: "<div>Mock text</div>", | ||
}; | ||
|
||
const expectedErrorMessage = "Request failed with status code 404"; | ||
|
||
expect.assertions(2); | ||
|
||
try { | ||
await testingAPI.send(emailData); | ||
} catch (error) { | ||
expect(error).toBeInstanceOf(MailtrapError); | ||
|
||
if (error instanceof MailtrapError) { | ||
expect(error.message).toEqual(expectedErrorMessage); | ||
} | ||
} | ||
}); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess since codeql is not triggered from the workflow, we don't have to mention it here.