@dhyasama/totem-models 2.3.1 → 2.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.npmignore +14 -0
- package/lib/Financials.js +1 -26
- package/package-lock.json +1163 -0
- package/package.json +1 -1
- package/test/Financials.js +151 -0
package/package.json
CHANGED
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var
|
|
4
|
+
|
|
5
|
+
should = require("should"),
|
|
6
|
+
_ = require('underscore'),
|
|
7
|
+
config = require('./config')['test'],
|
|
8
|
+
mongoose = require('mongoose'),
|
|
9
|
+
clearDB = require('mocha-mongoose')(config.db.uri, {noClear: true}),
|
|
10
|
+
Financials = mongoose.model('Financials');
|
|
11
|
+
|
|
12
|
+
var customerA = new mongoose.Types.ObjectId();
|
|
13
|
+
var customerB = new mongoose.Types.ObjectId();
|
|
14
|
+
var orgA = new mongoose.Types.ObjectId();
|
|
15
|
+
var orgB = new mongoose.Types.ObjectId();
|
|
16
|
+
|
|
17
|
+
describe('Financials', function() {
|
|
18
|
+
|
|
19
|
+
before(function(done) {
|
|
20
|
+
if (mongoose.connection.db) return done();
|
|
21
|
+
mongoose.connect(config.db.uri, done);
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
before(function(done) {
|
|
25
|
+
clearDB(done);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it('creates a financial document', function(done) {
|
|
29
|
+
|
|
30
|
+
var f = new Financials({
|
|
31
|
+
organization: orgA,
|
|
32
|
+
customer: customerA,
|
|
33
|
+
asOfDate: new Date(),
|
|
34
|
+
runway: 1
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
Financials.upsert(f, function(err, result) {
|
|
38
|
+
should.not.exist(err);
|
|
39
|
+
should.exist(result);
|
|
40
|
+
done();
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it('creates more financial documents', function(done) {
|
|
46
|
+
|
|
47
|
+
var f = new Financials({
|
|
48
|
+
organization: orgB,
|
|
49
|
+
customer: customerA,
|
|
50
|
+
asOfDate: new Date(),
|
|
51
|
+
runway: 2
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
Financials.upsert(f, function(err, result) {
|
|
55
|
+
|
|
56
|
+
should.not.exist(err);
|
|
57
|
+
should.exist(result);
|
|
58
|
+
|
|
59
|
+
var f = new Financials({
|
|
60
|
+
organization: orgB,
|
|
61
|
+
customer: customerB,
|
|
62
|
+
asOfDate: new Date(),
|
|
63
|
+
runway: 3
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
Financials.upsert(f, function(err, result) {
|
|
67
|
+
|
|
68
|
+
should.not.exist(err);
|
|
69
|
+
should.exist(result);
|
|
70
|
+
|
|
71
|
+
var f = new Financials({
|
|
72
|
+
organization: orgA,
|
|
73
|
+
customer: customerB,
|
|
74
|
+
asOfDate: new Date(),
|
|
75
|
+
runway: 4
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
Financials.upsert(f, function(err, result) {
|
|
79
|
+
should.not.exist(err);
|
|
80
|
+
should.exist(result);
|
|
81
|
+
done();
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
it('gets financials for an org', function(done) {
|
|
91
|
+
|
|
92
|
+
config.CUSTOMER_ID = customerA;
|
|
93
|
+
|
|
94
|
+
Financials.getByOrg(orgA, function(err, result) {
|
|
95
|
+
should.not.exist(err);
|
|
96
|
+
should.exist(result);
|
|
97
|
+
result.length.should.equal(1);
|
|
98
|
+
result[0].runway.should.equal(1);
|
|
99
|
+
done();
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
it('gets financials for the same org but different customer', function(done) {
|
|
105
|
+
|
|
106
|
+
config.CUSTOMER_ID = customerB;
|
|
107
|
+
|
|
108
|
+
Financials.getByOrg(orgA, function(err, result) {
|
|
109
|
+
should.not.exist(err);
|
|
110
|
+
should.exist(result);
|
|
111
|
+
result.length.should.equal(1);
|
|
112
|
+
result[0].runway.should.equal(4);
|
|
113
|
+
done();
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
it('removes financials for a customer', function(done) {
|
|
119
|
+
|
|
120
|
+
config.CUSTOMER_ID = customerA;
|
|
121
|
+
|
|
122
|
+
Financials.find({}, function(err, result) {
|
|
123
|
+
|
|
124
|
+
should.not.exist(err);
|
|
125
|
+
should.exist(result);
|
|
126
|
+
result.length.should.equal(4);
|
|
127
|
+
|
|
128
|
+
Financials.removeCustomerFinancials(config.CUSTOMER_ID, function(err, result) {
|
|
129
|
+
|
|
130
|
+
should.not.exist(err);
|
|
131
|
+
should.exist(result);
|
|
132
|
+
|
|
133
|
+
Financials.find({}, function(err, result) {
|
|
134
|
+
|
|
135
|
+
should.not.exist(err);
|
|
136
|
+
should.exist(result);
|
|
137
|
+
result.length.should.equal(2);
|
|
138
|
+
result[0].runway.should.equal(3);
|
|
139
|
+
result[1].runway.should.equal(4);
|
|
140
|
+
|
|
141
|
+
done();
|
|
142
|
+
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
});
|