diff options
author | Chocobozzz <me@florianbigard.com> | 2017-12-28 11:45:10 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2017-12-28 11:45:10 +0100 |
commit | db799da3d2b2ea465165df78ff71effa653b6309 (patch) | |
tree | 11a01db2c9521797f63b6ea6cc78745132505ee4 /server | |
parent | da854ddd502cd70685ef779c673b9e63757b8aa0 (diff) | |
download | PeerTube-db799da3d2b2ea465165df78ff71effa653b6309.tar.gz PeerTube-db799da3d2b2ea465165df78ff71effa653b6309.tar.zst PeerTube-db799da3d2b2ea465165df78ff71effa653b6309.zip |
Add get old comment on follow tests
Diffstat (limited to 'server')
-rw-r--r-- | server/models/video/video-comment.ts | 3 | ||||
-rw-r--r-- | server/tests/api/follows.ts | 75 |
2 files changed, 67 insertions, 11 deletions
diff --git a/server/models/video/video-comment.ts b/server/models/video/video-comment.ts index 1992c2dd8..d381ccafa 100644 --- a/server/models/video/video-comment.ts +++ b/server/models/video/video-comment.ts | |||
@@ -103,8 +103,10 @@ export class VideoCommentModel extends Model<VideoCommentModel> { | |||
103 | 103 | ||
104 | @BelongsTo(() => VideoCommentModel, { | 104 | @BelongsTo(() => VideoCommentModel, { |
105 | foreignKey: { | 105 | foreignKey: { |
106 | name: 'originCommentId', | ||
106 | allowNull: true | 107 | allowNull: true |
107 | }, | 108 | }, |
109 | as: 'OriginVideoComment', | ||
108 | onDelete: 'CASCADE' | 110 | onDelete: 'CASCADE' |
109 | }) | 111 | }) |
110 | OriginVideoComment: VideoCommentModel | 112 | OriginVideoComment: VideoCommentModel |
@@ -115,6 +117,7 @@ export class VideoCommentModel extends Model<VideoCommentModel> { | |||
115 | 117 | ||
116 | @BelongsTo(() => VideoCommentModel, { | 118 | @BelongsTo(() => VideoCommentModel, { |
117 | foreignKey: { | 119 | foreignKey: { |
120 | name: 'inReplyToCommentId', | ||
118 | allowNull: true | 121 | allowNull: true |
119 | }, | 122 | }, |
120 | as: 'InReplyToVideoComment', | 123 | as: 'InReplyToVideoComment', |
diff --git a/server/tests/api/follows.ts b/server/tests/api/follows.ts index 10eb48969..2ffa426a0 100644 --- a/server/tests/api/follows.ts +++ b/server/tests/api/follows.ts | |||
@@ -2,21 +2,17 @@ | |||
2 | 2 | ||
3 | import * as chai from 'chai' | 3 | import * as chai from 'chai' |
4 | import 'mocha' | 4 | import 'mocha' |
5 | import { VideoComment, VideoCommentThreadTree } from '../../../shared/models/videos/video-comment.model' | ||
5 | 6 | ||
6 | import { | 7 | import { |
7 | flushAndRunMultipleServers, | 8 | flushAndRunMultipleServers, flushTests, getVideosList, killallServers, ServerInfo, setAccessTokensToServers, uploadVideo, |
8 | flushTests, | ||
9 | getVideosList, | ||
10 | killallServers, | ||
11 | ServerInfo, | ||
12 | setAccessTokensToServers, | ||
13 | uploadVideo, | ||
14 | wait | 9 | wait |
15 | } from '../utils' | 10 | } from '../utils' |
16 | import { follow, getFollowersListPaginationAndSort, getFollowingListPaginationAndSort, unfollow } from '../utils/follows' | 11 | import { follow, getFollowersListPaginationAndSort, getFollowingListPaginationAndSort, unfollow } from '../utils/follows' |
17 | import { getUserAccessToken } from '../utils/login' | 12 | import { getUserAccessToken } from '../utils/login' |
18 | import { dateIsValid, webtorrentAdd } from '../utils/miscs' | 13 | import { dateIsValid, webtorrentAdd } from '../utils/miscs' |
19 | import { createUser } from '../utils/users' | 14 | import { createUser } from '../utils/users' |
15 | import { addVideoCommentReply, addVideoCommentThread, getVideoCommentThreads, getVideoThreadComments } from '../utils/video-comments' | ||
20 | import { getVideo, rateVideo, testVideoImage } from '../utils/videos' | 16 | import { getVideo, rateVideo, testVideoImage } from '../utils/videos' |
21 | 17 | ||
22 | const expect = chai.expect | 18 | const expect = chai.expect |
@@ -186,11 +182,29 @@ describe('Test follows', function () { | |||
186 | await createUser(servers[2].url, servers[2].accessToken, user.username, user.password) | 182 | await createUser(servers[2].url, servers[2].accessToken, user.username, user.password) |
187 | const userAccessToken = await getUserAccessToken(servers[2], user) | 183 | const userAccessToken = await getUserAccessToken(servers[2], user) |
188 | 184 | ||
189 | const res = await getVideosList(servers[2].url) | 185 | const resVideos = await getVideosList(servers[ 2 ].url) |
190 | const video4 = res.body.data.find(v => v.name === 'server3-4') | 186 | const video4 = resVideos.body.data.find(v => v.name === 'server3-4') |
191 | 187 | ||
192 | await rateVideo(servers[2].url, servers[2].accessToken, video4.id, 'like') | 188 | { |
193 | await rateVideo(servers[2].url, userAccessToken, video4.id, 'dislike') | 189 | await rateVideo(servers[ 2 ].url, servers[ 2 ].accessToken, video4.id, 'like') |
190 | await rateVideo(servers[ 2 ].url, userAccessToken, video4.id, 'dislike') | ||
191 | } | ||
192 | |||
193 | { | ||
194 | const text = 'my super first comment' | ||
195 | const res = await addVideoCommentThread(servers[ 2 ].url, servers[ 2 ].accessToken, video4.id, text) | ||
196 | const threadId = res.body.comment.id | ||
197 | |||
198 | const text1 = 'my super answer to thread 1' | ||
199 | const childCommentRes = await addVideoCommentReply(servers[ 2 ].url, servers[ 2 ].accessToken, video4.id, threadId, text1) | ||
200 | const childCommentId = childCommentRes.body.comment.id | ||
201 | |||
202 | const text2 = 'my super answer to answer of thread 1' | ||
203 | await addVideoCommentReply(servers[ 2 ].url, servers[ 2 ].accessToken, video4.id, childCommentId, text2) | ||
204 | |||
205 | const text3 = 'my second answer to thread 1' | ||
206 | await addVideoCommentReply(servers[ 2 ].url, servers[ 2 ].accessToken, video4.id, threadId, text3) | ||
207 | } | ||
194 | } | 208 | } |
195 | 209 | ||
196 | await wait(5000) | 210 | await wait(5000) |
@@ -249,6 +263,45 @@ describe('Test follows', function () { | |||
249 | expect(torrent.files).to.be.an('array') | 263 | expect(torrent.files).to.be.an('array') |
250 | expect(torrent.files.length).to.equal(1) | 264 | expect(torrent.files.length).to.equal(1) |
251 | expect(torrent.files[0].path).to.exist.and.to.not.equal('') | 265 | expect(torrent.files[0].path).to.exist.and.to.not.equal('') |
266 | |||
267 | { | ||
268 | const res1 = await getVideoCommentThreads(servers[0].url, video4.id, 0, 5) | ||
269 | |||
270 | expect(res1.body.total).to.equal(1) | ||
271 | expect(res1.body.data).to.be.an('array') | ||
272 | expect(res1.body.data).to.have.lengthOf(1) | ||
273 | |||
274 | const comment: VideoComment = res1.body.data[0] | ||
275 | expect(comment.inReplyToCommentId).to.be.null | ||
276 | expect(comment.text).equal('my super first comment') | ||
277 | expect(comment.videoId).to.equal(video4.id) | ||
278 | expect(comment.id).to.equal(comment.threadId) | ||
279 | expect(comment.account.name).to.equal('root') | ||
280 | expect(comment.account.host).to.equal('localhost:9003') | ||
281 | expect(comment.totalReplies).to.equal(3) | ||
282 | expect(dateIsValid(comment.createdAt as string)).to.be.true | ||
283 | expect(dateIsValid(comment.updatedAt as string)).to.be.true | ||
284 | |||
285 | const threadId = comment.threadId | ||
286 | |||
287 | const res2 = await getVideoThreadComments(servers[0].url, video4.id, threadId) | ||
288 | |||
289 | const tree: VideoCommentThreadTree = res2.body | ||
290 | expect(tree.comment.text).equal('my super first comment') | ||
291 | expect(tree.children).to.have.lengthOf(2) | ||
292 | |||
293 | const firstChild = tree.children[0] | ||
294 | expect(firstChild.comment.text).to.equal('my super answer to thread 1') | ||
295 | expect(firstChild.children).to.have.lengthOf(1) | ||
296 | |||
297 | const childOfFirstChild = firstChild.children[0] | ||
298 | expect(childOfFirstChild.comment.text).to.equal('my super answer to answer of thread 1') | ||
299 | expect(childOfFirstChild.children).to.have.lengthOf(0) | ||
300 | |||
301 | const secondChild = tree.children[1] | ||
302 | expect(secondChild.comment.text).to.equal('my second answer to thread 1') | ||
303 | expect(secondChild.children).to.have.lengthOf(0) | ||
304 | } | ||
252 | }) | 305 | }) |
253 | 306 | ||
254 | after(async function () { | 307 | after(async function () { |