forked from ialexanderz/CodeNews-Server
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuserTest.js
More file actions
68 lines (43 loc) · 1.4 KB
/
userTest.js
File metadata and controls
68 lines (43 loc) · 1.4 KB
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
const {User} = require('./models/User.js')
const {UserSchema} = require('./models/User.js')
const {Post} = require('./models/Post.js')
const {Comment} = require('./models/Comment.js')
require('./models')
const newUser = async () => {
try {
const newUser = new User({
username: 'user1',
imageFile: '',
email: 'user1@user.com',
password: 'pw1',
user_image: 'image'
})
await newUser.save()
// console.log(newUser)
const newPost = new Post({
title: 'Why Did Jack Ma Dissapear?',
post_content: 'https://www.bbc.com/news/technology-56448688',
post_upvote: ''
})
newPost.user = newUser
await newPost.save()
// console.log(newPost)
const foundPost = await Post.findOne( {title: 'Why Did Jack Ma Dissapear?'} )
console.log(foundPost)
const foundUser = await User.findById(foundPost.user)
console.log(foundUser)
const newComment = new Comment({
comment_content: 'i disagree!',
comment_upvote: 1,
})
newComment.user = newUser
await newComment.save()
newPost.comments.push(newComment)
await newPost.save()
console.log(newPost)
process.exit(0)
} catch(error) {
console.log(error)
}
}
newUser()