Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
validateTransaction(test, transaction, callback) {
logger.debug('Validating HTTP transaction by Gavel.js');
let gavelResult = { fields: {} };
try {
gavelResult = gavel.validate(transaction.expected, transaction.real);
} catch (validationError) {
logger.debug('Gavel.js validation errored:', validationError);
this.emitError(validationError, test);
}
test.title = transaction.id;
test.actual = transaction.real;
test.expected = transaction.expected;
test.request = transaction.request;
// TODO
// Gavel result MUST NOT be undefined. Check transaction runner tests
// to find where and why it is.
const { valid: isValid } = gavelResult;
if (isValid) {
try {
if (isXml) {
return xmlValidator.validate(expected, output).then(res => {
expect(res).toStrictEqual([]);
delete expected.body;
delete output.body;
const isValid = validate(expected, output).valid;
expect(isValid).toBeTruthy();
return shutdownPrism(prismMockProcessHandle, done);
});
}
const isValid = validate(expected, output).valid;
if (!!isValid) {
expect(isValid).toBeTruthy();
} else {
expect(output).toMatchObject(expected);
}
if (parsed.expect) {
expect(output.body).toStrictEqual(expected.body);
}
} finally {
shutdownPrism(prismMockProcessHandle, done);
}
});
});