forked from stephenplusplus/gcloud-datastore-schema
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
69 lines (62 loc) · 1.74 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
'use strict'
var assert = require('assert')
var gcloud = require('gcloud')
var schema = require('./')
describe('gcloud-datastore-schema', function () {
it('should catch errors from the readme', function (done) {
var dataset = schema(gcloud.datastore.dataset({ projectId: 'project-id' }))
dataset.register('Person', {
name: String,
age: Number,
tools: Array,
isPremiumUser: Boolean,
gpa: gcloud.datastore.double,
address: {
streetNumber: Number,
streetName: String,
zip: {
firstPart: Number,
secondPart: Number
}
},
fullName: function (input) {
return input.split(' ').length > 1
}
})
dataset.save({
key: dataset.key(['Person']),
data: {
name: 'Doc',
age: 8,
tools: ['Stethoscope', 'Positive attitude'],
gpa: gcloud.datastore.int(4.0),
address: {
streetNumber: 123,
streetName: 'Main',
zip: {
firstPart: 12345,
secondPart: 4444
}
},
fullName: 'Doc',
extraData: true,
extraExtraData: false
}
}, function (err) {
assert.strictEqual(err.code, 'ESCHEMAVIOLATION')
assert.strictEqual(err.message, 'Schema validation failed')
assert.deepEqual(err.errors, [
{
kind: 'Person',
errors: [
'Schema definition expected property: isPremiumUser',
'Schema definition violated for property: "gpa". Expected type: Double, received: Int',
'Schema definition violated for property: fullName',
'Unexpected properties found: extraData, extraExtraData'
]
}
])
done()
})
})
})