forked from guymorita/oaktree
-
Notifications
You must be signed in to change notification settings - Fork 0
/
demodata.js
285 lines (269 loc) · 6.23 KB
/
demodata.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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
//sign in using laura, she receives all of the messages
var async = require('async');
var oaktree = require('./app.js');
var request = require('supertest');
//dummy data to populate for demo
// founders (need to insert first so auto-add won't complain)
var f0 = {
username: 'hatch',
password: 'hatchpass',
phone: '12063732928'
};
var f1 = {
username: 'svnh',
password: 'svnh',
phone: '13840294736'
};
var f2 = {
username: 'guy',
password: 'guy',
phone: '19023948372'
};
var f3 = {
username: 'al',
password: 'qwertypass',
phone: '19023948372'
};
// regular users
var user0 = {
username: 'bob',
password: 'bobpass',
phone: '1(206)2320928'
};
var user1 = {
username: 'tom',
password: 'tompass',
phone: '18301320399'
};
var user2 = {
username: 'laura',
password: 'laurapass',
phone: '18496323933'
};
var user3 = {
username: 'sally',
password: 'sallypass',
phone: '12183920901'
};
var user4 = {
username: 'tuhin',
password: 'cerealisgood',
phone: '1-510-555-1212'
};
var user5 = {
username: 'maxwell',
password: 'bitwiseforever',
phone: '1(707)555-1212'
};
var user6 = {
username: 'haoliu',
password: 'prelinked',
phone: '15104951212'
};
var founderArray = [f0, f1, f2, f3];
var founderIds = [];
var userArray = [user0, user1, user2, user3, user4, user5, user6];
var userIds = [];
oaktree.Message.remove({}, function(){
oaktree.User.remove({}, function(){
oaktree.User.create(founderArray, function(err, f0, f1, f2, f3) {
founderIds.push(f0._id);
founderIds.push(f1._id);
founderIds.push(f2._id);
founderIds.push(f3._id);
async.eachSeries(userArray,
function(userObj, callback){
request(oaktree.server)
.post('/user/new/')
.set('content-type', 'application/json')
.send(JSON.stringify(userObj))
.end(function(err, res){
userIds.push(JSON.parse(res.res.text)._id);
callback();
});
},
function(err){
console.log('Created demo users.');
setTimeout(function(){
createMessages(userIds);
}, 5000);
});
});
});
});
var createMessages = function(userIds){
request(oaktree.server)
.get('/friends/add/'+ userIds[0] +'/'+ userIds[2])
.end(function(err,res){
request(oaktree.server)
.get('/friends/accept/'+ userIds[0] +'/'+ userIds[2])
.end(function(err,res){
console.log('bob and laura are now friends.');
});
});
var message0 = {
sender_id: founderIds[1],
sender_name: 'Savannah',
deviceToken: '11',
receiver_ids: [userIds[2]],
title: 'hey, hey, hey!',
content: 'world',
latlng: {
lat: 37.785385,
lng: -122.429747
}
};
var message1 = {
sender_id: founderIds[1],
sender_name: 'Savannah',
deviceToken: '12121',
receiver_ids: [userIds[2]],
title: 'sup dude',
content: 'you know how it is',
latlng: {
lat: 37.760317,
lng: -122.426845
}
};
var message2 = {
sender_id: founderIds[2],
sender_name: 'Guy',
deviceToken: '121',
receiver_ids: [userIds[2]],
title: 'shalom princess',
content: 'wassup',
latlng: {
lat: 37.784283,
lng: -122.474138
}
};
var message3 = {
sender_id: founderIds[0],
sender_name: 'Guy',
deviceToken: '121',
receiver_ids: [userIds[2]],
title: 'lol look at this!!!!',
content: 'super funny pic',
latlng: {
lat: 37.792355,
lng: -122.411889
}
};
var message4 = {
sender_id: userIds[2],
sender_name: 'Laura',
deviceToken: '121',
receiver_ids: [userIds[1]],
title: 'have fun at the gym!',
content: 'wahhoooo',
latlng: {
lat: 37.783715,
lng: -122.408976
}
};
var message5 = {
sender_id: userIds[2],
sender_name: 'Laura',
deviceToken: '121',
receiver_ids: [userIds[1]],
title: 'hope you enjoy this',
content: 'check it out',
latlng: {
lat: 37.784775,
lng: -122.402490
}
};
var message6 = {
sender_id: founderIds[1],
sender_name: 'Savannah',
deviceToken: '121',
receiver_ids: [userIds[2]],
title: 'have a nice day',
content: 'in the city',
latlng: {
lat: 37.780501,
lng: -122.432081
}
};
var message7 = {
sender_id: founderIds[2],
sender_name: 'Guy',
deviceToken: '121',
receiver_ids: [userIds[2]],
title: 'enjoy',
content: 'this gift I bought you',
latlng: {
lat: 37.803613,
lng: -122.414689
}
};
var message8 = {
sender_id: founderIds[1],
sender_name: 'Savannah',
deviceToken: '121',
receiver_ids: [userIds[2]],
title: "don't forget to buy this at the store",
content: 'milk',
latlng: {
lat: 37.783085,
lng: -122.414140
}
};
var message9 = {
sender_id: userIds[2],
sender_name: 'Laura',
deviceToken: '121',
receiver_ids: [founderIds[1]],
title: 'so excited to see you here',
content: 'at the zoo',
latlng: {
lat: 37.78309,
lng: -122.41410
}
};
var message10 = {
sender_id: userIds[2],
sender_name: 'Laura',
deviceToken: '121',
receiver_ids: [userIds[0]],
title: 'you have to see this',
content: 'cool stuff',
latlng: {
lat: 37.78775,
lng: -122.2490
}
};
var message11 = {
sender_id: founderIds[3],
sender_name: 'al',
deviceToken: '121',
receiver_ids: [userIds[2]],
title: "ha! remember when we..",
content: 'broke in that building and ate a bunch of cereal?',
latlng: {
lat: 37.783812,
lng: -122.408946
}
};
var messageArray = [message0, message1, message2, message3, message4, message5, message6, message7, message8, message9, message10, message11];
var messageIds = [];
async.eachSeries(messageArray,
function(message, callback){
request(oaktree.server)
.post('/message/')
.set('content-type', 'application/json')
.send(JSON.stringify(message))
.end(function(err, res){
messageIds.push(JSON.parse(res.res.text)[0]._id);
callback();
});
},
function(err){
if (err){
console.log('error in populating dummy msgs:', err);
} else {
console.log('Created demo messages');
}
}
);
};