]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
Add get old comment on follow tests
authorChocobozzz <me@florianbigard.com>
Thu, 28 Dec 2017 10:45:10 +0000 (11:45 +0100)
committerChocobozzz <me@florianbigard.com>
Thu, 28 Dec 2017 10:45:10 +0000 (11:45 +0100)
server/models/video/video-comment.ts
server/tests/api/follows.ts

index 1992c2dd88f1d175d6e88f32f3f0594ad3f86008..d381ccafa6e352248cc04296a6e8c66b8f4b30f0 100644 (file)
@@ -103,8 +103,10 @@ export class VideoCommentModel extends Model<VideoCommentModel> {
 
   @BelongsTo(() => VideoCommentModel, {
     foreignKey: {
+      name: 'originCommentId',
       allowNull: true
     },
+    as: 'OriginVideoComment',
     onDelete: 'CASCADE'
   })
   OriginVideoComment: VideoCommentModel
@@ -115,6 +117,7 @@ export class VideoCommentModel extends Model<VideoCommentModel> {
 
   @BelongsTo(() => VideoCommentModel, {
     foreignKey: {
+      name: 'inReplyToCommentId',
       allowNull: true
     },
     as: 'InReplyToVideoComment',
index 10eb48969d851bf88abf3d7410df4a60c4df376d..2ffa426a0658955084c9a4d79fa30bf0e6fbf388 100644 (file)
@@ -2,21 +2,17 @@
 
 import * as chai from 'chai'
 import 'mocha'
+import { VideoComment, VideoCommentThreadTree } from '../../../shared/models/videos/video-comment.model'
 
 import {
-  flushAndRunMultipleServers,
-  flushTests,
-  getVideosList,
-  killallServers,
-  ServerInfo,
-  setAccessTokensToServers,
-  uploadVideo,
+  flushAndRunMultipleServers, flushTests, getVideosList, killallServers, ServerInfo, setAccessTokensToServers, uploadVideo,
   wait
 } from '../utils'
 import { follow, getFollowersListPaginationAndSort, getFollowingListPaginationAndSort, unfollow } from '../utils/follows'
 import { getUserAccessToken } from '../utils/login'
 import { dateIsValid, webtorrentAdd } from '../utils/miscs'
 import { createUser } from '../utils/users'
+import { addVideoCommentReply, addVideoCommentThread, getVideoCommentThreads, getVideoThreadComments } from '../utils/video-comments'
 import { getVideo, rateVideo, testVideoImage } from '../utils/videos'
 
 const expect = chai.expect
@@ -186,11 +182,29 @@ describe('Test follows', function () {
       await createUser(servers[2].url, servers[2].accessToken, user.username, user.password)
       const userAccessToken = await getUserAccessToken(servers[2], user)
 
-      const res = await getVideosList(servers[2].url)
-      const video4 = res.body.data.find(v => v.name === 'server3-4')
+      const resVideos = await getVideosList(servers[ 2 ].url)
+      const video4 = resVideos.body.data.find(v => v.name === 'server3-4')
 
-      await rateVideo(servers[2].url, servers[2].accessToken, video4.id, 'like')
-      await rateVideo(servers[2].url, userAccessToken, video4.id, 'dislike')
+      {
+        await rateVideo(servers[ 2 ].url, servers[ 2 ].accessToken, video4.id, 'like')
+        await rateVideo(servers[ 2 ].url, userAccessToken, video4.id, 'dislike')
+      }
+
+      {
+        const text = 'my super first comment'
+        const res = await addVideoCommentThread(servers[ 2 ].url, servers[ 2 ].accessToken, video4.id, text)
+        const threadId = res.body.comment.id
+
+        const text1 = 'my super answer to thread 1'
+        const childCommentRes = await addVideoCommentReply(servers[ 2 ].url, servers[ 2 ].accessToken, video4.id, threadId, text1)
+        const childCommentId = childCommentRes.body.comment.id
+
+        const text2 = 'my super answer to answer of thread 1'
+        await addVideoCommentReply(servers[ 2 ].url, servers[ 2 ].accessToken, video4.id, childCommentId, text2)
+
+        const text3 = 'my second answer to thread 1'
+        await addVideoCommentReply(servers[ 2 ].url, servers[ 2 ].accessToken, video4.id, threadId, text3)
+      }
     }
 
     await wait(5000)
@@ -249,6 +263,45 @@ describe('Test follows', function () {
     expect(torrent.files).to.be.an('array')
     expect(torrent.files.length).to.equal(1)
     expect(torrent.files[0].path).to.exist.and.to.not.equal('')
+
+    {
+      const res1 = await getVideoCommentThreads(servers[0].url, video4.id, 0, 5)
+
+      expect(res1.body.total).to.equal(1)
+      expect(res1.body.data).to.be.an('array')
+      expect(res1.body.data).to.have.lengthOf(1)
+
+      const comment: VideoComment = res1.body.data[0]
+      expect(comment.inReplyToCommentId).to.be.null
+      expect(comment.text).equal('my super first comment')
+      expect(comment.videoId).to.equal(video4.id)
+      expect(comment.id).to.equal(comment.threadId)
+      expect(comment.account.name).to.equal('root')
+      expect(comment.account.host).to.equal('localhost:9003')
+      expect(comment.totalReplies).to.equal(3)
+      expect(dateIsValid(comment.createdAt as string)).to.be.true
+      expect(dateIsValid(comment.updatedAt as string)).to.be.true
+
+      const threadId = comment.threadId
+
+      const res2 = await getVideoThreadComments(servers[0].url, video4.id, threadId)
+
+      const tree: VideoCommentThreadTree = res2.body
+      expect(tree.comment.text).equal('my super first comment')
+      expect(tree.children).to.have.lengthOf(2)
+
+      const firstChild = tree.children[0]
+      expect(firstChild.comment.text).to.equal('my super answer to thread 1')
+      expect(firstChild.children).to.have.lengthOf(1)
+
+      const childOfFirstChild = firstChild.children[0]
+      expect(childOfFirstChild.comment.text).to.equal('my super answer to answer of thread 1')
+      expect(childOfFirstChild.children).to.have.lengthOf(0)
+
+      const secondChild = tree.children[1]
+      expect(secondChild.comment.text).to.equal('my second answer to thread 1')
+      expect(secondChild.children).to.have.lengthOf(0)
+    }
   })
 
   after(async function () {