forked from dresende/node-orm2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodel-one.js
More file actions
106 lines (82 loc) · 1.98 KB
/
model-one.js
File metadata and controls
106 lines (82 loc) · 1.98 KB
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
var should = require('should');
var helper = require('../support/spec_helper');
var ORM = require('../../');
describe("Model.one()", function() {
var db = null;
var Person = null;
var setup = function () {
return function (done) {
Person = db.define("person", {
name : String
});
return helper.dropSync(Person, function () {
Person.create([{
id : 1,
name: "Jeremy Doe"
}, {
id : 2,
name: "John Doe"
}, {
id : 3,
name: "Jane Doe"
}], done);
});
};
};
before(function (done) {
helper.connect(function (connection) {
db = connection;
return done();
});
});
after(function () {
return db.close();
});
describe("without arguments", function () {
before(setup());
it("should return first item in model", function (done) {
Person.one(function (err, person) {
should.equal(err, null);
person.name.should.equal("Jeremy Doe");
return done();
});
});
});
describe("without callback", function () {
before(setup());
it("should throw", function (done) {
Person.one.should.throw();
return done();
});
});
describe("with order", function () {
before(setup());
it("should return first item in model based on order", function (done) {
Person.one("-name", function (err, person) {
should.equal(err, null);
person.name.should.equal("John Doe");
return done();
});
});
});
describe("with conditions", function () {
before(setup());
it("should return first item in model based on conditions", function (done) {
Person.one({ name: "Jane Doe" }, function (err, person) {
should.equal(err, null);
person.name.should.equal("Jane Doe");
return done();
});
});
describe("if no match", function () {
before(setup());
it("should return null", function (done) {
Person.one({ name: "Jack Doe" }, function (err, person) {
should.equal(err, null);
should.equal(person, null);
return done();
});
});
});
});
});