-
Notifications
You must be signed in to change notification settings - Fork 0
/
populate_db.js
158 lines (137 loc) · 8.01 KB
/
populate_db.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
require('dotenv').config()
var mongoose = require('mongoose');
var ObjectId = require('mongodb').ObjectID;
var generateEmail = require('./src/Utils/generateemail')
var joinUser = require('./src/Utils/joinuser')
var createNewPoll = require('./src/Utils/createnewpoll')
var castVote = require('./src/Utils/castvote')
mongoose.connect('mongodb://localhost:27017/rankedchoicepoll', { useNewUrlParser: true });
var db = mongoose.connection;
db.on('error', console.error.bind(console, 'MongoDB connection error:'));
// Colors Poll
const mockColorItems = ["Red", "Orange", "Yellow", "Green", "Blue", "Indigo", "Violet"]
const mockColorVotes = [
["Indigo", "Yellow", "Violet", "Green", "Red", "Orange", "Blue"],
["Violet", "Indigo", "Blue"],
["Green", "Orange", "Indigo", "Yellow", "Violet"],
["Red", "Green", "Orange", "Indigo", "Yellow", "Violet"],
["Blue", "Red", "Yellow", "Green", "Orange", "Indigo", "Violet"],
["Yellow", "Green", "Orange", "Indigo", "Violet", "Blue", "Red"],
["Orange", "Indigo", "Violet", "Blue", "Red", "Yellow", "Green", ],]
const mockColorTitle = "Favorite Color"
// Food Poll
const mockAnimalItems = ["Rat", "Ox", "Tiger", "Rabbit", "Dragon", "Snake", "Horse", "Goat", "Monkey", "Rooster", "Dog", "Pig"]
const mockAnimalVotes = [
["Rat", "Horse", "Goat", "Monkey", "Rooster", "Dog", "Pig", "Ox", "Tiger", "Rabbit", "Dragon", "Snake"],
["Dog", "Pig", "Ox", "Tiger", "Rat", "Horse", "Goat", "Monkey", "Rooster", "Rabbit", "Dragon", "Snake"],
["Ox", "Tiger", "Rat", "Horse", "Goat", "Monkey", "Rooster", "Rabbit", "Dragon", "Snake", "Dog", "Pig"],
["Tiger", "Rat", "Horse", "Goat", "Ox", "Monkey", "Rooster", "Pig", "Rabbit", "Dragon", "Snake", "Dog"],
["Horse", "Tiger", "Rat", "Pig", "Rabbit", "Dragon", "Snake", "Dog", "Goat", "Ox", "Monkey", "Rooster"],
["Pig", "Rabbit", "Dragon", "Snake", "Dog", "Goat", "Ox", "Horse", "Tiger", "Rat", "Monkey", "Rooster"],
["Rooster", "Pig", "Rabbit", "Dragon", "Snake", "Dog", "Goat", "Ox", "Horse", "Tiger", "Rat", "Monkey"],
["Rabbit", "Dragon", "Rooster", "Ox", "Horse", "Tiger", "Rat", "Pig", "Snake", "Dog", "Goat", "Monkey"],
["Dragon", "Rooster", "Ox", "Horse", "Tiger", "Rabbit", "Rat", "Pig", "Snake", "Dog", "Goat", "Monkey"],
["Snake", "Dog", "Goat", "Monkey", "Dragon", "Rooster", "Ox", "Horse", "Tiger", "Rabbit", "Rat", "Pig"],
["Goat", "Monkey", "Dragon", "Snake", "Dog", "Rooster", "Ox", "Horse", "Tiger", "Rabbit", "Rat", "Pig"],
["Monkey", "Dragon", "Snake", "Goat", "Dog", "Rooster", "Ox", "Horse", "Tiger", "Rabbit", "Rat", "Pig"]]
const mockAnimalTitle = "Favorite Animal"
// Movie Poll
const mockMovieItems = ["Citizen Kane", "North By Northwest", "Toy Story", "Metropolis", "The Godfather", "Casablanca"]
const mockMovieVotes = [
["Citizen Kane", "North By Northwest", "Toy Story", "Metropolis", "The Godfather", "Casablanca"],
["North By Northwest", "Toy Story", "Citizen Kane", "Metropolis", "The Godfather", "Casablanca"],
["Casablanca", "Toy Story", "The Godfather", "Citizen Kane", "North By Northwest", "Metropolis"],
["Citizen Kane", "Casablanca", "The Godfather", "North By Northwest", "Metropolis", "Toy Story"],
["Metropolis", "Casablanca", "The Godfather", "Citizen Kane", "North By Northwest", "Toy Story"],
["Toy Story", "The Godfather", "Citizen Kane", "Metropolis", "Casablanca", "North By Northwest"],
["The Godfather", "Citizen Kane", "Toy Story", "Metropolis", "Casablanca", "North By Northwest"]]
const mockMovieTitle = "Favorite Movie"
// Movie Poll
const mockBoardGameItems = ["Chess", "Risk", "Sorry", "Monopoly", "Scrabble", "Settlers of Catan"]
const mockBoardGameVotes = [
["Chess", "Risk", "Sorry", "Monopoly", "Scrabble", "Settlers of Catan"],
["Sorry", "Monopoly", "Chess", "Risk", "Scrabble", "Settlers of Catan"],
["Monopoly", "Scrabble", "Settlers of Catan"],
["Settlers of Catan","Chess", "Risk", "Sorry", "Monopoly", "Scrabble"],
["Scrabble", "Chess", "Risk", "Sorry", "Monopoly", "Settlers of Catan"],
["Settlers of Catan", "Scrabble", "Chess", "Risk", "Sorry", "Monopoly"],
["Risk", "Scrabble", "Settlers of Catan", "Sorry", "Monopoly", "Chess"]]
const mockBoardGameTitle = "What board game would you like to play?"
// City Poll
const mockCityItems = ["Portland", "Seattle", "Los Angeles", "San Francisco", "Oakland", "San Diego"]
const mockCityVotes = [
["Portland", "Seattle", "Los Angeles", "San Francisco", "Oakland", "San Diego"],
["San Francisco", "Oakland", "San Diego", "Portland", "Seattle", "Los Angeles"],
["San Diego", "Seattle", "Los Angeles", "Oakland", "San Francisco", "Portland"],
["Oakland", "San Diego", "San Francisco", "Portland", "Seattle", "Los Angeles"],
["Seattle", "Los Angeles", "Oakland", "San Diego", "San Francisco", "Portland"],
["Los Angeles", "Seattle", "Portland", "Oakland", "San Diego", "San Francisco"],
["Portland", "Oakland", "San Diego", "Los Angeles", "Seattle", "San Francisco"],
["Seattle", "San Diego", "Los Angeles", "Oakland", "San Francisco", "Portland"],
["Los Angeles", "Seattle", "Portland", "Oakland", "San Diego", "San Francisco"],
["Oakland", "San Diego", "Portland", "Los Angeles", "Seattle", "San Francisco"]]
const mockCityTitle = "What is you favorite west coast city?"
const mockPollOptions = 5
const mockPollMembers = []
const mockPollMemberEmails = []
function returnRandom(a)
{
return Math.floor(Math.random() * a.length)
}
async function createMockUsers()
{
return new Promise(async (resolve, reject) => {
for (var i=0; i<100; i++)
{
const firstname = "Admin"
const lastname = "User"
const email = generateEmail.generateEmail()
const password = "password"
const response = await joinUser.joinUser(firstname, lastname, email, password)
mockPollMembers.push(response.user)
mockPollMemberEmails.push(email)
}
return resolve()
})
}
async function castMockVote(mockPollID, mockVotes, mockPollMembers)
{
return new Promise(async (resolve, reject) => {
// i === 1, admin user has not voted
for (var i=1; i<mockPollMembers.length; i++)
{
const voteResponse = await castVote.castVote(mockPollID, mockVotes[returnRandom(mockVotes)], mockPollMembers[i])
}
return resolve()
})
}
async function createMockPoll()
{
createMockUsers()
.then(async (userResponse) => {
const adminEmail = mockPollMemberEmails[0]
const adminID = mockPollMembers[0]
setTimeout(async() => {
const colorResponse = await createNewPoll.createNewPoll(adminID, mockPollOptions, mockColorItems, mockColorTitle, mockPollMembers)
console.log("Created new poll with ID: "+colorResponse.poll_id)
const castColorVotes = await castMockVote(colorResponse.poll_id, mockColorVotes, mockPollMembers)
const animalResponse = await createNewPoll.createNewPoll(adminID, mockPollOptions, mockAnimalItems, mockAnimalTitle, mockPollMembers)
console.log("Created new poll with ID: "+animalResponse.poll_id)
const castAnimalVotes = await castMockVote(animalResponse.poll_id, mockAnimalVotes, mockPollMembers)
const movieResponse = await createNewPoll.createNewPoll(adminID, mockPollOptions, mockMovieItems, mockMovieTitle, mockPollMembers)
console.log("Created new poll with ID: "+movieResponse.poll_id)
const castMovieVotes = await castMockVote(movieResponse.poll_id, mockMovieVotes, mockPollMembers)
const boardGameResponse = await createNewPoll.createNewPoll(adminID, mockPollOptions, mockBoardGameItems, mockBoardGameTitle, mockPollMembers)
console.log("Created new poll with ID: "+boardGameResponse.poll_id)
const castBoardGameVotes = await castMockVote(boardGameResponse.poll_id, mockBoardGameVotes, mockPollMembers)
const cityResponse = await createNewPoll.createNewPoll(adminID, mockPollOptions, mockCityItems, mockCityTitle, mockPollMembers)
console.log("Created new poll with ID: "+cityResponse.poll_id)
const castCityVotes = await castMockVote(cityResponse.poll_id, mockCityVotes, mockPollMembers)
console.log("Ready to close poll(s). Admin user is "+ mockPollMemberEmails[0])
}, 1000)
})
.catch((error) => {
console.log(error)
})
}
createMockPoll()