Skip to content

Commit e8d764b

Browse files
test: drop moved functionality from Testing
1 parent dbd5fc6 commit e8d764b

File tree

1 file changed

+0
-132
lines changed

1 file changed

+0
-132
lines changed

src/__tests__/lib/api/Testing.test.ts

-132
Original file line numberDiff line numberDiff line change
@@ -1,151 +1,19 @@
11
import axios from "axios";
2-
import AxiosMockAdapter from "axios-mock-adapter";
32

43
import Testing from "../../../lib/api/Testing";
5-
import handleSendingError from "../../../lib/axios-logger";
6-
7-
import CONFIG from "../../../config";
8-
import MailtrapError from "../../../lib/MailtrapError";
9-
10-
const { CLIENT_SETTINGS } = CONFIG;
11-
const { TESTING_ENDPOINT } = CLIENT_SETTINGS;
124

135
describe("lib/api/Testing: ", () => {
14-
let mock: AxiosMockAdapter;
156
const testInboxId = 100;
167
const testingAPI = new Testing(axios, testInboxId);
178

189
describe("class Testing(): ", () => {
1910
describe("init: ", () => {
2011
it("initalizes with all necessary params.", () => {
21-
expect(testingAPI).toHaveProperty("send");
2212
expect(testingAPI).toHaveProperty("projects");
2313
expect(testingAPI).toHaveProperty("inboxes");
2414
expect(testingAPI).toHaveProperty("messages");
2515
expect(testingAPI).toHaveProperty("attachments");
2616
});
2717
});
28-
29-
beforeAll(() => {
30-
/**
31-
* Init Axios interceptors for handling response.data, errors.
32-
*/
33-
axios.interceptors.response.use(
34-
(response) => response.data,
35-
handleSendingError
36-
);
37-
mock = new AxiosMockAdapter(axios);
38-
});
39-
40-
afterEach(() => {
41-
mock.reset();
42-
});
43-
44-
describe("send(): ", () => {
45-
it("successfully sends email.", async () => {
46-
const endpoint = `${TESTING_ENDPOINT}/api/send/${testInboxId}`;
47-
const expectedResponseData = {
48-
success: true,
49-
message_ids: ["0c7fd939-02cf-11ed-88c2-0a58a9feac02"],
50-
};
51-
mock.onPost(endpoint).reply(200, expectedResponseData);
52-
53-
const emailData = {
54-
from: {
55-
56-
name: "sender",
57-
},
58-
to: [
59-
{
60-
61-
name: "recipient",
62-
},
63-
],
64-
subject: "mock-subject",
65-
text: "Mock text",
66-
html: "<div>Mock text</div>",
67-
};
68-
69-
const result = await testingAPI.send(emailData);
70-
71-
expect(mock.history.post[0].url).toEqual(endpoint);
72-
expect(mock.history.post[0].data).toEqual(JSON.stringify(emailData));
73-
expect(result).toEqual(expectedResponseData);
74-
});
75-
76-
it("handles an API error.", async () => {
77-
const responseData = {
78-
success: false,
79-
errors: ["mock-error-1", "mock-error-2"],
80-
};
81-
82-
const endpoint = `${TESTING_ENDPOINT}/api/send/${testInboxId}`;
83-
84-
mock.onPost(endpoint).reply(400, responseData);
85-
86-
const emailData = {
87-
from: {
88-
89-
name: "sender",
90-
},
91-
to: [
92-
{
93-
94-
name: "recipient",
95-
},
96-
],
97-
subject: "mock-subject",
98-
text: "Mock text",
99-
html: "<div>Mock text</div>",
100-
};
101-
102-
const expectedErrorMessage = responseData.errors.join(",");
103-
104-
expect.assertions(3);
105-
106-
try {
107-
await testingAPI.send(emailData);
108-
} catch (error) {
109-
expect(mock.history.post[0].url).toEqual(endpoint);
110-
expect(mock.history.post[0].data).toEqual(JSON.stringify(emailData));
111-
112-
if (error instanceof Error) {
113-
expect(error.message).toEqual(expectedErrorMessage);
114-
}
115-
}
116-
});
117-
118-
it("handles an HTTP transport error.", async () => {
119-
const emailData = {
120-
from: {
121-
122-
name: "sender",
123-
},
124-
to: [
125-
{
126-
127-
name: "recipient",
128-
},
129-
],
130-
subject: "mock-subject",
131-
text: "Mock text",
132-
html: "<div>Mock text</div>",
133-
};
134-
135-
const expectedErrorMessage = "Request failed with status code 404";
136-
137-
expect.assertions(2);
138-
139-
try {
140-
await testingAPI.send(emailData);
141-
} catch (error) {
142-
expect(error).toBeInstanceOf(MailtrapError);
143-
144-
if (error instanceof MailtrapError) {
145-
expect(error.message).toEqual(expectedErrorMessage);
146-
}
147-
}
148-
});
149-
});
15018
});
15119
});

0 commit comments

Comments
 (0)