|
1 | 1 | import assert from 'assert' |
| 2 | +import { ObjectId as MongoObjectId } from 'mongodb' |
2 | 3 | import { Ajv } from '@feathersjs/schema' |
3 | 4 | import { |
4 | 5 | querySyntax, |
|
7 | 8 | defaultAppConfiguration, |
8 | 9 | getDataValidator, |
9 | 10 | getValidator, |
10 | | - queryProperties |
| 11 | + ObjectIdSchema |
11 | 12 | } from '../src' |
12 | 13 |
|
13 | 14 | describe('@feathersjs/schema/typebox', () => { |
@@ -39,20 +40,6 @@ describe('@feathersjs/schema/typebox', () => { |
39 | 40 | assert.ok(!validated) |
40 | 41 | }) |
41 | 42 |
|
42 | | - it('queryProperties errors for unsupported query types', () => { |
43 | | - assert.throws( |
44 | | - () => |
45 | | - queryProperties( |
46 | | - Type.Object({ |
47 | | - something: Type.Ref(Type.Object({}, { $id: 'something' })) |
48 | | - }) |
49 | | - ), |
50 | | - { |
51 | | - message: "Can not create query syntax schema for reference property 'something'" |
52 | | - } |
53 | | - ) |
54 | | - }) |
55 | | - |
56 | 43 | it('querySyntax works with no properties', async () => { |
57 | 44 | const schema = querySyntax(Type.Object({})) |
58 | 45 |
|
@@ -113,6 +100,26 @@ describe('@feathersjs/schema/typebox', () => { |
113 | 100 | assert.ok(validated) |
114 | 101 | }) |
115 | 102 |
|
| 103 | + // Test ObjectId validation |
| 104 | + it('ObjectId', async () => { |
| 105 | + const schema = Type.Object({ |
| 106 | + _id: ObjectIdSchema() |
| 107 | + }) |
| 108 | + |
| 109 | + const validator = new Ajv({ |
| 110 | + strict: false |
| 111 | + }).compile(schema) |
| 112 | + const validated = await validator({ |
| 113 | + _id: '507f191e810c19729de860ea' |
| 114 | + }) |
| 115 | + assert.ok(validated) |
| 116 | + |
| 117 | + const validated2 = await validator({ |
| 118 | + _id: new MongoObjectId() |
| 119 | + }) |
| 120 | + assert.ok(validated2) |
| 121 | + }) |
| 122 | + |
116 | 123 | it('validators', () => { |
117 | 124 | assert.strictEqual(typeof getDataValidator(Type.Object({}), new Ajv()), 'object') |
118 | 125 | assert.strictEqual(typeof getValidator(Type.Object({}), new Ajv()), 'function') |
|
0 commit comments