-
-
Notifications
You must be signed in to change notification settings - Fork 109
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f803fc4
commit 1b6cc3b
Showing
6 changed files
with
243 additions
and
118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* eslint-env mocha */ | ||
import Ajv from 'ajv' | ||
import expect from 'expect' | ||
import { callMongoMethod } from './helper' | ||
|
||
describe('using ajv', () => { | ||
before(() => { | ||
Collection2.defineValidation({ | ||
name: 'ajv', | ||
is: schema => schema instanceof Ajv, | ||
create: schema => { | ||
const instance = new Ajv() | ||
instance.definition = schema | ||
return instance | ||
}, | ||
extend: (s1, s2) => { | ||
// not impl | ||
return s2 | ||
}, | ||
clean: ({ doc, modifier, schema, userId, isLocalCollection, type }) => { | ||
// not impl | ||
}, | ||
validate: () => {}, | ||
freeze: false | ||
}); | ||
}) | ||
|
||
it('attach and get simpleSchema for normal collection', function () { | ||
;['ajvMc1', null].forEach(name => { | ||
const mc = new Mongo.Collection(name, Meteor.isClient ? { connection: null } : undefined); | ||
|
||
mc.attachSchema({ | ||
type: "object", | ||
properties: { foo: { type: "string" } }, | ||
required: ["foo"], | ||
additionalProperties: false, | ||
}); | ||
|
||
expect(mc.c2Schema() instanceof Ajv).toBe(true); | ||
}); | ||
}); | ||
it('handles prototype-less objects', async function () { | ||
const prototypelessTest = new Mongo.Collection( | ||
'prototypelessTestAjv', | ||
Meteor.isClient ? { connection: null } : undefined | ||
); | ||
|
||
prototypelessTest.attachSchema({ | ||
type: "object", | ||
properties: { foo: { type: "string" } }, | ||
required: ["foo"], | ||
additionalProperties: false, | ||
}); | ||
|
||
const prototypelessObject = Object.create(null); | ||
prototypelessObject.foo = 'bar'; | ||
|
||
await callMongoMethod(prototypelessTest, 'insert', [prototypelessObject]); | ||
}); | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.