MCPcopy Index your code
hub / github.com/Vincit/objection.js / testValidation

Function testValidation

tests/integration/insertGraph.js:261–313  ·  view source on GitHub ↗
(modifyGraph, expectedProperty)

Source from the content-addressed store, hash-verified

259 });
260
261 const testValidation = (modifyGraph, expectedProperty) => {
262 return (done) => {
263 const graph = _.cloneDeep(insertion);
264 modifyGraph(graph);
265
266 transaction(Model1, Model2, (Model1, Model2) => {
267 // We can modify Model1 and Model2 here since it is a subclass of the actual
268 // models shared between tests.
269 Model1.jsonSchema = {
270 type: 'object',
271 properties: {
272 id: { type: 'integer' },
273 model1Id: { type: 'integer' },
274 model1Prop1: { type: 'string' },
275 model1Prop2: { type: 'integer' },
276 },
277 };
278
279 Model2.jsonSchema = {
280 type: 'object',
281 properties: {
282 idCol: { type: 'integer' },
283 model1Id: { type: 'integer' },
284 model2Prop1: { type: 'string' },
285 model2Prop2: { type: 'integer' },
286 },
287 };
288
289 delete Model1.$$jsonSchema;
290 delete Model2.$$jsonSchema;
291
292 expect(Model1.getJsonSchema()).to.equal(Model1.jsonSchema);
293 expect(Model2.getJsonSchema()).to.equal(Model2.jsonSchema);
294
295 return Model1.query().insertGraph(graph, { allowRefs: true });
296 })
297 .then(() => {
298 done(new Error('should not get here'));
299 })
300 .catch((err) => {
301 expect(err).to.be.a(ValidationError);
302 expect(err.data).to.have.property(expectedProperty);
303
304 return Promise.all([session.knex('Model1'), session.knex('model2')]);
305 })
306 .then(([rows1, rows2]) => {
307 expect(rows1).to.have.length(1);
308 expect(rows2).to.have.length(1);
309 done();
310 })
311 .catch(done);
312 };
313 };
314
315 it(
316 'should validate models upon insertion and return correct validation paths',

Callers 1

insertGraph.jsFile · 0.85

Calls 7

thenMethod · 0.80
getJsonSchemaMethod · 0.80
insertGraphMethod · 0.80
catchMethod · 0.65
queryMethod · 0.65
knexMethod · 0.65
transactionInterface · 0.50

Tested by

no test coverage detected