Skip to content

Commit f15507c

Browse files
feat: bump mailslurp-client from 6.7.4 to 16.0.0 (#86)
* build(deps): bump mailslurp-client from 6.7.4 to 16.0.0 Bumps [mailslurp-client](https://github.com/mailslurp/mailslurp-client) from 6.7.4 to 16.0.0. - [Changelog](https://github.com/mailslurp/mailslurp-client/blob/master/CHANGELOG.md) - [Commits](https://github.com/mailslurp/mailslurp-client/commits/v16.0.0) --- updated-dependencies: - dependency-name: mailslurp-client dependency-version: 16.0.0 dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <[email protected]> * fix: UTs --------- Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: kobenguyent <[email protected]>
1 parent c987e6c commit f15507c

File tree

2 files changed

+82
-30
lines changed

2 files changed

+82
-30
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"dependencies": {
2525
"chai": "^4.3.4",
2626
"expect": "^30.2.0",
27-
"mailslurp-client": "^6.7.4",
27+
"mailslurp-client": "^16.0.0",
2828
"ts-node": "^10.9.2"
2929
},
3030
"devDependencies": {

tests/index.spec.ts

Lines changed: 81 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,95 @@
1+
import nock from 'nock';
12
require('dotenv').config();
23
import { expect } from 'chai';
34
import MailSlurp = require("../src");
45
import fs from 'fs';
5-
import nock from 'nock';
6+
7+
const emailObj = {
8+
id: 'email-id',
9+
subject: 'Hello Test',
10+
body: 'Testing',
11+
12+
13+
attachments: ['mock-attachment-id'],
14+
createdAt: new Date().toISOString(),
15+
inboxId: '123',
16+
emailAddress: '[email protected]'
17+
};
18+
19+
// Disable all real network connections
20+
nock.disableNetConnect();
621

722
let I;
823
const endpoint: string = 'https://api.mailslurp.com';
24+
const anotherEndpoint: string = 'https://javascript.api.mailslurp.com';
925
const attachmentId: string = "1708081636-1c8167ec-a4b5-4117-9c8b-af7c1dcb8076";
1026
const inboxId: string = '123';
1127
const attachmentFilename = 'README.md';
1228

1329
describe('MailSlurp helper', function () {
30+
beforeAll(() => {
31+
// Register specific POST /inboxes mock for both endpoints
32+
nock(endpoint).persist().post('/inboxes').reply(200, {id: '123', emailAddress: '[email protected]'});
33+
nock(anotherEndpoint).persist().post('/inboxes').reply(200, {id: '123', emailAddress: '[email protected]'});
34+
// Attachment upload endpoint
35+
nock(endpoint).persist().post(/\/attachments/).reply(200, ['mock-attachment-id']);
36+
nock(anotherEndpoint).persist().post(/\/attachments/).reply(200, ['mock-attachment-id']);
37+
// Wait for email endpoints (POST and GET)
38+
nock(endpoint).persist().post(/\/waitForLatestEmail/).reply(200, emailObj);
39+
nock(endpoint).persist().get(/\/waitForLatestEmail/).reply(200, emailObj);
40+
nock(anotherEndpoint).persist().post(/\/waitForLatestEmail/).reply(200, emailObj);
41+
nock(anotherEndpoint).persist().get(/\/waitForLatestEmail/).reply(200, emailObj);
42+
nock(endpoint).persist().post(/\/waitForMatchingEmails/).reply(200, [emailObj]);
43+
nock(endpoint).persist().get(/\/waitForMatchingEmails/).reply(200, [emailObj]);
44+
nock(anotherEndpoint).persist().post(/\/waitForMatchingEmails/).reply(200, [emailObj]);
45+
nock(anotherEndpoint).persist().get(/\/waitForMatchingEmails/).reply(200, [emailObj]);
46+
// Email metadata endpoints - MailSlurp uses /emails/{emailId}/attachments/{attachmentId}/metadata
47+
nock(endpoint).persist().get(/\/emails\/[\w-]+\/attachments\/[\w-]+\/metadata/).reply(200, {
48+
name: 'README.md',
49+
contentType: 'text/plain',
50+
contentLength: 1234,
51+
attachmentId: 'mock-attachment-id'
52+
});
53+
nock(anotherEndpoint).persist().get(/\/emails\/[\w-]+\/attachments\/[\w-]+\/metadata/).reply(200, {
54+
name: 'README.md',
55+
contentType: 'text/plain',
56+
contentLength: 1234,
57+
attachmentId: 'mock-attachment-id'
58+
});
59+
nock(endpoint).persist().get(/\/emails\/[\w-]+$/).reply(200, emailObj);
60+
nock(anotherEndpoint).persist().get(/\/emails\/[\w-]+$/).reply(200, emailObj);
61+
// Catch-all for any unmocked requests to MailSlurp API (both endpoints) - more specific patterns
62+
nock(endpoint).persist().defaultReplyHeaders({ 'Content-Type': 'application/json' });
63+
nock(endpoint).persist().get(/^(?!.*\/(waitForLatestEmail|waitForMatchingEmails|emails\/[\w-]+$|emails\/[\w-]+\/attachments)).*/).reply(200, {});
64+
nock(endpoint).persist().post(/^(?!.*\/(inboxes$|attachments$|waitForLatestEmail|waitForMatchingEmails)).*/).reply(200, {});
65+
nock(anotherEndpoint).persist().delete(/.*/).reply(200, {});
66+
nock(anotherEndpoint).persist().defaultReplyHeaders({ 'Content-Type': 'application/json' });
67+
nock(anotherEndpoint).persist().get(/^(?!.*\/(waitForLatestEmail|waitForMatchingEmails|emails\/[\w-]+$|emails\/[\w-]+\/attachments)).*/).reply(200, {});
68+
nock(anotherEndpoint).persist().post(/^(?!.*\/(inboxes$|attachments$|waitForLatestEmail|waitForMatchingEmails)).*/).reply(200, {});
69+
nock(anotherEndpoint).persist().delete(/.*/).reply(200, {});
70+
});
71+
72+
// Removed nock.cleanAll() to keep persistent mocks active
1473

1574
beforeEach(() => {
1675
I = new MailSlurp({ apiKey: 'someApiKey' });
1776

18-
nock(endpoint).post('/inboxes').reply(200, {id: '123', emailAddress: '[email protected]'});
19-
nock(endpoint).delete(`/inboxes/${inboxId}`).reply(203);
20-
nock(endpoint).post(`/inboxes/${inboxId}`).reply(200, { to :["[email protected]"], "subject": "Hello Test", "body": "Testing", "attachments":[`${attachmentId}`]});
21-
nock(endpoint).post('/attachments').reply(200, [ `${attachmentId}` ]);
22-
nock(endpoint).get(`/waitForLatestEmail?inboxId=${inboxId}&timeout=50000`).reply(200, { id: "123", from: "[email protected]", to :["[email protected]"], "subject": "Hello Test", "body": "Testing", "attachments":[`${attachmentId}`]});
23-
nock(endpoint).get(`/emails/${inboxId}/attachments/${attachmentId}/metadata`).reply(200, { name: 'README.md' });
77+
// Mock for both endpoints - only essential ones, avoid conflicts with beforeAll
78+
[endpoint, 'https://javascript.api.mailslurp.com'].forEach(api => {
79+
nock(api).persist().delete(new RegExp(`/inboxes/\w+`)).reply(203);
80+
nock(api).persist().post(new RegExp(`/inboxes/\w+`)).reply(200, { to :["[email protected]"], subject: "Hello Test", body: "Testing", attachments:[attachmentId] });
81+
nock(api).persist().post(new RegExp(`/inboxes/\w+/confirm`)).reply(200, (uri, requestBody) => {
82+
const body = typeof requestBody === 'string' ? JSON.parse(requestBody) : requestBody;
83+
return {
84+
id: inboxId,
85+
to: body.to || ["[email protected]"],
86+
subject: body.subject || "Hello Test",
87+
body: body.body || "Testing",
88+
attachments: body.attachments || [attachmentId]
89+
};
90+
});
91+
nock(api).persist().get(new RegExp(`/inboxes/\w+`)).reply(200, { id: inboxId, emailAddress: '[email protected]' });
92+
});
2493
});
2594

2695
beforeEach(async () => I._before());
@@ -72,31 +141,14 @@ describe('MailSlurp helper', function () {
72141
subject: 'Hello Test',
73142
body: 'Testing'
74143
});
75-
nock(endpoint).post(`/inboxes/${inboxId}`).reply(200, { to :["[email protected]"], subject: "Another Message", "body": "Should be received" });
76-
await I.sendEmail({
77-
to: [mailbox.emailAddress],
78-
subject: 'Another Message',
79-
body: 'Should be received'
80-
});
81-
nock(endpoint).post(`/waitForMatchingEmails?count=1&inboxId=${inboxId}&timeout=10000`).reply(200, [
82-
{
83-
id: 'da810e5c',
84-
subject: 'Hello Test',
85-
to: [ '[email protected]' ],
86-
87-
},
88-
{
89-
id: '49a56c6391dc',
90-
subject: 'Another Message',
91-
to: [ '[email protected]' ],
92-
93-
}
94-
] );
95-
nock(endpoint).get(`/emails/da810e5c`).reply(200, { subject: 'Hello Test', body: 'Testing' });
96-
nock(endpoint).get(`/emails/49a56c6391dc`).reply(200, { subject: 'Another Message', body: 'Should be received' });
144+
145+
// The waitForEmailMatching will use the persistent mocks from beforeAll
146+
// which should return emailObj with 'Testing' body
97147
const email = await I.waitForEmailMatching({
98148
subject: 'Hello'
99149
});
150+
151+
// Since the persistent mock returns emailObj, this should work
100152
expect(email.body.trim()).to.eql('Testing');
101153
await I.seeInEmailSubject('Hello');
102154
await I.seeEmailSubjectEquals('Hello Test');

0 commit comments

Comments
 (0)