]>
Commit | Line | Data |
---|---|---|
d3ea8975 C |
1 | /* tslint:disable:no-unused-expression */ |
2 | ||
3 | import * as chai from 'chai' | |
4 | import 'mocha' | |
5 | import { VideoComment, VideoCommentThreadTree } from '../../../shared/models/videos/video-comment.model' | |
6 | import { dateIsValid, flushTests, killallServers, runServer, ServerInfo, setAccessTokensToServers, uploadVideo } from '../utils' | |
7 | import { addVideoCommentReply, addVideoCommentThread, getVideoCommentThreads, getVideoThreadComments } from '../utils/video-comments' | |
8 | ||
9 | const expect = chai.expect | |
10 | ||
e2e22e40 | 11 | describe('Test video comments', function () { |
d3ea8975 C |
12 | let server: ServerInfo |
13 | let videoId | |
14 | let videoUUID | |
15 | let threadId | |
16 | ||
17 | before(async function () { | |
18 | this.timeout(10000) | |
19 | ||
20 | await flushTests() | |
21 | ||
22 | server = await runServer(1) | |
23 | ||
24 | await setAccessTokensToServers([ server ]) | |
25 | ||
26 | const res = await uploadVideo(server.url, server.accessToken, {}) | |
27 | videoUUID = res.body.video.uuid | |
28 | videoId = res.body.video.id | |
29 | }) | |
30 | ||
31 | it('Should not have threads on this video', async function () { | |
32 | const res = await getVideoCommentThreads(server.url, videoUUID, 0, 5) | |
33 | ||
34 | expect(res.body.total).to.equal(0) | |
35 | expect(res.body.data).to.be.an('array') | |
36 | expect(res.body.data).to.have.lengthOf(0) | |
37 | }) | |
38 | ||
39 | it('Should create a thread in this video', async function () { | |
40 | const text = 'my super first comment' | |
41 | ||
4635f59d C |
42 | const res = await addVideoCommentThread(server.url, server.accessToken, videoUUID, text) |
43 | const comment = res.body | |
44 | ||
45 | expect(comment.inReplyToCommentId).to.be.null | |
46 | expect(comment.text).equal('my super first comment') | |
47 | expect(comment.videoId).to.equal(videoId) | |
48 | expect(comment.id).to.equal(comment.threadId) | |
49 | expect(comment.account.name).to.equal('root') | |
50 | expect(comment.account.host).to.equal('localhost:9001') | |
51 | expect(comment.totalReplies).to.equal(0) | |
52 | expect(dateIsValid(comment.createdAt as string)).to.be.true | |
53 | expect(dateIsValid(comment.updatedAt as string)).to.be.true | |
d3ea8975 C |
54 | }) |
55 | ||
56 | it('Should list threads of this video', async function () { | |
57 | const res = await getVideoCommentThreads(server.url, videoUUID, 0, 5) | |
58 | ||
59 | expect(res.body.total).to.equal(1) | |
60 | expect(res.body.data).to.be.an('array') | |
61 | expect(res.body.data).to.have.lengthOf(1) | |
62 | ||
63 | const comment: VideoComment = res.body.data[0] | |
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') | |
4635f59d C |
69 | expect(comment.account.host).to.equal('localhost:9001') |
70 | expect(comment.totalReplies).to.equal(0) | |
d3ea8975 C |
71 | expect(dateIsValid(comment.createdAt as string)).to.be.true |
72 | expect(dateIsValid(comment.updatedAt as string)).to.be.true | |
73 | ||
74 | threadId = comment.threadId | |
75 | }) | |
76 | ||
77 | it('Should get all the thread created', async function () { | |
78 | const res = await getVideoThreadComments(server.url, videoUUID, threadId) | |
79 | ||
80 | const rootComment = res.body.comment | |
81 | expect(rootComment.inReplyToCommentId).to.be.null | |
82 | expect(rootComment.text).equal('my super first comment') | |
83 | expect(rootComment.videoId).to.equal(videoId) | |
84 | expect(dateIsValid(rootComment.createdAt as string)).to.be.true | |
85 | expect(dateIsValid(rootComment.updatedAt as string)).to.be.true | |
86 | }) | |
87 | ||
88 | it('Should create multiple replies in this thread', async function () { | |
89 | const text1 = 'my super answer to thread 1' | |
90 | const childCommentRes = await addVideoCommentReply(server.url, server.accessToken, videoId, threadId, text1) | |
91 | const childCommentId = childCommentRes.body.comment.id | |
92 | ||
93 | const text2 = 'my super answer to answer of thread 1' | |
94 | await addVideoCommentReply(server.url, server.accessToken, videoId, childCommentId, text2) | |
95 | ||
96 | const text3 = 'my second answer to thread 1' | |
97 | await addVideoCommentReply(server.url, server.accessToken, videoId, threadId, text3) | |
98 | }) | |
99 | ||
100 | it('Should get correctly the replies', async function () { | |
101 | const res = await getVideoThreadComments(server.url, videoUUID, threadId) | |
102 | ||
103 | const tree: VideoCommentThreadTree = res.body | |
104 | expect(tree.comment.text).equal('my super first comment') | |
105 | expect(tree.children).to.have.lengthOf(2) | |
106 | ||
107 | const firstChild = tree.children[0] | |
108 | expect(firstChild.comment.text).to.equal('my super answer to thread 1') | |
109 | expect(firstChild.children).to.have.lengthOf(1) | |
110 | ||
111 | const childOfFirstChild = firstChild.children[0] | |
112 | expect(childOfFirstChild.comment.text).to.equal('my super answer to answer of thread 1') | |
113 | expect(childOfFirstChild.children).to.have.lengthOf(0) | |
114 | ||
115 | const secondChild = tree.children[1] | |
116 | expect(secondChild.comment.text).to.equal('my second answer to thread 1') | |
117 | expect(secondChild.children).to.have.lengthOf(0) | |
118 | }) | |
119 | ||
120 | it('Should create other threads', async function () { | |
121 | const text1 = 'super thread 2' | |
122 | await addVideoCommentThread(server.url, server.accessToken, videoUUID, text1) | |
123 | ||
124 | const text2 = 'super thread 3' | |
125 | await addVideoCommentThread(server.url, server.accessToken, videoUUID, text2) | |
126 | }) | |
127 | ||
128 | it('Should list the threads', async function () { | |
129 | const res = await getVideoCommentThreads(server.url, videoUUID, 0, 5, 'createdAt') | |
130 | ||
131 | expect(res.body.total).to.equal(3) | |
132 | expect(res.body.data).to.be.an('array') | |
133 | expect(res.body.data).to.have.lengthOf(3) | |
134 | ||
135 | expect(res.body.data[0].text).to.equal('my super first comment') | |
4635f59d | 136 | expect(res.body.data[0].totalReplies).to.equal(2) |
d3ea8975 | 137 | expect(res.body.data[1].text).to.equal('super thread 2') |
4635f59d | 138 | expect(res.body.data[1].totalReplies).to.equal(1) |
d3ea8975 | 139 | expect(res.body.data[2].text).to.equal('super thread 3') |
4635f59d | 140 | expect(res.body.data[2].totalReplies).to.equal(0) |
d3ea8975 C |
141 | }) |
142 | ||
143 | after(async function () { | |
144 | killallServers([ server ]) | |
145 | ||
146 | // Keep the logs if the test failed | |
147 | if (this['ok']) { | |
148 | await flushTests() | |
149 | } | |
150 | }) | |
151 | }) |