Skip to content

Commit 2d035e4

Browse files
committed
Added test for usage of suggestions to be of type schema when present
1 parent 75aeeed commit 2d035e4

File tree

1 file changed

+64
-1
lines changed

1 file changed

+64
-1
lines changed

test/unit/ValidateV2.test.js

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,70 @@ describe('The Validation option', function () {
532532
});
533533
});
534534

535-
describe('suggestAvailableFixes ', function () {
535+
describe('suggestAvailableFixes for parametersResolution=Schema', function () {
536+
suggestAvailableFixesSpecs.forEach((specData) => {
537+
let schema = fs.readFileSync(specData.path, 'utf8'),
538+
collection = fs.readFileSync(suggestAvailableFixesCollection, 'utf8'),
539+
schemaPack = new Converter.SchemaPack({ type: 'string', data: schema },
540+
{ suggestAvailableFixes: true, parametersResolution: 'Schema' }),
541+
historyRequest = [],
542+
resultObj,
543+
responseResult,
544+
propertyMismatchMap = {};
545+
546+
before(function (done) {
547+
getAllTransactions(JSON.parse(collection), historyRequest);
548+
schemaPack.validateTransactionV2(historyRequest, (err, result) => {
549+
expect(err).to.be.null;
550+
resultObj = result.requests[historyRequest[0].id].endpoints[0];
551+
responseResult = resultObj.responses[historyRequest[0].response[0].id];
552+
553+
// check for expected mismatches length
554+
expect(resultObj.mismatches).to.have.lengthOf(4);
555+
expect(responseResult.mismatches).to.have.lengthOf(2);
556+
557+
// map all mismatch objects with it's property
558+
_.forEach(_.concat(resultObj.mismatches, responseResult.mismatches), (mismatch) => {
559+
propertyMismatchMap[mismatch.property] = mismatch;
560+
});
561+
done();
562+
});
563+
});
564+
565+
it('should suggest valid available fix for all kind of violated properties - version: ' +
566+
specData.version, function () {
567+
// check for all suggested value to be according to schema
568+
expect(propertyMismatchMap.PATHVARIABLE.suggestedFix.suggestedValue).to.eql('<integer>');
569+
expect(propertyMismatchMap.QUERYPARAM.suggestedFix.suggestedValue).to.eql('<number>');
570+
expect(propertyMismatchMap.HEADER.suggestedFix.suggestedValue.value).to.eql('<boolean>');
571+
expect(propertyMismatchMap.HEADER.suggestedFix.suggestedValue.description)
572+
.to.eql('(Required) Quantity of pets available');
573+
expect(propertyMismatchMap.BODY.suggestedFix.suggestedValue.name).to.eql('<string>');
574+
expect(propertyMismatchMap.BODY.suggestedFix.suggestedValue.tag).to.eql('<string>');
575+
// For enum, actual values in enum should be used
576+
expect(_.includes(['Bulldog', 'Retriever', 'Timberwolf', 'Grizzly', 'Husky'],
577+
propertyMismatchMap.BODY.suggestedFix.suggestedValue.breeds[2])).to.eql(true);
578+
expect(propertyMismatchMap.RESPONSE_HEADER.suggestedFix.suggestedValue).to.eql('<integer>');
579+
expect(propertyMismatchMap.RESPONSE_BODY.suggestedFix.suggestedValue.code).to.eql('<integer>');
580+
expect(propertyMismatchMap.RESPONSE_BODY.suggestedFix.suggestedValue.message).to.eql('<string>');
581+
});
582+
583+
it('should maintain valid properties/items in suggested value - version:' +
584+
specData.version, function () {
585+
expect(propertyMismatchMap.BODY.suggestedFix.suggestedValue.petId).to.eql(
586+
propertyMismatchMap.BODY.suggestedFix.actualValue.petId
587+
);
588+
expect(propertyMismatchMap.BODY.suggestedFix.suggestedValue.breeds[0]).to.eql(
589+
propertyMismatchMap.BODY.suggestedFix.actualValue.breeds[0]
590+
);
591+
expect(propertyMismatchMap.BODY.suggestedFix.suggestedValue.breeds[1]).to.eql(
592+
propertyMismatchMap.BODY.suggestedFix.actualValue.breeds[1]
593+
);
594+
});
595+
});
596+
});
597+
598+
describe('suggestAvailableFixes for parametersResolution=Example', function () {
536599
suggestAvailableFixesSpecs.forEach((specData) => {
537600
let schema = fs.readFileSync(specData.path, 'utf8'),
538601
collection = fs.readFileSync(suggestAvailableFixesCollection, 'utf8'),

0 commit comments

Comments
 (0)