-
Notifications
You must be signed in to change notification settings - Fork 23
/
47-schema_with_id.js
131 lines (106 loc) · 3.83 KB
/
47-schema_with_id.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
var assert = require('assert'),
_ = require('lodash'),
utils = require('../../../lib/utils');
var self = this;
describe('Bug #47: Schema with id (blueprints like)', function() {
before(function (done) {
var fixtures = {
UserFixture : {
identity : 'user',
attributes : {
username : {
type : 'string'
},
email : {
type : 'email'
},
}
},
PassportFixture : {
identity : 'passport',
attributes : {
id : {
type : 'string',
primaryKey : true,
columnName : '@rid'
},
password : {
type : 'string'
}
}
}
};
CREATE_TEST_WATERLINE(self, 'test_bug_47', fixtures, done);
});
after(function (done) {
DELETE_TEST_WATERLINE('test_bug_47', done);
});
describe('create user', function() {
/////////////////////////////////////////////////////
// TEST SETUP
////////////////////////////////////////////////////
var userRecord, passportRecord, passportNullIdRecord;
before(function (done) {
self.collections.User.create({ email: '[email protected]' }, function(err, user) {
if(err) { return done(err); }
userRecord = user;
self.collections.Passport.create({ password: 'passport1' }, function(err, passport) {
if(err) { return done(err); }
passportRecord = passport;
self.collections.Passport.create({ password: 'passport2', id: null }, function(err, passport2) {
if(err) { return done(err); }
passportNullIdRecord = passport2;
done();
});
});
});
});
/////////////////////////////////////////////////////
// TEST METHODS
////////////////////////////////////////////////////
it('should be robust against an insertion with id set', function(done) {
// we probably should throw an error...
self.collections.User.create({ email: '[email protected]', id: '#13:1' }, function(err, user) {
if(err) { return done(err); }
assert.equal(user.email, '[email protected]');
done();
});
});
it('regression test: should retrieve user by id', function(done) {
self.collections.User.findOne(userRecord.id, function(err, user) {
if(err) { return done(err); }
assert.equal(user.email, '[email protected]');
done();
});
});
it('should be robust against an insertion with a null id', function(done) {
self.collections.Passport.create({ password: 'blah', id: null }, function foundUser(err, passport) {
if(err) { return done(err); }
assert.equal(passport.password, 'blah');
done();
});
});
it('should be robust against an insertion with id set', function(done) {
// we probably should throw an error...
self.collections.Passport.create({ password: 'blah', id: '#13:1' }, function(err, passport) {
if(err) { return done(err); }
assert.equal(passport.password, 'blah');
done();
});
});
it('regression test: should retrieve passport by id', function(done) {
self.collections.Passport.findOne(passportRecord.id, function foundPassport(err, passport) {
if(err) { return done(err); }
assert.equal(passport.password, 'passport1');
done();
});
});
it('regression test: should retrieve passport by id even if submitted with id `null`', function(done) {
self.collections.Passport.findOne(passportNullIdRecord.id, function foundPassport(err, passport2) {
if(err) { return done(err); }
assert.equal(passport2.password, 'passport2');
done();
});
});
});
});