Skip to content

Commit

Permalink
Merge f4e252b into cc1825f
Browse files Browse the repository at this point in the history
  • Loading branch information
artem-zakharchenko committed May 30, 2019
2 parents cc1825f + f4e252b commit ef8dbeb
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 56 deletions.
4 changes: 3 additions & 1 deletion lib/validators/json-schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ const jsonSchemaOptions = {
val.length
} characters long).`,
maxLength: (prop, val, validator) =>
`The ${prop} property must not exceed ${validator} characters (currently$#{val.length} characters long).`,
`The ${prop} property must not exceed ${validator} characters (currently${
val.length
} characters long).`,
length: (prop, val, validator) =>
`The ${prop} property must be exactly ${validator} characters long (currently ${
val.length
Expand Down
97 changes: 47 additions & 50 deletions test/unit/mixins/validatable-http-message-test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const assert = require('chai').assert;
/* eslint-disable no-shadow */
const { assert } = require('chai');
const sinon = require('sinon');

const { HttpResponse } = require('../../../lib/model/http-response');
Expand Down Expand Up @@ -31,15 +32,15 @@ describe('Http validatable mixin', () => {
];

methods.forEach((method) => {
it('should have ' + method + ' method defined', () => {
it(`should have '${method}' method defined`, () => {
assert.isFunction(HttpResponse.prototype[method]);
});
});

describe('validatableComponents', () => {
const items = ['headers', 'body', 'statusCode'];
items.forEach((item) => {
it('should contain "' + item + '"', () => {
it(`should contain '${item}'`, () => {
assert.include(HttpResponse.validatableComponents, item);
});
});
Expand Down Expand Up @@ -89,7 +90,7 @@ describe('Http validatable mixin', () => {
});

describe('#validate()', () => {
result = null;
let result = null;
before(() => {
result = instance.validate();
});
Expand All @@ -100,7 +101,7 @@ describe('Http validatable mixin', () => {

const keys = ['headers', 'body', 'statusCode', 'version'];
keys.forEach((key) => {
it('should contain validatable Component key "' + key + '"', () => {
it(`should contain validatable Component key '${key}'`, () => {
assert.include(Object.keys(result), key);
});
});
Expand Down Expand Up @@ -242,18 +243,18 @@ describe('Http validatable mixin', () => {
});

describe('when any HTTP component contains error message', () => {
i = null;
let instance = null;
before(() => {
i = new HttpResponse({});
i.validation = {
instance = new HttpResponse({});
instance.validation = {
headers: {
results: [{ severity: 'error' }]
}
};
});

it('should return false', () => {
assert.isFalse(i.isValid());
assert.isFalse(instance.isValid());
});
});
});
Expand All @@ -271,15 +272,15 @@ describe('Http validatable mixin', () => {
});

it('should return content of validation property', () => {
validation = { booboo: 'foobar' };
const validation = { booboo: 'foobar' };
instance.validation = validation;
assert.equal(instance.validationResults(), validation);
});
});
});

describe('#lowercaseHeaders()', () => {
inst = null;
let inst = null;
before(() => {
inst = new HttpRequest({
headers: {
Expand Down Expand Up @@ -333,12 +334,9 @@ describe('Http validatable mixin', () => {
];

fields.forEach((field) => {
it(
"should set '" + field + "' property for the component",
() => {
assert.isDefined(instance.validation.headers[field]);
}
);
it(`should set '${field}' property for the component`, () => {
assert.isDefined(instance.validation.headers[field]);
});
});

it('should call setHeadersRealType', () => {
Expand Down Expand Up @@ -464,15 +462,15 @@ describe('Http validatable mixin', () => {
});

describe('added message', () => {
message = null;
let message = null;

before(() => {
index = instance.validation.headers.results.length - 1;
const index = instance.validation.headers.results.length - 1;
message = instance.validation.headers.results[index];
});

it('should have error severity', () => {
assert.equal(message['severity'], 'error');
assert.equal(message.severity, 'error');
});
});
});
Expand Down Expand Up @@ -576,8 +574,8 @@ describe('Http validatable mixin', () => {
});

// Body validation tests
describe('#validateBody()', function() {
before(function() {
describe('#validateBody()', () => {
before(() => {
sinon.spy(instance, 'setBodyRealType');
sinon.spy(instance, 'setBodyExpectedType');
sinon.spy(instance, 'setBodyValidator');
Expand Down Expand Up @@ -629,21 +627,22 @@ describe('Http validatable mixin', () => {
try {
instance.setBodyRealType();
} catch (error) {
// eslint-disable-next-line
message = error.message;
}

assert.include(message, 'String');
});
});

jsonContentTypes = [
const jsonContentTypes = [
'application/json',
'application/json; charset=utf-8',
'application/hal+json'
];

jsonContentTypes.forEach((contentType) => {
describe("header content-type is '#{contentType}'", () => {
describe(`header content-type is '${contentType}'`, () => {
let instance = null;

before(() => {
Expand All @@ -661,7 +660,7 @@ describe('Http validatable mixin', () => {
instance.setBodyRealType();
});

it('should set real type to ' + contentType + "'", () => {
it(`should set real type to '${contentType}'`, () => {
assert.equal(
instance.validation.body.realType,
contentType
Expand Down Expand Up @@ -877,7 +876,7 @@ Unexpected token '\\'' at 1:22
];

jsonContentTypes.forEach((contentType) => {
describe("expected headers have content-type '#{contentType}'", () => {
describe(`expected headers have content-type '${contentType}'`, () => {
describe('expected body is a parseable JSON', () => {
before(() => {
instance = new HttpResponse({
Expand All @@ -893,7 +892,7 @@ Unexpected token '\\'' at 1:22
instance.setBodyExpectedType();
});

it('should set expected type to ' + contentType, () => {
it(`should set expected type to ${contentType}`, () => {
assert.equal(
instance.validation.body.expectedType,
contentType
Expand Down Expand Up @@ -1025,7 +1024,7 @@ Unexpected token '\\'' at 1:22
});

it('it should not add any error to results', () => {
results = instance.validation.body.results;
const { results } = instance.validation.body;
assert.equal(results.length, 1);
});
});
Expand All @@ -1050,7 +1049,7 @@ Unexpected token '\\'' at 1:22
});

it('should set unknown validator error message to results', () => {
severities = instance.validation.body.results.map(
const severities = instance.validation.body.results.map(
(result) => result.severity
);
assert.include(severities, 'error');
Expand All @@ -1064,9 +1063,9 @@ Unexpected token '\\'' at 1:22
];

jsonContentTypes.forEach((realType) => {
describe('real is ' + realType, () => {
describe(`real is ${realType}`, () => {
jsonContentTypes.forEach((expectedType) => {
describe('expected is ' + expectedType, () => {
describe(`expected is ${expectedType}`, () => {
before(() => {
instance = new HttpResponse({
expected: {
Expand All @@ -1075,8 +1074,8 @@ Unexpected token '\\'' at 1:22
});
instance.validation = {};
instance.validation.body = {
realType: realType,
expectedType: expectedType
realType,
expectedType
};
instance.setBodyValidator();
});
Expand All @@ -1102,7 +1101,7 @@ Unexpected token '\\'' at 1:22
});
instance.validation = {};
instance.validation.body = {
realType: realType,
realType,
expectedType: 'application/schema+json'
};
instance.setBodyValidator();
Expand Down Expand Up @@ -1193,12 +1192,12 @@ Unexpected token '\\'' at 1:22
});

it('should set no validator for combination errror message', () => {
results = instance.validation.body.results;
results.forEach((result) => {
results.push(result.severity);
});

assert.include(results, 'error');
const severities = instance.validation.body.results.map(
(result) => {
return result.severity;
}
);
assert.include(severities, 'error');
});
});
});
Expand Down Expand Up @@ -1299,7 +1298,8 @@ Unexpected token '\\'' at 1:22

describe('when a validator throws an error', () => {
before(() => {
invalidSchema = require('../../fixtures/invalid-schema-v4');
// eslint-disable-next-line global-require
const invalidSchema = require('../../fixtures/invalid-schema-v4');
instance = new HttpResponse(response);
instance.body = '{}';
instance.expected = {
Expand Down Expand Up @@ -1381,7 +1381,7 @@ Unexpected token '\\'' at 1:22
});

it('should not throw', () => {
fn = () => {
const fn = () => {
instance.runBodyValidator();
};
assert.doesNotThrow(fn);
Expand Down Expand Up @@ -1416,12 +1416,9 @@ Unexpected token '\\'' at 1:22
];

fields.forEach((field) => {
it(
"should set '" + field + "' property for the component",
() => {
assert.isDefined(instance.validation.statusCode[field]);
}
);
it(`should set '${field}' property for the component`, () => {
assert.isDefined(instance.validation.statusCode[field]);
});
});

describe('expceted matches real', () => {
Expand Down Expand Up @@ -1485,15 +1482,15 @@ Unexpected token '\\'' at 1:22
});

jsonContentTypes.forEach((contentType) => {
describe("when content type is '" + contentType + "'", () => {
describe(`when content type is '${contentType}'`, () => {
it('should return true', () => {
assert.isTrue(instance.isJsonContentType(contentType));
});
});
});

nonJsonContentTypes.forEach((contentType) => {
describe("when content type is '" + contentType + "'", () => {
describe(`when content type is '${contentType}'`, () => {
it('should return false', () => {
assert.isFalse(instance.isJsonContentType(contentType));
});
Expand Down
10 changes: 5 additions & 5 deletions test/unit/validate-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ describe('Gavel proxies to functions with callbacks', () => {
assert.isTrue(results));
});

describe('for similar #{variant}s', () => {
describe(`for similar ${variant}s`, () => {
let results = null;
let error = null;

Expand All @@ -91,7 +91,7 @@ describe('Gavel proxies to functions with callbacks', () => {
assert.isTrue(results));
});

describe('for different #{variant}s', () => {
describe(`for different ${variant}s`, () => {
let results = null;
let error = null;

Expand Down Expand Up @@ -120,7 +120,7 @@ describe('Gavel proxies to functions with callbacks', () => {
describe('isValid', () => {
describe('when I provide data', () => {
['response', 'request'].forEach((variant) => {
describe('for two cloned #{variant}s', () => {
describe(`for two cloned ${variant}s`, () => {
let results = null;
let error = null;

Expand All @@ -143,7 +143,7 @@ describe('Gavel proxies to functions with callbacks', () => {
assert.isTrue(results));
});

describe('for similar #{variant}s', () => {
describe(`for similar ${variant}s`, () => {
let results = null;
let error = null;

Expand All @@ -166,7 +166,7 @@ describe('Gavel proxies to functions with callbacks', () => {
assert.isTrue(results));
});

describe('for different #{variant}s', () => {
describe(`for different ${variant}s`, () => {
let results = null;
let error = null;

Expand Down

0 comments on commit ef8dbeb

Please sign in to comment.