]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/videos/video-comments.ts
Try parallel check params tests
[github/Chocobozzz/PeerTube.git] / server / tests / api / videos / video-comments.ts
CommitLineData
d3ea8975
C
1/* tslint:disable:no-unused-expression */
2
3import * as chai from 'chai'
4import 'mocha'
c5d31dba 5import { VideoComment, VideoCommentThreadTree } from '../../../../shared/models/videos/video-comment.model'
7c3b7976 6import { cleanupTests, testImage } from '../../../../shared/extra-utils'
cf117aaa 7import {
3cd0734f 8 dateIsValid,
210feb6c 9 flushAndRunServer,
3cd0734f
C
10 ServerInfo,
11 setAccessTokensToServers,
12 updateMyAvatar,
cf117aaa 13 uploadVideo
94565d52 14} from '../../../../shared/extra-utils/index'
c5d31dba 15import {
3cd0734f
C
16 addVideoCommentReply,
17 addVideoCommentThread,
18 deleteVideoComment,
19 getVideoCommentThreads,
c5d31dba 20 getVideoThreadComments
94565d52 21} from '../../../../shared/extra-utils/videos/video-comments'
d3ea8975
C
22
23const expect = chai.expect
24
e2e22e40 25describe('Test video comments', function () {
d3ea8975
C
26 let server: ServerInfo
27 let videoId
28 let videoUUID
29 let threadId
4cb6d457 30 let replyToDeleteId: number
d3ea8975
C
31
32 before(async function () {
e212f887 33 this.timeout(30000)
d3ea8975 34
210feb6c 35 server = await flushAndRunServer(1)
d3ea8975
C
36
37 await setAccessTokensToServers([ server ])
38
39 const res = await uploadVideo(server.url, server.accessToken, {})
40 videoUUID = res.body.video.uuid
41 videoId = res.body.video.id
cf117aaa
C
42
43 await updateMyAvatar({
44 url: server.url,
45 accessToken: server.accessToken,
46 fixture: 'avatar.png'
47 })
d3ea8975
C
48 })
49
50 it('Should not have threads on this video', async function () {
51 const res = await getVideoCommentThreads(server.url, videoUUID, 0, 5)
52
53 expect(res.body.total).to.equal(0)
54 expect(res.body.data).to.be.an('array')
55 expect(res.body.data).to.have.lengthOf(0)
56 })
57
58 it('Should create a thread in this video', async function () {
59 const text = 'my super first comment'
60
4635f59d 61 const res = await addVideoCommentThread(server.url, server.accessToken, videoUUID, text)
d50acfab 62 const comment = res.body.comment
4635f59d
C
63
64 expect(comment.inReplyToCommentId).to.be.null
65 expect(comment.text).equal('my super first comment')
66 expect(comment.videoId).to.equal(videoId)
67 expect(comment.id).to.equal(comment.threadId)
68 expect(comment.account.name).to.equal('root')
69 expect(comment.account.host).to.equal('localhost:9001')
4cb6d457 70 expect(comment.account.url).to.equal('http://localhost:9001/accounts/root')
4635f59d
C
71 expect(comment.totalReplies).to.equal(0)
72 expect(dateIsValid(comment.createdAt as string)).to.be.true
73 expect(dateIsValid(comment.updatedAt as string)).to.be.true
d3ea8975
C
74 })
75
76 it('Should list threads of this video', async function () {
77 const res = await getVideoCommentThreads(server.url, videoUUID, 0, 5)
78
79 expect(res.body.total).to.equal(1)
80 expect(res.body.data).to.be.an('array')
81 expect(res.body.data).to.have.lengthOf(1)
82
83 const comment: VideoComment = res.body.data[0]
84 expect(comment.inReplyToCommentId).to.be.null
85 expect(comment.text).equal('my super first comment')
86 expect(comment.videoId).to.equal(videoId)
87 expect(comment.id).to.equal(comment.threadId)
88 expect(comment.account.name).to.equal('root')
4635f59d 89 expect(comment.account.host).to.equal('localhost:9001')
cf117aaa 90
7b0956ec 91 await testImage(server.url, 'avatar-resized', comment.account.avatar.path, '.png')
cf117aaa 92
4635f59d 93 expect(comment.totalReplies).to.equal(0)
d3ea8975
C
94 expect(dateIsValid(comment.createdAt as string)).to.be.true
95 expect(dateIsValid(comment.updatedAt as string)).to.be.true
96
97 threadId = comment.threadId
98 })
99
100 it('Should get all the thread created', async function () {
101 const res = await getVideoThreadComments(server.url, videoUUID, threadId)
102
103 const rootComment = res.body.comment
104 expect(rootComment.inReplyToCommentId).to.be.null
105 expect(rootComment.text).equal('my super first comment')
106 expect(rootComment.videoId).to.equal(videoId)
107 expect(dateIsValid(rootComment.createdAt as string)).to.be.true
108 expect(dateIsValid(rootComment.updatedAt as string)).to.be.true
109 })
110
111 it('Should create multiple replies in this thread', async function () {
112 const text1 = 'my super answer to thread 1'
113 const childCommentRes = await addVideoCommentReply(server.url, server.accessToken, videoId, threadId, text1)
114 const childCommentId = childCommentRes.body.comment.id
115
116 const text2 = 'my super answer to answer of thread 1'
117 await addVideoCommentReply(server.url, server.accessToken, videoId, childCommentId, text2)
118
119 const text3 = 'my second answer to thread 1'
120 await addVideoCommentReply(server.url, server.accessToken, videoId, threadId, text3)
121 })
122
123 it('Should get correctly the replies', async function () {
124 const res = await getVideoThreadComments(server.url, videoUUID, threadId)
125
126 const tree: VideoCommentThreadTree = res.body
127 expect(tree.comment.text).equal('my super first comment')
128 expect(tree.children).to.have.lengthOf(2)
129
130 const firstChild = tree.children[0]
131 expect(firstChild.comment.text).to.equal('my super answer to thread 1')
132 expect(firstChild.children).to.have.lengthOf(1)
133
134 const childOfFirstChild = firstChild.children[0]
135 expect(childOfFirstChild.comment.text).to.equal('my super answer to answer of thread 1')
136 expect(childOfFirstChild.children).to.have.lengthOf(0)
137
138 const secondChild = tree.children[1]
139 expect(secondChild.comment.text).to.equal('my second answer to thread 1')
140 expect(secondChild.children).to.have.lengthOf(0)
4cb6d457
C
141
142 replyToDeleteId = secondChild.comment.id
d3ea8975
C
143 })
144
145 it('Should create other threads', async function () {
146 const text1 = 'super thread 2'
147 await addVideoCommentThread(server.url, server.accessToken, videoUUID, text1)
148
149 const text2 = 'super thread 3'
150 await addVideoCommentThread(server.url, server.accessToken, videoUUID, text2)
151 })
152
153 it('Should list the threads', async function () {
154 const res = await getVideoCommentThreads(server.url, videoUUID, 0, 5, 'createdAt')
155
156 expect(res.body.total).to.equal(3)
157 expect(res.body.data).to.be.an('array')
158 expect(res.body.data).to.have.lengthOf(3)
159
160 expect(res.body.data[0].text).to.equal('my super first comment')
d50acfab 161 expect(res.body.data[0].totalReplies).to.equal(3)
d3ea8975 162 expect(res.body.data[1].text).to.equal('super thread 2')
d50acfab 163 expect(res.body.data[1].totalReplies).to.equal(0)
d3ea8975 164 expect(res.body.data[2].text).to.equal('super thread 3')
4635f59d 165 expect(res.body.data[2].totalReplies).to.equal(0)
d3ea8975
C
166 })
167
4cb6d457
C
168 it('Should delete a reply', async function () {
169 await deleteVideoComment(server.url, server.accessToken, videoId, replyToDeleteId)
170
171 const res = await getVideoThreadComments(server.url, videoUUID, threadId)
172
173 const tree: VideoCommentThreadTree = res.body
174 expect(tree.comment.text).equal('my super first comment')
175 expect(tree.children).to.have.lengthOf(1)
176
177 const firstChild = tree.children[0]
178 expect(firstChild.comment.text).to.equal('my super answer to thread 1')
179 expect(firstChild.children).to.have.lengthOf(1)
180
181 const childOfFirstChild = firstChild.children[0]
182 expect(childOfFirstChild.comment.text).to.equal('my super answer to answer of thread 1')
183 expect(childOfFirstChild.children).to.have.lengthOf(0)
184 })
185
186 it('Should delete a complete thread', async function () {
187 await deleteVideoComment(server.url, server.accessToken, videoId, threadId)
188
189 const res = await getVideoCommentThreads(server.url, videoUUID, 0, 5, 'createdAt')
190 expect(res.body.total).to.equal(2)
191 expect(res.body.data).to.be.an('array')
192 expect(res.body.data).to.have.lengthOf(2)
193
194 expect(res.body.data[0].text).to.equal('super thread 2')
195 expect(res.body.data[0].totalReplies).to.equal(0)
196 expect(res.body.data[1].text).to.equal('super thread 3')
197 expect(res.body.data[1].totalReplies).to.equal(0)
198 })
199
7c3b7976
C
200 after(async function () {
201 await cleanupTests([ server ])
d3ea8975
C
202 })
203})