@thisisagile/easy-test 15.26.2 → 15.27.0

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.
Files changed (121) hide show
  1. package/dist/chunk-6EKWTLNQ.mjs +12 -0
  2. package/dist/chunk-6EKWTLNQ.mjs.map +1 -0
  3. package/dist/chunk-KAVJOG5T.mjs +39 -0
  4. package/dist/chunk-KAVJOG5T.mjs.map +1 -0
  5. package/dist/chunk-LN24S2PC.mjs +41 -0
  6. package/dist/chunk-LN24S2PC.mjs.map +1 -0
  7. package/dist/chunk-O475TEG2.mjs +30 -0
  8. package/dist/chunk-O475TEG2.mjs.map +1 -0
  9. package/dist/chunk-QE3TR4BY.mjs +16 -0
  10. package/dist/chunk-QE3TR4BY.mjs.map +1 -0
  11. package/dist/chunk-Z4XAP66Q.mjs +44 -0
  12. package/dist/chunk-Z4XAP66Q.mjs.map +1 -0
  13. package/dist/index.js +590 -5
  14. package/dist/index.js.map +1 -1
  15. package/dist/matchers/Check.mjs +5 -34
  16. package/dist/matchers/Check.mjs.map +1 -1
  17. package/dist/matchers/HttpMatchers.mjs +19 -13
  18. package/dist/matchers/HttpMatchers.mjs.map +1 -1
  19. package/dist/matchers/Match.mjs +6 -29
  20. package/dist/matchers/Match.mjs.map +1 -1
  21. package/dist/matchers/ResultMatchers.mjs +14 -8
  22. package/dist/matchers/ResultMatchers.mjs.map +1 -1
  23. package/dist/matchers/toBeArrayOf.mjs +8 -2
  24. package/dist/matchers/toBeArrayOf.mjs.map +1 -1
  25. package/dist/matchers/toBeArrayOfWithLength.mjs +8 -2
  26. package/dist/matchers/toBeArrayOfWithLength.mjs.map +1 -1
  27. package/dist/matchers/toBeAt.mjs +8 -2
  28. package/dist/matchers/toBeAt.mjs.map +1 -1
  29. package/dist/matchers/toBeExactlyAt.mjs +11 -4
  30. package/dist/matchers/toBeExactlyAt.mjs.map +1 -1
  31. package/dist/matchers/toBeQueriedWith.mjs +8 -2
  32. package/dist/matchers/toBeQueriedWith.mjs.map +1 -1
  33. package/dist/matchers/toBeRoutedTo.mjs +14 -5
  34. package/dist/matchers/toBeRoutedTo.mjs.map +1 -1
  35. package/dist/matchers/toBeValid.mjs +10 -3
  36. package/dist/matchers/toBeValid.mjs.map +1 -1
  37. package/dist/matchers/toFailMatcher.mjs +13 -6
  38. package/dist/matchers/toFailMatcher.mjs.map +1 -1
  39. package/dist/matchers/toMatchArray.mjs +6 -1
  40. package/dist/matchers/toMatchArray.mjs.map +1 -1
  41. package/dist/matchers/toMatchExactJson.mjs +12 -4
  42. package/dist/matchers/toMatchExactJson.mjs.map +1 -1
  43. package/dist/matchers/toMatchException.mjs +10 -3
  44. package/dist/matchers/toMatchException.mjs.map +1 -1
  45. package/dist/matchers/toMatchJson.mjs +14 -5
  46. package/dist/matchers/toMatchJson.mjs.map +1 -1
  47. package/dist/matchers/toMatchRoute.mjs +10 -3
  48. package/dist/matchers/toMatchRoute.mjs.map +1 -1
  49. package/dist/matchers/toMatchText.mjs +10 -3
  50. package/dist/matchers/toMatchText.mjs.map +1 -1
  51. package/dist/matchers/toPassMatcher.mjs +13 -6
  52. package/dist/matchers/toPassMatcher.mjs.map +1 -1
  53. package/dist/mock/Fits.mjs +17 -9
  54. package/dist/mock/Fits.mjs.map +1 -1
  55. package/dist/mock/Mocks.mjs +9 -4
  56. package/dist/mock/Mocks.mjs.map +1 -1
  57. package/dist/utils/Eq.mjs +4 -7
  58. package/dist/utils/Eq.mjs.map +1 -1
  59. package/dist/utils/Req.mjs +4 -29
  60. package/dist/utils/Req.mjs.map +1 -1
  61. package/dist/utils/Types.mjs +4 -2
  62. package/dist/utils/Types.mjs.map +1 -1
  63. package/dist/utils/Utils.mjs +13 -14
  64. package/dist/utils/Utils.mjs.map +1 -1
  65. package/package.json +3 -2
  66. package/dist/matchers/Check.js +0 -64
  67. package/dist/matchers/Check.js.map +0 -1
  68. package/dist/matchers/HttpMatchers.js +0 -89
  69. package/dist/matchers/HttpMatchers.js.map +0 -1
  70. package/dist/matchers/Match.js +0 -59
  71. package/dist/matchers/Match.js.map +0 -1
  72. package/dist/matchers/ResultMatchers.js +0 -51
  73. package/dist/matchers/ResultMatchers.js.map +0 -1
  74. package/dist/matchers/index.js +0 -59
  75. package/dist/matchers/index.js.map +0 -1
  76. package/dist/matchers/toBeArrayOf.js +0 -33
  77. package/dist/matchers/toBeArrayOf.js.map +0 -1
  78. package/dist/matchers/toBeArrayOfWithLength.js +0 -36
  79. package/dist/matchers/toBeArrayOfWithLength.js.map +0 -1
  80. package/dist/matchers/toBeAt.js +0 -44
  81. package/dist/matchers/toBeAt.js.map +0 -1
  82. package/dist/matchers/toBeExactlyAt.js +0 -43
  83. package/dist/matchers/toBeExactlyAt.js.map +0 -1
  84. package/dist/matchers/toBeQueriedWith.js +0 -36
  85. package/dist/matchers/toBeQueriedWith.js.map +0 -1
  86. package/dist/matchers/toBeRoutedTo.js +0 -49
  87. package/dist/matchers/toBeRoutedTo.js.map +0 -1
  88. package/dist/matchers/toBeValid.js +0 -34
  89. package/dist/matchers/toBeValid.js.map +0 -1
  90. package/dist/matchers/toFailMatcher.js +0 -59
  91. package/dist/matchers/toFailMatcher.js.map +0 -1
  92. package/dist/matchers/toMatchArray.js +0 -38
  93. package/dist/matchers/toMatchArray.js.map +0 -1
  94. package/dist/matchers/toMatchExactJson.js +0 -42
  95. package/dist/matchers/toMatchExactJson.js.map +0 -1
  96. package/dist/matchers/toMatchException.js +0 -43
  97. package/dist/matchers/toMatchException.js.map +0 -1
  98. package/dist/matchers/toMatchJson.js +0 -43
  99. package/dist/matchers/toMatchJson.js.map +0 -1
  100. package/dist/matchers/toMatchRoute.js +0 -37
  101. package/dist/matchers/toMatchRoute.js.map +0 -1
  102. package/dist/matchers/toMatchText.js +0 -37
  103. package/dist/matchers/toMatchText.js.map +0 -1
  104. package/dist/matchers/toPassMatcher.js +0 -59
  105. package/dist/matchers/toPassMatcher.js.map +0 -1
  106. package/dist/mock/Fits.js +0 -71
  107. package/dist/mock/Fits.js.map +0 -1
  108. package/dist/mock/Mocks.js +0 -98
  109. package/dist/mock/Mocks.js.map +0 -1
  110. package/dist/mock/index.js +0 -25
  111. package/dist/mock/index.js.map +0 -1
  112. package/dist/utils/Eq.js +0 -35
  113. package/dist/utils/Eq.js.map +0 -1
  114. package/dist/utils/Req.js +0 -57
  115. package/dist/utils/Req.js.map +0 -1
  116. package/dist/utils/Response.js +0 -17
  117. package/dist/utils/Response.js.map +0 -1
  118. package/dist/utils/Types.js +0 -30
  119. package/dist/utils/Types.js.map +0 -1
  120. package/dist/utils/Utils.js +0 -62
  121. package/dist/utils/Utils.js.map +0 -1
package/dist/index.js CHANGED
@@ -3,6 +3,10 @@ var __defProp = Object.defineProperty;
3
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
6
10
  var __copyProps = (to, from, except, desc) => {
7
11
  if (from && typeof from === "object" || typeof from === "function") {
8
12
  for (let key of __getOwnPropNames(from))
@@ -11,15 +15,596 @@ var __copyProps = (to, from, except, desc) => {
11
15
  }
12
16
  return to;
13
17
  };
14
- var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
15
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
16
21
  var src_exports = {};
22
+ __export(src_exports, {
23
+ Fails: () => Fails,
24
+ FailsWith: () => FailsWith,
25
+ Match: () => Match,
26
+ MatchesExactJson: () => MatchesExactJson,
27
+ MatchesJson: () => MatchesJson,
28
+ Mocks: () => Mocks,
29
+ ObjectContainingJson: () => ObjectContainingJson,
30
+ ObjectContainingText: () => ObjectContainingText,
31
+ ObjectContainingTextExact: () => ObjectContainingTextExact,
32
+ Passes: () => Passes,
33
+ PassesWith: () => PassesWith,
34
+ check: () => check,
35
+ checkDefined: () => checkDefined,
36
+ fits: () => fits,
37
+ match: () => match,
38
+ mock: () => mock,
39
+ toBeArrayOf: () => toBeArrayOf,
40
+ toBeArrayOfWithLength: () => toBeArrayOfWithLength,
41
+ toBeAt: () => toBeAt,
42
+ toBeBadGateway: () => toBeBadGateway,
43
+ toBeBadRequest: () => toBeBadRequest,
44
+ toBeConflict: () => toBeConflict,
45
+ toBeCreated: () => toBeCreated,
46
+ toBeExactlyAt: () => toBeExactlyAt,
47
+ toBeForbidden: () => toBeForbidden,
48
+ toBeInternalServerError: () => toBeInternalServerError,
49
+ toBeNotFound: () => toBeNotFound,
50
+ toBeOk: () => toBeOk,
51
+ toBeOkWithItems: () => toBeOkWithItems,
52
+ toBeQueriedWith: () => toBeQueriedWith,
53
+ toBeRoutedTo: () => toBeRoutedTo,
54
+ toBeUnauthorized: () => toBeUnauthorized,
55
+ toBeValid: () => toBeValid,
56
+ toFail: () => toFail,
57
+ toFailMatcher: () => toFailMatcher,
58
+ toFailMatcherWith: () => toFailMatcherWith,
59
+ toFailWith: () => toFailWith,
60
+ toHaveNoContent: () => toHaveNoContent,
61
+ toHaveStatus: () => toHaveStatus,
62
+ toMatchArray: () => toMatchArray,
63
+ toMatchAsString: () => toMatchAsString,
64
+ toMatchExactJson: () => toMatchExactJson,
65
+ toMatchException: () => toMatchException,
66
+ toMatchJson: () => toMatchJson,
67
+ toMatchRoute: () => toMatchRoute,
68
+ toMatchText: () => toMatchText,
69
+ toPassMatcher: () => toPassMatcher,
70
+ toPassMatcherWith: () => toPassMatcherWith,
71
+ toResultWith: () => toResultWith,
72
+ weExpectedButReceivedInstead: () => weExpectedButReceivedInstead
73
+ });
17
74
  module.exports = __toCommonJS(src_exports);
18
- __reExport(src_exports, require("./matchers"), module.exports);
19
- __reExport(src_exports, require("./mock"), module.exports);
75
+
76
+ // src/utils/Utils.ts
77
+ var isDefined = (o) => o !== void 0 && o !== null;
78
+ var isNumber = (o) => isDefined(o) && typeof o === "number" && !Number.isNaN(o);
79
+ var isFunction = (o) => isDefined(o) && typeof o === "function";
80
+ var isA = (t, ...properties) => isDefined(t) && properties.every((p) => isDefined(t[p]));
81
+ var isArray = (o) => isDefined(o) && o instanceof Array;
82
+ var isObject = (o) => o != null && (typeof o === "object" || typeof o === "function") && !isArray(o);
83
+ var asJson = (a) => a?.toJSON ? a.toJSON() : isObject(a) ? a : void 0;
84
+ var asString = (a) => a?.toString();
85
+ var asNumber = (num, alt) => {
86
+ const n = parseInt(asString(num));
87
+ return isNumber(n) ? n : isFunction(alt) ? alt() : isNumber(alt) ? alt : NaN;
88
+ };
89
+ var toArray = (...items) => items.length > 1 ? items : isArray(items[0]) ? items[0] : isDefined(items[0]) ? [items[0]] : [];
90
+
91
+ // src/utils/Types.ts
92
+ var toMessage = (g, ...params) => asString(isFunction(g) ? g(...params) : g);
93
+
94
+ // src/matchers/Match.ts
95
+ var Match = class _Match {
96
+ constructor(subject, failed = false, message = "") {
97
+ this.subject = subject;
98
+ this.failed = failed;
99
+ this.message = message;
100
+ }
101
+ not(p, message) {
102
+ if (this.failed) {
103
+ return this;
104
+ }
105
+ try {
106
+ return new _Match(this.subject, !p(this.subject), toMessage(message, this.subject));
107
+ } catch (e) {
108
+ return new _Match(this.subject, true, e.message);
109
+ }
110
+ }
111
+ undefined(p, message) {
112
+ return this.not(() => isDefined(p(this.subject)), message);
113
+ }
114
+ else(message) {
115
+ return {
116
+ pass: !this.failed,
117
+ message: () => this.failed ? toMessage(this.message) : `${toMessage(message, this.subject)}, which we did not expect.`
118
+ };
119
+ }
120
+ };
121
+ var match = (subject) => new Match(subject);
122
+
123
+ // src/matchers/HttpMatchers.ts
124
+ var toHaveStatus = (res, code) => match(res).undefined((r) => r, "Response is unknown.").undefined(
125
+ (r) => r?.status?.id,
126
+ () => "Response does not have a status code"
127
+ ).not(
128
+ (r) => r.status.id === code,
129
+ (r) => `Response does not have code '${code}', but has code '${r.status.id}' instead.`
130
+ ).else(`Response does have status code '${code}'.`);
131
+ var toBeOk = (res) => toHaveStatus(res, 200);
132
+ var toBeCreated = (res) => toHaveStatus(res, 201);
133
+ var toHaveNoContent = (res) => toHaveStatus(res, 204);
134
+ var toBeBadRequest = (res) => toHaveStatus(res, 400);
135
+ var toBeUnauthorized = (res) => toHaveStatus(res, 401);
136
+ var toBeForbidden = (res) => toHaveStatus(res, 403);
137
+ var toBeNotFound = (res) => toHaveStatus(res, 404);
138
+ var toBeConflict = (res) => toHaveStatus(res, 409);
139
+ var toBeInternalServerError = (res) => toHaveStatus(res, 500);
140
+ var toBeBadGateway = (res) => toHaveStatus(res, 502);
141
+ var toBeOkWithItems = (res, length) => match(res).undefined((r) => r.status?.id, "Response did not have a status").not(
142
+ (r) => r.status.id === 200,
143
+ (r) => `Response did not have status '200'. It had status '${r.status.id}' instead.`
144
+ ).undefined((r) => r?.body?.data?.items, `Response did not have any items.`).not(
145
+ (r) => (r?.body?.data?.itemCount ?? 0) >= length,
146
+ (r) => `Response did not have at least ${length} items. It only had ${r?.body?.data?.itemCount ?? 0} items.`
147
+ ).else(`Response had status 200 and at least ${length} items`);
148
+ expect.extend({
149
+ toBeOk,
150
+ toBeOkWithItems,
151
+ toBeCreated,
152
+ toHaveNoContent,
153
+ toBeNotFound,
154
+ toBeBadRequest,
155
+ toBeUnauthorized,
156
+ toBeForbidden,
157
+ toBeConflict,
158
+ toBeInternalServerError,
159
+ toHaveStatus,
160
+ toBeBadGateway
161
+ });
162
+
163
+ // src/matchers/Check.ts
164
+ var Check = class _Check {
165
+ constructor(ctx, received, expected, failed = false, message = "") {
166
+ this.ctx = ctx;
167
+ this.received = received;
168
+ this.expected = expected;
169
+ this.failed = failed;
170
+ this.message = message;
171
+ }
172
+ print(message) {
173
+ return (typeof message === "function" ? message([this.received, this.expected]) : message).replace("{r}", this.ctx.utils.printReceived(this.received)).replace("{e}", this.ctx.utils.printExpected(this.expected)).replace("{diff}", this.ctx.utils.diff(this.received, this.expected) ?? "");
174
+ }
175
+ not(p, message) {
176
+ if (this.failed) {
177
+ return this;
178
+ }
179
+ try {
180
+ return new _Check(this.ctx, this.received, this.expected, !p([this.received, this.expected]), this.print(message));
181
+ } catch (e) {
182
+ return new _Check(this.ctx, this.received, this.expected, true, e.message);
183
+ }
184
+ }
185
+ undefined(p, message) {
186
+ return this.not(() => isDefined(p([this.received, this.expected])), this.print(message));
187
+ }
188
+ else(message = "Expected {r} not to match with {e}, but it did.") {
189
+ return {
190
+ pass: !this.failed,
191
+ message: () => this.failed ? this.message : this.print(message)
192
+ };
193
+ }
194
+ };
195
+ var check = (ctx, received, expected) => new Check(ctx, received, expected);
196
+ var checkDefined = (ctx, received, expected) => new Check(ctx, received, expected).undefined(([r]) => r, "Received array is undefined.").undefined(([, e]) => e, "Expected array is undefined.");
197
+
198
+ // src/matchers/ResultMatchers.ts
199
+ var notDefined = "Results is not defined.";
200
+ var doesNotFail = "Results does not fail.";
201
+ var hasMessage = (res, message) => res.results.some((r) => r.message === message);
202
+ var messages = (res) => "'" + res?.results.map((r) => r.message).join("', '") + "'";
203
+ var toResultWith = (results, message) => match(results).undefined((r) => r, notDefined).not(
204
+ (r) => hasMessage(r, message),
205
+ (r) => `Results does not have message '${message}', but it has messages ${messages(r)} instead.`
206
+ ).else(`Succeeds with message ${message}`);
207
+ var toFail = (results) => match(results).undefined((r) => r, notDefined).not((r) => !r.isValid, doesNotFail).else("Results does not fail");
208
+ var toFailWith = (results, message) => match(results).undefined((r) => r, notDefined).not((r) => !r.isValid, doesNotFail).not(
209
+ (r) => hasMessage(r, message),
210
+ (r) => `Fails, but results does not have message '${message}', but it has messages ${messages(r)} instead.`
211
+ ).else(`Fails with message '${message}'`);
212
+ expect.extend({
213
+ toResultWith,
214
+ toFail,
215
+ toFailWith
216
+ });
217
+
218
+ // src/matchers/toBeArrayOf.ts
219
+ var toBeArrayOf = (items, ctor) => match(items).undefined((it) => it, "Subject is undefined.").not((it) => it instanceof Array, "Subject is not an array.").not((it) => it.every((i) => i instanceof ctor), `Not all elements are of type '${ctor.name}'.`).else(`All elements in array are of type '${ctor.name}'`);
220
+ expect.extend({
221
+ toBeArrayOf
222
+ });
223
+
224
+ // src/matchers/toBeArrayOfWithLength.ts
225
+ var toBeArrayOfWithLength = (items, ctor, length) => match(items).undefined((it) => it, "Subject is undefined.").not((it) => it instanceof Array, "Subject is not an array.").not(
226
+ (it) => it.length === length,
227
+ (it) => `Subject does not have ${length} elements, but ${it.length}.`
228
+ ).not((it) => it.every((i) => i instanceof ctor), `Not all elements are of type '${ctor.name}'.`).else(`Subject has ${length} elements, which are all of type '${ctor.name}'`);
229
+ expect.extend({
230
+ toBeArrayOfWithLength
231
+ });
232
+
233
+ // src/matchers/toBeAt.ts
234
+ var toBeAt = (tester, uc, id) => {
235
+ return match(tester).undefined((t) => t, "Tester is undefined").undefined((t) => t.url, "Tester does not contain a URL").undefined(() => uc, "Use case is undefined").not(
236
+ (t) => t.url.includes(`/${uc?.app.id}`),
237
+ (t) => `We expected the tester to be at app '${uc?.app.id}', but it is at '${t?.url}' instead.`
238
+ ).not(
239
+ (t) => t.url.includes(`/${uc?.id}`),
240
+ (t) => `We expected the tester to be at use case '${uc?.id}', but it is at '${t?.url}' instead.`
241
+ ).not(
242
+ (t) => t.url.includes(id ? `/${id}` : ""),
243
+ (t) => `We expected the path to contain '/42', but it is '${t?.url}' instead.`
244
+ ).else((t) => `The tester is at '${t?.url}'`);
245
+ };
246
+ expect.extend({
247
+ toBeAt
248
+ });
249
+
250
+ // src/matchers/toBeExactlyAt.ts
251
+ var toUrl = (uc, id) => {
252
+ const i = isDefined(id) ? `/${id}` : "";
253
+ return `/${uc.app.id}/${uc.id}${i}`;
254
+ };
255
+ var toBeExactlyAt = (tester, uc, id) => {
256
+ return match(tester).undefined((t) => t, "Tester is undefined").undefined((t) => t.url, "Tester does not contain a URL").undefined(() => uc, "Use case is undefined").not(
257
+ (t) => t.url.includes(toUrl(uc, id)),
258
+ (t) => `We expected the tester to be at: '${toUrl(uc, id)}', but it is at: '${t?.url}' instead.`
259
+ ).else((t) => `The tester is at '${t?.url}'`);
260
+ };
261
+ expect.extend({
262
+ toBeExactlyAt
263
+ });
264
+
265
+ // src/matchers/toFailMatcher.ts
266
+ var Fails = {
267
+ Yes: "Match fails, instead of passes.",
268
+ No: (reason) => `Match doesn't fail, because '${reason}'`
269
+ };
270
+ var FailsWith = {
271
+ Yes: "Match fails with correct message.",
272
+ No: (message, instead) => `Match does fail, however not with message '${message}', but with message '${instead}' instead.`
273
+ };
274
+ var toFailMatcher = (result) => match(result).not(
275
+ (c) => !c.pass,
276
+ (c) => Fails.No(c.message())
277
+ ).else(Fails.Yes);
278
+ var toFailMatcherWith = (result, message) => match(result).not(
279
+ (c) => !c.pass,
280
+ (c) => Fails.No(c.message())
281
+ ).not(
282
+ (c) => c.message().includes(toMessage(message)),
283
+ (c) => FailsWith.No(toMessage(message), c.message())
284
+ ).else(FailsWith.Yes);
285
+ expect.extend({
286
+ toFailMatcher,
287
+ toFailMatcherWith
288
+ });
289
+
290
+ // src/matchers/toBeValid.ts
291
+ var toBeValid = (v) => match(v).undefined((s) => s, "Subject is undefined.").not((s) => isA(s, "isValid"), "Subject is not validatable.").not((s) => s.isValid, `Subject is not valid.`).else(`Subject is valid`);
292
+ expect.extend({
293
+ toBeValid
294
+ });
295
+
296
+ // src/matchers/toMatchArray.ts
297
+ function toMatchArray(received, expected) {
298
+ return checkDefined(this, received, expected).not(
299
+ ([r, e]) => r.length === e.length,
300
+ ([r, e]) => `Received array has length ${r.length}, while expected array has length ${e.length}.`
301
+ ).not(([r, e]) => r.every((el, i) => this.equals(el, e[i])), "Elements in {r} do not match elements in {e}. \n\n {diff}.").else();
302
+ }
303
+ expect.extend({
304
+ toMatchArray
305
+ });
306
+
307
+ // src/utils/Eq.ts
308
+ var import_expect_utils = require("@jest/expect-utils");
309
+ var eq = {
310
+ exact: (a, b) => (0, import_expect_utils.equals)(a, b, []),
311
+ subset: (a, b) => (0, import_expect_utils.equals)(a, b, [import_expect_utils.iterableEquality, import_expect_utils.subsetEquality]),
312
+ string: (a, b) => asString(a) === asString(b)
313
+ };
314
+
315
+ // src/matchers/toMatchExactJson.ts
316
+ var MatchesExactJson = {
317
+ SubjectUndefined: "Subject is undefined.",
318
+ SubsetUndefined: "Object to match with is undefined.",
319
+ DoesNotMatch: "Object does not exactly match subject.",
320
+ Yes: "Object matches subject exactly"
321
+ };
322
+ var toMatchExactJson = (value, json) => match(value).undefined((v) => v, MatchesExactJson.SubjectUndefined).undefined(() => json, MatchesExactJson.SubsetUndefined).not((v) => eq.exact(v, json), MatchesExactJson.DoesNotMatch).else(() => MatchesExactJson.Yes);
323
+ expect.extend({
324
+ toMatchExactJson
325
+ });
326
+
327
+ // src/matchers/toMatchException.ts
328
+ var toMatchException = (received, expected, reason) => match(expected).undefined((e) => e.id, "Expected value is not an exception.").not(
329
+ (e) => e.id === received.id,
330
+ (e) => `Expected exception has id '${e.id}', while the received exception has id '${received.id}'.`
331
+ ).not(
332
+ () => !isDefined(reason) || isDefined(reason) && isDefined(received.reason),
333
+ () => `We expected to have reason '${reason}', but we received no reason.`
334
+ ).not(
335
+ () => !isDefined(reason) || isDefined(reason) && received.reason === reason,
336
+ () => `We expected to have reason '${reason}', but we received reason '${received.reason}'.`
337
+ ).else(`Expected exception matches received exception`);
338
+ expect.extend({
339
+ toMatchException
340
+ });
341
+
342
+ // src/matchers/toMatchJson.ts
343
+ var MatchesJson = {
344
+ SubjectUndefined: "Subject is undefined.",
345
+ SubsetUndefined: "Subset to match with is undefined.",
346
+ DoesNotMatch: "Subset does not match subject.",
347
+ Yes: "Subset matches subject"
348
+ };
349
+ var toMatchJson = (value, subset) => match(value).undefined((v) => v, MatchesJson.SubjectUndefined).undefined(() => subset, MatchesJson.SubsetUndefined).not((v) => eq.subset(asJson(v), asJson(subset)), MatchesJson.DoesNotMatch).else(() => MatchesJson.Yes);
350
+ expect.extend({
351
+ toMatchJson
352
+ });
353
+
354
+ // src/matchers/toMatchRoute.ts
355
+ var toMatchRoute = (uri, route) => match(uri).undefined((u) => u, "Subject is undefined.").undefined(() => route, "Route to include is undefined.").not(
356
+ (u) => asString(u).includes(asString(route)),
357
+ (u) => `Uri '${u}' does not include '${route}'.`
358
+ ).else((u) => `Uri '${u}' includes '${route}'`);
359
+ expect.extend({
360
+ toMatchRoute
361
+ });
362
+
363
+ // src/matchers/toMatchText.ts
364
+ var toMatchText = (value, text) => match(value).undefined((v) => v, "Subject is undefined.").undefined(() => text, "Text to match with is undefined.").not(
365
+ (v) => asString(v) === asString(text),
366
+ (v) => `Text '${v}' does not match with text '${text}'.`
367
+ ).else((v) => `Text '${v}' matches`);
368
+ expect.extend({
369
+ toMatchText
370
+ });
371
+
372
+ // src/matchers/toPassMatcher.ts
373
+ var Passes = {
374
+ Yes: "Match passes, instead of fails.",
375
+ No: (reason) => `Match doesn't pass, because '${reason}'`
376
+ };
377
+ var PassesWith = {
378
+ Yes: "Match passes with correct message.",
379
+ No: (message, instead) => `Match does pass, however not with message '${message}', but with message '${instead}' instead.`
380
+ };
381
+ var toPassMatcher = (result) => match(result).not(
382
+ (c) => c.pass,
383
+ (c) => Passes.No(c.message())
384
+ ).else(Passes.Yes);
385
+ var toPassMatcherWith = (result, message) => match(result).not(
386
+ (c) => c.pass,
387
+ (c) => Passes.No(c.message())
388
+ ).not(
389
+ (c) => c.message().includes(toMessage(message)),
390
+ (c) => PassesWith.No(toMessage(message), c.message())
391
+ ).else(PassesWith.Yes);
392
+ expect.extend({
393
+ toPassMatcher,
394
+ toPassMatcherWith
395
+ });
396
+
397
+ // src/matchers/toBeQueriedWith.ts
398
+ var toBeQueriedWith = (query, expected) => match(query?.mock?.calls).undefined((c) => c, "Query is unknown.").not((c) => c.length === 1, "Query did not execute.").not(
399
+ (c) => c[0][0].toString() === expected?.toString(),
400
+ (c) => `We expected query '${expected}', but we received query '${c[0][0]}' instead.`
401
+ ).else(`Received query does match '${expected}'`);
402
+ expect.extend({
403
+ toBeQueriedWith
404
+ });
405
+
406
+ // src/matchers/toBeRoutedTo.ts
407
+ var weExpectedButReceivedInstead = ([r, e]) => `We expected ${asString(e)}, but we received '${asString(r)}' instead.`;
408
+ function toMatchAsString(received, expected) {
409
+ return checkDefined(this, received, expected).not(
410
+ ([r, e]) => this.equals(asString(r), asString(e)),
411
+ ([r, e]) => weExpectedButReceivedInstead([r, e])
412
+ ).else();
413
+ }
414
+ var toBeRoutedTo = (query, expected) => match(query?.mock?.calls).undefined((c) => c, "Uri is unknown.").not((c) => c.length === 1, "Method was not called.").not(
415
+ (c) => asString(c[0][0]) === asString(expected),
416
+ (c) => `We expected uri '${asString(expected)}', but we received uri '${asString(c[0][0])}' instead.`
417
+ ).else(`Called uri does match '${asString(expected)}'`);
418
+ expect.extend({
419
+ toBeRoutedTo
420
+ });
421
+
422
+ // src/mock/Fits.ts
423
+ var import_expect = require("expect");
424
+ var ObjectContainingText = class extends import_expect.AsymmetricMatcher {
425
+ asymmetricMatch(other) {
426
+ return asString(other).includes(asString(this.sample));
427
+ }
428
+ toString() {
429
+ return `String${this.inverse ? "Not" : ""}Containing`;
430
+ }
431
+ };
432
+ var ObjectContainingTextExact = class extends import_expect.AsymmetricMatcher {
433
+ asymmetricMatch(other) {
434
+ return asString(other) === asString(this.sample);
435
+ }
436
+ toString() {
437
+ return `String${this.inverse ? "Not" : ""}Containing`;
438
+ }
439
+ };
440
+ var ObjectContainingJson = class extends import_expect.AsymmetricMatcher {
441
+ asymmetricMatch(other) {
442
+ return eq.subset(asJson(other), asJson(this.sample));
443
+ }
444
+ toString() {
445
+ return `Object${this.inverse ? "Not" : ""}Containing`;
446
+ }
447
+ };
448
+ var fits = {
449
+ any: () => expect.anything(),
450
+ type: (type) => expect.any(type),
451
+ with: (o) => expect.objectContaining(o),
452
+ text: (s) => new ObjectContainingText(s),
453
+ textExact: (s) => new ObjectContainingTextExact(s),
454
+ uri: (u) => fits.textExact(u),
455
+ json: (s) => new ObjectContainingJson(s),
456
+ items: (...items) => expect.arrayContaining(toArray(...items))
457
+ };
458
+
459
+ // src/utils/Req.ts
460
+ var Req = class {
461
+ constructor(state = {}) {
462
+ this.state = state;
463
+ this.skip = isDefined(this.query?.skip) ? asNumber(this.query?.skip) : void 0;
464
+ this.take = isDefined(this.query?.take) ? asNumber(this.query?.take) : void 0;
465
+ }
466
+ skip;
467
+ take;
468
+ get id() {
469
+ return this.state.id ?? this.path.id;
470
+ }
471
+ get q() {
472
+ return this.state.q ?? this.query.q;
473
+ }
474
+ get path() {
475
+ return this.state?.path ?? {};
476
+ }
477
+ get query() {
478
+ return this.state?.query ?? {};
479
+ }
480
+ get body() {
481
+ return this.state.body;
482
+ }
483
+ get headers() {
484
+ return this.state.headers;
485
+ }
486
+ get = (key) => this?.state[key.toString()] ?? this.path[key.toString()] ?? this.query[key.toString()];
487
+ };
488
+
489
+ // src/mock/Mocks.ts
490
+ var Mocks = class {
491
+ clear = () => jest.clearAllMocks();
492
+ impl = (f) => jest.fn().mockImplementation(f);
493
+ property = (object, getter, value) => jest.spyOn(object, getter, "get").mockReturnValue(value);
494
+ reject = (value) => jest.fn().mockRejectedValue(value);
495
+ rejectWith = (props = {}) => jest.fn().mockRejectedValue(mock.a(props));
496
+ req = {
497
+ id: (id) => new Req({ id }),
498
+ q: (q) => new Req({ q }),
499
+ with: (a) => new Req(a),
500
+ body: (body) => new Req({ body }),
501
+ path: (path) => new Req({ path }),
502
+ query: (query) => new Req({ query })
503
+ };
504
+ resp = {
505
+ items: (status, items = []) => ({
506
+ status,
507
+ body: {
508
+ data: {
509
+ code: status.id,
510
+ itemCount: items.length,
511
+ items
512
+ }
513
+ }
514
+ }),
515
+ errors: (status, message, errors = []) => ({
516
+ status,
517
+ body: {
518
+ error: {
519
+ code: status.id,
520
+ message,
521
+ errorCount: errors.length,
522
+ errors
523
+ }
524
+ }
525
+ })
526
+ };
527
+ resolve = (value) => jest.fn().mockResolvedValue(value);
528
+ resolveWith = (props = {}) => jest.fn().mockResolvedValue(mock.a(props));
529
+ return = (value) => jest.fn().mockReturnValue(value);
530
+ returnWith = (props = {}) => jest.fn().mockReturnValue(mock.a(props));
531
+ this = () => jest.fn().mockReturnThis();
532
+ provider = {
533
+ data: (...items) => ({
534
+ execute: jest.fn().mockResolvedValue({
535
+ body: {
536
+ data: {
537
+ itemCount: items.length,
538
+ items
539
+ }
540
+ }
541
+ })
542
+ })
543
+ };
544
+ empty = (props = {}) => props;
545
+ a = this.empty;
546
+ an = this.empty;
547
+ date = (epoch = 1621347575) => {
548
+ const date = new Date(epoch);
549
+ date.toString = mock.return("Mon Jan 19 1970 19:22:27 GMT+0100 (Central European Standard Time)");
550
+ date.toLocaleDateString = mock.return("19/01/1970");
551
+ date.toDateString = mock.return("19/01/1970");
552
+ return date;
553
+ };
554
+ once = (...values) => values.reduce((m, v) => m.mockImplementationOnce(() => v), jest.fn());
555
+ };
556
+ var mock = new Mocks();
20
557
  // Annotate the CommonJS export names for ESM import in node:
21
558
  0 && (module.exports = {
22
- ...require("./matchers"),
23
- ...require("./mock")
559
+ Fails,
560
+ FailsWith,
561
+ Match,
562
+ MatchesExactJson,
563
+ MatchesJson,
564
+ Mocks,
565
+ ObjectContainingJson,
566
+ ObjectContainingText,
567
+ ObjectContainingTextExact,
568
+ Passes,
569
+ PassesWith,
570
+ check,
571
+ checkDefined,
572
+ fits,
573
+ match,
574
+ mock,
575
+ toBeArrayOf,
576
+ toBeArrayOfWithLength,
577
+ toBeAt,
578
+ toBeBadGateway,
579
+ toBeBadRequest,
580
+ toBeConflict,
581
+ toBeCreated,
582
+ toBeExactlyAt,
583
+ toBeForbidden,
584
+ toBeInternalServerError,
585
+ toBeNotFound,
586
+ toBeOk,
587
+ toBeOkWithItems,
588
+ toBeQueriedWith,
589
+ toBeRoutedTo,
590
+ toBeUnauthorized,
591
+ toBeValid,
592
+ toFail,
593
+ toFailMatcher,
594
+ toFailMatcherWith,
595
+ toFailWith,
596
+ toHaveNoContent,
597
+ toHaveStatus,
598
+ toMatchArray,
599
+ toMatchAsString,
600
+ toMatchExactJson,
601
+ toMatchException,
602
+ toMatchJson,
603
+ toMatchRoute,
604
+ toMatchText,
605
+ toPassMatcher,
606
+ toPassMatcherWith,
607
+ toResultWith,
608
+ weExpectedButReceivedInstead
24
609
  });
25
610
  //# sourceMappingURL=index.js.map