@tryghost/email-mock-receiver 0.2.1 → 0.2.3

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.
@@ -31,6 +31,8 @@ class EmailMockReceiver {
31
31
 
32
32
  sentEmailCount(count) {
33
33
  assert.equal(this.#snapshots.length, count, 'Email count does not match');
34
+
35
+ return this;
34
36
  }
35
37
 
36
38
  /**
@@ -39,30 +41,50 @@ class EmailMockReceiver {
39
41
  * @param {Number} snapshotIndex index of snapshot to match
40
42
  * @returns {EmailMockReceiver} current instance
41
43
  */
42
- matchHTMLSnapshot(replacements = [], snapshotIndex = 0) {
44
+ #matchTextSnapshot(replacements, snapshotIndex, field) {
43
45
  const error = new AssertionError({});
44
46
 
45
47
  let assertion = {
46
48
  properties: null,
47
- field: 'html',
48
- hint: `[html ${snapshotIndex + 1}]`,
49
+ field: field,
50
+ hint: `[${field} ${snapshotIndex + 1}]`,
49
51
  error
50
52
  };
51
53
 
52
- let html = this.#snapshots[snapshotIndex].html;
54
+ let text = this.#snapshots[snapshotIndex][field];
53
55
  if (replacements.length) {
54
56
  for (const [, {pattern, replacement}] of Object.entries(replacements)) {
55
- html = html.replace(pattern, replacement);
57
+ text = text.replace(pattern, replacement);
56
58
  }
57
59
  }
58
60
 
59
- this.#snapshotManager.assertSnapshot({
60
- html: html
61
- }, assertion);
61
+ const assertedObject = {};
62
+ assertedObject[field] = text;
63
+ this.#snapshotManager.assertSnapshot(assertedObject, assertion);
62
64
 
63
65
  return this;
64
66
  }
65
67
 
68
+ /**
69
+ *
70
+ * @param {Replacement[]} [replacements] replacement patterns
71
+ * @param {Number} [snapshotIndex] index of snapshot to match
72
+ * @returns {EmailMockReceiver} current instance
73
+ */
74
+ matchHTMLSnapshot(replacements = [], snapshotIndex = 0) {
75
+ return this.#matchTextSnapshot(replacements, snapshotIndex, 'html');
76
+ }
77
+
78
+ /**
79
+ *
80
+ * @param {Replacement[]} [replacements replacement patterns
81
+ * @param {Number} [snapshotIndex] index of snapshot to match
82
+ * @returns {EmailMockReceiver} current instance
83
+ */
84
+ matchPlaintextSnapshot(replacements = [], snapshotIndex = 0) {
85
+ return this.#matchTextSnapshot(replacements, snapshotIndex, 'text');
86
+ }
87
+
66
88
  /**
67
89
  *
68
90
  * @param {Object} [properties] - properties to match
@@ -80,6 +102,7 @@ class EmailMockReceiver {
80
102
 
81
103
  const metadata = Object.assign({}, this.#snapshots[snapshotIndex]);
82
104
  delete metadata.html;
105
+ delete metadata.text;
83
106
 
84
107
  this.#snapshotManager.assertSnapshot({
85
108
  metadata
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tryghost/email-mock-receiver",
3
- "version": "0.2.1",
3
+ "version": "0.2.3",
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": "886860d772381ed643fc23251ba9dde3d605d0b0"
28
+ "gitHead": "2e7899ed169bdfbfa05b0126519e632d000aac6d"
29
29
  }