@redocly/openapi-core 1.0.0-beta.104 → 1.0.0-beta.107

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 (203) hide show
  1. package/README.md +4 -4
  2. package/__tests__/utils.ts +8 -6
  3. package/lib/benchmark/benches/recommended-oas3.bench.js +1 -1
  4. package/lib/benchmark/utils.d.ts +2 -2
  5. package/lib/benchmark/utils.js +2 -2
  6. package/lib/bundle.d.ts +2 -2
  7. package/lib/bundle.js +2 -2
  8. package/lib/config/all.d.ts +2 -2
  9. package/lib/config/all.js +1 -1
  10. package/lib/config/builtIn.d.ts +2 -2
  11. package/lib/config/builtIn.js +2 -2
  12. package/lib/config/config-resolvers.d.ts +5 -5
  13. package/lib/config/config-resolvers.js +39 -36
  14. package/lib/config/config.d.ts +6 -5
  15. package/lib/config/config.js +27 -20
  16. package/lib/config/load.js +6 -7
  17. package/lib/config/minimal.d.ts +2 -2
  18. package/lib/config/minimal.js +3 -2
  19. package/lib/config/recommended.d.ts +2 -2
  20. package/lib/config/recommended.js +3 -2
  21. package/lib/config/rules.d.ts +2 -2
  22. package/lib/config/rules.js +1 -1
  23. package/lib/config/types.d.ts +23 -19
  24. package/lib/config/utils.d.ts +5 -5
  25. package/lib/config/utils.js +43 -26
  26. package/lib/decorators/common/remove-x-internal.js +2 -2
  27. package/lib/format/format.js +1 -1
  28. package/lib/index.d.ts +2 -2
  29. package/lib/index.js +3 -2
  30. package/lib/js-yaml/index.js +1 -6
  31. package/lib/lint.d.ts +2 -2
  32. package/lib/lint.js +16 -6
  33. package/lib/redocly/registry-api.d.ts +1 -1
  34. package/lib/redocly/registry-api.js +2 -2
  35. package/lib/rules/ajv.d.ts +1 -1
  36. package/lib/rules/ajv.js +6 -6
  37. package/lib/rules/common/info-license-url.d.ts +1 -1
  38. package/lib/rules/common/info-license-url.js +5 -10
  39. package/lib/rules/common/info-license.d.ts +2 -0
  40. package/lib/rules/common/info-license.js +17 -0
  41. package/lib/rules/common/no-enum-type-mismatch.js +1 -3
  42. package/lib/rules/common/no-invalid-parameter-examples.js +3 -3
  43. package/lib/rules/common/no-invalid-schema-examples.js +3 -3
  44. package/lib/rules/common/operation-operationId.js +1 -1
  45. package/lib/rules/common/path-not-include-query.js +1 -1
  46. package/lib/rules/common/paths-kebab-case.js +4 -1
  47. package/lib/rules/common/spec.js +1 -1
  48. package/lib/rules/oas2/index.js +4 -4
  49. package/lib/rules/oas2/remove-unused-components.js +3 -3
  50. package/lib/rules/oas3/index.js +4 -4
  51. package/lib/rules/oas3/no-empty-servers.js +1 -1
  52. package/lib/rules/oas3/no-invalid-media-type-examples.js +2 -2
  53. package/lib/rules/oas3/remove-unused-components.js +2 -2
  54. package/lib/rules/other/stats.js +43 -14
  55. package/lib/rules/utils.d.ts +3 -2
  56. package/lib/rules/utils.js +19 -4
  57. package/lib/types/index.d.ts +2 -2
  58. package/lib/types/redocly-yaml.js +8 -7
  59. package/lib/utils.d.ts +5 -2
  60. package/lib/utils.js +20 -2
  61. package/lib/walk.d.ts +2 -1
  62. package/lib/walk.js +6 -3
  63. package/package.json +2 -2
  64. package/src/__tests__/__snapshots__/bundle.test.ts.snap +141 -0
  65. package/src/__tests__/bundle.test.ts +68 -34
  66. package/src/__tests__/codeframes.test.ts +13 -14
  67. package/src/__tests__/fixtures/.redocly.lint-ignore.yaml +5 -0
  68. package/src/__tests__/js-yaml.test.ts +6 -4
  69. package/src/__tests__/lint.test.ts +127 -12
  70. package/src/__tests__/login.test.ts +2 -2
  71. package/src/__tests__/normalizeVisitors.test.ts +4 -4
  72. package/src/__tests__/ref-utils.test.ts +13 -13
  73. package/src/__tests__/resolve-http.test.ts +1 -1
  74. package/src/__tests__/resolve.test.ts +14 -11
  75. package/src/__tests__/utils.test.ts +42 -1
  76. package/src/__tests__/walk.test.ts +48 -56
  77. package/src/benchmark/benches/lint-with-many-rules.bench.ts +1 -1
  78. package/src/benchmark/benches/lint-with-nested-rule.bench.ts +1 -1
  79. package/src/benchmark/benches/lint-with-no-rules.bench.ts +1 -1
  80. package/src/benchmark/benches/lint-with-top-level-rule-report.bench.ts +1 -1
  81. package/src/benchmark/benches/lint-with-top-level-rule.bench.ts +1 -1
  82. package/src/benchmark/benches/recommended-oas3.bench.ts +3 -3
  83. package/src/benchmark/benches/resolve-with-no-external.bench.ts +1 -1
  84. package/src/benchmark/benchmark.js +9 -5
  85. package/src/benchmark/utils.ts +5 -5
  86. package/src/bundle.ts +18 -17
  87. package/src/config/__tests__/__snapshots__/config-resolvers.test.ts.snap +3 -1
  88. package/src/config/__tests__/config-resolvers.test.ts +123 -121
  89. package/src/config/__tests__/config.test.ts +76 -76
  90. package/src/config/__tests__/fixtures/resolve-config/api/plugin.js +4 -2
  91. package/src/config/__tests__/fixtures/resolve-config/plugin.js +4 -1
  92. package/src/config/__tests__/load.test.ts +2 -2
  93. package/src/config/__tests__/resolve-plugins.test.ts +3 -3
  94. package/src/config/__tests__/utils.test.ts +83 -0
  95. package/src/config/all.ts +3 -4
  96. package/src/config/builtIn.ts +5 -5
  97. package/src/config/config-resolvers.ts +122 -83
  98. package/src/config/config.ts +36 -32
  99. package/src/config/load.ts +13 -16
  100. package/src/config/minimal.ts +5 -4
  101. package/src/config/recommended.ts +5 -4
  102. package/src/config/rules.ts +6 -6
  103. package/src/config/types.ts +28 -19
  104. package/src/config/utils.ts +74 -54
  105. package/src/decorators/__tests__/filter-out.test.ts +8 -4
  106. package/src/decorators/__tests__/remove-x-internal.test.ts +5 -5
  107. package/src/decorators/common/filters/filter-helper.ts +1 -1
  108. package/src/decorators/common/info-description-override.ts +1 -1
  109. package/src/decorators/common/operation-description-override.ts +1 -1
  110. package/src/decorators/common/remove-x-internal.ts +4 -4
  111. package/src/decorators/common/tag-description-override.ts +1 -1
  112. package/src/format/codeframes.ts +4 -4
  113. package/src/format/format.ts +10 -10
  114. package/src/index.ts +3 -4
  115. package/src/js-yaml/index.ts +3 -8
  116. package/src/lint.ts +22 -18
  117. package/src/oas-types.ts +1 -6
  118. package/src/redocly/__tests__/redocly-client.test.ts +25 -19
  119. package/src/redocly/index.ts +6 -4
  120. package/src/redocly/registry-api.ts +6 -6
  121. package/src/ref-utils.ts +2 -2
  122. package/src/resolve.ts +7 -4
  123. package/src/rules/__tests__/no-unresolved-refs.test.ts +4 -4
  124. package/src/rules/__tests__/utils.test.ts +160 -0
  125. package/src/rules/ajv.ts +7 -8
  126. package/src/rules/common/__tests__/info-description.test.ts +3 -3
  127. package/src/rules/common/__tests__/info-license.test.ts +2 -2
  128. package/src/rules/common/__tests__/license-url.test.ts +2 -2
  129. package/src/rules/common/__tests__/no-ambiguous-paths.test.ts +1 -1
  130. package/src/rules/common/__tests__/no-enum-type-mismatch.test.ts +8 -8
  131. package/src/rules/common/__tests__/no-identical-paths.test.ts +1 -1
  132. package/src/rules/common/__tests__/no-path-trailing-slash.test.ts +3 -3
  133. package/src/rules/common/__tests__/operation-2xx-response.test.ts +3 -3
  134. package/src/rules/common/__tests__/operation-4xx-response.test.ts +3 -3
  135. package/src/rules/common/__tests__/operation-operationId-unique.test.ts +2 -2
  136. package/src/rules/common/__tests__/operation-operationId-url-safe.test.ts +1 -1
  137. package/src/rules/common/__tests__/operation-parameters-unique.test.ts +4 -4
  138. package/src/rules/common/__tests__/operation-security-defined.test.ts +2 -2
  139. package/src/rules/common/__tests__/operation-singular-tag.test.ts +2 -2
  140. package/src/rules/common/__tests__/path-http-verbs-order.test.ts +2 -2
  141. package/src/rules/common/__tests__/path-not-include-query.test.ts +2 -2
  142. package/src/rules/common/__tests__/path-params-defined.test.ts +3 -3
  143. package/src/rules/common/__tests__/paths-kebab-case.test.ts +15 -15
  144. package/src/rules/common/__tests__/scalar-property-missing-example.test.ts +8 -8
  145. package/src/rules/common/__tests__/spec.test.ts +2 -2
  146. package/src/rules/common/__tests__/tag-description.test.ts +2 -2
  147. package/src/rules/common/__tests__/tags-alphabetical.test.ts +2 -2
  148. package/src/rules/common/assertions/__tests__/asserts.test.ts +513 -130
  149. package/src/rules/common/assertions/index.ts +6 -6
  150. package/src/rules/common/info-license-url.ts +4 -9
  151. package/src/rules/common/info-license.ts +15 -0
  152. package/src/rules/common/no-ambiguous-paths.ts +1 -1
  153. package/src/rules/common/no-enum-type-mismatch.ts +12 -9
  154. package/src/rules/common/no-invalid-parameter-examples.ts +4 -4
  155. package/src/rules/common/no-invalid-schema-examples.ts +4 -4
  156. package/src/rules/common/operation-operationId.ts +1 -1
  157. package/src/rules/common/operation-parameters-unique.ts +2 -2
  158. package/src/rules/common/path-not-include-query.ts +1 -1
  159. package/src/rules/common/path-params-defined.ts +1 -1
  160. package/src/rules/common/paths-kebab-case.ts +4 -1
  161. package/src/rules/common/scalar-property-missing-example.ts +1 -1
  162. package/src/rules/common/spec.ts +10 -7
  163. package/src/rules/no-unresolved-refs.ts +1 -1
  164. package/src/rules/oas2/__tests__/boolean-parameter-prefixes.test.ts +3 -3
  165. package/src/rules/oas2/__tests__/spec/info.test.ts +12 -12
  166. package/src/rules/oas2/__tests__/spec/operation.test.ts +4 -4
  167. package/src/rules/oas2/__tests__/spec/paths.test.ts +10 -10
  168. package/src/rules/oas2/__tests__/spec/referenceableScalars.test.ts +6 -2
  169. package/src/rules/oas2/__tests__/spec/utils.ts +6 -6
  170. package/src/rules/oas2/index.ts +3 -3
  171. package/src/rules/oas2/remove-unused-components.ts +13 -8
  172. package/src/rules/oas3/__tests__/boolean-parameter-prefixes.test.ts +3 -3
  173. package/src/rules/oas3/__tests__/no-example-value-and-externalValue.test.ts +2 -2
  174. package/src/rules/oas3/__tests__/no-invalid-media-type-examples.test.ts +13 -13
  175. package/src/rules/oas3/__tests__/no-server-example.com.test.ts +2 -2
  176. package/src/rules/oas3/__tests__/no-server-trailing-slash.test.ts +3 -3
  177. package/src/rules/oas3/__tests__/no-unused-components.test.ts +1 -1
  178. package/src/rules/oas3/__tests__/spec/callbacks.test.ts +1 -1
  179. package/src/rules/oas3/__tests__/spec/info.test.ts +12 -12
  180. package/src/rules/oas3/__tests__/spec/operation.test.ts +8 -8
  181. package/src/rules/oas3/__tests__/spec/paths.test.ts +10 -10
  182. package/src/rules/oas3/__tests__/spec/referenceableScalars.test.ts +12 -12
  183. package/src/rules/oas3/__tests__/spec/servers.test.ts +15 -15
  184. package/src/rules/oas3/__tests__/spec/spec.test.ts +6 -6
  185. package/src/rules/oas3/__tests__/spec/utils.ts +6 -6
  186. package/src/rules/oas3/index.ts +3 -3
  187. package/src/rules/oas3/no-empty-servers.ts +1 -1
  188. package/src/rules/oas3/no-invalid-media-type-examples.ts +14 -6
  189. package/src/rules/oas3/no-servers-empty-enum.ts +9 -10
  190. package/src/rules/oas3/remove-unused-components.ts +18 -7
  191. package/src/rules/other/stats.ts +46 -17
  192. package/src/rules/utils.ts +19 -3
  193. package/src/types/index.ts +5 -5
  194. package/src/types/redocly-yaml.ts +8 -7
  195. package/src/typings/common.ts +9 -1
  196. package/src/typings/openapi.ts +1 -1
  197. package/src/utils.ts +31 -8
  198. package/src/visitors.ts +4 -4
  199. package/src/walk.ts +15 -11
  200. package/tsconfig.tsbuildinfo +1 -1
  201. package/lib/rules/common/license-url.d.ts +0 -2
  202. package/lib/rules/common/license-url.js +0 -12
  203. package/src/rules/common/license-url.ts +0 -10
@@ -15,230 +15,613 @@ describe('oas3 assertions', () => {
15
15
  describe('pattern', () => {
16
16
  it('value should match regex pattern', () => {
17
17
  expect(asserts.pattern('test string', '/test/', baseLocation)).toEqual({ isValid: true });
18
- expect(asserts.pattern('test string', '/test me/', baseLocation)).toEqual({ isValid: false, location: baseLocation });
19
- expect(asserts.pattern(['test string', 'test me'], '/test/', baseLocation)).toEqual({ isValid: true });
20
- expect(asserts.pattern(['test string', 'test me'], '/test me/', baseLocation)).toEqual({ isValid: false, location: baseLocation.key() });
21
- expect(asserts.pattern('./components/smth/test.yaml', '/^(./)?components/.*.yaml$/', baseLocation)).toEqual({ isValid: true });
22
- expect(asserts.pattern('./other.yaml', '/^(./)?components/.*.yaml$/', baseLocation)).toEqual({ isValid: false, location: baseLocation });
18
+ expect(asserts.pattern('test string', '/test me/', baseLocation)).toEqual({
19
+ isValid: false,
20
+ location: baseLocation,
21
+ });
22
+ expect(asserts.pattern(['test string', 'test me'], '/test/', baseLocation)).toEqual({
23
+ isValid: true,
24
+ });
25
+ expect(asserts.pattern(['test string', 'test me'], '/test me/', baseLocation)).toEqual({
26
+ isValid: false,
27
+ location: baseLocation.key(),
28
+ });
29
+ expect(
30
+ asserts.pattern(
31
+ './components/smth/test.yaml',
32
+ '/^(./)?components/.*.yaml$/',
33
+ baseLocation
34
+ )
35
+ ).toEqual({ isValid: true });
36
+ expect(
37
+ asserts.pattern('./other.yaml', '/^(./)?components/.*.yaml$/', baseLocation)
38
+ ).toEqual({ isValid: false, location: baseLocation });
23
39
  });
24
40
  });
25
41
 
26
42
  describe('ref', () => {
27
43
  it('value should have ref', () => {
28
- expect(asserts.ref({ $ref: 'text' }, true, baseLocation, { $ref: 'text' })).toEqual({ isValid: true, location: baseLocation });
29
- expect(asserts.ref({}, true, baseLocation, {})).toEqual({ isValid: false, location: baseLocation.key() });
44
+ expect(asserts.ref({ $ref: 'text' }, true, baseLocation, { $ref: 'text' })).toEqual({
45
+ isValid: true,
46
+ location: baseLocation,
47
+ });
48
+ expect(asserts.ref({}, true, baseLocation, {})).toEqual({
49
+ isValid: false,
50
+ location: baseLocation.key(),
51
+ });
30
52
  });
31
53
 
32
54
  it('value should not have ref', () => {
33
- expect(asserts.ref({ $ref: 'text' }, false, baseLocation, { $ref: 'text' })).toEqual({ isValid: false, location: baseLocation });
34
- expect(asserts.ref({}, false, baseLocation, {})).toEqual({ isValid: true, location: baseLocation.key() });
55
+ expect(asserts.ref({ $ref: 'text' }, false, baseLocation, { $ref: 'text' })).toEqual({
56
+ isValid: false,
57
+ location: baseLocation,
58
+ });
59
+ expect(asserts.ref({}, false, baseLocation, {})).toEqual({
60
+ isValid: true,
61
+ location: baseLocation.key(),
62
+ });
35
63
  });
36
64
 
37
65
  it('value should match regex pattern', () => {
38
- expect(asserts.ref({ $ref: 'test string' }, '/test/', baseLocation, { $ref: 'test string' })).toEqual({ isValid: true, location: baseLocation });
39
- expect(asserts.ref({ $ref: 'test string' }, '/test me/', baseLocation, { $ref: 'test string' })).toEqual({ isValid: false, location: baseLocation });
40
- expect(asserts.ref({ $ref: './components/smth/test.yaml' }, '/^(./)?components/.*.yaml$/', baseLocation, { $ref: './components/smth/test.yaml' })).toEqual({ isValid: true, location: baseLocation });
41
- expect(asserts.ref({ $ref: './paths/smth/test.yaml' }, '/^(./)?components/.*.yaml$/', baseLocation, { $ref: './paths/smth/test.yaml' })).toEqual({ isValid: false, location: baseLocation });
66
+ expect(
67
+ asserts.ref({ $ref: 'test string' }, '/test/', baseLocation, { $ref: 'test string' })
68
+ ).toEqual({ isValid: true, location: baseLocation });
69
+ expect(
70
+ asserts.ref({ $ref: 'test string' }, '/test me/', baseLocation, { $ref: 'test string' })
71
+ ).toEqual({ isValid: false, location: baseLocation });
72
+ expect(
73
+ asserts.ref(
74
+ { $ref: './components/smth/test.yaml' },
75
+ '/^(./)?components/.*.yaml$/',
76
+ baseLocation,
77
+ { $ref: './components/smth/test.yaml' }
78
+ )
79
+ ).toEqual({ isValid: true, location: baseLocation });
80
+ expect(
81
+ asserts.ref(
82
+ { $ref: './paths/smth/test.yaml' },
83
+ '/^(./)?components/.*.yaml$/',
84
+ baseLocation,
85
+ { $ref: './paths/smth/test.yaml' }
86
+ )
87
+ ).toEqual({ isValid: false, location: baseLocation });
42
88
  });
43
89
  });
44
90
 
45
91
  describe('enum', () => {
46
92
  it('value should be among predefined keys', () => {
47
93
  expect(asserts.enum('test', ['test', 'example'], baseLocation)).toEqual({ isValid: true });
48
- expect(asserts.enum(['test'], ['test', 'example'], baseLocation)).toEqual({ isValid: true });
49
- expect(asserts.enum(['test', 'example'], ['test', 'example'], baseLocation)).toEqual({ isValid: true });
50
- expect(asserts.enum(['test', 'example', 'foo'], ['test', 'example'], baseLocation)).toEqual({ isValid: false, location: baseLocation.child('foo').key() });
51
- expect(asserts.enum('test', ['foo', 'example'], baseLocation)).toEqual({ isValid: false, location: baseLocation });
52
- expect(asserts.enum(['test', 'foo'], ['test', 'example'], baseLocation)).toEqual({ isValid: false, location: baseLocation.child('foo').key() });
94
+ expect(asserts.enum(['test'], ['test', 'example'], baseLocation)).toEqual({
95
+ isValid: true,
96
+ });
97
+ expect(asserts.enum(['test', 'example'], ['test', 'example'], baseLocation)).toEqual({
98
+ isValid: true,
99
+ });
100
+ expect(asserts.enum(['test', 'example', 'foo'], ['test', 'example'], baseLocation)).toEqual(
101
+ { isValid: false, location: baseLocation.child('foo').key() }
102
+ );
103
+ expect(asserts.enum('test', ['foo', 'example'], baseLocation)).toEqual({
104
+ isValid: false,
105
+ location: baseLocation,
106
+ });
107
+ expect(asserts.enum(['test', 'foo'], ['test', 'example'], baseLocation)).toEqual({
108
+ isValid: false,
109
+ location: baseLocation.child('foo').key(),
110
+ });
53
111
  });
54
112
  });
55
113
 
56
114
  describe('defined', () => {
57
115
  it('value should be defined', () => {
58
- expect(asserts.defined('test', true, baseLocation)).toEqual({ isValid: true, location: baseLocation });
59
- expect(asserts.defined(undefined, true, baseLocation)).toEqual({ isValid: false, location: baseLocation });
116
+ expect(asserts.defined('test', true, baseLocation)).toEqual({
117
+ isValid: true,
118
+ location: baseLocation,
119
+ });
120
+ expect(asserts.defined(undefined, true, baseLocation)).toEqual({
121
+ isValid: false,
122
+ location: baseLocation,
123
+ });
60
124
  });
61
125
  it('value should be undefined', () => {
62
- expect(asserts.defined(undefined, false, baseLocation)).toEqual({ isValid: true, location: baseLocation });
63
- expect(asserts.defined('test', false, baseLocation)).toEqual({ isValid: false, location: baseLocation });
126
+ expect(asserts.defined(undefined, false, baseLocation)).toEqual({
127
+ isValid: true,
128
+ location: baseLocation,
129
+ });
130
+ expect(asserts.defined('test', false, baseLocation)).toEqual({
131
+ isValid: false,
132
+ location: baseLocation,
133
+ });
64
134
  });
65
135
  });
66
136
 
67
137
  describe('undefined', () => {
68
138
  it('value should be undefined', () => {
69
- expect(asserts.undefined(undefined, true, baseLocation)).toEqual({ isValid: true, location: baseLocation });
70
- expect(asserts.undefined('test', true, baseLocation)).toEqual({ isValid: false, location: baseLocation });
139
+ expect(asserts.undefined(undefined, true, baseLocation)).toEqual({
140
+ isValid: true,
141
+ location: baseLocation,
142
+ });
143
+ expect(asserts.undefined('test', true, baseLocation)).toEqual({
144
+ isValid: false,
145
+ location: baseLocation,
146
+ });
71
147
  });
72
148
  it('value should be defined', () => {
73
- expect(asserts.undefined('test', false, baseLocation)).toEqual({ isValid: true, location: baseLocation });
74
- expect(asserts.undefined(undefined, false, baseLocation)).toEqual({ isValid: false, location: baseLocation });
149
+ expect(asserts.undefined('test', false, baseLocation)).toEqual({
150
+ isValid: true,
151
+ location: baseLocation,
152
+ });
153
+ expect(asserts.undefined(undefined, false, baseLocation)).toEqual({
154
+ isValid: false,
155
+ location: baseLocation,
156
+ });
75
157
  });
76
158
  });
77
159
 
78
160
  describe('required', () => {
79
161
  it('values should be required', () => {
80
- expect(asserts.required(['one', 'two', 'three'], ['one', 'two'], baseLocation)).toEqual({ isValid: true });
81
- expect(asserts.required(['one', 'two'], ['one', 'two', 'three'], baseLocation)).toEqual({ isValid: false, location: baseLocation.key() });
162
+ expect(asserts.required(['one', 'two', 'three'], ['one', 'two'], baseLocation)).toEqual({
163
+ isValid: true,
164
+ });
165
+ expect(asserts.required(['one', 'two'], ['one', 'two', 'three'], baseLocation)).toEqual({
166
+ isValid: false,
167
+ location: baseLocation.key(),
168
+ });
82
169
  });
83
170
  });
84
171
 
85
172
  describe('nonEmpty', () => {
86
173
  it('value should not be empty', () => {
87
- expect(asserts.nonEmpty('test', true, baseLocation)).toEqual({ isValid: true, location: baseLocation });
88
- expect(asserts.nonEmpty('', true, baseLocation)).toEqual({ isValid: false, location: baseLocation });
89
- expect(asserts.nonEmpty(null, true, baseLocation)).toEqual({ isValid: false, location: baseLocation });
90
- expect(asserts.nonEmpty(undefined, true, baseLocation)).toEqual({ isValid: false, location: baseLocation });
174
+ expect(asserts.nonEmpty('test', true, baseLocation)).toEqual({
175
+ isValid: true,
176
+ location: baseLocation,
177
+ });
178
+ expect(asserts.nonEmpty('', true, baseLocation)).toEqual({
179
+ isValid: false,
180
+ location: baseLocation,
181
+ });
182
+ expect(asserts.nonEmpty(null, true, baseLocation)).toEqual({
183
+ isValid: false,
184
+ location: baseLocation,
185
+ });
186
+ expect(asserts.nonEmpty(undefined, true, baseLocation)).toEqual({
187
+ isValid: false,
188
+ location: baseLocation,
189
+ });
91
190
  });
92
191
  it('value should be empty', () => {
93
- expect(asserts.nonEmpty('', false, baseLocation)).toEqual({ isValid: true, location: baseLocation });
94
- expect(asserts.nonEmpty(null, false, baseLocation)).toEqual({ isValid: true, location: baseLocation });
95
- expect(asserts.nonEmpty(undefined, false, baseLocation)).toEqual({ isValid: true, location: baseLocation });
96
- expect(asserts.nonEmpty('test', false, baseLocation)).toEqual({ isValid: false, location: baseLocation });
192
+ expect(asserts.nonEmpty('', false, baseLocation)).toEqual({
193
+ isValid: true,
194
+ location: baseLocation,
195
+ });
196
+ expect(asserts.nonEmpty(null, false, baseLocation)).toEqual({
197
+ isValid: true,
198
+ location: baseLocation,
199
+ });
200
+ expect(asserts.nonEmpty(undefined, false, baseLocation)).toEqual({
201
+ isValid: true,
202
+ location: baseLocation,
203
+ });
204
+ expect(asserts.nonEmpty('test', false, baseLocation)).toEqual({
205
+ isValid: false,
206
+ location: baseLocation,
207
+ });
97
208
  });
98
209
  });
99
210
 
100
211
  describe('minLength', () => {
101
212
  it('value should have less or equal than 5 symbols length', () => {
102
- expect(asserts.minLength('test', 5, baseLocation)).toEqual({ isValid: false, location: baseLocation });
103
- expect(asserts.minLength([1, 2, 3, 4], 5, baseLocation)).toEqual({ isValid: false, location: baseLocation });
104
- expect(asserts.minLength([1, 2, 3, 4, 5], 5, baseLocation)).toEqual({ isValid: true, location: baseLocation });
105
- expect(asserts.minLength([1, 2, 3, 4, 5, 6], 5, baseLocation)).toEqual({ isValid: true, location: baseLocation });
106
- expect(asserts.minLength('example', 5, baseLocation)).toEqual({ isValid: true, location: baseLocation });
107
- expect(asserts.minLength([], 5, baseLocation)).toEqual({ isValid: false, location: baseLocation });
108
- expect(asserts.minLength('', 5, baseLocation)).toEqual({ isValid: false, location: baseLocation });
213
+ expect(asserts.minLength('test', 5, baseLocation)).toEqual({
214
+ isValid: false,
215
+ location: baseLocation,
216
+ });
217
+ expect(asserts.minLength([1, 2, 3, 4], 5, baseLocation)).toEqual({
218
+ isValid: false,
219
+ location: baseLocation,
220
+ });
221
+ expect(asserts.minLength([1, 2, 3, 4, 5], 5, baseLocation)).toEqual({
222
+ isValid: true,
223
+ location: baseLocation,
224
+ });
225
+ expect(asserts.minLength([1, 2, 3, 4, 5, 6], 5, baseLocation)).toEqual({
226
+ isValid: true,
227
+ location: baseLocation,
228
+ });
229
+ expect(asserts.minLength('example', 5, baseLocation)).toEqual({
230
+ isValid: true,
231
+ location: baseLocation,
232
+ });
233
+ expect(asserts.minLength([], 5, baseLocation)).toEqual({
234
+ isValid: false,
235
+ location: baseLocation,
236
+ });
237
+ expect(asserts.minLength('', 5, baseLocation)).toEqual({
238
+ isValid: false,
239
+ location: baseLocation,
240
+ });
109
241
  });
110
242
  });
111
243
 
112
244
  describe('maxLength', () => {
113
245
  it('value should have more or equal than 5 symbols length', () => {
114
- expect(asserts.maxLength('test', 5, baseLocation)).toEqual({ isValid: true, location: baseLocation });
115
- expect(asserts.maxLength([1, 2, 3, 4], 5, baseLocation)).toEqual({ isValid: true, location: baseLocation });
116
- expect(asserts.maxLength([1, 2, 3, 4, 5], 5, baseLocation)).toEqual({ isValid: true, location: baseLocation });
117
- expect(asserts.maxLength([1, 2, 3, 4, 5, 6], 5, baseLocation)).toEqual({ isValid: false, location: baseLocation });
118
- expect(asserts.maxLength('example', 5, baseLocation)).toEqual({ isValid: false, location: baseLocation });
119
- expect(asserts.maxLength([], 5, baseLocation)).toEqual({ isValid: true, location: baseLocation });
120
- expect(asserts.maxLength('', 5, baseLocation)).toEqual({ isValid: true, location: baseLocation });
246
+ expect(asserts.maxLength('test', 5, baseLocation)).toEqual({
247
+ isValid: true,
248
+ location: baseLocation,
249
+ });
250
+ expect(asserts.maxLength([1, 2, 3, 4], 5, baseLocation)).toEqual({
251
+ isValid: true,
252
+ location: baseLocation,
253
+ });
254
+ expect(asserts.maxLength([1, 2, 3, 4, 5], 5, baseLocation)).toEqual({
255
+ isValid: true,
256
+ location: baseLocation,
257
+ });
258
+ expect(asserts.maxLength([1, 2, 3, 4, 5, 6], 5, baseLocation)).toEqual({
259
+ isValid: false,
260
+ location: baseLocation,
261
+ });
262
+ expect(asserts.maxLength('example', 5, baseLocation)).toEqual({
263
+ isValid: false,
264
+ location: baseLocation,
265
+ });
266
+ expect(asserts.maxLength([], 5, baseLocation)).toEqual({
267
+ isValid: true,
268
+ location: baseLocation,
269
+ });
270
+ expect(asserts.maxLength('', 5, baseLocation)).toEqual({
271
+ isValid: true,
272
+ location: baseLocation,
273
+ });
121
274
  });
122
275
  });
123
276
 
124
277
  describe('casing', () => {
125
278
  it('value should be camelCase', () => {
126
- expect(asserts.casing(['testExample', 'fooBar'], 'camelCase', baseLocation)).toEqual({ isValid: true });
127
- expect(asserts.casing(['testExample', 'FooBar'], 'camelCase', baseLocation)).toEqual({ isValid: false, location: baseLocation.child('FooBar').key() });
279
+ expect(asserts.casing(['testExample', 'fooBar'], 'camelCase', baseLocation)).toEqual({
280
+ isValid: true,
281
+ });
282
+ expect(asserts.casing(['testExample', 'FooBar'], 'camelCase', baseLocation)).toEqual({
283
+ isValid: false,
284
+ location: baseLocation.child('FooBar').key(),
285
+ });
128
286
  expect(asserts.casing('testExample', 'camelCase', baseLocation)).toEqual({ isValid: true });
129
- expect(asserts.casing('TestExample', 'camelCase', baseLocation)).toEqual({ isValid: false, location: baseLocation });
130
- expect(asserts.casing('test-example', 'camelCase', baseLocation)).toEqual({ isValid: false, location: baseLocation });
131
- expect(asserts.casing('test_example', 'camelCase', baseLocation)).toEqual({ isValid: false, location: baseLocation });
287
+ expect(asserts.casing('TestExample', 'camelCase', baseLocation)).toEqual({
288
+ isValid: false,
289
+ location: baseLocation,
290
+ });
291
+ expect(asserts.casing('test-example', 'camelCase', baseLocation)).toEqual({
292
+ isValid: false,
293
+ location: baseLocation,
294
+ });
295
+ expect(asserts.casing('test_example', 'camelCase', baseLocation)).toEqual({
296
+ isValid: false,
297
+ location: baseLocation,
298
+ });
132
299
  });
133
300
  it('value should be PascalCase', () => {
134
- expect(asserts.casing('TestExample', 'PascalCase', baseLocation)).toEqual({ isValid: true });
135
- expect(asserts.casing(['TestExample', 'FooBar'], 'PascalCase', baseLocation)).toEqual({ isValid: true });
136
- expect(asserts.casing(['TestExample', 'fooBar'], 'PascalCase', baseLocation)).toEqual({ isValid: false, location: baseLocation.child('fooBar').key() });
137
- expect(asserts.casing('testExample', 'PascalCase', baseLocation)).toEqual({ isValid: false, location: baseLocation });
138
- expect(asserts.casing('test-example', 'PascalCase', baseLocation)).toEqual({ isValid: false, location: baseLocation });
139
- expect(asserts.casing('test_example', 'PascalCase', baseLocation)).toEqual({ isValid: false, location: baseLocation });
301
+ expect(asserts.casing('TestExample', 'PascalCase', baseLocation)).toEqual({
302
+ isValid: true,
303
+ });
304
+ expect(asserts.casing(['TestExample', 'FooBar'], 'PascalCase', baseLocation)).toEqual({
305
+ isValid: true,
306
+ });
307
+ expect(asserts.casing(['TestExample', 'fooBar'], 'PascalCase', baseLocation)).toEqual({
308
+ isValid: false,
309
+ location: baseLocation.child('fooBar').key(),
310
+ });
311
+ expect(asserts.casing('testExample', 'PascalCase', baseLocation)).toEqual({
312
+ isValid: false,
313
+ location: baseLocation,
314
+ });
315
+ expect(asserts.casing('test-example', 'PascalCase', baseLocation)).toEqual({
316
+ isValid: false,
317
+ location: baseLocation,
318
+ });
319
+ expect(asserts.casing('test_example', 'PascalCase', baseLocation)).toEqual({
320
+ isValid: false,
321
+ location: baseLocation,
322
+ });
140
323
  });
141
324
  it('value should be kebab-case', () => {
142
- expect(asserts.casing('test-example', 'kebab-case', baseLocation)).toEqual({ isValid: true });
143
- expect(asserts.casing(['test-example', 'foo-bar'], 'kebab-case', baseLocation)).toEqual({ isValid: true });
144
- expect(asserts.casing(['test-example', 'foo_bar'], 'kebab-case', baseLocation)).toEqual({ isValid: false, location: baseLocation.child('foo_bar').key() });
145
- expect(asserts.casing('testExample', 'kebab-case', baseLocation)).toEqual({ isValid: false, location: baseLocation });
146
- expect(asserts.casing('TestExample', 'kebab-case', baseLocation)).toEqual({ isValid: false, location: baseLocation });
147
- expect(asserts.casing('test_example', 'kebab-case', baseLocation)).toEqual({ isValid: false, location: baseLocation });
325
+ expect(asserts.casing('test-example', 'kebab-case', baseLocation)).toEqual({
326
+ isValid: true,
327
+ });
328
+ expect(asserts.casing(['test-example', 'foo-bar'], 'kebab-case', baseLocation)).toEqual({
329
+ isValid: true,
330
+ });
331
+ expect(asserts.casing(['test-example', 'foo_bar'], 'kebab-case', baseLocation)).toEqual({
332
+ isValid: false,
333
+ location: baseLocation.child('foo_bar').key(),
334
+ });
335
+ expect(asserts.casing('testExample', 'kebab-case', baseLocation)).toEqual({
336
+ isValid: false,
337
+ location: baseLocation,
338
+ });
339
+ expect(asserts.casing('TestExample', 'kebab-case', baseLocation)).toEqual({
340
+ isValid: false,
341
+ location: baseLocation,
342
+ });
343
+ expect(asserts.casing('test_example', 'kebab-case', baseLocation)).toEqual({
344
+ isValid: false,
345
+ location: baseLocation,
346
+ });
148
347
  });
149
348
  it('value should be snake_case', () => {
150
- expect(asserts.casing('test_example', 'snake_case', baseLocation)).toEqual({ isValid: true });
151
- expect(asserts.casing(['test_example', 'foo_bar'], 'snake_case', baseLocation)).toEqual({ isValid: true });
152
- expect(asserts.casing(['test_example', 'foo-bar'], 'snake_case', baseLocation)).toEqual({ isValid: false, location: baseLocation.child('foo-bar').key() });
153
- expect(asserts.casing('testExample', 'snake_case', baseLocation)).toEqual({ isValid: false, location: baseLocation });
154
- expect(asserts.casing('TestExample', 'snake_case', baseLocation)).toEqual({ isValid: false, location: baseLocation });
155
- expect(asserts.casing('test-example', 'snake_case', baseLocation)).toEqual({ isValid: false, location: baseLocation });
349
+ expect(asserts.casing('test_example', 'snake_case', baseLocation)).toEqual({
350
+ isValid: true,
351
+ });
352
+ expect(asserts.casing(['test_example', 'foo_bar'], 'snake_case', baseLocation)).toEqual({
353
+ isValid: true,
354
+ });
355
+ expect(asserts.casing(['test_example', 'foo-bar'], 'snake_case', baseLocation)).toEqual({
356
+ isValid: false,
357
+ location: baseLocation.child('foo-bar').key(),
358
+ });
359
+ expect(asserts.casing('testExample', 'snake_case', baseLocation)).toEqual({
360
+ isValid: false,
361
+ location: baseLocation,
362
+ });
363
+ expect(asserts.casing('TestExample', 'snake_case', baseLocation)).toEqual({
364
+ isValid: false,
365
+ location: baseLocation,
366
+ });
367
+ expect(asserts.casing('test-example', 'snake_case', baseLocation)).toEqual({
368
+ isValid: false,
369
+ location: baseLocation,
370
+ });
156
371
  });
157
372
  it('value should be MACRO_CASE', () => {
158
- expect(asserts.casing('TEST_EXAMPLE', 'MACRO_CASE', baseLocation)).toEqual({ isValid: true });
159
- expect(asserts.casing(['TEST_EXAMPLE', 'FOO_BAR'], 'MACRO_CASE', baseLocation)).toEqual({ isValid: true });
160
- expect(asserts.casing(['TEST_EXAMPLE', 'FOO-BAR'], 'MACRO_CASE', baseLocation)).toEqual({ isValid: false, location: baseLocation.child('FOO-BAR').key() });
161
- expect(asserts.casing('TEST_EXAMPLE_', 'MACRO_CASE', baseLocation)).toEqual({ isValid: false, location: baseLocation });
162
- expect(asserts.casing('_TEST_EXAMPLE', 'MACRO_CASE', baseLocation)).toEqual({ isValid: false, location: baseLocation });
163
- expect(asserts.casing('TEST__EXAMPLE', 'MACRO_CASE', baseLocation)).toEqual({ isValid: false, location: baseLocation });
164
- expect(asserts.casing('TEST-EXAMPLE', 'MACRO_CASE', baseLocation)).toEqual({ isValid: false, location: baseLocation });
165
- expect(asserts.casing('testExample', 'MACRO_CASE', baseLocation)).toEqual({ isValid: false, location: baseLocation });
166
- expect(asserts.casing('TestExample', 'MACRO_CASE', baseLocation)).toEqual({ isValid: false, location: baseLocation });
167
- expect(asserts.casing('test-example', 'MACRO_CASE', baseLocation)).toEqual({ isValid: false, location: baseLocation });
373
+ expect(asserts.casing('TEST_EXAMPLE', 'MACRO_CASE', baseLocation)).toEqual({
374
+ isValid: true,
375
+ });
376
+ expect(asserts.casing(['TEST_EXAMPLE', 'FOO_BAR'], 'MACRO_CASE', baseLocation)).toEqual({
377
+ isValid: true,
378
+ });
379
+ expect(asserts.casing(['TEST_EXAMPLE', 'FOO-BAR'], 'MACRO_CASE', baseLocation)).toEqual({
380
+ isValid: false,
381
+ location: baseLocation.child('FOO-BAR').key(),
382
+ });
383
+ expect(asserts.casing('TEST_EXAMPLE_', 'MACRO_CASE', baseLocation)).toEqual({
384
+ isValid: false,
385
+ location: baseLocation,
386
+ });
387
+ expect(asserts.casing('_TEST_EXAMPLE', 'MACRO_CASE', baseLocation)).toEqual({
388
+ isValid: false,
389
+ location: baseLocation,
390
+ });
391
+ expect(asserts.casing('TEST__EXAMPLE', 'MACRO_CASE', baseLocation)).toEqual({
392
+ isValid: false,
393
+ location: baseLocation,
394
+ });
395
+ expect(asserts.casing('TEST-EXAMPLE', 'MACRO_CASE', baseLocation)).toEqual({
396
+ isValid: false,
397
+ location: baseLocation,
398
+ });
399
+ expect(asserts.casing('testExample', 'MACRO_CASE', baseLocation)).toEqual({
400
+ isValid: false,
401
+ location: baseLocation,
402
+ });
403
+ expect(asserts.casing('TestExample', 'MACRO_CASE', baseLocation)).toEqual({
404
+ isValid: false,
405
+ location: baseLocation,
406
+ });
407
+ expect(asserts.casing('test-example', 'MACRO_CASE', baseLocation)).toEqual({
408
+ isValid: false,
409
+ location: baseLocation,
410
+ });
168
411
  });
169
412
  it('value should be COBOL-CASE', () => {
170
- expect(asserts.casing('TEST-EXAMPLE', 'COBOL-CASE', baseLocation)).toEqual({ isValid: true });
171
- expect(asserts.casing(['TEST-EXAMPLE', 'FOO-BAR'], 'COBOL-CASE', baseLocation)).toEqual({ isValid: true });
172
- expect(asserts.casing(['TEST-EXAMPLE', 'FOO_BAR'], 'COBOL-CASE', baseLocation)).toEqual({ isValid: false, location: baseLocation.child('FOO_BAR').key() });
173
- expect(asserts.casing('TEST-EXAMPLE-', 'COBOL-CASE', baseLocation)).toEqual({ isValid: false, location: baseLocation });
174
- expect(asserts.casing('0TEST-EXAMPLE', 'COBOL-CASE', baseLocation)).toEqual({ isValid: false, location: baseLocation });
175
- expect(asserts.casing('-TEST-EXAMPLE', 'COBOL-CASE', baseLocation)).toEqual({ isValid: false, location: baseLocation });
176
- expect(asserts.casing('TEST--EXAMPLE', 'COBOL-CASE', baseLocation)).toEqual({ isValid: false, location: baseLocation });
177
- expect(asserts.casing('TEST_EXAMPLE', 'COBOL-CASE', baseLocation)).toEqual({ isValid: false, location: baseLocation });
178
- expect(asserts.casing('testExample', 'COBOL-CASE', baseLocation)).toEqual({ isValid: false, location: baseLocation });
179
- expect(asserts.casing('TestExample', 'COBOL-CASE', baseLocation)).toEqual({ isValid: false, location: baseLocation });
180
- expect(asserts.casing('test-example', 'COBOL-CASE', baseLocation)).toEqual({ isValid: false, location: baseLocation });
413
+ expect(asserts.casing('TEST-EXAMPLE', 'COBOL-CASE', baseLocation)).toEqual({
414
+ isValid: true,
415
+ });
416
+ expect(asserts.casing(['TEST-EXAMPLE', 'FOO-BAR'], 'COBOL-CASE', baseLocation)).toEqual({
417
+ isValid: true,
418
+ });
419
+ expect(asserts.casing(['TEST-EXAMPLE', 'FOO_BAR'], 'COBOL-CASE', baseLocation)).toEqual({
420
+ isValid: false,
421
+ location: baseLocation.child('FOO_BAR').key(),
422
+ });
423
+ expect(asserts.casing('TEST-EXAMPLE-', 'COBOL-CASE', baseLocation)).toEqual({
424
+ isValid: false,
425
+ location: baseLocation,
426
+ });
427
+ expect(asserts.casing('0TEST-EXAMPLE', 'COBOL-CASE', baseLocation)).toEqual({
428
+ isValid: false,
429
+ location: baseLocation,
430
+ });
431
+ expect(asserts.casing('-TEST-EXAMPLE', 'COBOL-CASE', baseLocation)).toEqual({
432
+ isValid: false,
433
+ location: baseLocation,
434
+ });
435
+ expect(asserts.casing('TEST--EXAMPLE', 'COBOL-CASE', baseLocation)).toEqual({
436
+ isValid: false,
437
+ location: baseLocation,
438
+ });
439
+ expect(asserts.casing('TEST_EXAMPLE', 'COBOL-CASE', baseLocation)).toEqual({
440
+ isValid: false,
441
+ location: baseLocation,
442
+ });
443
+ expect(asserts.casing('testExample', 'COBOL-CASE', baseLocation)).toEqual({
444
+ isValid: false,
445
+ location: baseLocation,
446
+ });
447
+ expect(asserts.casing('TestExample', 'COBOL-CASE', baseLocation)).toEqual({
448
+ isValid: false,
449
+ location: baseLocation,
450
+ });
451
+ expect(asserts.casing('test-example', 'COBOL-CASE', baseLocation)).toEqual({
452
+ isValid: false,
453
+ location: baseLocation,
454
+ });
181
455
  });
182
456
  it('value should be flatcase', () => {
183
457
  expect(asserts.casing('testexample', 'flatcase', baseLocation)).toEqual({ isValid: true });
184
- expect(asserts.casing(['testexample', 'foobar'], 'flatcase', baseLocation)).toEqual({ isValid: true });
185
- expect(asserts.casing(['testexample', 'foo_bar'], 'flatcase', baseLocation)).toEqual({ isValid: false, location: baseLocation.child('foo_bar').key() });
186
- expect(asserts.casing('testexample_', 'flatcase', baseLocation)).toEqual({ isValid: false, location: baseLocation });
187
- expect(asserts.casing('0testexample', 'flatcase', baseLocation)).toEqual({ isValid: false, location: baseLocation });
188
- expect(asserts.casing('testExample', 'flatcase', baseLocation)).toEqual({ isValid: false, location: baseLocation });
189
- expect(asserts.casing('TestExample', 'flatcase', baseLocation)).toEqual({ isValid: false, location: baseLocation });
190
- expect(asserts.casing('test-example', 'flatcase', baseLocation)).toEqual({ isValid: false, location: baseLocation });
458
+ expect(asserts.casing(['testexample', 'foobar'], 'flatcase', baseLocation)).toEqual({
459
+ isValid: true,
460
+ });
461
+ expect(asserts.casing(['testexample', 'foo_bar'], 'flatcase', baseLocation)).toEqual({
462
+ isValid: false,
463
+ location: baseLocation.child('foo_bar').key(),
464
+ });
465
+ expect(asserts.casing('testexample_', 'flatcase', baseLocation)).toEqual({
466
+ isValid: false,
467
+ location: baseLocation,
468
+ });
469
+ expect(asserts.casing('0testexample', 'flatcase', baseLocation)).toEqual({
470
+ isValid: false,
471
+ location: baseLocation,
472
+ });
473
+ expect(asserts.casing('testExample', 'flatcase', baseLocation)).toEqual({
474
+ isValid: false,
475
+ location: baseLocation,
476
+ });
477
+ expect(asserts.casing('TestExample', 'flatcase', baseLocation)).toEqual({
478
+ isValid: false,
479
+ location: baseLocation,
480
+ });
481
+ expect(asserts.casing('test-example', 'flatcase', baseLocation)).toEqual({
482
+ isValid: false,
483
+ location: baseLocation,
484
+ });
191
485
  });
192
486
  });
193
487
 
194
488
  describe.skip('sortOrder', () => {
195
489
  it('value should be ordered in ASC direction', () => {
196
- expect(asserts.sortOrder(['example', 'foo', 'test'], 'asc', baseLocation)).toEqual({ isValid: true, location: baseLocation });
197
- expect(asserts.sortOrder(['example', 'foo', 'test'], { direction: 'asc' }, baseLocation)).toEqual({ isValid: true, location: baseLocation });
198
- expect(asserts.sortOrder(['example'], 'asc', baseLocation)).toEqual({ isValid: true, location: baseLocation });
199
- expect(asserts.sortOrder(['example', 'test', 'foo'], 'asc', baseLocation)).toEqual({ isValid: false, location: baseLocation });
200
- expect(asserts.sortOrder(['example', 'foo', 'test'], 'desc', baseLocation)).toEqual({ isValid: false, location: baseLocation });
201
- expect(asserts.sortOrder([{ name: 'bar' }, { name: 'baz' }, { name: 'foo' }], { direction: 'asc', property: 'name' }, baseLocation)).toEqual({ isValid: true, location: baseLocation });
202
- expect(asserts.sortOrder([{ name: 'bar' }, { name: 'baz' }, { name: 'foo' }], { direction: 'desc', property: 'name' }, baseLocation)).toEqual({ isValid: false, location: baseLocation });
490
+ expect(asserts.sortOrder(['example', 'foo', 'test'], 'asc', baseLocation)).toEqual({
491
+ isValid: true,
492
+ location: baseLocation,
493
+ });
494
+ expect(
495
+ asserts.sortOrder(['example', 'foo', 'test'], { direction: 'asc' }, baseLocation)
496
+ ).toEqual({ isValid: true, location: baseLocation });
497
+ expect(asserts.sortOrder(['example'], 'asc', baseLocation)).toEqual({
498
+ isValid: true,
499
+ location: baseLocation,
500
+ });
501
+ expect(asserts.sortOrder(['example', 'test', 'foo'], 'asc', baseLocation)).toEqual({
502
+ isValid: false,
503
+ location: baseLocation,
504
+ });
505
+ expect(asserts.sortOrder(['example', 'foo', 'test'], 'desc', baseLocation)).toEqual({
506
+ isValid: false,
507
+ location: baseLocation,
508
+ });
509
+ expect(
510
+ asserts.sortOrder(
511
+ [{ name: 'bar' }, { name: 'baz' }, { name: 'foo' }],
512
+ { direction: 'asc', property: 'name' },
513
+ baseLocation
514
+ )
515
+ ).toEqual({ isValid: true, location: baseLocation });
516
+ expect(
517
+ asserts.sortOrder(
518
+ [{ name: 'bar' }, { name: 'baz' }, { name: 'foo' }],
519
+ { direction: 'desc', property: 'name' },
520
+ baseLocation
521
+ )
522
+ ).toEqual({ isValid: false, location: baseLocation });
203
523
  });
204
524
  it('value should be ordered in DESC direction', () => {
205
- expect(asserts.sortOrder(['test', 'foo', 'example'], 'desc', baseLocation)).toEqual({ isValid: true, location: baseLocation });
206
- expect(asserts.sortOrder(['test', 'foo', 'example'], { direction: 'desc' }, baseLocation)).toEqual({ isValid: true, location: baseLocation });
207
- expect(asserts.sortOrder(['example'], 'desc', baseLocation)).toEqual({ isValid: true, location: baseLocation });
208
- expect(asserts.sortOrder(['example', 'test', 'foo'], 'desc', baseLocation)).toEqual({ isValid: false, location: baseLocation });
209
- expect(asserts.sortOrder(['test', 'foo', 'example'], 'asc', baseLocation)).toEqual({ isValid: false, location: baseLocation });
210
- expect(asserts.sortOrder([{ name: 'foo' }, { name: 'baz' }, { name: 'bar' }], { direction: 'desc', property: 'name' }, baseLocation)).toEqual({ isValid: true, location: baseLocation });
211
- expect(asserts.sortOrder([{ name: 'foo' }, { name: 'baz' }, { name: 'bar' }], { direction: 'asc', property: 'name' }, baseLocation)).toEqual({ isValid: false, location: baseLocation });
525
+ expect(asserts.sortOrder(['test', 'foo', 'example'], 'desc', baseLocation)).toEqual({
526
+ isValid: true,
527
+ location: baseLocation,
528
+ });
529
+ expect(
530
+ asserts.sortOrder(['test', 'foo', 'example'], { direction: 'desc' }, baseLocation)
531
+ ).toEqual({ isValid: true, location: baseLocation });
532
+ expect(asserts.sortOrder(['example'], 'desc', baseLocation)).toEqual({
533
+ isValid: true,
534
+ location: baseLocation,
535
+ });
536
+ expect(asserts.sortOrder(['example', 'test', 'foo'], 'desc', baseLocation)).toEqual({
537
+ isValid: false,
538
+ location: baseLocation,
539
+ });
540
+ expect(asserts.sortOrder(['test', 'foo', 'example'], 'asc', baseLocation)).toEqual({
541
+ isValid: false,
542
+ location: baseLocation,
543
+ });
544
+ expect(
545
+ asserts.sortOrder(
546
+ [{ name: 'foo' }, { name: 'baz' }, { name: 'bar' }],
547
+ { direction: 'desc', property: 'name' },
548
+ baseLocation
549
+ )
550
+ ).toEqual({ isValid: true, location: baseLocation });
551
+ expect(
552
+ asserts.sortOrder(
553
+ [{ name: 'foo' }, { name: 'baz' }, { name: 'bar' }],
554
+ { direction: 'asc', property: 'name' },
555
+ baseLocation
556
+ )
557
+ ).toEqual({ isValid: false, location: baseLocation });
212
558
  });
213
559
  });
214
560
 
215
561
  describe('mutuallyExclusive', () => {
216
562
  it('node should not have more than one property from predefined list', () => {
217
- expect(asserts.mutuallyExclusive(Object.keys(fakeNode), ['foo', 'test'], baseLocation)).toEqual({ isValid: true, location: baseLocation.key() });
218
- expect(asserts.mutuallyExclusive(Object.keys(fakeNode), [], baseLocation)).toEqual({ isValid: true, location: baseLocation.key() });
219
- expect(asserts.mutuallyExclusive(Object.keys(fakeNode), ['foo', 'bar'], baseLocation)).toEqual({ isValid: false, location: baseLocation.key() });
220
- expect(asserts.mutuallyExclusive(Object.keys(fakeNode), ['foo', 'bar', 'test'], baseLocation)).toEqual({ isValid: false, location: baseLocation.key() });
563
+ expect(
564
+ asserts.mutuallyExclusive(Object.keys(fakeNode), ['foo', 'test'], baseLocation)
565
+ ).toEqual({ isValid: true, location: baseLocation.key() });
566
+ expect(asserts.mutuallyExclusive(Object.keys(fakeNode), [], baseLocation)).toEqual({
567
+ isValid: true,
568
+ location: baseLocation.key(),
569
+ });
570
+ expect(
571
+ asserts.mutuallyExclusive(Object.keys(fakeNode), ['foo', 'bar'], baseLocation)
572
+ ).toEqual({ isValid: false, location: baseLocation.key() });
573
+ expect(
574
+ asserts.mutuallyExclusive(Object.keys(fakeNode), ['foo', 'bar', 'test'], baseLocation)
575
+ ).toEqual({ isValid: false, location: baseLocation.key() });
221
576
  });
222
577
  });
223
578
 
224
579
  describe('mutuallyRequired', () => {
225
580
  it('node should have all the properties from predefined list', () => {
226
- expect(asserts.mutuallyRequired(Object.keys(fakeNode), ['foo', 'bar'], baseLocation)).toEqual({ isValid: true, location: baseLocation.key() });
227
- expect(asserts.mutuallyRequired(Object.keys(fakeNode), ['foo', 'bar', 'baz'], baseLocation)).toEqual({ isValid: true, location: baseLocation.key() });
228
- expect(asserts.mutuallyRequired(Object.keys(fakeNode), [], baseLocation)).toEqual({ isValid: true, location: baseLocation.key() });
229
- expect(asserts.mutuallyRequired(Object.keys(fakeNode), ['foo', 'test'], baseLocation)).toEqual({ isValid: false, location: baseLocation.key() });
230
- expect(asserts.mutuallyRequired(Object.keys(fakeNode), ['foo', 'bar', 'test'], baseLocation)).toEqual({ isValid: false, location: baseLocation.key() });
581
+ expect(
582
+ asserts.mutuallyRequired(Object.keys(fakeNode), ['foo', 'bar'], baseLocation)
583
+ ).toEqual({ isValid: true, location: baseLocation.key() });
584
+ expect(
585
+ asserts.mutuallyRequired(Object.keys(fakeNode), ['foo', 'bar', 'baz'], baseLocation)
586
+ ).toEqual({ isValid: true, location: baseLocation.key() });
587
+ expect(asserts.mutuallyRequired(Object.keys(fakeNode), [], baseLocation)).toEqual({
588
+ isValid: true,
589
+ location: baseLocation.key(),
590
+ });
591
+ expect(
592
+ asserts.mutuallyRequired(Object.keys(fakeNode), ['foo', 'test'], baseLocation)
593
+ ).toEqual({ isValid: false, location: baseLocation.key() });
594
+ expect(
595
+ asserts.mutuallyRequired(Object.keys(fakeNode), ['foo', 'bar', 'test'], baseLocation)
596
+ ).toEqual({ isValid: false, location: baseLocation.key() });
231
597
  });
232
598
  });
233
599
 
234
600
  describe('requireAny', () => {
235
601
  it('node must have at least one property from predefined list', () => {
236
- expect(asserts.requireAny(Object.keys(fakeNode), ['foo', 'test'], baseLocation)).toEqual({ isValid: true, location: baseLocation.key() });
237
- expect(asserts.requireAny(Object.keys(fakeNode), ['test', 'bar'], baseLocation)).toEqual({ isValid: true, location: baseLocation.key() });
238
- expect(asserts.requireAny(Object.keys(fakeNode), [], baseLocation)).toEqual({ isValid: false, location: baseLocation.key() });
239
- expect(asserts.requireAny(Object.keys(fakeNode), ['test', 'test1'], baseLocation)).toEqual({ isValid: false, location: baseLocation.key() });
240
- expect(asserts.requireAny(Object.keys(fakeNode), ['foo', 'bar'], baseLocation)).toEqual({ isValid: true, location: baseLocation.key() });
241
- expect(asserts.requireAny(Object.keys(fakeNode), ['foo', 'bar', 'test'], baseLocation)).toEqual({ isValid: true, location: baseLocation.key() });
602
+ expect(asserts.requireAny(Object.keys(fakeNode), ['foo', 'test'], baseLocation)).toEqual({
603
+ isValid: true,
604
+ location: baseLocation.key(),
605
+ });
606
+ expect(asserts.requireAny(Object.keys(fakeNode), ['test', 'bar'], baseLocation)).toEqual({
607
+ isValid: true,
608
+ location: baseLocation.key(),
609
+ });
610
+ expect(asserts.requireAny(Object.keys(fakeNode), [], baseLocation)).toEqual({
611
+ isValid: false,
612
+ location: baseLocation.key(),
613
+ });
614
+ expect(asserts.requireAny(Object.keys(fakeNode), ['test', 'test1'], baseLocation)).toEqual({
615
+ isValid: false,
616
+ location: baseLocation.key(),
617
+ });
618
+ expect(asserts.requireAny(Object.keys(fakeNode), ['foo', 'bar'], baseLocation)).toEqual({
619
+ isValid: true,
620
+ location: baseLocation.key(),
621
+ });
622
+ expect(
623
+ asserts.requireAny(Object.keys(fakeNode), ['foo', 'bar', 'test'], baseLocation)
624
+ ).toEqual({ isValid: true, location: baseLocation.key() });
242
625
  });
243
626
  });
244
627
  });