@pact-foundation/pact 16.3.1 → 16.5.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.
- package/CHANGELOG.md +23 -0
- package/CONTRIBUTING.md +2 -2
- package/README.md +22 -12
- package/package.json +26 -47
- package/scripts/ci/build-and-test.sh +0 -3
- package/scripts/install-plugins.js +104 -0
- package/src/common/graphQL/configurationError.js +2 -22
- package/src/common/graphQL/configurationError.js.map +1 -1
- package/src/common/graphQL/graphQL.d.ts +2 -2
- package/src/common/graphQL/graphQL.js +11 -14
- package/src/common/graphQL/graphQL.js.map +1 -1
- package/src/common/graphQL/graphQLQueryError.js +2 -22
- package/src/common/graphQL/graphQLQueryError.js.map +1 -1
- package/src/common/logger.js +9 -9
- package/src/common/logger.js.map +1 -1
- package/src/common/matchingRules.d.ts +7 -1
- package/src/common/matchingRules.js +42 -22
- package/src/common/matchingRules.js.map +1 -1
- package/src/common/net.js +36 -42
- package/src/common/net.js.map +1 -1
- package/src/common/net.spec.js +39 -87
- package/src/common/net.spec.js.map +1 -1
- package/src/common/request.js +33 -82
- package/src/common/request.js.map +1 -1
- package/src/common/request.spec.js +29 -73
- package/src/common/request.spec.js.map +1 -1
- package/src/common/spec.js +3 -4
- package/src/common/spec.js.map +1 -1
- package/src/dsl/apolloGraphql.js +7 -25
- package/src/dsl/apolloGraphql.js.map +1 -1
- package/src/dsl/apolloGraphql.spec.js +21 -58
- package/src/dsl/apolloGraphql.spec.js.map +1 -1
- package/src/dsl/graphql.d.ts +2 -2
- package/src/dsl/graphql.js +29 -48
- package/src/dsl/graphql.js.map +1 -1
- package/src/dsl/graphql.spec.js +92 -117
- package/src/dsl/graphql.spec.js.map +1 -1
- package/src/dsl/interaction.d.ts +2 -2
- package/src/dsl/interaction.js +41 -48
- package/src/dsl/interaction.js.map +1 -1
- package/src/dsl/interaction.spec.js +109 -132
- package/src/dsl/interaction.spec.js.map +1 -1
- package/src/dsl/matchers.d.ts +2 -3
- package/src/dsl/matchers.js +19 -31
- package/src/dsl/matchers.js.map +1 -1
- package/src/dsl/matchers.spec.js +279 -289
- package/src/dsl/matchers.spec.js.map +1 -1
- package/src/dsl/message.d.ts +3 -3
- package/src/dsl/options.d.ts +3 -3
- package/src/dsl/verifier/proxy/hooks.d.ts +2 -2
- package/src/dsl/verifier/proxy/hooks.js +42 -112
- package/src/dsl/verifier/proxy/hooks.js.map +1 -1
- package/src/dsl/verifier/proxy/hooks.spec.js +86 -199
- package/src/dsl/verifier/proxy/hooks.spec.js.map +1 -1
- package/src/dsl/verifier/proxy/messages.d.ts +2 -2
- package/src/dsl/verifier/proxy/messages.js +88 -106
- package/src/dsl/verifier/proxy/messages.js.map +1 -1
- package/src/dsl/verifier/proxy/parseBody.d.ts +1 -1
- package/src/dsl/verifier/proxy/parseBody.js +3 -3
- package/src/dsl/verifier/proxy/parseBody.js.map +1 -1
- package/src/dsl/verifier/proxy/parseBody.spec.js +35 -113
- package/src/dsl/verifier/proxy/parseBody.spec.js.map +1 -1
- package/src/dsl/verifier/proxy/proxy.d.ts +2 -2
- package/src/dsl/verifier/proxy/proxy.js +22 -26
- package/src/dsl/verifier/proxy/proxy.js.map +1 -1
- package/src/dsl/verifier/proxy/proxy.spec.js +11 -53
- package/src/dsl/verifier/proxy/proxy.spec.js.map +1 -1
- package/src/dsl/verifier/proxy/proxyRequest.d.ts +3 -3
- package/src/dsl/verifier/proxy/proxyRequest.js +7 -7
- package/src/dsl/verifier/proxy/proxyRequest.js.map +1 -1
- package/src/dsl/verifier/proxy/proxyRequest.spec.js +54 -104
- package/src/dsl/verifier/proxy/proxyRequest.spec.js.map +1 -1
- package/src/dsl/verifier/proxy/stateHandler/setupStates.d.ts +3 -3
- package/src/dsl/verifier/proxy/stateHandler/setupStates.js +14 -18
- package/src/dsl/verifier/proxy/stateHandler/setupStates.js.map +1 -1
- package/src/dsl/verifier/proxy/stateHandler/setupStates.spec.js +76 -193
- package/src/dsl/verifier/proxy/stateHandler/setupStates.spec.js.map +1 -1
- package/src/dsl/verifier/proxy/stateHandler/stateHandler.d.ts +2 -2
- package/src/dsl/verifier/proxy/stateHandler/stateHandler.js +23 -72
- package/src/dsl/verifier/proxy/stateHandler/stateHandler.js.map +1 -1
- package/src/dsl/verifier/proxy/stateHandler/stateHandler.spec.js +37 -122
- package/src/dsl/verifier/proxy/stateHandler/stateHandler.spec.js.map +1 -1
- package/src/dsl/verifier/proxy/tracer.d.ts +1 -1
- package/src/dsl/verifier/proxy/tracer.js +42 -35
- package/src/dsl/verifier/proxy/tracer.js.map +1 -1
- package/src/dsl/verifier/proxy/types.d.ts +5 -5
- package/src/dsl/verifier/types.d.ts +3 -3
- package/src/dsl/verifier/verifier.d.ts +5 -1
- package/src/dsl/verifier/verifier.js +53 -60
- package/src/dsl/verifier/verifier.js.map +1 -1
- package/src/dsl/verifier/verifier.spec.js +84 -151
- package/src/dsl/verifier/verifier.spec.js.map +1 -1
- package/src/errors/configurationError.js +2 -22
- package/src/errors/configurationError.js.map +1 -1
- package/src/errors/graphQLQueryError.js +2 -22
- package/src/errors/graphQLQueryError.js.map +1 -1
- package/src/errors/matcherError.js +2 -22
- package/src/errors/matcherError.js.map +1 -1
- package/src/errors/verificationError.js +2 -22
- package/src/errors/verificationError.js.map +1 -1
- package/src/httpPact/ffi.d.ts +2 -2
- package/src/httpPact/ffi.js +28 -29
- package/src/httpPact/ffi.js.map +1 -1
- package/src/httpPact/ffi.spec.js +40 -83
- package/src/httpPact/ffi.spec.js.map +1 -1
- package/src/httpPact/index.d.ts +3 -3
- package/src/httpPact/index.js +92 -149
- package/src/httpPact/index.js.map +1 -1
- package/src/httpPact/index.spec.js +102 -195
- package/src/httpPact/index.spec.js.map +1 -1
- package/src/httpPact/tracing.js +20 -28
- package/src/httpPact/tracing.js.map +1 -1
- package/src/index.d.ts +25 -25
- package/src/index.js +29 -29
- package/src/index.js.map +1 -1
- package/src/messageConsumerPact.d.ts +5 -5
- package/src/messageConsumerPact.js +59 -53
- package/src/messageConsumerPact.js.map +1 -1
- package/src/messageConsumerPact.spec.js +55 -97
- package/src/messageConsumerPact.spec.js.map +1 -1
- package/src/messageProviderPact.d.ts +3 -3
- package/src/messageProviderPact.js +68 -85
- package/src/messageProviderPact.js.map +1 -1
- package/src/messageProviderPact.spec.js +96 -123
- package/src/messageProviderPact.spec.js.map +1 -1
- package/src/pact.integration.spec.js +242 -351
- package/src/pact.integration.spec.js.map +1 -1
- package/src/v3/display.d.ts +1 -1
- package/src/v3/display.js +44 -58
- package/src/v3/display.js.map +1 -1
- package/src/v3/ffi.js +20 -16
- package/src/v3/ffi.js.map +1 -1
- package/src/v3/ffi.spec.js +7 -42
- package/src/v3/ffi.spec.js.map +1 -1
- package/src/v3/graphql/graphQL.d.ts +4 -4
- package/src/v3/graphql/graphQL.js +50 -75
- package/src/v3/graphql/graphQL.js.map +1 -1
- package/src/v3/graphql/index.d.ts +1 -1
- package/src/v3/graphql/index.js +1 -1
- package/src/v3/graphql/index.js.map +1 -1
- package/src/v3/index.d.ts +4 -12
- package/src/v3/index.js +4 -12
- package/src/v3/index.js.map +1 -1
- package/src/v3/matchers.d.ts +15 -3
- package/src/v3/matchers.js +131 -148
- package/src/v3/matchers.js.map +1 -1
- package/src/v3/matchers.spec.js +281 -232
- package/src/v3/matchers.spec.js.map +1 -1
- package/src/v3/pact.d.ts +2 -2
- package/src/v3/pact.js +108 -151
- package/src/v3/pact.js.map +1 -1
- package/src/v3/pact.spec.js +94 -0
- package/src/v3/pact.spec.js.map +1 -0
- package/src/v3/types.d.ts +19 -3
- package/src/v3/types.js +22 -1
- package/src/v3/types.js.map +1 -1
- package/src/v4/graphql/graphQLInteractionWithRequest.d.ts +4 -4
- package/src/v4/graphql/graphQLInteractionWithRequest.js +21 -17
- package/src/v4/graphql/graphQLInteractionWithRequest.js.map +1 -1
- package/src/v4/graphql/graphQLRequestBuilder.d.ts +3 -3
- package/src/v4/graphql/graphQLRequestBuilder.js +18 -20
- package/src/v4/graphql/graphQLRequestBuilder.js.map +1 -1
- package/src/v4/graphql/index.d.ts +6 -6
- package/src/v4/graphql/index.js +21 -17
- package/src/v4/graphql/index.js.map +1 -1
- package/src/v4/graphql/types.d.ts +5 -5
- package/src/v4/http/index.d.ts +2 -2
- package/src/v4/http/index.js +53 -93
- package/src/v4/http/index.js.map +1 -1
- package/src/v4/http/index.spec.d.ts +1 -0
- package/src/v4/http/index.spec.js +73 -0
- package/src/v4/http/index.spec.js.map +1 -0
- package/src/v4/http/interactionWithCompleteRequest.d.ts +4 -7
- package/src/v4/http/interactionWithCompleteRequest.js +6 -10
- package/src/v4/http/interactionWithCompleteRequest.js.map +1 -1
- package/src/v4/http/interactionWithPlugin.d.ts +3 -3
- package/src/v4/http/interactionWithPlugin.js +14 -11
- package/src/v4/http/interactionWithPlugin.js.map +1 -1
- package/src/v4/http/interactionWithPluginRequest.d.ts +4 -3
- package/src/v4/http/interactionWithPluginRequest.js +17 -9
- package/src/v4/http/interactionWithPluginRequest.js.map +1 -1
- package/src/v4/http/interactionWithPluginResponse.d.ts +2 -2
- package/src/v4/http/interactionWithPluginResponse.js +10 -48
- package/src/v4/http/interactionWithPluginResponse.js.map +1 -1
- package/src/v4/http/interactionWithRequest.d.ts +4 -3
- package/src/v4/http/interactionWithRequest.js +17 -9
- package/src/v4/http/interactionWithRequest.js.map +1 -1
- package/src/v4/http/interactionWithRequest.spec.d.ts +1 -0
- package/src/v4/http/interactionWithRequest.spec.js +82 -0
- package/src/v4/http/interactionWithRequest.spec.js.map +1 -0
- package/src/v4/http/interactionWithResponse.d.ts +2 -2
- package/src/v4/http/interactionWithResponse.js +10 -48
- package/src/v4/http/interactionWithResponse.js.map +1 -1
- package/src/v4/http/requestBuilder.d.ts +4 -3
- package/src/v4/http/requestBuilder.js +36 -34
- package/src/v4/http/requestBuilder.js.map +1 -1
- package/src/v4/http/requestBuilder.spec.d.ts +1 -0
- package/src/v4/http/requestBuilder.spec.js +42 -0
- package/src/v4/http/requestBuilder.spec.js.map +1 -0
- package/src/v4/http/requestWithPluginBuilder.d.ts +3 -2
- package/src/v4/http/requestWithPluginBuilder.js +30 -46
- package/src/v4/http/requestWithPluginBuilder.js.map +1 -1
- package/src/v4/http/requestWithPluginBuilder.spec.d.ts +1 -0
- package/src/v4/http/requestWithPluginBuilder.spec.js +34 -0
- package/src/v4/http/requestWithPluginBuilder.spec.js.map +1 -0
- package/src/v4/http/responseBuilder.d.ts +4 -3
- package/src/v4/http/responseBuilder.js +28 -25
- package/src/v4/http/responseBuilder.js.map +1 -1
- package/src/v4/http/responseBuilder.spec.d.ts +1 -0
- package/src/v4/http/responseBuilder.spec.js +42 -0
- package/src/v4/http/responseBuilder.spec.js.map +1 -0
- package/src/v4/http/responseWithPluginBuilder.d.ts +1 -1
- package/src/v4/http/responseWithPluginBuilder.js +5 -25
- package/src/v4/http/responseWithPluginBuilder.js.map +1 -1
- package/src/v4/http/responseWithPluginBuilder.spec.d.ts +1 -0
- package/src/v4/http/responseWithPluginBuilder.spec.js +34 -0
- package/src/v4/http/responseWithPluginBuilder.spec.js.map +1 -0
- package/src/v4/http/types.d.ts +13 -4
- package/src/v4/http/unconfiguredInteraction.d.ts +6 -5
- package/src/v4/http/unconfiguredInteraction.js +31 -26
- package/src/v4/http/unconfiguredInteraction.js.map +1 -1
- package/src/v4/index.d.ts +6 -5
- package/src/v4/index.js +32 -35
- package/src/v4/index.js.map +1 -1
- package/src/v4/message/asynchronousMessage.d.ts +7 -6
- package/src/v4/message/asynchronousMessage.js +157 -190
- package/src/v4/message/asynchronousMessage.js.map +1 -1
- package/src/v4/message/index.d.ts +7 -6
- package/src/v4/message/index.js +188 -217
- package/src/v4/message/index.js.map +1 -1
- package/src/v4/message/types.d.ts +5 -3
- package/src/v4/types.d.ts +3 -3
- package/src/xml/index.d.ts +4 -0
- package/src/xml/index.js +21 -0
- package/src/xml/index.js.map +1 -0
- package/src/{v3/xml → xml}/xmlBuilder.d.ts +1 -3
- package/src/{v3/xml → xml}/xmlBuilder.js +7 -9
- package/src/xml/xmlBuilder.js.map +1 -0
- package/src/{v3/xml → xml}/xmlElement.d.ts +2 -2
- package/src/xml/xmlElement.js +73 -0
- package/src/xml/xmlElement.js.map +1 -0
- package/src/xml/xmlElement.spec.d.ts +1 -0
- package/src/xml/xmlElement.spec.js +107 -0
- package/src/xml/xmlElement.spec.js.map +1 -0
- package/src/xml/xmlNode.js +7 -0
- package/src/xml/xmlNode.js.map +1 -0
- package/src/{v3/xml → xml}/xmlText.d.ts +1 -1
- package/src/xml/xmlText.js +15 -0
- package/src/xml/xmlText.js.map +1 -0
- package/scripts/install-plugins +0 -106
- package/src/v3/xml/xmlBuilder.js.map +0 -1
- package/src/v3/xml/xmlElement.js +0 -90
- package/src/v3/xml/xmlElement.js.map +0 -1
- package/src/v3/xml/xmlElement.spec.js +0 -113
- package/src/v3/xml/xmlElement.spec.js.map +0 -1
- package/src/v3/xml/xmlNode.js +0 -10
- package/src/v3/xml/xmlNode.js.map +0 -1
- package/src/v3/xml/xmlText.js +0 -31
- package/src/v3/xml/xmlText.js.map +0 -1
- /package/src/v3/{xml/xmlElement.spec.d.ts → pact.spec.d.ts} +0 -0
- /package/src/{v3/xml → xml}/xmlNode.d.ts +0 -0
package/src/dsl/matchers.spec.js
CHANGED
|
@@ -1,33 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
describe('
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
var f = { a: 'working example' };
|
|
3
|
+
const matchers_1 = require("./matchers");
|
|
4
|
+
describe('Matcher', () => {
|
|
5
|
+
describe('can compile the types', () => {
|
|
6
|
+
describe('with interfaces', () => {
|
|
7
|
+
it('compiles with nested examples from issue 1054', () => {
|
|
8
|
+
const f = { a: 'working example' };
|
|
21
9
|
(0, matchers_1.like)(f);
|
|
22
|
-
(0, matchers_1.like)(
|
|
10
|
+
(0, matchers_1.like)({ ...f });
|
|
23
11
|
(0, matchers_1.like)(Object.freeze(f));
|
|
24
|
-
|
|
12
|
+
const r = { id: 'some guid', foo: { a: 'example' } };
|
|
25
13
|
(0, matchers_1.like)(r);
|
|
26
|
-
(0, matchers_1.like)(
|
|
14
|
+
(0, matchers_1.like)({ ...r });
|
|
27
15
|
(0, matchers_1.like)(Object.freeze(f));
|
|
28
16
|
});
|
|
29
|
-
it('compiles when InterfaceToTemplate is used',
|
|
30
|
-
|
|
17
|
+
it('compiles when InterfaceToTemplate is used', () => {
|
|
18
|
+
const template = {
|
|
31
19
|
someArray: ['one', 'two'],
|
|
32
20
|
someNumber: 1,
|
|
33
21
|
someString: "it's a string",
|
|
@@ -36,12 +24,12 @@ describe('Matcher', function () {
|
|
|
36
24
|
bar: 'some other string',
|
|
37
25
|
},
|
|
38
26
|
};
|
|
39
|
-
|
|
27
|
+
const _unused = (0, matchers_1.like)(template);
|
|
40
28
|
});
|
|
41
29
|
});
|
|
42
|
-
describe('with types',
|
|
43
|
-
it('compiles',
|
|
44
|
-
|
|
30
|
+
describe('with types', () => {
|
|
31
|
+
it('compiles', () => {
|
|
32
|
+
const template = {
|
|
45
33
|
someArray: ['one', 'two'],
|
|
46
34
|
someNumber: 1,
|
|
47
35
|
someString: "it's a string",
|
|
@@ -50,11 +38,11 @@ describe('Matcher', function () {
|
|
|
50
38
|
bar: 'some other string',
|
|
51
39
|
},
|
|
52
40
|
};
|
|
53
|
-
|
|
41
|
+
const _unused = (0, matchers_1.like)(template);
|
|
54
42
|
});
|
|
55
43
|
});
|
|
56
|
-
it('compiles nested likes',
|
|
57
|
-
|
|
44
|
+
it('compiles nested likes', () => {
|
|
45
|
+
const _unused = (0, matchers_1.like)({
|
|
58
46
|
someArray: ['one', 'two'],
|
|
59
47
|
someNumber: (0, matchers_1.like)(1),
|
|
60
48
|
someString: "it's a string",
|
|
@@ -65,155 +53,157 @@ describe('Matcher', function () {
|
|
|
65
53
|
});
|
|
66
54
|
});
|
|
67
55
|
});
|
|
68
|
-
describe('#validateExample',
|
|
69
|
-
describe('when given a valid regex',
|
|
70
|
-
describe('and a matching example',
|
|
71
|
-
it('returns true',
|
|
72
|
-
|
|
56
|
+
describe('#validateExample', () => {
|
|
57
|
+
describe('when given a valid regex', () => {
|
|
58
|
+
describe('and a matching example', () => {
|
|
59
|
+
it('returns true', () => {
|
|
60
|
+
expect((0, matchers_1.validateExample)('2010-01-01', matchers_1.ISO8601_DATE_FORMAT)).toBe(true);
|
|
73
61
|
});
|
|
74
62
|
});
|
|
75
|
-
describe('and a failing example',
|
|
76
|
-
it('returns false',
|
|
77
|
-
|
|
63
|
+
describe('and a failing example', () => {
|
|
64
|
+
it('returns false', () => {
|
|
65
|
+
expect((0, matchers_1.validateExample)('not a date', matchers_1.ISO8601_DATE_FORMAT)).toBe(false);
|
|
78
66
|
});
|
|
79
67
|
});
|
|
80
68
|
});
|
|
81
|
-
describe('when given an invalid regex',
|
|
82
|
-
it('returns an error',
|
|
83
|
-
|
|
69
|
+
describe('when given an invalid regex', () => {
|
|
70
|
+
it('returns an error', () => {
|
|
71
|
+
expect(() => {
|
|
84
72
|
(0, matchers_1.validateExample)('', 'abc(');
|
|
85
|
-
}).
|
|
73
|
+
}).toThrow(Error);
|
|
86
74
|
});
|
|
87
75
|
});
|
|
88
76
|
});
|
|
89
|
-
describe('#term',
|
|
90
|
-
describe('when given a valid regular expression and example',
|
|
91
|
-
it('returns a serialized Ruby object',
|
|
92
|
-
|
|
77
|
+
describe('#term', () => {
|
|
78
|
+
describe('when given a valid regular expression and example', () => {
|
|
79
|
+
it('returns a serialized Ruby object', () => {
|
|
80
|
+
const expected = {
|
|
93
81
|
value: 'myawesomeword',
|
|
94
82
|
regex: '\\w+',
|
|
95
83
|
'pact:matcher:type': 'regex',
|
|
96
84
|
};
|
|
97
|
-
|
|
85
|
+
const match = (0, matchers_1.term)({
|
|
98
86
|
generate: 'myawesomeword',
|
|
99
87
|
matcher: '\\w+',
|
|
100
88
|
});
|
|
101
|
-
|
|
89
|
+
expect(JSON.stringify(match)).toContain(JSON.stringify(expected));
|
|
102
90
|
});
|
|
103
91
|
});
|
|
104
|
-
describe('when not provided with a valid expression',
|
|
105
|
-
|
|
92
|
+
describe('when not provided with a valid expression', () => {
|
|
93
|
+
// biome-ignore lint/suspicious/noExplicitAny: intentionally passing invalid argument types to test error handling
|
|
94
|
+
const createTheTerm = (badArg) => () => {
|
|
106
95
|
(0, matchers_1.term)(badArg);
|
|
107
|
-
};
|
|
108
|
-
describe('when no term is provided',
|
|
109
|
-
it('throws an Error',
|
|
110
|
-
|
|
96
|
+
};
|
|
97
|
+
describe('when no term is provided', () => {
|
|
98
|
+
it('throws an Error', () => {
|
|
99
|
+
expect(createTheTerm.call({}, undefined)).toThrow(Error);
|
|
111
100
|
});
|
|
112
101
|
});
|
|
113
|
-
describe('when an invalid term is provided',
|
|
114
|
-
it('throws an Error',
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
102
|
+
describe('when an invalid term is provided', () => {
|
|
103
|
+
it('throws an Error', () => {
|
|
104
|
+
expect(createTheTerm({})).toThrow(Error);
|
|
105
|
+
expect(createTheTerm('')).toThrow(Error);
|
|
106
|
+
expect(createTheTerm({ value: 'foo' })).toThrow(Error);
|
|
107
|
+
expect(createTheTerm({ matcher: '\\w+' })).toThrow(Error);
|
|
119
108
|
});
|
|
120
109
|
});
|
|
121
110
|
});
|
|
122
|
-
describe("when given an example that doesn't match the regular expression",
|
|
123
|
-
it('fails with an error',
|
|
124
|
-
|
|
111
|
+
describe("when given an example that doesn't match the regular expression", () => {
|
|
112
|
+
it('fails with an error', () => {
|
|
113
|
+
expect(() => {
|
|
125
114
|
(0, matchers_1.term)({
|
|
126
115
|
generate: 'abc',
|
|
127
116
|
matcher: matchers_1.ISO8601_DATE_FORMAT,
|
|
128
117
|
});
|
|
129
|
-
}).
|
|
118
|
+
}).toThrow(Error);
|
|
130
119
|
});
|
|
131
120
|
});
|
|
132
121
|
});
|
|
133
|
-
describe('#somethingLike',
|
|
134
|
-
describe('when provided a value',
|
|
135
|
-
it('returns a serialized Ruby object',
|
|
136
|
-
|
|
122
|
+
describe('#somethingLike', () => {
|
|
123
|
+
describe('when provided a value', () => {
|
|
124
|
+
it('returns a serialized Ruby object', () => {
|
|
125
|
+
const expected = {
|
|
137
126
|
value: 'myspecialvalue',
|
|
138
127
|
'pact:matcher:type': 'type',
|
|
139
128
|
};
|
|
140
|
-
|
|
141
|
-
|
|
129
|
+
const match = (0, matchers_1.somethingLike)('myspecialvalue');
|
|
130
|
+
expect(JSON.stringify(match)).toContain(JSON.stringify(expected));
|
|
142
131
|
});
|
|
143
132
|
});
|
|
144
|
-
describe('when not provided with a valid value',
|
|
145
|
-
|
|
133
|
+
describe('when not provided with a valid value', () => {
|
|
134
|
+
// biome-ignore lint/suspicious/noExplicitAny: intentionally passing invalid argument types to test error handling
|
|
135
|
+
const createTheValue = (badArg) => () => {
|
|
146
136
|
(0, matchers_1.somethingLike)(badArg);
|
|
147
|
-
};
|
|
148
|
-
describe('when no value is provided',
|
|
149
|
-
it('`throws an Error',
|
|
150
|
-
|
|
137
|
+
};
|
|
138
|
+
describe('when no value is provided', () => {
|
|
139
|
+
it('`throws an Error', () => {
|
|
140
|
+
expect(createTheValue.call({}, undefined)).toThrow(Error);
|
|
151
141
|
});
|
|
152
142
|
});
|
|
153
|
-
describe('when an invalid value is provided',
|
|
154
|
-
it('throws an Error',
|
|
155
|
-
|
|
156
|
-
|
|
143
|
+
describe('when an invalid value is provided', () => {
|
|
144
|
+
it('throws an Error', () => {
|
|
145
|
+
expect(createTheValue(undefined)).toThrow(Error);
|
|
146
|
+
expect(createTheValue(() => { })).toThrow(Error);
|
|
157
147
|
});
|
|
158
148
|
});
|
|
159
149
|
});
|
|
160
150
|
});
|
|
161
|
-
describe('#eachLike',
|
|
162
|
-
describe('when content is null',
|
|
163
|
-
it('provides null as contents',
|
|
164
|
-
|
|
151
|
+
describe('#eachLike', () => {
|
|
152
|
+
describe('when content is null', () => {
|
|
153
|
+
it('provides null as contents', () => {
|
|
154
|
+
const expected = {
|
|
165
155
|
value: [null],
|
|
166
156
|
'pact:matcher:type': 'type',
|
|
167
157
|
min: 1,
|
|
168
158
|
};
|
|
169
|
-
|
|
170
|
-
|
|
159
|
+
const match = (0, matchers_1.eachLike)(null, { min: 1 });
|
|
160
|
+
expect(JSON.stringify(match)).toContain(JSON.stringify(expected));
|
|
171
161
|
});
|
|
172
162
|
});
|
|
173
|
-
describe('when an object is provided',
|
|
174
|
-
it('provides the object as contents',
|
|
175
|
-
|
|
163
|
+
describe('when an object is provided', () => {
|
|
164
|
+
it('provides the object as contents', () => {
|
|
165
|
+
const expected = {
|
|
176
166
|
value: [{ a: 1 }],
|
|
177
167
|
'pact:matcher:type': 'type',
|
|
178
168
|
min: 1,
|
|
179
169
|
};
|
|
180
|
-
|
|
181
|
-
|
|
170
|
+
const match = (0, matchers_1.eachLike)({ a: 1 }, { min: 1 });
|
|
171
|
+
expect(JSON.stringify(match)).toContain(JSON.stringify(expected));
|
|
182
172
|
});
|
|
183
173
|
});
|
|
184
|
-
describe('when object.min is invalid',
|
|
185
|
-
it('throws an Error message',
|
|
186
|
-
|
|
174
|
+
describe('when object.min is invalid', () => {
|
|
175
|
+
it('throws an Error message', () => {
|
|
176
|
+
expect(() => {
|
|
187
177
|
(0, matchers_1.eachLike)({ a: 1 }, { min: 0 });
|
|
188
|
-
}).
|
|
178
|
+
}).toThrow(Error);
|
|
189
179
|
});
|
|
190
180
|
});
|
|
191
|
-
describe('when an array is provided',
|
|
192
|
-
it('provides the array as contents',
|
|
193
|
-
|
|
181
|
+
describe('when an array is provided', () => {
|
|
182
|
+
it('provides the array as contents', () => {
|
|
183
|
+
const expected = {
|
|
194
184
|
value: [[1, 2, 3]],
|
|
195
185
|
'pact:matcher:type': 'type',
|
|
196
186
|
min: 1,
|
|
197
187
|
};
|
|
198
|
-
|
|
199
|
-
|
|
188
|
+
const match = (0, matchers_1.eachLike)([1, 2, 3], { min: 1 });
|
|
189
|
+
expect(JSON.stringify(match)).toContain(JSON.stringify(expected));
|
|
200
190
|
});
|
|
201
191
|
});
|
|
202
|
-
describe('when a value is provided',
|
|
203
|
-
it('adds the value in contents',
|
|
204
|
-
|
|
192
|
+
describe('when a value is provided', () => {
|
|
193
|
+
it('adds the value in contents', () => {
|
|
194
|
+
const expected = {
|
|
205
195
|
value: ['test'],
|
|
206
196
|
'pact:matcher:type': 'type',
|
|
207
197
|
min: 1,
|
|
208
198
|
};
|
|
209
|
-
|
|
210
|
-
|
|
199
|
+
const match = (0, matchers_1.eachLike)('test', { min: 1 });
|
|
200
|
+
expect(JSON.stringify(match)).toContain(JSON.stringify(expected));
|
|
211
201
|
});
|
|
212
202
|
});
|
|
213
|
-
describe('when the content has Pact.Macters',
|
|
214
|
-
describe('of type somethingLike',
|
|
215
|
-
it('nests somethingLike correctly',
|
|
216
|
-
|
|
203
|
+
describe('when the content has Pact.Macters', () => {
|
|
204
|
+
describe('of type somethingLike', () => {
|
|
205
|
+
it('nests somethingLike correctly', () => {
|
|
206
|
+
const expected = {
|
|
217
207
|
value: [
|
|
218
208
|
{
|
|
219
209
|
id: {
|
|
@@ -225,13 +215,13 @@ describe('Matcher', function () {
|
|
|
225
215
|
'pact:matcher:type': 'type',
|
|
226
216
|
min: 1,
|
|
227
217
|
};
|
|
228
|
-
|
|
229
|
-
|
|
218
|
+
const match = (0, matchers_1.eachLike)({ id: (0, matchers_1.somethingLike)(10) }, { min: 1 });
|
|
219
|
+
expect(JSON.stringify(match)).toContain(JSON.stringify(expected));
|
|
230
220
|
});
|
|
231
221
|
});
|
|
232
|
-
describe('of type term',
|
|
233
|
-
it('nests term correctly',
|
|
234
|
-
|
|
222
|
+
describe('of type term', () => {
|
|
223
|
+
it('nests term correctly', () => {
|
|
224
|
+
const expected = {
|
|
235
225
|
value: [
|
|
236
226
|
{
|
|
237
227
|
colour: {
|
|
@@ -244,19 +234,19 @@ describe('Matcher', function () {
|
|
|
244
234
|
'pact:matcher:type': 'type',
|
|
245
235
|
min: 1,
|
|
246
236
|
};
|
|
247
|
-
|
|
237
|
+
const match = (0, matchers_1.eachLike)({
|
|
248
238
|
colour: (0, matchers_1.term)({
|
|
249
239
|
generate: 'red',
|
|
250
240
|
matcher: 'red|green',
|
|
251
241
|
}),
|
|
252
242
|
}, { min: 1 });
|
|
253
243
|
//
|
|
254
|
-
|
|
244
|
+
expect(JSON.stringify(match)).toContain(JSON.stringify(expected));
|
|
255
245
|
});
|
|
256
246
|
});
|
|
257
|
-
describe('of type eachLike',
|
|
258
|
-
it('nests eachlike in contents',
|
|
259
|
-
|
|
247
|
+
describe('of type eachLike', () => {
|
|
248
|
+
it('nests eachlike in contents', () => {
|
|
249
|
+
const expected = {
|
|
260
250
|
value: [
|
|
261
251
|
{
|
|
262
252
|
value: ['blue'],
|
|
@@ -267,13 +257,13 @@ describe('Matcher', function () {
|
|
|
267
257
|
'pact:matcher:type': 'type',
|
|
268
258
|
min: 1,
|
|
269
259
|
};
|
|
270
|
-
|
|
271
|
-
|
|
260
|
+
const match = (0, matchers_1.eachLike)((0, matchers_1.eachLike)('blue', { min: 1 }), { min: 1 });
|
|
261
|
+
expect(JSON.stringify(match)).toContain(JSON.stringify(expected));
|
|
272
262
|
});
|
|
273
263
|
});
|
|
274
|
-
describe('complex object with multiple Pact.Matchers',
|
|
275
|
-
it('nests objects correctly',
|
|
276
|
-
|
|
264
|
+
describe('complex object with multiple Pact.Matchers', () => {
|
|
265
|
+
it('nests objects correctly', () => {
|
|
266
|
+
const expected = {
|
|
277
267
|
value: [
|
|
278
268
|
{
|
|
279
269
|
value: [
|
|
@@ -322,241 +312,241 @@ describe('Matcher', function () {
|
|
|
322
312
|
'pact:matcher:type': 'type',
|
|
323
313
|
min: 1,
|
|
324
314
|
};
|
|
325
|
-
|
|
315
|
+
const match = (0, matchers_1.eachLike)((0, matchers_1.eachLike)({
|
|
326
316
|
colour: (0, matchers_1.term)({ generate: 'red', matcher: 'red|green|blue' }),
|
|
327
317
|
size: (0, matchers_1.somethingLike)(10),
|
|
328
318
|
tag: (0, matchers_1.eachLike)([(0, matchers_1.somethingLike)('jumper'), (0, matchers_1.somethingLike)('shirt')], { min: 2 }),
|
|
329
319
|
}, { min: 1 }), { min: 1 });
|
|
330
|
-
|
|
320
|
+
expect(JSON.parse(JSON.stringify(match))).toMatchObject(JSON.parse(JSON.stringify(expected)));
|
|
331
321
|
});
|
|
332
322
|
});
|
|
333
323
|
});
|
|
334
|
-
describe('When no options.min is not provided',
|
|
335
|
-
it('defaults to a min of 1',
|
|
336
|
-
|
|
324
|
+
describe('When no options.min is not provided', () => {
|
|
325
|
+
it('defaults to a min of 1', () => {
|
|
326
|
+
const expected = {
|
|
337
327
|
value: [{ a: 1 }],
|
|
338
328
|
'pact:matcher:type': 'type',
|
|
339
329
|
min: 1,
|
|
340
330
|
};
|
|
341
|
-
|
|
342
|
-
|
|
331
|
+
const match = (0, matchers_1.eachLike)({ a: 1 });
|
|
332
|
+
expect(JSON.stringify(match)).toContain(JSON.stringify(expected));
|
|
343
333
|
});
|
|
344
334
|
});
|
|
345
|
-
describe('When a options.min is provided',
|
|
346
|
-
it('provides the object as contents',
|
|
347
|
-
|
|
335
|
+
describe('When a options.min is provided', () => {
|
|
336
|
+
it('provides the object as contents', () => {
|
|
337
|
+
const expected = {
|
|
348
338
|
value: [{ a: 1 }, { a: 1 }, { a: 1 }],
|
|
349
339
|
'pact:matcher:type': 'type',
|
|
350
340
|
min: 3,
|
|
351
341
|
};
|
|
352
|
-
|
|
353
|
-
|
|
342
|
+
const match = (0, matchers_1.eachLike)({ a: 1 }, { min: 3 });
|
|
343
|
+
expect(JSON.stringify(match)).toContain(JSON.stringify(expected));
|
|
354
344
|
});
|
|
355
345
|
});
|
|
356
346
|
});
|
|
357
|
-
describe('#email',
|
|
358
|
-
describe('when given a valid Email address',
|
|
359
|
-
it('creates a valid matcher',
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
});
|
|
365
|
-
});
|
|
366
|
-
describe('when given an invalid Email address',
|
|
367
|
-
it('returns an error',
|
|
368
|
-
|
|
347
|
+
describe('#email', () => {
|
|
348
|
+
describe('when given a valid Email address', () => {
|
|
349
|
+
it('creates a valid matcher', () => {
|
|
350
|
+
expect((0, matchers_1.email)('hello@world.com')).toBeTypeOf('object');
|
|
351
|
+
expect((0, matchers_1.email)('hello@world.com.au')).toBeTypeOf('object');
|
|
352
|
+
expect((0, matchers_1.email)('hello@a.co')).toBeTypeOf('object');
|
|
353
|
+
expect((0, matchers_1.email)()).toBeTypeOf('object');
|
|
354
|
+
});
|
|
355
|
+
});
|
|
356
|
+
describe('when given an invalid Email address', () => {
|
|
357
|
+
it('returns an error', () => {
|
|
358
|
+
expect(() => {
|
|
369
359
|
(0, matchers_1.email)('hello.world.c');
|
|
370
|
-
}).
|
|
360
|
+
}).toThrow(Error);
|
|
371
361
|
});
|
|
372
362
|
});
|
|
373
363
|
});
|
|
374
|
-
describe('#uuid',
|
|
375
|
-
describe('when given a valid UUID',
|
|
376
|
-
it('creates a valid matcher',
|
|
377
|
-
|
|
378
|
-
|
|
364
|
+
describe('#uuid', () => {
|
|
365
|
+
describe('when given a valid UUID', () => {
|
|
366
|
+
it('creates a valid matcher', () => {
|
|
367
|
+
expect((0, matchers_1.uuid)('ce118b6e-d8e1-11e7-9296-cec278b6b50a')).toBeTypeOf('object');
|
|
368
|
+
expect((0, matchers_1.uuid)()).toBeTypeOf('object');
|
|
379
369
|
});
|
|
380
370
|
});
|
|
381
|
-
describe('when given an invalid UUID',
|
|
382
|
-
it('returns an error',
|
|
383
|
-
|
|
371
|
+
describe('when given an invalid UUID', () => {
|
|
372
|
+
it('returns an error', () => {
|
|
373
|
+
expect(() => {
|
|
384
374
|
(0, matchers_1.uuid)('abc');
|
|
385
|
-
}).
|
|
375
|
+
}).toThrow(Error);
|
|
386
376
|
});
|
|
387
377
|
});
|
|
388
378
|
});
|
|
389
|
-
describe('#ipv4Address',
|
|
390
|
-
describe('when given a valid ipv4Address',
|
|
391
|
-
it('creates a valid matcher',
|
|
392
|
-
|
|
393
|
-
|
|
379
|
+
describe('#ipv4Address', () => {
|
|
380
|
+
describe('when given a valid ipv4Address', () => {
|
|
381
|
+
it('creates a valid matcher', () => {
|
|
382
|
+
expect((0, matchers_1.ipv4Address)('127.0.0.1')).toBeTypeOf('object');
|
|
383
|
+
expect((0, matchers_1.ipv4Address)()).toBeTypeOf('object');
|
|
394
384
|
});
|
|
395
385
|
});
|
|
396
|
-
describe('when given an invalid ipv4Address',
|
|
397
|
-
it('returns an error',
|
|
398
|
-
|
|
386
|
+
describe('when given an invalid ipv4Address', () => {
|
|
387
|
+
it('returns an error', () => {
|
|
388
|
+
expect(() => {
|
|
399
389
|
(0, matchers_1.ipv4Address)('abc');
|
|
400
|
-
}).
|
|
390
|
+
}).toThrow(Error);
|
|
401
391
|
});
|
|
402
392
|
});
|
|
403
393
|
});
|
|
404
|
-
describe('#ipv6Address',
|
|
405
|
-
describe('when given a valid ipv6Address',
|
|
406
|
-
it('creates a valid matcher',
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
394
|
+
describe('#ipv6Address', () => {
|
|
395
|
+
describe('when given a valid ipv6Address', () => {
|
|
396
|
+
it('creates a valid matcher', () => {
|
|
397
|
+
expect((0, matchers_1.ipv6Address)('::1')).toBeTypeOf('object');
|
|
398
|
+
expect((0, matchers_1.ipv6Address)('2001:0db8:85a3:0000:0000:8a2e:0370:7334')).toBeTypeOf('object');
|
|
399
|
+
expect((0, matchers_1.ipv6Address)()).toBeTypeOf('object');
|
|
410
400
|
});
|
|
411
401
|
});
|
|
412
|
-
describe('when given an invalid ipv6Address',
|
|
413
|
-
it('returns an error',
|
|
414
|
-
|
|
402
|
+
describe('when given an invalid ipv6Address', () => {
|
|
403
|
+
it('returns an error', () => {
|
|
404
|
+
expect(() => {
|
|
415
405
|
(0, matchers_1.ipv6Address)('abc');
|
|
416
|
-
}).
|
|
406
|
+
}).toThrow(Error);
|
|
417
407
|
});
|
|
418
408
|
});
|
|
419
409
|
});
|
|
420
|
-
describe('#hexadecimal',
|
|
421
|
-
describe('when given a valid hexadecimal',
|
|
422
|
-
it('creates a valid matcher',
|
|
423
|
-
|
|
424
|
-
|
|
410
|
+
describe('#hexadecimal', () => {
|
|
411
|
+
describe('when given a valid hexadecimal', () => {
|
|
412
|
+
it('creates a valid matcher', () => {
|
|
413
|
+
expect((0, matchers_1.hexadecimal)('6F')).toBeTypeOf('object');
|
|
414
|
+
expect((0, matchers_1.hexadecimal)()).toBeTypeOf('object');
|
|
425
415
|
});
|
|
426
416
|
});
|
|
427
|
-
describe('when given an invalid hexadecimal',
|
|
428
|
-
it('returns an error',
|
|
429
|
-
|
|
417
|
+
describe('when given an invalid hexadecimal', () => {
|
|
418
|
+
it('returns an error', () => {
|
|
419
|
+
expect(() => {
|
|
430
420
|
(0, matchers_1.hexadecimal)('x1');
|
|
431
|
-
}).
|
|
421
|
+
}).toThrow(Error);
|
|
432
422
|
});
|
|
433
423
|
});
|
|
434
424
|
});
|
|
435
|
-
describe('#boolean',
|
|
436
|
-
describe('when used it should create a JSON object',
|
|
437
|
-
it('creates a valid matcher',
|
|
438
|
-
|
|
439
|
-
|
|
425
|
+
describe('#boolean', () => {
|
|
426
|
+
describe('when used it should create a JSON object', () => {
|
|
427
|
+
it('creates a valid matcher', () => {
|
|
428
|
+
expect((0, matchers_1.boolean)()).toBeTypeOf('object');
|
|
429
|
+
expect((0, matchers_1.boolean)().value).toBe(true);
|
|
440
430
|
});
|
|
441
|
-
it('sets value=false',
|
|
442
|
-
|
|
443
|
-
|
|
431
|
+
it('sets value=false', () => {
|
|
432
|
+
expect((0, matchers_1.boolean)(false)).toBeTypeOf('object');
|
|
433
|
+
expect((0, matchers_1.boolean)(false).value).toBe(false);
|
|
444
434
|
});
|
|
445
|
-
it('sets value=true',
|
|
446
|
-
|
|
447
|
-
|
|
435
|
+
it('sets value=true', () => {
|
|
436
|
+
expect((0, matchers_1.boolean)(true)).toBeTypeOf('object');
|
|
437
|
+
expect((0, matchers_1.boolean)(true).value).toBe(true);
|
|
448
438
|
});
|
|
449
439
|
});
|
|
450
440
|
});
|
|
451
|
-
describe('#string',
|
|
452
|
-
describe('when given a valid string',
|
|
453
|
-
it('creates a valid matcher',
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
441
|
+
describe('#string', () => {
|
|
442
|
+
describe('when given a valid string', () => {
|
|
443
|
+
it('creates a valid matcher', () => {
|
|
444
|
+
expect((0, matchers_1.string)('test')).toBeTypeOf('object');
|
|
445
|
+
expect((0, matchers_1.string)()).toBeTypeOf('object');
|
|
446
|
+
expect((0, matchers_1.string)('test').value).toBe('test');
|
|
457
447
|
});
|
|
458
448
|
});
|
|
459
449
|
});
|
|
460
|
-
describe('#decimal',
|
|
461
|
-
describe('when given a valid decimal',
|
|
462
|
-
it('creates a valid matcher',
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
450
|
+
describe('#decimal', () => {
|
|
451
|
+
describe('when given a valid decimal', () => {
|
|
452
|
+
it('creates a valid matcher', () => {
|
|
453
|
+
expect((0, matchers_1.decimal)(10.1)).toBeTypeOf('object');
|
|
454
|
+
expect((0, matchers_1.decimal)()).toBeTypeOf('object');
|
|
455
|
+
expect((0, matchers_1.decimal)(0.0).value).toBe(0.0);
|
|
466
456
|
});
|
|
467
457
|
});
|
|
468
458
|
});
|
|
469
|
-
describe('#integer',
|
|
470
|
-
describe('when given a valid integer',
|
|
471
|
-
it('creates a valid matcher',
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
459
|
+
describe('#integer', () => {
|
|
460
|
+
describe('when given a valid integer', () => {
|
|
461
|
+
it('creates a valid matcher', () => {
|
|
462
|
+
expect((0, matchers_1.integer)(10)).toBeTypeOf('object');
|
|
463
|
+
expect((0, matchers_1.integer)()).toBeTypeOf('object');
|
|
464
|
+
expect((0, matchers_1.integer)(0).value).toBe(0);
|
|
475
465
|
});
|
|
476
466
|
});
|
|
477
467
|
});
|
|
478
|
-
describe('Date Matchers',
|
|
479
|
-
describe('#rfc1123Timestamp',
|
|
480
|
-
describe('when given a valid rfc1123Timestamp',
|
|
481
|
-
it('creates a valid matcher',
|
|
482
|
-
|
|
483
|
-
|
|
468
|
+
describe('Date Matchers', () => {
|
|
469
|
+
describe('#rfc1123Timestamp', () => {
|
|
470
|
+
describe('when given a valid rfc1123Timestamp', () => {
|
|
471
|
+
it('creates a valid matcher', () => {
|
|
472
|
+
expect((0, matchers_1.rfc1123Timestamp)('Mon, 31 Oct 2016 15:21:41 -0400')).toBeTypeOf('object');
|
|
473
|
+
expect((0, matchers_1.rfc1123Timestamp)()).toBeTypeOf('object');
|
|
484
474
|
});
|
|
485
475
|
});
|
|
486
|
-
describe('when given an invalid rfc1123Timestamp',
|
|
487
|
-
it('returns an error',
|
|
488
|
-
|
|
476
|
+
describe('when given an invalid rfc1123Timestamp', () => {
|
|
477
|
+
it('returns an error', () => {
|
|
478
|
+
expect(() => {
|
|
489
479
|
(0, matchers_1.rfc1123Timestamp)('abc');
|
|
490
|
-
}).
|
|
480
|
+
}).toThrow(Error);
|
|
491
481
|
});
|
|
492
482
|
});
|
|
493
483
|
});
|
|
494
|
-
describe('#iso8601Time',
|
|
495
|
-
describe('when given a valid iso8601Time',
|
|
496
|
-
it('creates a valid matcher',
|
|
497
|
-
|
|
498
|
-
|
|
484
|
+
describe('#iso8601Time', () => {
|
|
485
|
+
describe('when given a valid iso8601Time', () => {
|
|
486
|
+
it('creates a valid matcher', () => {
|
|
487
|
+
expect((0, matchers_1.iso8601Time)('T22:44:30.652Z')).toBeTypeOf('object');
|
|
488
|
+
expect((0, matchers_1.iso8601Time)()).toBeTypeOf('object');
|
|
499
489
|
});
|
|
500
490
|
});
|
|
501
|
-
describe('when given an invalid iso8601Time',
|
|
502
|
-
it('returns an error',
|
|
503
|
-
|
|
491
|
+
describe('when given an invalid iso8601Time', () => {
|
|
492
|
+
it('returns an error', () => {
|
|
493
|
+
expect(() => {
|
|
504
494
|
(0, matchers_1.iso8601Time)('abc');
|
|
505
|
-
}).
|
|
495
|
+
}).toThrow(Error);
|
|
506
496
|
});
|
|
507
497
|
});
|
|
508
498
|
});
|
|
509
|
-
describe('#iso8601Date',
|
|
510
|
-
describe('when given a valid iso8601Date',
|
|
511
|
-
it('creates a valid matcher',
|
|
512
|
-
|
|
513
|
-
|
|
499
|
+
describe('#iso8601Date', () => {
|
|
500
|
+
describe('when given a valid iso8601Date', () => {
|
|
501
|
+
it('creates a valid matcher', () => {
|
|
502
|
+
expect((0, matchers_1.iso8601Date)('2017-12-05')).toBeTypeOf('object');
|
|
503
|
+
expect((0, matchers_1.iso8601Date)()).toBeTypeOf('object');
|
|
514
504
|
});
|
|
515
505
|
});
|
|
516
|
-
describe('when given an invalid iso8601Date',
|
|
517
|
-
it('returns an error',
|
|
518
|
-
|
|
506
|
+
describe('when given an invalid iso8601Date', () => {
|
|
507
|
+
it('returns an error', () => {
|
|
508
|
+
expect(() => {
|
|
519
509
|
(0, matchers_1.iso8601Date)('abc');
|
|
520
|
-
}).
|
|
510
|
+
}).toThrow(Error);
|
|
521
511
|
});
|
|
522
512
|
});
|
|
523
513
|
});
|
|
524
|
-
describe('#iso8601DateTime',
|
|
525
|
-
describe('when given a valid iso8601DateTime',
|
|
526
|
-
it('creates a valid matcher',
|
|
527
|
-
|
|
528
|
-
|
|
514
|
+
describe('#iso8601DateTime', () => {
|
|
515
|
+
describe('when given a valid iso8601DateTime', () => {
|
|
516
|
+
it('creates a valid matcher', () => {
|
|
517
|
+
expect((0, matchers_1.iso8601DateTime)('2015-08-06T16:53:10+01:00')).toBeTypeOf('object');
|
|
518
|
+
expect((0, matchers_1.iso8601DateTime)()).toBeTypeOf('object');
|
|
529
519
|
});
|
|
530
520
|
});
|
|
531
|
-
describe('when given an invalid iso8601DateTime',
|
|
532
|
-
it('returns an error',
|
|
533
|
-
|
|
521
|
+
describe('when given an invalid iso8601DateTime', () => {
|
|
522
|
+
it('returns an error', () => {
|
|
523
|
+
expect(() => {
|
|
534
524
|
(0, matchers_1.iso8601DateTime)('abc');
|
|
535
|
-
}).
|
|
525
|
+
}).toThrow(Error);
|
|
536
526
|
});
|
|
537
527
|
});
|
|
538
528
|
});
|
|
539
|
-
describe('#iso8601DateTimeWithMillis',
|
|
540
|
-
describe('when given a valid iso8601DateTimeWithMillis',
|
|
541
|
-
it('creates a valid matcher',
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
529
|
+
describe('#iso8601DateTimeWithMillis', () => {
|
|
530
|
+
describe('when given a valid iso8601DateTimeWithMillis', () => {
|
|
531
|
+
it('creates a valid matcher', () => {
|
|
532
|
+
expect((0, matchers_1.iso8601DateTimeWithMillis)('2015-08-06T16:53:10.123+01:00')).toBeTypeOf('object');
|
|
533
|
+
expect((0, matchers_1.iso8601DateTimeWithMillis)('2015-08-06T16:53:10.537357Z')).toBeTypeOf('object');
|
|
534
|
+
expect((0, matchers_1.iso8601DateTimeWithMillis)('2020-12-10T09:01:29.06Z')).toBeTypeOf('object');
|
|
535
|
+
expect((0, matchers_1.iso8601DateTimeWithMillis)('2020-12-10T09:01:29.1Z')).toBeTypeOf('object');
|
|
536
|
+
expect((0, matchers_1.iso8601DateTimeWithMillis)()).toBeTypeOf('object');
|
|
547
537
|
});
|
|
548
538
|
});
|
|
549
|
-
describe('when given an invalid iso8601DateTimeWithMillis',
|
|
550
|
-
it('returns an error',
|
|
551
|
-
|
|
539
|
+
describe('when given an invalid iso8601DateTimeWithMillis', () => {
|
|
540
|
+
it('returns an error', () => {
|
|
541
|
+
expect(() => {
|
|
552
542
|
(0, matchers_1.iso8601DateTimeWithMillis)('abc');
|
|
553
|
-
}).
|
|
543
|
+
}).toThrow(Error);
|
|
554
544
|
});
|
|
555
545
|
});
|
|
556
546
|
});
|
|
557
|
-
describe('#extractPayload',
|
|
558
|
-
describe('when given an object with no matchers',
|
|
559
|
-
|
|
547
|
+
describe('#extractPayload', () => {
|
|
548
|
+
describe('when given an object with no matchers', () => {
|
|
549
|
+
const object = {
|
|
560
550
|
some: 'data',
|
|
561
551
|
more: 'strings',
|
|
562
552
|
an: ['array'],
|
|
@@ -565,12 +555,12 @@ describe('Matcher', function () {
|
|
|
565
555
|
withNumber: 1,
|
|
566
556
|
},
|
|
567
557
|
};
|
|
568
|
-
it('returns just that object',
|
|
569
|
-
|
|
558
|
+
it('returns just that object', () => {
|
|
559
|
+
expect((0, matchers_1.extractPayload)(object)).toEqual(object);
|
|
570
560
|
});
|
|
571
561
|
});
|
|
572
|
-
describe('when given an object with null values',
|
|
573
|
-
|
|
562
|
+
describe('when given an object with null values', () => {
|
|
563
|
+
const object = {
|
|
574
564
|
some: 'data',
|
|
575
565
|
more: null,
|
|
576
566
|
an: [null],
|
|
@@ -580,12 +570,12 @@ describe('Matcher', function () {
|
|
|
580
570
|
andNull: null,
|
|
581
571
|
},
|
|
582
572
|
};
|
|
583
|
-
it('returns just that object',
|
|
584
|
-
|
|
573
|
+
it('returns just that object', () => {
|
|
574
|
+
expect((0, matchers_1.extractPayload)(object)).toEqual(object);
|
|
585
575
|
});
|
|
586
576
|
});
|
|
587
|
-
describe('when given an object with some matchers',
|
|
588
|
-
|
|
577
|
+
describe('when given an object with some matchers', () => {
|
|
578
|
+
const someMatchers = {
|
|
589
579
|
some: (0, matchers_1.somethingLike)('data'),
|
|
590
580
|
more: 'strings',
|
|
591
581
|
an: ['array'],
|
|
@@ -597,7 +587,7 @@ describe('Matcher', function () {
|
|
|
597
587
|
withAnotherNumber: (0, matchers_1.somethingLike)(2),
|
|
598
588
|
},
|
|
599
589
|
};
|
|
600
|
-
|
|
590
|
+
const expected = {
|
|
601
591
|
some: 'data',
|
|
602
592
|
more: 'strings',
|
|
603
593
|
an: ['array'],
|
|
@@ -609,24 +599,24 @@ describe('Matcher', function () {
|
|
|
609
599
|
withAnotherNumber: 2,
|
|
610
600
|
},
|
|
611
601
|
};
|
|
612
|
-
it('returns without matching guff',
|
|
613
|
-
|
|
602
|
+
it('returns without matching guff', () => {
|
|
603
|
+
expect((0, matchers_1.extractPayload)(someMatchers)).toEqual(expected);
|
|
614
604
|
});
|
|
615
605
|
});
|
|
616
|
-
describe('when given a simple matcher',
|
|
617
|
-
it('removes all matching guff',
|
|
618
|
-
|
|
619
|
-
|
|
606
|
+
describe('when given a simple matcher', () => {
|
|
607
|
+
it('removes all matching guff', () => {
|
|
608
|
+
const expected = 'myawesomeword';
|
|
609
|
+
const matcher = (0, matchers_1.term)({
|
|
620
610
|
generate: 'myawesomeword',
|
|
621
611
|
matcher: '\\w+',
|
|
622
612
|
});
|
|
623
|
-
|
|
624
|
-
|
|
613
|
+
expect((0, matchers_1.isMatcher)(matcher)).toBe(true);
|
|
614
|
+
expect((0, matchers_1.extractPayload)(matcher)).toEqual(expected);
|
|
625
615
|
});
|
|
626
616
|
});
|
|
627
|
-
describe('when given a complex nested object with matchers',
|
|
628
|
-
it('removes all matching guff',
|
|
629
|
-
|
|
617
|
+
describe('when given a complex nested object with matchers', () => {
|
|
618
|
+
it('removes all matching guff', () => {
|
|
619
|
+
const o = (0, matchers_1.somethingLike)({
|
|
630
620
|
stringMatcher: {
|
|
631
621
|
awesomeSetting: (0, matchers_1.somethingLike)('a string'),
|
|
632
622
|
},
|
|
@@ -646,7 +636,7 @@ describe('Matcher', function () {
|
|
|
646
636
|
}, { min: 3 }),
|
|
647
637
|
},
|
|
648
638
|
});
|
|
649
|
-
|
|
639
|
+
const expected = {
|
|
650
640
|
stringMatcher: {
|
|
651
641
|
awesomeSetting: 'a string',
|
|
652
642
|
},
|
|
@@ -676,7 +666,7 @@ describe('Matcher', function () {
|
|
|
676
666
|
],
|
|
677
667
|
},
|
|
678
668
|
};
|
|
679
|
-
|
|
669
|
+
expect((0, matchers_1.extractPayload)(o)).toEqual(expected);
|
|
680
670
|
});
|
|
681
671
|
});
|
|
682
672
|
});
|