@upyo/mock 0.1.0-dev.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +186 -0
- package/dist/index.cjs +336 -0
- package/dist/index.d.cts +276 -0
- package/dist/index.d.ts +276 -0
- package/dist/index.js +335 -0
- package/package.json +71 -0
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
import { Message, Receipt, Transport, TransportOptions } from "@upyo/core";
|
|
2
|
+
|
|
3
|
+
//#region src/config.d.ts
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Configuration interface for Mock transport.
|
|
7
|
+
*
|
|
8
|
+
* This interface defines options for configuring the mock transport's
|
|
9
|
+
* behavior for testing scenarios.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* const config: MockConfig = {
|
|
14
|
+
* defaultResponse: { successful: true, messageId: "test-123" },
|
|
15
|
+
* delay: 100,
|
|
16
|
+
* failureRate: 0.1
|
|
17
|
+
* };
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
interface MockConfig {
|
|
21
|
+
/**
|
|
22
|
+
* The default response to return for send operations.
|
|
23
|
+
*
|
|
24
|
+
* @default { successful: true, messageId: "mock-message-id" }
|
|
25
|
+
*/
|
|
26
|
+
readonly defaultResponse?: {
|
|
27
|
+
readonly successful: true;
|
|
28
|
+
readonly messageId: string;
|
|
29
|
+
} | {
|
|
30
|
+
readonly successful: false;
|
|
31
|
+
readonly errorMessages: readonly string[];
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* Fixed delay in milliseconds for all send operations.
|
|
35
|
+
*
|
|
36
|
+
* @default 0
|
|
37
|
+
*/
|
|
38
|
+
readonly delay?: number;
|
|
39
|
+
/**
|
|
40
|
+
* Random delay range in milliseconds for send operations.
|
|
41
|
+
* When set, overrides the fixed delay setting.
|
|
42
|
+
*/
|
|
43
|
+
readonly randomDelayRange?: {
|
|
44
|
+
readonly min: number;
|
|
45
|
+
readonly max: number;
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* Failure rate (0.0 to 1.0) for random failures.
|
|
49
|
+
* When set, sends will randomly fail at the specified rate.
|
|
50
|
+
*
|
|
51
|
+
* @default 0
|
|
52
|
+
*/
|
|
53
|
+
readonly failureRate?: number;
|
|
54
|
+
/**
|
|
55
|
+
* Whether to automatically generate unique message IDs for successful responses.
|
|
56
|
+
*
|
|
57
|
+
* @default true
|
|
58
|
+
*/
|
|
59
|
+
readonly generateUniqueMessageIds?: boolean;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Resolved mock configuration with all optional fields filled with default values.
|
|
63
|
+
*
|
|
64
|
+
* This type represents the final configuration after applying defaults,
|
|
65
|
+
* used internally by the mock transport implementation.
|
|
66
|
+
*/
|
|
67
|
+
type ResolvedMockConfig = Required<MockConfig>;
|
|
68
|
+
/**
|
|
69
|
+
* Creates a resolved mock configuration by applying default values to optional fields.
|
|
70
|
+
*
|
|
71
|
+
* This function takes a partial mock configuration and returns a complete
|
|
72
|
+
* configuration with all optional fields filled with sensible defaults.
|
|
73
|
+
*
|
|
74
|
+
* @param config - The mock configuration with optional fields
|
|
75
|
+
* @returns A resolved configuration with all defaults applied
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* ```typescript
|
|
79
|
+
* const resolved = createMockConfig({
|
|
80
|
+
* delay: 100
|
|
81
|
+
* });
|
|
82
|
+
*
|
|
83
|
+
* // resolved.defaultResponse will be { successful: true, messageId: "mock-message-id" }
|
|
84
|
+
* // resolved.failureRate will be 0 (default)
|
|
85
|
+
* // resolved.generateUniqueMessageIds will be true (default)
|
|
86
|
+
* ```
|
|
87
|
+
*/
|
|
88
|
+
//#endregion
|
|
89
|
+
//#region src/mock-transport.d.ts
|
|
90
|
+
/**
|
|
91
|
+
* A mock transport implementation for testing purposes.
|
|
92
|
+
*
|
|
93
|
+
* This transport doesn't actually send emails but stores them in memory,
|
|
94
|
+
* making it useful for unit testing email functionality. It provides
|
|
95
|
+
* comprehensive testing capabilities including message verification,
|
|
96
|
+
* behavior simulation, and async utilities.
|
|
97
|
+
*/
|
|
98
|
+
declare class MockTransport implements Transport {
|
|
99
|
+
/**
|
|
100
|
+
* The resolved configuration used by this mock transport.
|
|
101
|
+
*/
|
|
102
|
+
config: ResolvedMockConfig;
|
|
103
|
+
private sentMessages;
|
|
104
|
+
private nextResponse;
|
|
105
|
+
private messageIdCounter;
|
|
106
|
+
/**
|
|
107
|
+
* Creates a new MockTransport instance.
|
|
108
|
+
*
|
|
109
|
+
* @param config Configuration options for the mock transport behavior.
|
|
110
|
+
*/
|
|
111
|
+
constructor(config?: MockConfig);
|
|
112
|
+
/**
|
|
113
|
+
* Sends an email message through the mock transport.
|
|
114
|
+
*
|
|
115
|
+
* The message is stored in memory and can be retrieved for testing verification.
|
|
116
|
+
* Respects configured delays, failure rates, and response overrides.
|
|
117
|
+
*
|
|
118
|
+
* @param message The email message to send.
|
|
119
|
+
* @param options Transport options including abort signal.
|
|
120
|
+
* @returns A promise that resolves to a receipt indicating success or failure.
|
|
121
|
+
* @throws {DOMException} When the operation is aborted via `AbortSignal`.
|
|
122
|
+
*/
|
|
123
|
+
send(message: Message, options?: TransportOptions): Promise<Receipt>;
|
|
124
|
+
/**
|
|
125
|
+
* Sends multiple email messages through the mock transport.
|
|
126
|
+
*
|
|
127
|
+
* Each message is processed sequentially using the send() method, respecting
|
|
128
|
+
* all configured behavior including delays and failure rates.
|
|
129
|
+
*
|
|
130
|
+
* @param messages An iterable or async iterable of messages to send.
|
|
131
|
+
* @param options Transport options including abort signal.
|
|
132
|
+
* @returns An async iterable of receipts, one for each message.
|
|
133
|
+
* @throws {DOMException} When the operation is aborted via `AbortSignal`.
|
|
134
|
+
*/
|
|
135
|
+
sendMany(messages: Iterable<Message> | AsyncIterable<Message>, options?: TransportOptions): AsyncIterable<Receipt>;
|
|
136
|
+
/**
|
|
137
|
+
* Get all messages that have been "sent" through this transport.
|
|
138
|
+
*
|
|
139
|
+
* @returns A readonly array containing copies of all sent messages.
|
|
140
|
+
*/
|
|
141
|
+
getSentMessages(): readonly Message[];
|
|
142
|
+
/**
|
|
143
|
+
* Get the last message that was sent, or undefined if no messages have been sent.
|
|
144
|
+
*
|
|
145
|
+
* @returns The most recently sent message, or undefined if none.
|
|
146
|
+
*/
|
|
147
|
+
getLastSentMessage(): Message | undefined;
|
|
148
|
+
/**
|
|
149
|
+
* Get the total number of messages that have been sent.
|
|
150
|
+
*
|
|
151
|
+
* @returns The count of messages sent through this transport.
|
|
152
|
+
*/
|
|
153
|
+
getSentMessagesCount(): number;
|
|
154
|
+
/**
|
|
155
|
+
* Clear all stored messages.
|
|
156
|
+
*
|
|
157
|
+
* This removes all messages from the internal storage but does not
|
|
158
|
+
* reset other configuration like delays or failure rates.
|
|
159
|
+
*/
|
|
160
|
+
clearSentMessages(): void;
|
|
161
|
+
/**
|
|
162
|
+
* Set the response that will be returned for the next send operation.
|
|
163
|
+
*
|
|
164
|
+
* After being used once, it will revert to the default response.
|
|
165
|
+
* This is useful for testing specific success or failure scenarios.
|
|
166
|
+
*
|
|
167
|
+
* @param receipt The receipt to return for the next send operation.
|
|
168
|
+
*/
|
|
169
|
+
setNextResponse(receipt: Receipt): void;
|
|
170
|
+
/**
|
|
171
|
+
* Set the default response that will be returned for send operations.
|
|
172
|
+
*
|
|
173
|
+
* This response is used when no next response is set and random failures
|
|
174
|
+
* are not triggered.
|
|
175
|
+
*
|
|
176
|
+
* @param receipt The default receipt to return for send operations.
|
|
177
|
+
*/
|
|
178
|
+
setDefaultResponse(receipt: Receipt): void;
|
|
179
|
+
/**
|
|
180
|
+
* Set the failure rate (0.0 to 1.0). When set, sends will randomly fail
|
|
181
|
+
* at the specified rate instead of using the configured responses.
|
|
182
|
+
*
|
|
183
|
+
* @param rate The failure rate as a decimal between 0.0 and 1.0.
|
|
184
|
+
* @throws {RangeError} When rate is not between 0.0 and 1.0.
|
|
185
|
+
*/
|
|
186
|
+
setFailureRate(rate: number): void;
|
|
187
|
+
/**
|
|
188
|
+
* Set a fixed delay in milliseconds for all send operations.
|
|
189
|
+
*
|
|
190
|
+
* This overrides any random delay range that was previously configured.
|
|
191
|
+
*
|
|
192
|
+
* @param milliseconds The delay in milliseconds (must be non-negative).
|
|
193
|
+
* @throws {RangeError} When milliseconds is negative.
|
|
194
|
+
*/
|
|
195
|
+
setDelay(milliseconds: number): void;
|
|
196
|
+
/**
|
|
197
|
+
* Set a random delay range in milliseconds for send operations.
|
|
198
|
+
*
|
|
199
|
+
* This overrides any fixed delay that was previously configured.
|
|
200
|
+
*
|
|
201
|
+
* @param min The minimum delay in milliseconds.
|
|
202
|
+
* @param max The maximum delay in milliseconds.
|
|
203
|
+
* @throws {RangeError} When min or max is negative, or min > max.
|
|
204
|
+
*/
|
|
205
|
+
setRandomDelay(min: number, max: number): void;
|
|
206
|
+
/**
|
|
207
|
+
* Find the first message matching the given predicate.
|
|
208
|
+
*
|
|
209
|
+
* @param predicate A function that tests each message.
|
|
210
|
+
* @returns The first matching message, or undefined if none found.
|
|
211
|
+
*/
|
|
212
|
+
findMessageBy(predicate: (message: Message) => boolean): Message | undefined;
|
|
213
|
+
/**
|
|
214
|
+
* Find all messages matching the given predicate.
|
|
215
|
+
*
|
|
216
|
+
* @param predicate A function that tests each message.
|
|
217
|
+
* @returns An array of all matching messages.
|
|
218
|
+
*/
|
|
219
|
+
findMessagesBy(predicate: (message: Message) => boolean): readonly Message[];
|
|
220
|
+
/**
|
|
221
|
+
* Get all messages sent to a specific email address.
|
|
222
|
+
*
|
|
223
|
+
* Searches through To, CC, and BCC recipients to find messages
|
|
224
|
+
* that were sent to the specified email address.
|
|
225
|
+
*
|
|
226
|
+
* @param email The email address to search for.
|
|
227
|
+
* @returns An array of messages sent to the specified address.
|
|
228
|
+
*/
|
|
229
|
+
getMessagesTo(email: string): readonly Message[];
|
|
230
|
+
/**
|
|
231
|
+
* Get all messages with a specific subject.
|
|
232
|
+
*
|
|
233
|
+
* @param subject The exact subject line to match.
|
|
234
|
+
* @returns An array of messages with the specified subject.
|
|
235
|
+
*/
|
|
236
|
+
getMessagesBySubject(subject: string): readonly Message[];
|
|
237
|
+
/**
|
|
238
|
+
* Wait for a specific number of messages to be sent.
|
|
239
|
+
*
|
|
240
|
+
* This method polls the message count until the target is reached or
|
|
241
|
+
* the timeout expires. Useful for testing async email workflows where you
|
|
242
|
+
* need to wait for messages to be sent.
|
|
243
|
+
*
|
|
244
|
+
* @param count The number of messages to wait for.
|
|
245
|
+
* @param timeout The timeout in milliseconds (default: 5000).
|
|
246
|
+
* @returns A promise that resolves when the count is reached.
|
|
247
|
+
* @throws {Error} When the timeout is exceeded before reaching the target
|
|
248
|
+
* count.
|
|
249
|
+
*/
|
|
250
|
+
waitForMessageCount(count: number, timeout?: number): Promise<void>;
|
|
251
|
+
/**
|
|
252
|
+
* Wait for a message matching the given predicate.
|
|
253
|
+
*
|
|
254
|
+
* This method polls for a matching message until one is found or the timeout
|
|
255
|
+
* expires. Useful for testing async email workflows where you need to wait
|
|
256
|
+
* for specific messages.
|
|
257
|
+
*
|
|
258
|
+
* @param predicate A function that tests each message for a match.
|
|
259
|
+
* @param timeout The timeout in milliseconds (default: 5000).
|
|
260
|
+
* @returns A promise that resolves with the matching message.
|
|
261
|
+
* @throws {Error} When the timeout is exceeded before finding a matching
|
|
262
|
+
* message.
|
|
263
|
+
*/
|
|
264
|
+
waitForMessage(predicate: (message: Message) => boolean, timeout?: number): Promise<Message>;
|
|
265
|
+
/**
|
|
266
|
+
* Reset the transport to its initial state.
|
|
267
|
+
*
|
|
268
|
+
* Clears all messages, resets all configuration to defaults, and
|
|
269
|
+
* resets the message ID counter. This is useful for test cleanup.
|
|
270
|
+
*/
|
|
271
|
+
reset(): void;
|
|
272
|
+
private applyDelay;
|
|
273
|
+
private getResponse;
|
|
274
|
+
}
|
|
275
|
+
//#endregion
|
|
276
|
+
export { MockConfig, MockTransport };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
import { Message, Receipt, Transport, TransportOptions } from "@upyo/core";
|
|
2
|
+
|
|
3
|
+
//#region src/config.d.ts
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Configuration interface for Mock transport.
|
|
7
|
+
*
|
|
8
|
+
* This interface defines options for configuring the mock transport's
|
|
9
|
+
* behavior for testing scenarios.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* const config: MockConfig = {
|
|
14
|
+
* defaultResponse: { successful: true, messageId: "test-123" },
|
|
15
|
+
* delay: 100,
|
|
16
|
+
* failureRate: 0.1
|
|
17
|
+
* };
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
interface MockConfig {
|
|
21
|
+
/**
|
|
22
|
+
* The default response to return for send operations.
|
|
23
|
+
*
|
|
24
|
+
* @default { successful: true, messageId: "mock-message-id" }
|
|
25
|
+
*/
|
|
26
|
+
readonly defaultResponse?: {
|
|
27
|
+
readonly successful: true;
|
|
28
|
+
readonly messageId: string;
|
|
29
|
+
} | {
|
|
30
|
+
readonly successful: false;
|
|
31
|
+
readonly errorMessages: readonly string[];
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* Fixed delay in milliseconds for all send operations.
|
|
35
|
+
*
|
|
36
|
+
* @default 0
|
|
37
|
+
*/
|
|
38
|
+
readonly delay?: number;
|
|
39
|
+
/**
|
|
40
|
+
* Random delay range in milliseconds for send operations.
|
|
41
|
+
* When set, overrides the fixed delay setting.
|
|
42
|
+
*/
|
|
43
|
+
readonly randomDelayRange?: {
|
|
44
|
+
readonly min: number;
|
|
45
|
+
readonly max: number;
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* Failure rate (0.0 to 1.0) for random failures.
|
|
49
|
+
* When set, sends will randomly fail at the specified rate.
|
|
50
|
+
*
|
|
51
|
+
* @default 0
|
|
52
|
+
*/
|
|
53
|
+
readonly failureRate?: number;
|
|
54
|
+
/**
|
|
55
|
+
* Whether to automatically generate unique message IDs for successful responses.
|
|
56
|
+
*
|
|
57
|
+
* @default true
|
|
58
|
+
*/
|
|
59
|
+
readonly generateUniqueMessageIds?: boolean;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Resolved mock configuration with all optional fields filled with default values.
|
|
63
|
+
*
|
|
64
|
+
* This type represents the final configuration after applying defaults,
|
|
65
|
+
* used internally by the mock transport implementation.
|
|
66
|
+
*/
|
|
67
|
+
type ResolvedMockConfig = Required<MockConfig>;
|
|
68
|
+
/**
|
|
69
|
+
* Creates a resolved mock configuration by applying default values to optional fields.
|
|
70
|
+
*
|
|
71
|
+
* This function takes a partial mock configuration and returns a complete
|
|
72
|
+
* configuration with all optional fields filled with sensible defaults.
|
|
73
|
+
*
|
|
74
|
+
* @param config - The mock configuration with optional fields
|
|
75
|
+
* @returns A resolved configuration with all defaults applied
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* ```typescript
|
|
79
|
+
* const resolved = createMockConfig({
|
|
80
|
+
* delay: 100
|
|
81
|
+
* });
|
|
82
|
+
*
|
|
83
|
+
* // resolved.defaultResponse will be { successful: true, messageId: "mock-message-id" }
|
|
84
|
+
* // resolved.failureRate will be 0 (default)
|
|
85
|
+
* // resolved.generateUniqueMessageIds will be true (default)
|
|
86
|
+
* ```
|
|
87
|
+
*/
|
|
88
|
+
//#endregion
|
|
89
|
+
//#region src/mock-transport.d.ts
|
|
90
|
+
/**
|
|
91
|
+
* A mock transport implementation for testing purposes.
|
|
92
|
+
*
|
|
93
|
+
* This transport doesn't actually send emails but stores them in memory,
|
|
94
|
+
* making it useful for unit testing email functionality. It provides
|
|
95
|
+
* comprehensive testing capabilities including message verification,
|
|
96
|
+
* behavior simulation, and async utilities.
|
|
97
|
+
*/
|
|
98
|
+
declare class MockTransport implements Transport {
|
|
99
|
+
/**
|
|
100
|
+
* The resolved configuration used by this mock transport.
|
|
101
|
+
*/
|
|
102
|
+
config: ResolvedMockConfig;
|
|
103
|
+
private sentMessages;
|
|
104
|
+
private nextResponse;
|
|
105
|
+
private messageIdCounter;
|
|
106
|
+
/**
|
|
107
|
+
* Creates a new MockTransport instance.
|
|
108
|
+
*
|
|
109
|
+
* @param config Configuration options for the mock transport behavior.
|
|
110
|
+
*/
|
|
111
|
+
constructor(config?: MockConfig);
|
|
112
|
+
/**
|
|
113
|
+
* Sends an email message through the mock transport.
|
|
114
|
+
*
|
|
115
|
+
* The message is stored in memory and can be retrieved for testing verification.
|
|
116
|
+
* Respects configured delays, failure rates, and response overrides.
|
|
117
|
+
*
|
|
118
|
+
* @param message The email message to send.
|
|
119
|
+
* @param options Transport options including abort signal.
|
|
120
|
+
* @returns A promise that resolves to a receipt indicating success or failure.
|
|
121
|
+
* @throws {DOMException} When the operation is aborted via `AbortSignal`.
|
|
122
|
+
*/
|
|
123
|
+
send(message: Message, options?: TransportOptions): Promise<Receipt>;
|
|
124
|
+
/**
|
|
125
|
+
* Sends multiple email messages through the mock transport.
|
|
126
|
+
*
|
|
127
|
+
* Each message is processed sequentially using the send() method, respecting
|
|
128
|
+
* all configured behavior including delays and failure rates.
|
|
129
|
+
*
|
|
130
|
+
* @param messages An iterable or async iterable of messages to send.
|
|
131
|
+
* @param options Transport options including abort signal.
|
|
132
|
+
* @returns An async iterable of receipts, one for each message.
|
|
133
|
+
* @throws {DOMException} When the operation is aborted via `AbortSignal`.
|
|
134
|
+
*/
|
|
135
|
+
sendMany(messages: Iterable<Message> | AsyncIterable<Message>, options?: TransportOptions): AsyncIterable<Receipt>;
|
|
136
|
+
/**
|
|
137
|
+
* Get all messages that have been "sent" through this transport.
|
|
138
|
+
*
|
|
139
|
+
* @returns A readonly array containing copies of all sent messages.
|
|
140
|
+
*/
|
|
141
|
+
getSentMessages(): readonly Message[];
|
|
142
|
+
/**
|
|
143
|
+
* Get the last message that was sent, or undefined if no messages have been sent.
|
|
144
|
+
*
|
|
145
|
+
* @returns The most recently sent message, or undefined if none.
|
|
146
|
+
*/
|
|
147
|
+
getLastSentMessage(): Message | undefined;
|
|
148
|
+
/**
|
|
149
|
+
* Get the total number of messages that have been sent.
|
|
150
|
+
*
|
|
151
|
+
* @returns The count of messages sent through this transport.
|
|
152
|
+
*/
|
|
153
|
+
getSentMessagesCount(): number;
|
|
154
|
+
/**
|
|
155
|
+
* Clear all stored messages.
|
|
156
|
+
*
|
|
157
|
+
* This removes all messages from the internal storage but does not
|
|
158
|
+
* reset other configuration like delays or failure rates.
|
|
159
|
+
*/
|
|
160
|
+
clearSentMessages(): void;
|
|
161
|
+
/**
|
|
162
|
+
* Set the response that will be returned for the next send operation.
|
|
163
|
+
*
|
|
164
|
+
* After being used once, it will revert to the default response.
|
|
165
|
+
* This is useful for testing specific success or failure scenarios.
|
|
166
|
+
*
|
|
167
|
+
* @param receipt The receipt to return for the next send operation.
|
|
168
|
+
*/
|
|
169
|
+
setNextResponse(receipt: Receipt): void;
|
|
170
|
+
/**
|
|
171
|
+
* Set the default response that will be returned for send operations.
|
|
172
|
+
*
|
|
173
|
+
* This response is used when no next response is set and random failures
|
|
174
|
+
* are not triggered.
|
|
175
|
+
*
|
|
176
|
+
* @param receipt The default receipt to return for send operations.
|
|
177
|
+
*/
|
|
178
|
+
setDefaultResponse(receipt: Receipt): void;
|
|
179
|
+
/**
|
|
180
|
+
* Set the failure rate (0.0 to 1.0). When set, sends will randomly fail
|
|
181
|
+
* at the specified rate instead of using the configured responses.
|
|
182
|
+
*
|
|
183
|
+
* @param rate The failure rate as a decimal between 0.0 and 1.0.
|
|
184
|
+
* @throws {RangeError} When rate is not between 0.0 and 1.0.
|
|
185
|
+
*/
|
|
186
|
+
setFailureRate(rate: number): void;
|
|
187
|
+
/**
|
|
188
|
+
* Set a fixed delay in milliseconds for all send operations.
|
|
189
|
+
*
|
|
190
|
+
* This overrides any random delay range that was previously configured.
|
|
191
|
+
*
|
|
192
|
+
* @param milliseconds The delay in milliseconds (must be non-negative).
|
|
193
|
+
* @throws {RangeError} When milliseconds is negative.
|
|
194
|
+
*/
|
|
195
|
+
setDelay(milliseconds: number): void;
|
|
196
|
+
/**
|
|
197
|
+
* Set a random delay range in milliseconds for send operations.
|
|
198
|
+
*
|
|
199
|
+
* This overrides any fixed delay that was previously configured.
|
|
200
|
+
*
|
|
201
|
+
* @param min The minimum delay in milliseconds.
|
|
202
|
+
* @param max The maximum delay in milliseconds.
|
|
203
|
+
* @throws {RangeError} When min or max is negative, or min > max.
|
|
204
|
+
*/
|
|
205
|
+
setRandomDelay(min: number, max: number): void;
|
|
206
|
+
/**
|
|
207
|
+
* Find the first message matching the given predicate.
|
|
208
|
+
*
|
|
209
|
+
* @param predicate A function that tests each message.
|
|
210
|
+
* @returns The first matching message, or undefined if none found.
|
|
211
|
+
*/
|
|
212
|
+
findMessageBy(predicate: (message: Message) => boolean): Message | undefined;
|
|
213
|
+
/**
|
|
214
|
+
* Find all messages matching the given predicate.
|
|
215
|
+
*
|
|
216
|
+
* @param predicate A function that tests each message.
|
|
217
|
+
* @returns An array of all matching messages.
|
|
218
|
+
*/
|
|
219
|
+
findMessagesBy(predicate: (message: Message) => boolean): readonly Message[];
|
|
220
|
+
/**
|
|
221
|
+
* Get all messages sent to a specific email address.
|
|
222
|
+
*
|
|
223
|
+
* Searches through To, CC, and BCC recipients to find messages
|
|
224
|
+
* that were sent to the specified email address.
|
|
225
|
+
*
|
|
226
|
+
* @param email The email address to search for.
|
|
227
|
+
* @returns An array of messages sent to the specified address.
|
|
228
|
+
*/
|
|
229
|
+
getMessagesTo(email: string): readonly Message[];
|
|
230
|
+
/**
|
|
231
|
+
* Get all messages with a specific subject.
|
|
232
|
+
*
|
|
233
|
+
* @param subject The exact subject line to match.
|
|
234
|
+
* @returns An array of messages with the specified subject.
|
|
235
|
+
*/
|
|
236
|
+
getMessagesBySubject(subject: string): readonly Message[];
|
|
237
|
+
/**
|
|
238
|
+
* Wait for a specific number of messages to be sent.
|
|
239
|
+
*
|
|
240
|
+
* This method polls the message count until the target is reached or
|
|
241
|
+
* the timeout expires. Useful for testing async email workflows where you
|
|
242
|
+
* need to wait for messages to be sent.
|
|
243
|
+
*
|
|
244
|
+
* @param count The number of messages to wait for.
|
|
245
|
+
* @param timeout The timeout in milliseconds (default: 5000).
|
|
246
|
+
* @returns A promise that resolves when the count is reached.
|
|
247
|
+
* @throws {Error} When the timeout is exceeded before reaching the target
|
|
248
|
+
* count.
|
|
249
|
+
*/
|
|
250
|
+
waitForMessageCount(count: number, timeout?: number): Promise<void>;
|
|
251
|
+
/**
|
|
252
|
+
* Wait for a message matching the given predicate.
|
|
253
|
+
*
|
|
254
|
+
* This method polls for a matching message until one is found or the timeout
|
|
255
|
+
* expires. Useful for testing async email workflows where you need to wait
|
|
256
|
+
* for specific messages.
|
|
257
|
+
*
|
|
258
|
+
* @param predicate A function that tests each message for a match.
|
|
259
|
+
* @param timeout The timeout in milliseconds (default: 5000).
|
|
260
|
+
* @returns A promise that resolves with the matching message.
|
|
261
|
+
* @throws {Error} When the timeout is exceeded before finding a matching
|
|
262
|
+
* message.
|
|
263
|
+
*/
|
|
264
|
+
waitForMessage(predicate: (message: Message) => boolean, timeout?: number): Promise<Message>;
|
|
265
|
+
/**
|
|
266
|
+
* Reset the transport to its initial state.
|
|
267
|
+
*
|
|
268
|
+
* Clears all messages, resets all configuration to defaults, and
|
|
269
|
+
* resets the message ID counter. This is useful for test cleanup.
|
|
270
|
+
*/
|
|
271
|
+
reset(): void;
|
|
272
|
+
private applyDelay;
|
|
273
|
+
private getResponse;
|
|
274
|
+
}
|
|
275
|
+
//#endregion
|
|
276
|
+
export { MockConfig, MockTransport };
|