Skip to content
This repository was archived by the owner on Nov 8, 2024. It is now read-only.

Commit 48251fd

Browse files
chore: adapts "actual" namespace in validators
1 parent 4b24fb6 commit 48251fd

File tree

9 files changed

+90
-93
lines changed

9 files changed

+90
-93
lines changed

lib/units/validateBody.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,8 +242,8 @@ function validateBody(expected, actual) {
242242
const validator =
243243
ValidatorClass &&
244244
new ValidatorClass(
245-
actual.body,
246-
usesJsonSchema ? expected.bodySchema : expected.body
245+
usesJsonSchema ? expected.bodySchema : expected.body,
246+
actual.body
247247
);
248248

249249
// Without ".validate()" it cannot evaluate output to result.

lib/units/validateHeaders.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ function validateHeaders(expected, actual) {
2828
expectedType === APIARY_JSON_HEADER_TYPE;
2929

3030
const validator = hasJsonHeaders
31-
? new HeadersJsonExample(values.actual, values.expected)
31+
? new HeadersJsonExample(values.expected, values.actual)
3232
: null;
3333

3434
// if you don't call ".validate()", it never evaluates any results.

lib/validators/headers-json-example.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,17 @@ const getSchema = (json) => {
3838
};
3939

4040
class HeadersJsonExample extends JsonSchema {
41-
constructor(real, expected) {
42-
if (typeof real !== 'object') {
43-
throw new errors.MalformedDataError('Real is not an Object');
41+
constructor(expected, actual) {
42+
if (typeof actual !== 'object') {
43+
throw new errors.MalformedDataError('Actual is not an Object');
4444
}
4545

4646
if (typeof expected !== 'object') {
4747
throw new errors.MalformedDataError('Expected is not an Object');
4848
}
4949

5050
const preparedExpected = prepareHeaders(expected);
51-
const preparedReal = prepareHeaders(real);
51+
const preparedActual = prepareHeaders(actual);
5252
const preparedSchema = getSchema(preparedExpected);
5353

5454
if (preparedSchema && preparedSchema.properties) {
@@ -60,10 +60,10 @@ class HeadersJsonExample extends JsonSchema {
6060
});
6161
}
6262

63-
super(preparedReal, preparedSchema);
63+
super(preparedSchema, preparedActual);
6464

6565
this.expected = preparedExpected;
66-
this.real = preparedReal;
66+
this.actual = preparedActual;
6767
this.schema = preparedSchema;
6868
}
6969

lib/validators/json-example.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ class JsonExample extends JsonSchema {
2626
* @throw {SchemaNotJsonParsableError} when given schema is not a json parsable string or valid json
2727
* @throw {NotEnoughDataError} when at least one of expected data and json schema is not given
2828
*/
29-
constructor(real, expected) {
30-
if (typeof real !== 'string') {
29+
constructor(expected, actual) {
30+
if (typeof actual !== 'string') {
3131
const outError = new errors.MalformedDataError(
32-
'JsonExample validator: provided real data is not string'
32+
'JsonExample validator: provided actual data is not string'
3333
);
34-
outError.data = real;
34+
outError.data = actual;
3535
throw outError;
3636
}
3737

@@ -44,7 +44,7 @@ class JsonExample extends JsonSchema {
4444
}
4545

4646
const schema = getSchema(expected);
47-
super(real, schema);
47+
super(schema, actual);
4848
}
4949
}
5050

lib/validators/json-schema.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,12 @@ const jsonSchemaOptions = {
8080
class JsonSchema {
8181
/**
8282
* Constructs a JsonValidator and validates given data.
83-
* @param {Object | string} data
8483
* @param {Object | string} schema
84+
* @param {Object | string} data
8585
*/
86-
constructor(data, schema) {
87-
this.data = data;
86+
constructor(schema, data) {
8887
this.schema = schema;
88+
this.data = data;
8989

9090
if (typeof this.data === 'string') {
9191
try {

lib/validators/text-diff.js

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
const DiffMatchPatch = require('googlediff');
22
const errors = require('../errors');
33

4+
const sanitizeSurrogatePairs = (data) => {
5+
return data.replace(/[\uD800-\uDBFF]/g, '').replace(/[\uDC00-\uDFFF]/g, '');
6+
};
7+
48
class TextDiff {
5-
constructor(real, expected) {
6-
if (typeof real !== 'string') {
9+
constructor(expected, actual) {
10+
if (typeof actual !== 'string') {
711
const outError = new errors.DataNotStringError(
8-
'String validator real: input data is not string'
12+
'String validator actual: input data is not string'
913
);
10-
outError.data = real;
14+
outError.data = actual;
1115
throw outError;
1216
}
1317

@@ -19,28 +23,22 @@ class TextDiff {
1923
throw outError;
2024
}
2125

22-
this.real = real;
2326
this.expected = expected;
27+
this.actual = actual;
2428
}
2529

2630
validate() {
27-
const sanitizeSurrogatePairs = (data) => {
28-
return data
29-
.replace(/[\uD800-\uDBFF]/g, '')
30-
.replace(/[\uDC00-\uDFFF]/g, '');
31-
};
32-
3331
this.output = null;
3432
const dmp = new DiffMatchPatch();
3533

3634
try {
37-
const patch = dmp.patch_make(this.real, this.expected);
35+
const patch = dmp.patch_make(this.actual, this.expected);
3836
this.output = dmp.patch_toText(patch);
3937
return this.output;
4038
} catch (error) {
4139
if (error instanceof URIError) {
4240
const patch = dmp.patch_make(
43-
sanitizeSurrogatePairs(this.real),
41+
sanitizeSurrogatePairs(this.actual),
4442
sanitizeSurrogatePairs(this.expected)
4543
);
4644
this.output = dmp.patch_toText(patch);

test/unit/validators/headers-json-example-validator-test.js

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ describe('HeadersJsonExample', () => {
1616
describe('when I provede real data as non obejct', () => {
1717
it('should throw an exception', () => {
1818
const fn = () => {
19-
headersValidator = new HeadersJsonExample('', { header1: 'value1' });
19+
headersValidator = new HeadersJsonExample({ header1: 'value1' }, '');
2020
};
2121
assert.throw(fn, 'is not an Object');
2222
});
@@ -25,7 +25,7 @@ describe('HeadersJsonExample', () => {
2525
describe('when I provede expected data as non obejct', () => {
2626
it('should throw an exception', () => {
2727
const fn = () => {
28-
headersValidator = new HeadersJsonExample({ header1: 'value1' }, '');
28+
headersValidator = new HeadersJsonExample('', { header1: 'value1' });
2929
};
3030
assert.throw(fn, 'is not an Object');
3131
});
@@ -62,8 +62,8 @@ describe('HeadersJsonExample', () => {
6262
describe('when provided real and expected headers differ in upper/lower-case state of keys', () => {
6363
before(() => {
6464
headersValidator = new HeadersJsonExample(
65-
fixtures.sampleHeadersMixedCase,
66-
fixtures.sampleHeaders
65+
fixtures.sampleHeaders,
66+
fixtures.sampleHeadersMixedCase
6767
);
6868
});
6969

@@ -78,8 +78,8 @@ describe('HeadersJsonExample', () => {
7878
describe('when provided real and expected headers differ in one value (real change) of a key different by upper/lower', () => {
7979
before(() => {
8080
headersValidator = new HeadersJsonExample(
81-
fixtures.sampleHeadersMixedCaseDiffers,
82-
fixtures.sampleHeaders
81+
fixtures.sampleHeaders,
82+
fixtures.sampleHeadersMixedCaseDiffers
8383
);
8484
});
8585
describe('and I run validate()', () => {
@@ -93,8 +93,8 @@ describe('HeadersJsonExample', () => {
9393
describe('when key is missing in provided headers', () => {
9494
beforeEach(() => {
9595
headersValidator = new HeadersJsonExample(
96-
fixtures.sampleHeadersMissing,
97-
fixtures.sampleHeaders
96+
fixtures.sampleHeaders,
97+
fixtures.sampleHeadersMissing
9898
);
9999
});
100100
describe('and i run validate()', () => {
@@ -113,8 +113,8 @@ describe('HeadersJsonExample', () => {
113113
describe('when value of content negotiation header in provided headers differs', () => {
114114
beforeEach(() => {
115115
headersValidator = new HeadersJsonExample(
116-
fixtures.sampleHeadersDiffers,
117-
fixtures.sampleHeaders
116+
fixtures.sampleHeaders,
117+
fixtures.sampleHeadersDiffers
118118
);
119119
});
120120

@@ -138,8 +138,8 @@ describe('HeadersJsonExample', () => {
138138
describe('when key is added to provided headers', () => {
139139
before(() => {
140140
headersValidator = new HeadersJsonExample(
141-
fixtures.sampleHeadersAdded,
142-
fixtures.sampleHeaders
141+
fixtures.sampleHeaders,
142+
fixtures.sampleHeadersAdded
143143
);
144144
});
145145

@@ -153,7 +153,7 @@ describe('HeadersJsonExample', () => {
153153

154154
describe('when real is empty object and expected is proper object', () => {
155155
before(() => {
156-
headersValidator = new HeadersJsonExample({}, fixtures.sampleHeaders);
156+
headersValidator = new HeadersJsonExample(fixtures.sampleHeaders, {});
157157
});
158158

159159
describe('and i run validate()', () => {
@@ -167,8 +167,8 @@ describe('HeadersJsonExample', () => {
167167
describe('when non content negotiation header header values differs', () => {
168168
before(() => {
169169
headersValidator = new HeadersJsonExample(
170-
fixtures.sampleHeadersWithNonContentNegotiationChanged,
171-
fixtures.sampleHeadersNonContentNegotiation
170+
fixtures.sampleHeadersNonContentNegotiation,
171+
fixtures.sampleHeadersWithNonContentNegotiationChanged
172172
);
173173
});
174174

@@ -184,8 +184,8 @@ describe('HeadersJsonExample', () => {
184184
output = null;
185185
before(() => {
186186
headersValidator = new HeadersJsonExample(
187-
fixtures.sampleHeadersMissing,
188-
fixtures.sampleHeaders
187+
fixtures.sampleHeaders,
188+
fixtures.sampleHeadersMissing
189189
);
190190
output = headersValidator.validate();
191191
});

test/unit/validators/json-example-test.js

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,9 @@ describe('JsonExample', () => {
1212
describe('when I provide non string real data', () => {
1313
it('should throw exception', () => {
1414
const fn = () => {
15-
bodyValidator = new JsonExample(
16-
{ malformed: 'malformed ' },
17-
"{'header1': 'value1'}"
18-
);
15+
bodyValidator = new JsonExample("{'header1': 'value1'}", {
16+
malformed: 'malformed '
17+
});
1918
};
2019
assert.throws(fn);
2120
});
@@ -25,8 +24,8 @@ describe('JsonExample', () => {
2524
it('should not throw exception', () => {
2625
fn = () => {
2726
bodyValidator = new JsonExample(
28-
'"Number of profiles deleted: com.viacom.auth.infrastructure.DocumentsUpdated@1"',
29-
'{"header1": "value1"}'
27+
'{"header1": "value1"}',
28+
'"Number of profiles deleted: com.viacom.auth.infrastructure.DocumentsUpdated@1"'
3029
);
3130
};
3231
assert.doesNotThrow(fn);
@@ -37,8 +36,8 @@ describe('JsonExample', () => {
3736
it('should not throw exception', () => {
3837
const fn = () => {
3938
bodyValidator = new JsonExample(
40-
'{"header1": "value1"}',
41-
'"Number of profiles deleted: com.viacom.auth.infrastructure.DocumentsUpdated@1"'
39+
'"Number of profiles deleted: com.viacom.auth.infrastructure.DocumentsUpdated@1"',
40+
'{"header1": "value1"}'
4241
);
4342
};
4443
assert.doesNotThrow(fn);
@@ -109,8 +108,8 @@ describe('JsonExample', () => {
109108
describe('when key is missing in provided real data', () => {
110109
before(() => {
111110
bodyValidator = new JsonExample(
112-
fixtures.sampleJsonSimpleKeyMissing,
113-
fixtures.sampleJson
111+
fixtures.sampleJson,
112+
fixtures.sampleJsonSimpleKeyMissing
114113
);
115114
});
116115
describe('and i run validate()', () => {
@@ -122,7 +121,7 @@ describe('JsonExample', () => {
122121

123122
describe.skip('when value has different primitive type', () => {
124123
before(() => {
125-
bodyValidator = new JsonExample('{"a": "a"}', '{"a": 1}');
124+
bodyValidator = new JsonExample('{"a": 1}', '{"a": "a"}');
126125
});
127126
describe('and i run validate()', () => {
128127
it('PROPOSAL: should return 1 errors', () => {
@@ -150,8 +149,8 @@ describe('JsonExample', () => {
150149
describe('when key is added to provided data', () => {
151150
before(() => {
152151
bodyValidator = new JsonExample(
153-
fixtures.sampleJsonComplexKeyAdded,
154-
fixtures.sampleJson
152+
fixtures.sampleJson,
153+
fixtures.sampleJsonComplexKeyAdded
155154
);
156155
});
157156
describe('and i run validate()', () => {
@@ -180,8 +179,8 @@ describe('JsonExample', () => {
180179
describe('when key value is a null', () => {
181180
before(() => {
182181
bodyValidator = new JsonExample(
183-
'{"a": "a","b": null }',
184-
'{"a":"a", "b": null}'
182+
'{"a":"a", "b": null}',
183+
'{"a": "a","b": null }'
185184
);
186185
});
187186
describe('and i run validate()', () => {
@@ -195,7 +194,7 @@ describe('JsonExample', () => {
195194
describe('when expected and real data are different on root level', () => {
196195
describe('when expected is object and real is array', () => {
197196
before(() => {
198-
bodyValidator = new JsonExample('[{"a":1}]', '{"a":1}');
197+
bodyValidator = new JsonExample('{"a":1}', '[{"a":1}]');
199198
});
200199
describe('and i run validate()', () => {
201200
it('should not throw exception', () => {
@@ -210,7 +209,7 @@ describe('JsonExample', () => {
210209

211210
describe('when expected is array and real is object', () => {
212211
before(() => {
213-
bodyValidator = new JsonExample('{"a":1}', '[{"a":1}]');
212+
bodyValidator = new JsonExample('[{"a":1}]', '{"a":1}');
214213
});
215214
describe('and i run validate()', () => {
216215
it('should not throw exception', () => {
@@ -224,7 +223,7 @@ describe('JsonExample', () => {
224223

225224
describe('when expected is primitive and real is object', () => {
226225
before(() => {
227-
bodyValidator = new JsonExample('0', '{"a":1}');
226+
bodyValidator = new JsonExample('{"a":1}', '0');
228227
});
229228
describe('and i run validate()', () => {
230229
it('should not throw exception', () => {
@@ -238,7 +237,7 @@ describe('JsonExample', () => {
238237

239238
describe('when expected array and real is object', () => {
240239
before(() => {
241-
bodyValidator = new JsonExample('[0,1,2]', '{"a":1}');
240+
bodyValidator = new JsonExample('{"a":1}', '[0,1,2]');
242241
});
243242
describe('and i run validate()', () => {
244243
it('should not throw exception', () => {
@@ -252,7 +251,7 @@ describe('JsonExample', () => {
252251

253252
describe('when real is empty object and expected is non-empty object', () => {
254253
before(() => {
255-
bodyValidator = new JsonExample('{}', '{"a":1}');
254+
bodyValidator = new JsonExample('{"a":1}', '{}');
256255
});
257256

258257
describe('and i run validate()', () => {

0 commit comments

Comments
 (0)