-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
110 lines (100 loc) · 3.45 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
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
var should = require("should");
var Data = require('./protolus-data');
var User;
//var Thing = Data.require('Thing');
var Thing;
//todo: do build-up & tear down of datasources
describe('Protolus.Data', function(){
//*
describe('uses MySQL to', function(){
Data.Source.MySQL = require('./sources/mysql');
var connection;
var id;
before(function(){
connection = new Data.Source.MySQL({
name : 'database',
host : 'localhost',
user : 'root',
//password : '',
database : 'protolus'
});
User = Data.require('User');
});
it('save an object', function(done){
var user = new User();
user.set('first_name', 'Abbey');
user.set('last_name', 'Sparrow');
user.set('email', '[email protected]');
user.save(function(){
id = user.get('id');
should.exist(user.get('id'));
done();
});
});
it('load and alter an object without saving a new one', function(done){
var user = new User();
user.load(id, function(){
user.set('first_name', 'blah');
user.save(function(){
id.should.equal(user.get('id'));
var reloadedUser = new User();
reloadedUser.load(user.get('id'), function(){
reloadedUser.get('first_name').should.equal('blah');
done();
});
});
});
});
it('select a set of objects >= to the one we created', function(done){
Data.query('User', 'id >= '+id, function(results){
results.length.should.equal(1);
done();
});
});
});
//*/
//*
describe('uses MongoDB to', function(){
Data.Source.MongoDB = require('./sources/mongo');
var connection;
var id;
before(function(){
connection = new Data.Source.MongoDB({
name : 'mongo_ds',
host : 'localhost',
database : 'protolus'
});
Thing = Data.require('Thing');
});
it('save an object', function(done){
var thing = new Thing();
thing.set('worg', 'Abbey');
thing.set('field', 'Sparrow');
thing.set('company', '[email protected]');
thing.save(function(){
id = thing.get('id');
should.exist(thing.get('_id'));
should.exist(id); //virtual makes '_id' > 'id'
done();
});
});
it('load and alter an object without saving a new one', function(done){
var thing = new Thing();
thing.load(id, function(){
thing.set('field', 'blah');
thing.save(function(){
id.toString().should.equal(thing.get('id').toString());
done();
});
});
});
it('select a set of objects == to the one we created', function(done){
Data.query('Thing', 'id = '+id, function(results){
results.length.should.equal(1);
done();
});
});
});
//*/
//describe('uses AMQP to');
});