1 /* tslint:disable:no-unused-expression */
3 import * as chai from 'chai'
5 import { VideoComment, VideoCommentThreadTree } from '../../../../shared/models/videos/video-comment.model'
6 import { testImage } from '../../../../shared/extra-utils'
13 setAccessTokensToServers,
16 } from '../../../../shared/extra-utils/index'
19 addVideoCommentThread,
21 getVideoCommentThreads,
22 getVideoThreadComments
23 } from '../../../../shared/extra-utils/videos/video-comments'
25 const expect = chai.expect
27 describe('Test video comments', function () {
28 let server: ServerInfo
32 let replyToDeleteId: number
34 before(async function () {
37 server = await flushAndRunServer(1)
39 await setAccessTokensToServers([ server ])
41 const res = await uploadVideo(server.url, server.accessToken, {})
42 videoUUID = res.body.video.uuid
43 videoId = res.body.video.id
45 await updateMyAvatar({
47 accessToken: server.accessToken,
52 it('Should not have threads on this video', async function () {
53 const res = await getVideoCommentThreads(server.url, videoUUID, 0, 5)
55 expect(res.body.total).to.equal(0)
56 expect(res.body.data).to.be.an('array')
57 expect(res.body.data).to.have.lengthOf(0)
60 it('Should create a thread in this video', async function () {
61 const text = 'my super first comment'
63 const res = await addVideoCommentThread(server.url, server.accessToken, videoUUID, text)
64 const comment = res.body.comment
66 expect(comment.inReplyToCommentId).to.be.null
67 expect(comment.text).equal('my super first comment')
68 expect(comment.videoId).to.equal(videoId)
69 expect(comment.id).to.equal(comment.threadId)
70 expect(comment.account.name).to.equal('root')
71 expect(comment.account.host).to.equal('localhost:9001')
72 expect(comment.account.url).to.equal('http://localhost:9001/accounts/root')
73 expect(comment.totalReplies).to.equal(0)
74 expect(dateIsValid(comment.createdAt as string)).to.be.true
75 expect(dateIsValid(comment.updatedAt as string)).to.be.true
78 it('Should list threads of this video', async function () {
79 const res = await getVideoCommentThreads(server.url, videoUUID, 0, 5)
81 expect(res.body.total).to.equal(1)
82 expect(res.body.data).to.be.an('array')
83 expect(res.body.data).to.have.lengthOf(1)
85 const comment: VideoComment = res.body.data[0]
86 expect(comment.inReplyToCommentId).to.be.null
87 expect(comment.text).equal('my super first comment')
88 expect(comment.videoId).to.equal(videoId)
89 expect(comment.id).to.equal(comment.threadId)
90 expect(comment.account.name).to.equal('root')
91 expect(comment.account.host).to.equal('localhost:9001')
93 await testImage(server.url, 'avatar-resized', comment.account.avatar.path, '.png')
95 expect(comment.totalReplies).to.equal(0)
96 expect(dateIsValid(comment.createdAt as string)).to.be.true
97 expect(dateIsValid(comment.updatedAt as string)).to.be.true
99 threadId = comment.threadId
102 it('Should get all the thread created', async function () {
103 const res = await getVideoThreadComments(server.url, videoUUID, threadId)
105 const rootComment = res.body.comment
106 expect(rootComment.inReplyToCommentId).to.be.null
107 expect(rootComment.text).equal('my super first comment')
108 expect(rootComment.videoId).to.equal(videoId)
109 expect(dateIsValid(rootComment.createdAt as string)).to.be.true
110 expect(dateIsValid(rootComment.updatedAt as string)).to.be.true
113 it('Should create multiple replies in this thread', async function () {
114 const text1 = 'my super answer to thread 1'
115 const childCommentRes = await addVideoCommentReply(server.url, server.accessToken, videoId, threadId, text1)
116 const childCommentId = childCommentRes.body.comment.id
118 const text2 = 'my super answer to answer of thread 1'
119 await addVideoCommentReply(server.url, server.accessToken, videoId, childCommentId, text2)
121 const text3 = 'my second answer to thread 1'
122 await addVideoCommentReply(server.url, server.accessToken, videoId, threadId, text3)
125 it('Should get correctly the replies', async function () {
126 const res = await getVideoThreadComments(server.url, videoUUID, threadId)
128 const tree: VideoCommentThreadTree = res.body
129 expect(tree.comment.text).equal('my super first comment')
130 expect(tree.children).to.have.lengthOf(2)
132 const firstChild = tree.children[0]
133 expect(firstChild.comment.text).to.equal('my super answer to thread 1')
134 expect(firstChild.children).to.have.lengthOf(1)
136 const childOfFirstChild = firstChild.children[0]
137 expect(childOfFirstChild.comment.text).to.equal('my super answer to answer of thread 1')
138 expect(childOfFirstChild.children).to.have.lengthOf(0)
140 const secondChild = tree.children[1]
141 expect(secondChild.comment.text).to.equal('my second answer to thread 1')
142 expect(secondChild.children).to.have.lengthOf(0)
144 replyToDeleteId = secondChild.comment.id
147 it('Should create other threads', async function () {
148 const text1 = 'super thread 2'
149 await addVideoCommentThread(server.url, server.accessToken, videoUUID, text1)
151 const text2 = 'super thread 3'
152 await addVideoCommentThread(server.url, server.accessToken, videoUUID, text2)
155 it('Should list the threads', async function () {
156 const res = await getVideoCommentThreads(server.url, videoUUID, 0, 5, 'createdAt')
158 expect(res.body.total).to.equal(3)
159 expect(res.body.data).to.be.an('array')
160 expect(res.body.data).to.have.lengthOf(3)
162 expect(res.body.data[0].text).to.equal('my super first comment')
163 expect(res.body.data[0].totalReplies).to.equal(3)
164 expect(res.body.data[1].text).to.equal('super thread 2')
165 expect(res.body.data[1].totalReplies).to.equal(0)
166 expect(res.body.data[2].text).to.equal('super thread 3')
167 expect(res.body.data[2].totalReplies).to.equal(0)
170 it('Should delete a reply', async function () {
171 await deleteVideoComment(server.url, server.accessToken, videoId, replyToDeleteId)
173 const res = await getVideoThreadComments(server.url, videoUUID, threadId)
175 const tree: VideoCommentThreadTree = res.body
176 expect(tree.comment.text).equal('my super first comment')
177 expect(tree.children).to.have.lengthOf(1)
179 const firstChild = tree.children[0]
180 expect(firstChild.comment.text).to.equal('my super answer to thread 1')
181 expect(firstChild.children).to.have.lengthOf(1)
183 const childOfFirstChild = firstChild.children[0]
184 expect(childOfFirstChild.comment.text).to.equal('my super answer to answer of thread 1')
185 expect(childOfFirstChild.children).to.have.lengthOf(0)
188 it('Should delete a complete thread', async function () {
189 await deleteVideoComment(server.url, server.accessToken, videoId, threadId)
191 const res = await getVideoCommentThreads(server.url, videoUUID, 0, 5, 'createdAt')
192 expect(res.body.total).to.equal(2)
193 expect(res.body.data).to.be.an('array')
194 expect(res.body.data).to.have.lengthOf(2)
196 expect(res.body.data[0].text).to.equal('super thread 2')
197 expect(res.body.data[0].totalReplies).to.equal(0)
198 expect(res.body.data[1].text).to.equal('super thread 3')
199 expect(res.body.data[1].totalReplies).to.equal(0)
203 killallServers([ server ])