jstests/core/doc_validation_error.js
// document that fails validation and then checks the produced document validation error.
document that fails validation and then checks the produced document validation error.
document that fails validation and then checks the produced document validation error .
function executeDocumentValidationTestCase(testCase) {
    assert.commandWorked(testDB.dropDatabase());
    let validator;
    if (typeof testCase.validator === "string") {
        validator = {
            $jsonSchema: JSON.parse(cat(thirdPartyJSONSchemaDirectory + testCase.validator))
        };
    } else {
        validator = testCase.validator;
    }
    assert.commandWorked(testDB.createCollection(coll.getName(), {validator: validator}));
    const result = coll.insert(testCase.inputDocument);
    assertDocumentValidationFailure(result, coll);
    assert.docEq(result.getWriteError().errInfo.details,
                 testCase.expectedError,
                 `Test case ${testCase.name}`);
}
function executeDocumentValidationTestCase ( testCase ) { assert . commandWorked ( testDB . dropDatabase ( ) ) ; let validator ; if ( typeof testCase . validator === "string" ) { validator = { $jsonSchema : JSON . parse ( cat ( thirdPartyJSONSchemaDirectory + testCase . validator ) ) } ; } else { validator = testCase . validator ; } assert . commandWorked ( testDB . createCollection ( coll . getName ( ) , { validator : validator } ) ) ; const result = coll . insert ( testCase . inputDocument ) ; assertDocumentValidationFailure ( result , coll ) ; assert . docEq ( result . getWriteError ( ) . errInfo . details , testCase . expectedError , ` ${ testCase . name } ` ) ; }
document that fails validation and then checks the produced document validation error.
document that fails validation and then checks the produced document validation error .
// Drop the test database. // Get the schema of document validator. // Load a JSON Schema from a file in the third-party schema directory using // 'testCase.validator' as a name of a file. // Create a collection with a validator specified. // Attempt to insert a document. // Verify that document validation failed and the document validation error matches the // expected.