@tryghost/email-mock-receiver 0.2.0 → 0.2.2
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/lib/email-mock-receiver.js +29 -8
- package/package.json +2 -2
|
@@ -39,30 +39,50 @@ class EmailMockReceiver {
|
|
|
39
39
|
* @param {Number} snapshotIndex index of snapshot to match
|
|
40
40
|
* @returns {EmailMockReceiver} current instance
|
|
41
41
|
*/
|
|
42
|
-
|
|
42
|
+
#matchTextSnapshot(replacements, snapshotIndex, field) {
|
|
43
43
|
const error = new AssertionError({});
|
|
44
44
|
|
|
45
45
|
let assertion = {
|
|
46
46
|
properties: null,
|
|
47
|
-
field:
|
|
48
|
-
hint: `[
|
|
47
|
+
field: field,
|
|
48
|
+
hint: `[${field} ${snapshotIndex + 1}]`,
|
|
49
49
|
error
|
|
50
50
|
};
|
|
51
51
|
|
|
52
|
-
let
|
|
52
|
+
let text = this.#snapshots[snapshotIndex][field];
|
|
53
53
|
if (replacements.length) {
|
|
54
54
|
for (const [, {pattern, replacement}] of Object.entries(replacements)) {
|
|
55
|
-
|
|
55
|
+
text = text.replace(pattern, replacement);
|
|
56
56
|
}
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
59
|
+
const assertedObject = {};
|
|
60
|
+
assertedObject[field] = text;
|
|
61
|
+
this.#snapshotManager.assertSnapshot(assertedObject, assertion);
|
|
62
62
|
|
|
63
63
|
return this;
|
|
64
64
|
}
|
|
65
65
|
|
|
66
|
+
/**
|
|
67
|
+
*
|
|
68
|
+
* @param {Replacement[]} [replacements] replacement patterns
|
|
69
|
+
* @param {Number} [snapshotIndex] index of snapshot to match
|
|
70
|
+
* @returns {EmailMockReceiver} current instance
|
|
71
|
+
*/
|
|
72
|
+
matchHTMLSnapshot(replacements = [], snapshotIndex = 0) {
|
|
73
|
+
return this.#matchTextSnapshot(replacements, snapshotIndex, 'html');
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
*
|
|
78
|
+
* @param {Replacement[]} [replacements replacement patterns
|
|
79
|
+
* @param {Number} [snapshotIndex] index of snapshot to match
|
|
80
|
+
* @returns {EmailMockReceiver} current instance
|
|
81
|
+
*/
|
|
82
|
+
matchPlaintextSnapshot(replacements = [], snapshotIndex = 0) {
|
|
83
|
+
return this.#matchTextSnapshot(replacements, snapshotIndex, 'text');
|
|
84
|
+
}
|
|
85
|
+
|
|
66
86
|
/**
|
|
67
87
|
*
|
|
68
88
|
* @param {Object} [properties] - properties to match
|
|
@@ -80,6 +100,7 @@ class EmailMockReceiver {
|
|
|
80
100
|
|
|
81
101
|
const metadata = Object.assign({}, this.#snapshots[snapshotIndex]);
|
|
82
102
|
delete metadata.html;
|
|
103
|
+
delete metadata.text;
|
|
83
104
|
|
|
84
105
|
this.#snapshotManager.assertSnapshot({
|
|
85
106
|
metadata
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tryghost/email-mock-receiver",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"repository": "https://github.com/TryGhost/framework/tree/main/packages/email-mock-receiver",
|
|
5
5
|
"author": "Ghost Foundation",
|
|
6
6
|
"license": "MIT",
|
|
@@ -25,5 +25,5 @@
|
|
|
25
25
|
"mocha": "10.2.0",
|
|
26
26
|
"sinon": "15.0.3"
|
|
27
27
|
},
|
|
28
|
-
"gitHead": "
|
|
28
|
+
"gitHead": "f1e7f166b8d1c090d48be8d203b4f427b4909ec1"
|
|
29
29
|
}
|