@dhyasama/totem-models 1.0.0

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/package.json ADDED
@@ -0,0 +1,37 @@
1
+ {
2
+ "name": "@dhyasama/totem-models",
3
+ "version": "1.0.0",
4
+ "author": "Jason Reynolds",
5
+ "license": "none",
6
+ "description": "Models for Totem platform",
7
+ "main": "index.js",
8
+ "scripts": {
9
+ "test": "NODE_ENV=test node ./changeBSON && mocha -R spec -t 15000"
10
+ },
11
+ "publishConfig": {
12
+ "registry": "https://registry.npmjs.org/"
13
+ },
14
+ "dependencies": {
15
+ "@dhyasama/ffvc-crypto": "^1.0.0",
16
+ "@dhyasama/ffvc-geoip": "^1.0.0",
17
+ "@dhyasama/ffvc-s3": "^1.0.0",
18
+ "@dhyasama/ffvc-utilities": "^2.0.0",
19
+ "async": "^0.9.0",
20
+ "awesome-phonenumber": "^1.0.14",
21
+ "bcrypt": "^0.8.0",
22
+ "bluebird": "^3.5.0",
23
+ "escape-string-regexp": "^1.0.5",
24
+ "mongoose-deep-populate": "^3.0.0",
25
+ "mongoose-filter-denormalize": "^0.2.1",
26
+ "mongoose-post-find": "0.0.2",
27
+ "phone-formatter": "0.0.2",
28
+ "underscore": "~1.5.0",
29
+ "validator": "^5.4.0"
30
+ },
31
+ "devDependencies": {
32
+ "mocha-mongoose": "^1.2.0",
33
+ "mongoose": "~4.5.7",
34
+ "nock": "^7.2.2",
35
+ "should": "^11.1.1"
36
+ }
37
+ }
@@ -0,0 +1,139 @@
1
+ "use strict";
2
+
3
+ var
4
+
5
+ should = require("should"),
6
+ config = require('./config')['test'],
7
+ mongoose = require('mongoose'),
8
+ models = require('../index')(mongoose, config),
9
+ clearDB = require('mocha-mongoose')(config.db.uri, {noClear: true}),
10
+ Crypto = require('@dhyasama/ffvc-crypto'),
11
+ crypto = new Crypto({'key': config.crypto.key}),
12
+ Account = mongoose.model('Account'),
13
+ Person = mongoose.model('Person'),
14
+ person = new Person();
15
+
16
+ var accountid;
17
+
18
+
19
+ describe('Account', function() {
20
+
21
+ before(function(done) {
22
+ if (mongoose.connection.db) return done();
23
+ mongoose.connect(config.db.uri, done);
24
+ });
25
+
26
+ before(function(done) {
27
+ clearDB(done);
28
+ });
29
+
30
+ it('creates an account', function(done) {
31
+
32
+ person.name.first = 'George';
33
+ person.slug = 'george';
34
+
35
+ Person.upsert(person, 'test', function(err, newPerson) {
36
+
37
+ should.not.exist(err);
38
+ should.exist(newPerson);
39
+
40
+ crypto.hash('testy', function(err, hash) {
41
+
42
+ should.not.exist(err);
43
+ should.exist(hash);
44
+
45
+ var account = new Account();
46
+
47
+ account.username = 'testy';
48
+ account.email = 'sebastian+soler@gmail.com'
49
+ account.reset.token = '123456789';
50
+ account.setup.token = '987654321';
51
+ account.password = hash;
52
+ account.person = newPerson;
53
+ account.active = true;
54
+
55
+ Account.upsert(account, function(err, updatedAccount) {
56
+ should.not.exist(err);
57
+ should.exist(updatedAccount);
58
+ accountid = updatedAccount.id;
59
+ done();
60
+ });
61
+
62
+ });
63
+
64
+ });
65
+
66
+ });
67
+
68
+ it('finds by id', function(done) {
69
+
70
+ Account.getById(accountid, function(err, account) {
71
+ should.not.exist(err);
72
+ should.exist(account);
73
+ account.id.should.equal(accountid);
74
+ done();
75
+ });
76
+
77
+ });
78
+
79
+ it('finds by username', function(done) {
80
+
81
+ Account.findByUsername('testy', function(err, account) {
82
+ should.not.exist(err);
83
+ should.exist(account);
84
+ done();
85
+ });
86
+
87
+ });
88
+
89
+ it('finds by email', function(done) {
90
+
91
+ Account.findByEmail('sebastian+soler@gmail.com', function(err, account) {
92
+ should.not.exist(err);
93
+ should.exist(account);
94
+ done();
95
+ });
96
+
97
+ });
98
+
99
+ it('finds by reset token', function(done) {
100
+
101
+ Account.findByResetToken('123456789', function(err, account) {
102
+ should.not.exist(err);
103
+ should.exist(account);
104
+ done();
105
+ });
106
+
107
+ });
108
+
109
+ it('finds by setup token', function(done) {
110
+
111
+ Account.findBySetupToken('987654321', function(err, account) {
112
+ should.not.exist(err);
113
+ should.exist(account);
114
+ done();
115
+ });
116
+
117
+ });
118
+
119
+ it('finds by username and password', function(done) {
120
+
121
+ Account.findByCredentials('testy', 'testy', function(err, account) {
122
+ should.not.exist(err);
123
+ should.exist(account);
124
+ done();
125
+ });
126
+
127
+ });
128
+
129
+ it('lists all active accounts', function(done) {
130
+
131
+ Account.listAllAccounts(function(err, result) {
132
+ should.not.exist(err);
133
+ should.exist(result);
134
+ done();
135
+ });
136
+
137
+ });
138
+
139
+ });
@@ -0,0 +1,167 @@
1
+ "use strict";
2
+
3
+ var
4
+
5
+ should = require("should"),
6
+ config = require('./config')['test'],
7
+ mongoose = require('mongoose'),
8
+ clearDB = require('mocha-mongoose')(config.db.uri, {noClear: true}),
9
+ Activity = mongoose.model('Activity'),
10
+ username = 'STING',
11
+ remoteAddress = '108.29.95.108',
12
+ nock = require('nock');
13
+
14
+ describe('Activity', function() {
15
+
16
+ before(function(done) {
17
+ if (mongoose.connection.db) return done();
18
+ mongoose.connect(config.db.uri, done);
19
+ });
20
+
21
+ before(function(done) {
22
+ clearDB(done);
23
+ });
24
+
25
+ it('adds a login success for a new user', function(done) {
26
+
27
+ var scope = nock('https://freegeoip.net/json')
28
+ .get('/' + remoteAddress)
29
+ .reply(200, {
30
+ ip: '108.29.95.108',
31
+ country_code: 'US',
32
+ country_name: 'United States',
33
+ region_code: 'NY',
34
+ region_name: 'New York',
35
+ city: 'New York',
36
+ zip_code: '10036',
37
+ time_zone: 'America/New_York',
38
+ latitude: 40.7605,
39
+ longitude: -73.9933,
40
+ metro_code: 501
41
+ });
42
+
43
+ Activity.add(username, 'LOGIN SUCCESS', remoteAddress, null, null, function(err, item) {
44
+ should.not.exist(err);
45
+ should.exist(item);
46
+ item.type.should.equal('LOGIN SUCCESS');
47
+ done();
48
+ });
49
+
50
+ });
51
+
52
+ it('adds a document download', function(done) {
53
+
54
+ var scope = nock('https://freegeoip.net/json')
55
+ .get('/' + remoteAddress)
56
+ .reply(200, {
57
+ ip: '108.29.95.108',
58
+ country_code: 'US',
59
+ country_name: 'United States',
60
+ region_code: 'NY',
61
+ region_name: 'New York',
62
+ city: 'New York',
63
+ zip_code: '10036',
64
+ time_zone: 'America/New_York',
65
+ latitude: 40.7605,
66
+ longitude: -73.9933,
67
+ metro_code: 501
68
+ });
69
+
70
+ Activity.add(username, 'DOCUMENT DOWNLOAD', remoteAddress, '/messages/123456789', 'report.pdf', function(err, item) {
71
+ should.not.exist(err);
72
+ should.exist(item);
73
+ item.type.should.equal('DOCUMENT DOWNLOAD');
74
+ done();
75
+ });
76
+
77
+ });
78
+
79
+ it('finds all activity for a user', function(done) {
80
+
81
+ var scope = nock('https://freegeoip.net/json')
82
+ .get('/' + remoteAddress)
83
+ .reply(200, {
84
+ ip: '108.29.95.108',
85
+ country_code: 'US',
86
+ country_name: 'United States',
87
+ region_code: 'NY',
88
+ region_name: 'New York',
89
+ city: 'New York',
90
+ zip_code: '10036',
91
+ time_zone: 'America/New_York',
92
+ latitude: 40.7605,
93
+ longitude: -73.9933,
94
+ metro_code: 501
95
+ });
96
+
97
+ Activity.list(username, 2, function(err, activity) {
98
+ should.not.exist(err);
99
+ should.exist(activity);
100
+ activity.items.length.should.equal(2);
101
+ done();
102
+ });
103
+
104
+ });
105
+
106
+ it('adds activity without a username', function(done) {
107
+
108
+ var scope = nock('https://freegeoip.net/json')
109
+ .get('/' + remoteAddress)
110
+ .reply(200, {
111
+ ip: '108.29.95.108',
112
+ country_code: 'US',
113
+ country_name: 'United States',
114
+ region_code: 'NY',
115
+ region_name: 'New York',
116
+ city: 'New York',
117
+ zip_code: '10036',
118
+ time_zone: 'America/New_York',
119
+ latitude: 40.7605,
120
+ longitude: -73.9933,
121
+ metro_code: 501
122
+ });
123
+
124
+ try {
125
+ Activity.add(null, 'LOGIN SUCCESS', remoteAddress, null, null, function(err, item) {
126
+ should.not.exist(item);
127
+ done();
128
+ });
129
+ }
130
+ catch (err) {
131
+ err.message.should.equal('username is required');
132
+ done();
133
+ }
134
+
135
+ });
136
+
137
+ it('adds activity with an invalid remoteAddress', function(done) {
138
+
139
+ var scope = nock('https://freegeoip.net/json')
140
+ .get('/' + remoteAddress)
141
+ .reply(200, {
142
+ ip: '108.29.95.108',
143
+ country_code: 'US',
144
+ country_name: 'United States',
145
+ region_code: 'NY',
146
+ region_name: 'New York',
147
+ city: 'New York',
148
+ zip_code: '10036',
149
+ time_zone: 'America/New_York',
150
+ latitude: 40.7605,
151
+ longitude: -73.9933,
152
+ metro_code: 501
153
+ });
154
+
155
+ Activity.add(username, 'LOGIN SUCCESS', 'UNKNOWN', null, null, function(err, item) {
156
+ should.not.exist(err);
157
+ should.exist(item);
158
+ item.type.should.equal('LOGIN SUCCESS');
159
+ var x = item.geolocation;
160
+ x.should.be.an.Object;
161
+ //item.geolocation.should.be.an.Object.and.be.empty;
162
+ done();
163
+ });
164
+
165
+ });
166
+
167
+ });
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+
3
+ var
4
+
5
+ should = require("should"),
6
+ config = require('./config')['test'],
7
+ mongoose = require('mongoose'),
8
+ clearDB = require('mocha-mongoose')(config.db.uri, {noClear: true}),
9
+ CalendarEvent = mongoose.model('CalendarEvent');
10
+
11
+
12
+
13
+ describe('CalendarEvent', function() {
14
+
15
+ before(function(done) {
16
+ if (mongoose.connection.db) return done();
17
+ mongoose.connect(config.db.uri, done);
18
+ });
19
+
20
+ before(function(done) {
21
+ clearDB(done);
22
+ });
23
+
24
+ it('creates a calendar event', function(done) {
25
+
26
+ var ce = new CalendarEvent();
27
+ ce.account = new mongoose.Types.ObjectId();
28
+ ce.email = 'jason+test@ffvc.com';
29
+ ce.provider = 'google';
30
+ ce.eventId = '_SOMETHING_FAKE_go46ba565334b9k710j0b9o70p3aba188ok4cpl6h142c9l6s_20180320T150000Z';
31
+ ce.status = 'confirmed';
32
+ ce.processed = false;
33
+ ce.allInternal = false;
34
+ ce.attendees = [
35
+ {
36
+ "email" : "steven@ffvc.com",
37
+ "displayName" : "Steven Greenberg"
38
+ },
39
+ {
40
+ "email" : "john@ffvc.com",
41
+ "displayName" : "John Frankel"
42
+ }
43
+ ];
44
+ ce.createdOn = new Date();
45
+ ce.updatedOn = new Date();
46
+ ce.raw = '{\n \"kind\": \"calendar#event\",\n \"etag\": \"\\\"2978843514960000\\\"\",\n \"id\": \"6219q6mncfg3jtc36hjqfjsedg\",\n \"status\": \"confirmed\",\n \"htmlLink\": \"https://www.google.com/calendar/event?eid=NjIxOXE2bW5jZmczanRjMzZoanFmanNlZGcgamFzb25AZmZ2Yy5jb20\",\n \"created\": \"2017-03-13T16:15:57.000Z\",\n \"updated\": \"2017-03-13T16:15:57.480Z\",\n \"summary\": \"JCR OOO\",\n \"creator\": {\n \"email\": \"jason@ffvc.com\",\n \"displayName\": \"Jason Reynolds\",\n \"self\": true\n },\n \"organizer\": {\n \"email\": \"jason@ffvc.com\",\n \"displayName\": \"Jason Reynolds\",\n \"self\": true\n },\n \"start\": {\n \"dateTime\": \"2017-03-21T17:30:00-04:00\"\n },\n \"end\": {\n \"dateTime\": \"2017-03-21T18:00:00-04:00\"\n },\n \"iCalUID\": \"6219q6mncfg3jtc36hjqfjsedg@google.com\",\n \"sequence\": 0,\n \"reminders\": {\n \"useDefault\": true\n }\n}';
47
+
48
+ CalendarEvent.upsert(ce, function(err, result) {
49
+
50
+ should.not.exist(err);
51
+ should.exist(result);
52
+
53
+ return done();
54
+
55
+ });
56
+
57
+ });
58
+
59
+ });
package/test/Fund.js ADDED
@@ -0,0 +1,113 @@
1
+ "use strict";
2
+
3
+ var
4
+
5
+ should = require("should"),
6
+ config = require('./config')['test'],
7
+ mongoose = require('mongoose'),
8
+ clearDB = require('mocha-mongoose')(config.db.uri, {noClear: true}),
9
+ Fund = mongoose.model('Fund');
10
+
11
+ describe('Fund', function() {
12
+
13
+ before(function (done) {
14
+ if (mongoose.connection.db) return done();
15
+ mongoose.connect(config.db.uri, done);
16
+ });
17
+
18
+ before(function (done) {
19
+ clearDB(done);
20
+ });
21
+
22
+ var myHugeFund;
23
+
24
+ it('creates a fund', function (done) {
25
+
26
+ var fund = new Fund();
27
+ fund.name = 'My Huge Fund';
28
+ fund.slug = 'my-huge-fund';
29
+ fund.shortName = 'Huge';
30
+ fund.org = new mongoose.Types.ObjectId()
31
+
32
+ Fund.upsert(fund, 'test-user', function(err, result) {
33
+ should.not.exist(err);
34
+ should.exist(result);
35
+ result.name.should.equal('My Huge Fund');
36
+ result.slug.should.equal('my-huge-fund');
37
+ myHugeFund = result;
38
+ done();
39
+ });
40
+
41
+ });
42
+
43
+ it('lists funds', function (done) {
44
+
45
+ Fund.list(function(err, result) {
46
+ should.not.exist(err);
47
+ should.exist(result);
48
+ result.length.should.equal(1);
49
+ done();
50
+ });
51
+
52
+ });
53
+
54
+ it('gets a fund by slug', function (done) {
55
+
56
+ Fund.getBySlug('my-huge-fund', function(err, result) {
57
+ should.not.exist(err);
58
+ should.exist(result);
59
+ result.length.should.equal(1);
60
+ result[0].slug.should.equal('my-huge-fund');
61
+ done();
62
+ });
63
+
64
+ });
65
+
66
+ it('gets a fund by a slug that does not exist', function (done) {
67
+
68
+ Fund.getBySlug('someones-small-fund', function(err, result) {
69
+ should.not.exist(err);
70
+ should.exist(result);
71
+ result.length.should.equal(0);
72
+ done();
73
+ });
74
+
75
+ });
76
+
77
+ it('gets a fund by id', function (done) {
78
+
79
+ Fund.getById(myHugeFund.id, function(err, result) {
80
+ should.not.exist(err);
81
+ should.exist(result);
82
+ result.id.should.equal(myHugeFund.id);
83
+ done();
84
+ });
85
+
86
+ });
87
+
88
+ it('updates a fund', function (done) {
89
+
90
+ myHugeFund.name = 'My Fund Is Bigger Than Yours';
91
+ myHugeFund.org = new mongoose.Types.ObjectId();
92
+
93
+ Fund.upsert(myHugeFund, 'test-user', function(err, result) {
94
+ should.not.exist(err);
95
+ should.exist(result);
96
+ result.name.should.equal('My Fund Is Bigger Than Yours');
97
+ done();
98
+ });
99
+
100
+ });
101
+
102
+ it('gets a count of funds', function (done) {
103
+
104
+ Fund.getCount(function(err, result) {
105
+ should.not.exist(err);
106
+ should.exist(result);
107
+ result.should.equal(1);
108
+ done();
109
+ });
110
+
111
+ });
112
+
113
+ });