-
Notifications
You must be signed in to change notification settings - Fork 0
/
seed.ts
218 lines (189 loc) · 5.44 KB
/
seed.ts
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
import bcrypt from 'bcryptjs'
import { db } from '#app/database/db.ts'
import { createPost } from '#app/modules/posts/post-service.ts'
import { VoteDirection } from '#app/modules/posts/post-types.ts'
import { vote } from '#app/modules/posts/scoring/vote-service.ts'
import { getPasswordHash } from '#app/utils/auth.server.ts'
export async function seed() {
console.log('seeding...')
let alice = '100'
let bob = '101'
let charlie = '102'
await db
.insertInto('User')
.values({
id: alice,
username: 'alice',
email: '[email protected]',
isAdmin: 0,
})
.execute()
await db
.insertInto('Password')
.values({
userId: alice,
hash: await getPasswordHash('123456'),
})
.execute()
await db
.insertInto('User')
.values({
id: bob,
username: 'bob',
email: '[email protected]',
isAdmin: 0,
// password: { create: createPassword('bob') },
})
.execute()
await db
.insertInto('User')
.values({
id: charlie,
username: 'charlie',
email: '[email protected]',
isAdmin: 0,
// password: { create: createPassword('charlie') },
})
.execute()
// await seedStats()
// First, alice creates a post
let post1 = await db.transaction().execute(async trx => {
return await createPost(
trx,
null,
'So, pregnant people can’t cross state lines to get abortions but guys like Kyle Rittenhouse can cross state lines to murder people. Seems fair.',
alice,
{ isPrivate: false, withUpvote: true },
)
})
// Then bob posts a response to alice's post
let post2 = await db.transaction().execute(async trx => {
return await createPost(
trx,
post1,
'Kyle Rittenhouse was acquitted of murder charges. Clear video evidence showed he acted in self defense.',
bob,
{ isPrivate: false, withUpvote: true },
)
})
// And also downvotes
db.transaction().execute(
async trx => await vote(trx, bob, post1, VoteDirection.Down),
)
// And responds to bob's response
await db.transaction().execute(async trx => {
return await createPost(
trx,
post2,
'That trial was a sham. They were never going to convict.',
alice,
{ isPrivate: false, withUpvote: true },
)
})
// And then creates another unrelated post
let post4 = await db.transaction().execute(async trx => {
return await createPost(
trx,
null,
'Sudafed, Benadryl and most decongestants don’t work: FDA advisory panel https://trib.al/sJmOJBP',
alice,
{ isPrivate: false, withUpvote: true },
)
})
// And respond's to Alices's latest post
await db.transaction().execute(async trx => {
return await createPost(
trx,
post4,
'This is misleading. Regular Benadryl is an antihistamine; it is not a decongestant. There is a Benadryl branded product that is impacted. https://www.nbcnews.com/news/amp/rcna104424',
bob,
{ isPrivate: false, withUpvote: true },
)
})
// Alice post's again
let post6 = await db.transaction().execute(async trx => {
return await createPost(
trx,
null,
"Right now, real wages for the average American worker is higher than it was before the pandemic, with lower wage workers seeing the largest gains. That's Bidenomics.",
alice,
{ isPrivate: false, withUpvote: true },
)
})
// And respond's to Alice's third post
await db.transaction().execute(async trx => {
return await createPost(
trx,
post6,
"The tweet's claim about real wages contains a factual error. On 3/15/20 when US COVID lockdowns began real wages adjusted for inflation (AFI) were $11.15. As of 7/16/23 real wages AFI are $11.05. Real wages AFI remain lower (not higher) than before the pandemic.",
bob,
{ isPrivate: false, withUpvote: true },
)
})
await db.transaction().execute(async trx => {
await vote(trx, alice, post6, VoteDirection.Down)
// agreed with 2 (shown 3)
await vote(trx, charlie, post2, VoteDirection.Up)
// changed mind after seeing 2
await vote(trx, charlie, post1, VoteDirection.Down)
// changed mind back (for no particular reason)
await vote(trx, charlie, post1, VoteDirection.Up)
// duplicate vote
await vote(trx, charlie, post1, VoteDirection.Up)
// changed mind back again
await vote(trx, charlie, post1, VoteDirection.Down)
// and s some other votes
await vote(trx, charlie, post1, VoteDirection.Down)
await vote(trx, charlie, post2, VoteDirection.Down)
await vote(trx, charlie, post2, VoteDirection.Up)
await vote(trx, charlie, 3, 1)
await vote(trx, charlie, 2, -1)
await vote(trx, bob, 6, -1)
await vote(trx, alice, 5, -1)
await vote(trx, alice, 4, -1)
})
// Create developer user with password 'password'. Can login with this user by pointing browser to /dev-login
const id = 'developer'
await db
.insertInto('User')
.values({
id: id,
username: 'developer',
email: '[email protected]',
isAdmin: 0,
})
.execute()
const hashedPassword = await bcrypt.hash('password', 10)
await db
.insertInto('Password')
.values({
hash: hashedPassword,
userId: id,
})
.returningAll()
.executeTakeFirstOrThrow()
// Create test admin user with password 'password'. For testing admin features.
const adminId = 'testadmin'
await db
.insertInto('User')
.values({
id: adminId,
username: 'testadmin',
email: '[email protected]',
isAdmin: 1,
})
.execute()
const hashedAdminPassword = await bcrypt.hash('password', 10)
await db
.insertInto('Password')
.values({
hash: hashedAdminPassword,
userId: adminId,
})
.returningAll()
.executeTakeFirstOrThrow()
}
seed().catch(e => {
console.error(e)
process.exit(1)
})