-
Notifications
You must be signed in to change notification settings - Fork 18
Add sending domain update and company info endpoints #153
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
Merged
Merged
Changes from all commits
Commits
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 hidden or 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 hidden or 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,43 @@ | ||
| import { MailtrapClient } from "mailtrap"; | ||
|
|
||
| const TOKEN = "<YOUR-TOKEN-HERE>"; | ||
| const DOMAIN_ID = Number("<YOUR-DOMAIN-ID-HERE>"); | ||
|
|
||
| const client = new MailtrapClient({ token: TOKEN }); | ||
|
|
||
| async function companyInfoFlow() { | ||
| try { | ||
| // Create the company info required for compliance verification | ||
| const created = await client.companyInfo.create(DOMAIN_ID, { | ||
| name: "Mailtrap", | ||
| address: "123 Main St", | ||
| city: "San Francisco", | ||
| country: "US", | ||
| zip_code: "94105", | ||
| website_url: "https://mailtrap.io", | ||
| phone: "+1-555-0100", | ||
| privacy_policy_url: "https://mailtrap.io/privacy", | ||
| terms_of_service_url: "https://mailtrap.io/terms", | ||
| info_level: "business", | ||
| }); | ||
| console.log("Created company info:", JSON.stringify(created, null, 2)); | ||
|
|
||
| // Get the company info of a sending domain | ||
| const companyInfo = await client.companyInfo.get(DOMAIN_ID); | ||
| console.log("Company info:", JSON.stringify(companyInfo, null, 2)); | ||
|
|
||
| // Update only some of the fields | ||
| const updated = await client.companyInfo.update(DOMAIN_ID, { | ||
| city: "New York", | ||
| zip_code: "10001", | ||
| }); | ||
| console.log("Updated company info:", JSON.stringify(updated, null, 2)); | ||
| } catch (error) { | ||
| console.error( | ||
| "Error in companyInfoFlow:", | ||
| error instanceof Error ? error.message : String(error) | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| companyInfoFlow(); |
This file contains hidden or 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 hidden or 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,109 @@ | ||
| import axios, { AxiosInstance } from "axios"; | ||
| import MockAdapter from "axios-mock-adapter"; | ||
|
|
||
| import CompanyInfoBaseAPI from "../../../../lib/api/CompanyInfo"; | ||
| import { CompanyInfo } from "../../../../types/api/company-info"; | ||
|
|
||
| describe("lib/api/CompanyInfo: ", () => { | ||
| const axiosInstance: AxiosInstance = axios.create(); | ||
| const mock = new MockAdapter(axiosInstance); | ||
|
|
||
| // Add the response interceptor that returns response.data | ||
| axiosInstance.interceptors.response.use((response) => response.data); | ||
|
|
||
| const companyInfoAPI = new CompanyInfoBaseAPI(axiosInstance); | ||
| const domainId = 999; | ||
| const companyInfoURL = `https://mailtrap.io/api/domains/${domainId}/company_info`; | ||
|
|
||
| describe("class CompanyInfoBaseAPI(): ", () => { | ||
| describe("init: ", () => { | ||
| it("initializes with all necessary params.", () => { | ||
| expect(companyInfoAPI).toHaveProperty("get"); | ||
| expect(companyInfoAPI).toHaveProperty("create"); | ||
| expect(companyInfoAPI).toHaveProperty("update"); | ||
| }); | ||
| }); | ||
|
|
||
| describe("companyInfo.get(): ", () => { | ||
| it("should get the company info of a sending domain.", async () => { | ||
| const mockCompanyInfo: CompanyInfo = { | ||
| name: "Mailtrap", | ||
| address: "123 Main St", | ||
| city: "San Francisco", | ||
| country: "US", | ||
| phone: "+1-555-0100", | ||
| zip_code: "94105", | ||
| privacy_policy_url: "https://mailtrap.io/privacy", | ||
| terms_of_service_url: "https://mailtrap.io/terms", | ||
| website_url: "https://mailtrap.io", | ||
| info_level: "business", | ||
| }; | ||
|
|
||
| mock.onGet(companyInfoURL).reply(200, { data: mockCompanyInfo }); | ||
|
|
||
| const result = await companyInfoAPI.get(domainId); | ||
|
|
||
| expect(result).toEqual({ data: mockCompanyInfo }); | ||
| }); | ||
| }); | ||
|
|
||
| describe("companyInfo.create(): ", () => { | ||
| it("should create the company info of a sending domain.", async () => { | ||
| const createParams = { | ||
| name: "Mailtrap", | ||
| address: "123 Main St", | ||
| city: "San Francisco", | ||
| country: "US", | ||
| zip_code: "94105", | ||
| website_url: "https://mailtrap.io", | ||
| info_level: "business" as const, | ||
| }; | ||
|
|
||
| const mockCompanyInfo: CompanyInfo = { | ||
| ...createParams, | ||
| phone: null, | ||
| privacy_policy_url: null, | ||
| terms_of_service_url: null, | ||
| }; | ||
|
|
||
| mock | ||
| .onPost(companyInfoURL, { company_info: createParams }) | ||
| .reply(200, { data: mockCompanyInfo }); | ||
|
|
||
| const result = await companyInfoAPI.create(domainId, createParams); | ||
|
|
||
| expect(result).toEqual({ data: mockCompanyInfo }); | ||
| }); | ||
| }); | ||
|
|
||
| describe("companyInfo.update(): ", () => { | ||
| it("should update the company info of a sending domain.", async () => { | ||
| const updateParams = { | ||
| city: "New York", | ||
| zip_code: "10001", | ||
| }; | ||
|
|
||
| const mockCompanyInfo: CompanyInfo = { | ||
| name: "Mailtrap", | ||
| address: "123 Main St", | ||
| city: "New York", | ||
| country: "US", | ||
| phone: null, | ||
| zip_code: "10001", | ||
| privacy_policy_url: null, | ||
| terms_of_service_url: null, | ||
| website_url: "https://mailtrap.io", | ||
| info_level: "business", | ||
| }; | ||
|
|
||
| mock | ||
| .onPatch(companyInfoURL, { company_info: updateParams }) | ||
| .reply(200, { data: mockCompanyInfo }); | ||
|
|
||
| const result = await companyInfoAPI.update(domainId, updateParams); | ||
|
|
||
| expect(result).toEqual({ data: mockCompanyInfo }); | ||
| }); | ||
| }); | ||
| }); | ||
| }); |
This file contains hidden or 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 hidden or 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 hidden or 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,21 @@ | ||
| import { AxiosInstance } from "axios"; | ||
|
|
||
| import CompanyInfoApi from "./resources/CompanyInfo"; | ||
|
|
||
| export default class CompanyInfoBaseAPI { | ||
| private client: AxiosInstance; | ||
|
|
||
| public get: CompanyInfoApi["get"]; | ||
|
|
||
| public create: CompanyInfoApi["create"]; | ||
|
|
||
| public update: CompanyInfoApi["update"]; | ||
|
|
||
| constructor(client: AxiosInstance) { | ||
| this.client = client; | ||
| const companyInfo = new CompanyInfoApi(this.client); | ||
| this.get = companyInfo.get.bind(companyInfo); | ||
| this.create = companyInfo.create.bind(companyInfo); | ||
| this.update = companyInfo.update.bind(companyInfo); | ||
| } | ||
| } |
This file contains hidden or 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
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.
Uh oh!
There was an error while loading. Please reload this page.