aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/videos
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-07-09 14:15:11 +0200
committerChocobozzz <me@florianbigard.com>2021-07-20 15:27:18 +0200
commit12edc1495a36b2199f1bf1ba37f50c7b694be382 (patch)
tree3abfe2e5b54076de73fbfa25386d0313fc3b7242 /server/tests/api/videos
parenta54618880c394ad7571f3f3222dc96ec2dd10d9a (diff)
downloadPeerTube-12edc1495a36b2199f1bf1ba37f50c7b694be382.tar.gz
PeerTube-12edc1495a36b2199f1bf1ba37f50c7b694be382.tar.zst
PeerTube-12edc1495a36b2199f1bf1ba37f50c7b694be382.zip
Introduce comments command
Diffstat (limited to 'server/tests/api/videos')
-rw-r--r--server/tests/api/videos/multiple-servers.ts99
-rw-r--r--server/tests/api/videos/video-comments.ts193
2 files changed, 132 insertions, 160 deletions
diff --git a/server/tests/api/videos/multiple-servers.ts b/server/tests/api/videos/multiple-servers.ts
index a59d5a858..2148d8e1c 100644
--- a/server/tests/api/videos/multiple-servers.ts
+++ b/server/tests/api/videos/multiple-servers.ts
@@ -3,7 +3,7 @@
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import * as request from 'supertest' 5import * as request from 'supertest'
6import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' 6import { HttpStatusCode } from '@shared/core-utils'
7import { 7import {
8 buildAbsoluteFixturePath, 8 buildAbsoluteFixturePath,
9 checkTmpIsEmpty, 9 checkTmpIsEmpty,
@@ -27,18 +27,10 @@ import {
27 userLogin, 27 userLogin,
28 viewVideo, 28 viewVideo,
29 wait, 29 wait,
30 waitJobs,
30 webtorrentAdd 31 webtorrentAdd
31} from '../../../../shared/extra-utils' 32} from '@shared/extra-utils'
32import { waitJobs } from '../../../../shared/extra-utils/server/jobs' 33import { VideoCommentThreadTree, VideoPrivacy } from '@shared/models'
33import {
34 addVideoCommentReply,
35 addVideoCommentThread,
36 deleteVideoComment,
37 findCommentId,
38 getVideoCommentThreads,
39 getVideoThreadComments
40} from '../../../../shared/extra-utils/videos/video-comments'
41import { VideoComment, VideoCommentThreadTree, VideoPrivacy } from '../../../../shared/models/videos'
42 34
43const expect = chai.expect 35const expect = chai.expect
44 36
@@ -762,36 +754,36 @@ describe('Test multiple servers', function () {
762 754
763 { 755 {
764 const text = 'my super first comment' 756 const text = 'my super first comment'
765 await addVideoCommentThread(servers[0].url, servers[0].accessToken, videoUUID, text) 757 await servers[0].commentsCommand.createThread({ videoId: videoUUID, text })
766 } 758 }
767 759
768 { 760 {
769 const text = 'my super second comment' 761 const text = 'my super second comment'
770 await addVideoCommentThread(servers[2].url, servers[2].accessToken, videoUUID, text) 762 await servers[2].commentsCommand.createThread({ videoId: videoUUID, text })
771 } 763 }
772 764
773 await waitJobs(servers) 765 await waitJobs(servers)
774 766
775 { 767 {
776 const threadId = await findCommentId(servers[1].url, videoUUID, 'my super first comment') 768 const threadId = await servers[1].commentsCommand.findCommentId({ videoId: videoUUID, text: 'my super first comment' })
777 769
778 const text = 'my super answer to thread 1' 770 const text = 'my super answer to thread 1'
779 await addVideoCommentReply(servers[1].url, servers[1].accessToken, videoUUID, threadId, text) 771 await servers[1].commentsCommand.addReply({ videoId: videoUUID, toCommentId: threadId, text })
780 } 772 }
781 773
782 await waitJobs(servers) 774 await waitJobs(servers)
783 775
784 { 776 {
785 const threadId = await findCommentId(servers[2].url, videoUUID, 'my super first comment') 777 const threadId = await servers[2].commentsCommand.findCommentId({ videoId: videoUUID, text: 'my super first comment' })
786 778
787 const res2 = await getVideoThreadComments(servers[2].url, videoUUID, threadId) 779 const body = await servers[2].commentsCommand.getThread({ videoId: videoUUID, threadId })
788 const childCommentId = res2.body.children[0].comment.id 780 const childCommentId = body.children[0].comment.id
789 781
790 const text3 = 'my second answer to thread 1' 782 const text3 = 'my second answer to thread 1'
791 await addVideoCommentReply(servers[2].url, servers[2].accessToken, videoUUID, threadId, text3) 783 await servers[2].commentsCommand.addReply({ videoId: videoUUID, toCommentId: threadId, text: text3 })
792 784
793 const text2 = 'my super answer to answer of thread 1' 785 const text2 = 'my super answer to answer of thread 1'
794 await addVideoCommentReply(servers[2].url, servers[2].accessToken, videoUUID, childCommentId, text2) 786 await servers[2].commentsCommand.addReply({ videoId: videoUUID, toCommentId: childCommentId, text: text2 })
795 } 787 }
796 788
797 await waitJobs(servers) 789 await waitJobs(servers)
@@ -799,14 +791,14 @@ describe('Test multiple servers', function () {
799 791
800 it('Should have these threads', async function () { 792 it('Should have these threads', async function () {
801 for (const server of servers) { 793 for (const server of servers) {
802 const res = await getVideoCommentThreads(server.url, videoUUID, 0, 5) 794 const body = await server.commentsCommand.listThreads({ videoId: videoUUID })
803 795
804 expect(res.body.total).to.equal(2) 796 expect(body.total).to.equal(2)
805 expect(res.body.data).to.be.an('array') 797 expect(body.data).to.be.an('array')
806 expect(res.body.data).to.have.lengthOf(2) 798 expect(body.data).to.have.lengthOf(2)
807 799
808 { 800 {
809 const comment: VideoComment = res.body.data.find(c => c.text === 'my super first comment') 801 const comment = body.data.find(c => c.text === 'my super first comment')
810 expect(comment).to.not.be.undefined 802 expect(comment).to.not.be.undefined
811 expect(comment.inReplyToCommentId).to.be.null 803 expect(comment.inReplyToCommentId).to.be.null
812 expect(comment.account.name).to.equal('root') 804 expect(comment.account.name).to.equal('root')
@@ -817,7 +809,7 @@ describe('Test multiple servers', function () {
817 } 809 }
818 810
819 { 811 {
820 const comment: VideoComment = res.body.data.find(c => c.text === 'my super second comment') 812 const comment = body.data.find(c => c.text === 'my super second comment')
821 expect(comment).to.not.be.undefined 813 expect(comment).to.not.be.undefined
822 expect(comment.inReplyToCommentId).to.be.null 814 expect(comment.inReplyToCommentId).to.be.null
823 expect(comment.account.name).to.equal('root') 815 expect(comment.account.name).to.equal('root')
@@ -831,12 +823,11 @@ describe('Test multiple servers', function () {
831 823
832 it('Should have these comments', async function () { 824 it('Should have these comments', async function () {
833 for (const server of servers) { 825 for (const server of servers) {
834 const res1 = await getVideoCommentThreads(server.url, videoUUID, 0, 5) 826 const body = await server.commentsCommand.listThreads({ videoId: videoUUID })
835 const threadId = res1.body.data.find(c => c.text === 'my super first comment').id 827 const threadId = body.data.find(c => c.text === 'my super first comment').id
836 828
837 const res2 = await getVideoThreadComments(server.url, videoUUID, threadId) 829 const tree = await server.commentsCommand.getThread({ videoId: videoUUID, threadId })
838 830
839 const tree: VideoCommentThreadTree = res2.body
840 expect(tree.comment.text).equal('my super first comment') 831 expect(tree.comment.text).equal('my super first comment')
841 expect(tree.comment.account.name).equal('root') 832 expect(tree.comment.account.name).equal('root')
842 expect(tree.comment.account.host).equal('localhost:' + servers[0].port) 833 expect(tree.comment.account.host).equal('localhost:' + servers[0].port)
@@ -865,19 +856,17 @@ describe('Test multiple servers', function () {
865 it('Should delete a reply', async function () { 856 it('Should delete a reply', async function () {
866 this.timeout(10000) 857 this.timeout(10000)
867 858
868 await deleteVideoComment(servers[2].url, servers[2].accessToken, videoUUID, childOfFirstChild.comment.id) 859 await servers[2].commentsCommand.delete({ videoId: videoUUID, commentId: childOfFirstChild.comment.id })
869 860
870 await waitJobs(servers) 861 await waitJobs(servers)
871 }) 862 })
872 863
873 it('Should have this comment marked as deleted', async function () { 864 it('Should have this comment marked as deleted', async function () {
874 for (const server of servers) { 865 for (const server of servers) {
875 const res1 = await getVideoCommentThreads(server.url, videoUUID, 0, 5) 866 const { data } = await server.commentsCommand.listThreads({ videoId: videoUUID })
876 const threadId = res1.body.data.find(c => c.text === 'my super first comment').id 867 const threadId = data.find(c => c.text === 'my super first comment').id
877
878 const res2 = await getVideoThreadComments(server.url, videoUUID, threadId)
879 868
880 const tree: VideoCommentThreadTree = res2.body 869 const tree = await server.commentsCommand.getThread({ videoId: videoUUID, threadId })
881 expect(tree.comment.text).equal('my super first comment') 870 expect(tree.comment.text).equal('my super first comment')
882 871
883 const firstChild = tree.children[0] 872 const firstChild = tree.children[0]
@@ -898,23 +887,23 @@ describe('Test multiple servers', function () {
898 it('Should delete the thread comments', async function () { 887 it('Should delete the thread comments', async function () {
899 this.timeout(10000) 888 this.timeout(10000)
900 889
901 const res = await getVideoCommentThreads(servers[0].url, videoUUID, 0, 5) 890 const { data } = await servers[0].commentsCommand.listThreads({ videoId: videoUUID })
902 const threadId = res.body.data.find(c => c.text === 'my super first comment').id 891 const commentId = data.find(c => c.text === 'my super first comment').id
903 await deleteVideoComment(servers[0].url, servers[0].accessToken, videoUUID, threadId) 892 await servers[0].commentsCommand.delete({ videoId: videoUUID, commentId })
904 893
905 await waitJobs(servers) 894 await waitJobs(servers)
906 }) 895 })
907 896
908 it('Should have the threads marked as deleted on other servers too', async function () { 897 it('Should have the threads marked as deleted on other servers too', async function () {
909 for (const server of servers) { 898 for (const server of servers) {
910 const res = await getVideoCommentThreads(server.url, videoUUID, 0, 5) 899 const body = await server.commentsCommand.listThreads({ videoId: videoUUID })
911 900
912 expect(res.body.total).to.equal(2) 901 expect(body.total).to.equal(2)
913 expect(res.body.data).to.be.an('array') 902 expect(body.data).to.be.an('array')
914 expect(res.body.data).to.have.lengthOf(2) 903 expect(body.data).to.have.lengthOf(2)
915 904
916 { 905 {
917 const comment: VideoComment = res.body.data[0] 906 const comment = body.data[0]
918 expect(comment).to.not.be.undefined 907 expect(comment).to.not.be.undefined
919 expect(comment.inReplyToCommentId).to.be.null 908 expect(comment.inReplyToCommentId).to.be.null
920 expect(comment.account.name).to.equal('root') 909 expect(comment.account.name).to.equal('root')
@@ -925,7 +914,7 @@ describe('Test multiple servers', function () {
925 } 914 }
926 915
927 { 916 {
928 const deletedComment: VideoComment = res.body.data[1] 917 const deletedComment = body.data[1]
929 expect(deletedComment).to.not.be.undefined 918 expect(deletedComment).to.not.be.undefined
930 expect(deletedComment.isDeleted).to.be.true 919 expect(deletedComment.isDeleted).to.be.true
931 expect(deletedComment.deletedAt).to.not.be.null 920 expect(deletedComment.deletedAt).to.not.be.null
@@ -943,22 +932,22 @@ describe('Test multiple servers', function () {
943 it('Should delete a remote thread by the origin server', async function () { 932 it('Should delete a remote thread by the origin server', async function () {
944 this.timeout(5000) 933 this.timeout(5000)
945 934
946 const res = await getVideoCommentThreads(servers[0].url, videoUUID, 0, 5) 935 const { data } = await servers[0].commentsCommand.listThreads({ videoId: videoUUID })
947 const threadId = res.body.data.find(c => c.text === 'my super second comment').id 936 const commentId = data.find(c => c.text === 'my super second comment').id
948 await deleteVideoComment(servers[0].url, servers[0].accessToken, videoUUID, threadId) 937 await servers[0].commentsCommand.delete({ videoId: videoUUID, commentId })
949 938
950 await waitJobs(servers) 939 await waitJobs(servers)
951 }) 940 })
952 941
953 it('Should have the threads marked as deleted on other servers too', async function () { 942 it('Should have the threads marked as deleted on other servers too', async function () {
954 for (const server of servers) { 943 for (const server of servers) {
955 const res = await getVideoCommentThreads(server.url, videoUUID, 0, 5) 944 const body = await server.commentsCommand.listThreads({ videoId: videoUUID })
956 945
957 expect(res.body.total).to.equal(2) 946 expect(body.total).to.equal(2)
958 expect(res.body.data).to.have.lengthOf(2) 947 expect(body.data).to.have.lengthOf(2)
959 948
960 { 949 {
961 const comment: VideoComment = res.body.data[0] 950 const comment = body.data[0]
962 expect(comment.text).to.equal('') 951 expect(comment.text).to.equal('')
963 expect(comment.isDeleted).to.be.true 952 expect(comment.isDeleted).to.be.true
964 expect(comment.createdAt).to.not.be.null 953 expect(comment.createdAt).to.not.be.null
@@ -968,7 +957,7 @@ describe('Test multiple servers', function () {
968 } 957 }
969 958
970 { 959 {
971 const comment: VideoComment = res.body.data[1] 960 const comment = body.data[1]
972 expect(comment.text).to.equal('') 961 expect(comment.text).to.equal('')
973 expect(comment.isDeleted).to.be.true 962 expect(comment.isDeleted).to.be.true
974 expect(comment.createdAt).to.not.be.null 963 expect(comment.createdAt).to.not.be.null
@@ -997,7 +986,7 @@ describe('Test multiple servers', function () {
997 expect(res.body.downloadEnabled).to.be.false 986 expect(res.body.downloadEnabled).to.be.false
998 987
999 const text = 'my super forbidden comment' 988 const text = 'my super forbidden comment'
1000 await addVideoCommentThread(server.url, server.accessToken, videoUUID, text, HttpStatusCode.CONFLICT_409) 989 await server.commentsCommand.createThread({ videoId: videoUUID, text, expectedStatus: HttpStatusCode.CONFLICT_409 })
1001 } 990 }
1002 }) 991 })
1003 }) 992 })
diff --git a/server/tests/api/videos/video-comments.ts b/server/tests/api/videos/video-comments.ts
index b6b002307..548d9fbf5 100644
--- a/server/tests/api/videos/video-comments.ts
+++ b/server/tests/api/videos/video-comments.ts
@@ -2,38 +2,33 @@
2 2
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { VideoComment, VideoCommentAdmin, VideoCommentThreadTree } from '@shared/models'
6import { cleanupTests, testImage } from '../../../../shared/extra-utils'
7import { 5import {
6 cleanupTests,
7 CommentsCommand,
8 createUser, 8 createUser,
9 dateIsValid, 9 dateIsValid,
10 flushAndRunServer, 10 flushAndRunServer,
11 getAccessToken, 11 getAccessToken,
12 ServerInfo, 12 ServerInfo,
13 setAccessTokensToServers, 13 setAccessTokensToServers,
14 testImage,
14 updateMyAvatar, 15 updateMyAvatar,
15 uploadVideo 16 uploadVideo
16} from '../../../../shared/extra-utils/index' 17} from '@shared/extra-utils'
17import {
18 addVideoCommentReply,
19 addVideoCommentThread,
20 deleteVideoComment,
21 getAdminVideoComments,
22 getVideoCommentThreads,
23 getVideoThreadComments
24} from '../../../../shared/extra-utils/videos/video-comments'
25 18
26const expect = chai.expect 19const expect = chai.expect
27 20
28describe('Test video comments', function () { 21describe('Test video comments', function () {
29 let server: ServerInfo 22 let server: ServerInfo
30 let videoId 23 let videoId: number
31 let videoUUID 24 let videoUUID: string
32 let threadId 25 let threadId: number
33 let replyToDeleteId: number 26 let replyToDeleteId: number
34 27
35 let userAccessTokenServer1: string 28 let userAccessTokenServer1: string
36 29
30 let command: CommentsCommand
31
37 before(async function () { 32 before(async function () {
38 this.timeout(30000) 33 this.timeout(30000)
39 34
@@ -58,24 +53,25 @@ describe('Test video comments', function () {
58 password: 'password' 53 password: 'password'
59 }) 54 })
60 userAccessTokenServer1 = await getAccessToken(server.url, 'user1', 'password') 55 userAccessTokenServer1 = await getAccessToken(server.url, 'user1', 'password')
56
57 command = server.commentsCommand
61 }) 58 })
62 59
63 describe('User comments', function () { 60 describe('User comments', function () {
64 61
65 it('Should not have threads on this video', async function () { 62 it('Should not have threads on this video', async function () {
66 const res = await getVideoCommentThreads(server.url, videoUUID, 0, 5) 63 const body = await command.listThreads({ videoId: videoUUID })
67 64
68 expect(res.body.total).to.equal(0) 65 expect(body.total).to.equal(0)
69 expect(res.body.totalNotDeletedComments).to.equal(0) 66 expect(body.totalNotDeletedComments).to.equal(0)
70 expect(res.body.data).to.be.an('array') 67 expect(body.data).to.be.an('array')
71 expect(res.body.data).to.have.lengthOf(0) 68 expect(body.data).to.have.lengthOf(0)
72 }) 69 })
73 70
74 it('Should create a thread in this video', async function () { 71 it('Should create a thread in this video', async function () {
75 const text = 'my super first comment' 72 const text = 'my super first comment'
76 73
77 const res = await addVideoCommentThread(server.url, server.accessToken, videoUUID, text) 74 const comment = await command.createThread({ videoId: videoUUID, text })
78 const comment = res.body.comment
79 75
80 expect(comment.inReplyToCommentId).to.be.null 76 expect(comment.inReplyToCommentId).to.be.null
81 expect(comment.text).equal('my super first comment') 77 expect(comment.text).equal('my super first comment')
@@ -91,14 +87,14 @@ describe('Test video comments', function () {
91 }) 87 })
92 88
93 it('Should list threads of this video', async function () { 89 it('Should list threads of this video', async function () {
94 const res = await getVideoCommentThreads(server.url, videoUUID, 0, 5) 90 const body = await command.listThreads({ videoId: videoUUID })
95 91
96 expect(res.body.total).to.equal(1) 92 expect(body.total).to.equal(1)
97 expect(res.body.totalNotDeletedComments).to.equal(1) 93 expect(body.totalNotDeletedComments).to.equal(1)
98 expect(res.body.data).to.be.an('array') 94 expect(body.data).to.be.an('array')
99 expect(res.body.data).to.have.lengthOf(1) 95 expect(body.data).to.have.lengthOf(1)
100 96
101 const comment: VideoComment = res.body.data[0] 97 const comment = body.data[0]
102 expect(comment.inReplyToCommentId).to.be.null 98 expect(comment.inReplyToCommentId).to.be.null
103 expect(comment.text).equal('my super first comment') 99 expect(comment.text).equal('my super first comment')
104 expect(comment.videoId).to.equal(videoId) 100 expect(comment.videoId).to.equal(videoId)
@@ -117,9 +113,9 @@ describe('Test video comments', function () {
117 }) 113 })
118 114
119 it('Should get all the thread created', async function () { 115 it('Should get all the thread created', async function () {
120 const res = await getVideoThreadComments(server.url, videoUUID, threadId) 116 const body = await command.getThread({ videoId: videoUUID, threadId })
121 117
122 const rootComment = res.body.comment 118 const rootComment = body.comment
123 expect(rootComment.inReplyToCommentId).to.be.null 119 expect(rootComment.inReplyToCommentId).to.be.null
124 expect(rootComment.text).equal('my super first comment') 120 expect(rootComment.text).equal('my super first comment')
125 expect(rootComment.videoId).to.equal(videoId) 121 expect(rootComment.videoId).to.equal(videoId)
@@ -129,20 +125,19 @@ describe('Test video comments', function () {
129 125
130 it('Should create multiple replies in this thread', async function () { 126 it('Should create multiple replies in this thread', async function () {
131 const text1 = 'my super answer to thread 1' 127 const text1 = 'my super answer to thread 1'
132 const childCommentRes = await addVideoCommentReply(server.url, server.accessToken, videoId, threadId, text1) 128 const created = await command.addReply({ videoId, toCommentId: threadId, text: text1 })
133 const childCommentId = childCommentRes.body.comment.id 129 const childCommentId = created.id
134 130
135 const text2 = 'my super answer to answer of thread 1' 131 const text2 = 'my super answer to answer of thread 1'
136 await addVideoCommentReply(server.url, server.accessToken, videoId, childCommentId, text2) 132 await command.addReply({ videoId, toCommentId: childCommentId, text: text2 })
137 133
138 const text3 = 'my second answer to thread 1' 134 const text3 = 'my second answer to thread 1'
139 await addVideoCommentReply(server.url, server.accessToken, videoId, threadId, text3) 135 await command.addReply({ videoId, toCommentId: threadId, text: text3 })
140 }) 136 })
141 137
142 it('Should get correctly the replies', async function () { 138 it('Should get correctly the replies', async function () {
143 const res = await getVideoThreadComments(server.url, videoUUID, threadId) 139 const tree = await command.getThread({ videoId: videoUUID, threadId })
144 140
145 const tree: VideoCommentThreadTree = res.body
146 expect(tree.comment.text).equal('my super first comment') 141 expect(tree.comment.text).equal('my super first comment')
147 expect(tree.children).to.have.lengthOf(2) 142 expect(tree.children).to.have.lengthOf(2)
148 143
@@ -163,42 +158,41 @@ describe('Test video comments', function () {
163 158
164 it('Should create other threads', async function () { 159 it('Should create other threads', async function () {
165 const text1 = 'super thread 2' 160 const text1 = 'super thread 2'
166 await addVideoCommentThread(server.url, server.accessToken, videoUUID, text1) 161 await command.createThread({ videoId: videoUUID, text: text1 })
167 162
168 const text2 = 'super thread 3' 163 const text2 = 'super thread 3'
169 await addVideoCommentThread(server.url, server.accessToken, videoUUID, text2) 164 await command.createThread({ videoId: videoUUID, text: text2 })
170 }) 165 })
171 166
172 it('Should list the threads', async function () { 167 it('Should list the threads', async function () {
173 const res = await getVideoCommentThreads(server.url, videoUUID, 0, 5, 'createdAt') 168 const body = await command.listThreads({ videoId: videoUUID, sort: 'createdAt' })
174 169
175 expect(res.body.total).to.equal(3) 170 expect(body.total).to.equal(3)
176 expect(res.body.totalNotDeletedComments).to.equal(6) 171 expect(body.totalNotDeletedComments).to.equal(6)
177 expect(res.body.data).to.be.an('array') 172 expect(body.data).to.be.an('array')
178 expect(res.body.data).to.have.lengthOf(3) 173 expect(body.data).to.have.lengthOf(3)
179 174
180 expect(res.body.data[0].text).to.equal('my super first comment') 175 expect(body.data[0].text).to.equal('my super first comment')
181 expect(res.body.data[0].totalReplies).to.equal(3) 176 expect(body.data[0].totalReplies).to.equal(3)
182 expect(res.body.data[1].text).to.equal('super thread 2') 177 expect(body.data[1].text).to.equal('super thread 2')
183 expect(res.body.data[1].totalReplies).to.equal(0) 178 expect(body.data[1].totalReplies).to.equal(0)
184 expect(res.body.data[2].text).to.equal('super thread 3') 179 expect(body.data[2].text).to.equal('super thread 3')
185 expect(res.body.data[2].totalReplies).to.equal(0) 180 expect(body.data[2].totalReplies).to.equal(0)
186 }) 181 })
187 182
188 it('Should delete a reply', async function () { 183 it('Should delete a reply', async function () {
189 await deleteVideoComment(server.url, server.accessToken, videoId, replyToDeleteId) 184 await command.delete({ videoId, commentId: replyToDeleteId })
190 185
191 { 186 {
192 const res = await getVideoCommentThreads(server.url, videoUUID, 0, 5, 'createdAt') 187 const body = await command.listThreads({ videoId: videoUUID, sort: 'createdAt' })
193 188
194 expect(res.body.total).to.equal(3) 189 expect(body.total).to.equal(3)
195 expect(res.body.totalNotDeletedComments).to.equal(5) 190 expect(body.totalNotDeletedComments).to.equal(5)
196 } 191 }
197 192
198 { 193 {
199 const res = await getVideoThreadComments(server.url, videoUUID, threadId) 194 const tree = await command.getThread({ videoId: videoUUID, threadId })
200 195
201 const tree: VideoCommentThreadTree = res.body
202 expect(tree.comment.text).equal('my super first comment') 196 expect(tree.comment.text).equal('my super first comment')
203 expect(tree.children).to.have.lengthOf(2) 197 expect(tree.children).to.have.lengthOf(2)
204 198
@@ -220,99 +214,88 @@ describe('Test video comments', function () {
220 }) 214 })
221 215
222 it('Should delete a complete thread', async function () { 216 it('Should delete a complete thread', async function () {
223 await deleteVideoComment(server.url, server.accessToken, videoId, threadId) 217 await command.delete({ videoId, commentId: threadId })
224 218
225 const res = await getVideoCommentThreads(server.url, videoUUID, 0, 5, 'createdAt') 219 const body = await command.listThreads({ videoId: videoUUID, sort: 'createdAt' })
226 expect(res.body.total).to.equal(3) 220 expect(body.total).to.equal(3)
227 expect(res.body.data).to.be.an('array') 221 expect(body.data).to.be.an('array')
228 expect(res.body.data).to.have.lengthOf(3) 222 expect(body.data).to.have.lengthOf(3)
229 223
230 expect(res.body.data[0].text).to.equal('') 224 expect(body.data[0].text).to.equal('')
231 expect(res.body.data[0].isDeleted).to.be.true 225 expect(body.data[0].isDeleted).to.be.true
232 expect(res.body.data[0].deletedAt).to.not.be.null 226 expect(body.data[0].deletedAt).to.not.be.null
233 expect(res.body.data[0].account).to.be.null 227 expect(body.data[0].account).to.be.null
234 expect(res.body.data[0].totalReplies).to.equal(2) 228 expect(body.data[0].totalReplies).to.equal(2)
235 expect(res.body.data[1].text).to.equal('super thread 2') 229 expect(body.data[1].text).to.equal('super thread 2')
236 expect(res.body.data[1].totalReplies).to.equal(0) 230 expect(body.data[1].totalReplies).to.equal(0)
237 expect(res.body.data[2].text).to.equal('super thread 3') 231 expect(body.data[2].text).to.equal('super thread 3')
238 expect(res.body.data[2].totalReplies).to.equal(0) 232 expect(body.data[2].totalReplies).to.equal(0)
239 }) 233 })
240 234
241 it('Should count replies from the video author correctly', async function () { 235 it('Should count replies from the video author correctly', async function () {
242 const text = 'my super first comment' 236 await command.createThread({ videoId: videoUUID, text: 'my super first comment' })
243 await addVideoCommentThread(server.url, server.accessToken, videoUUID, text) 237
244 let res = await getVideoCommentThreads(server.url, videoUUID, 0, 5) 238 const { data } = await command.listThreads({ videoId: videoUUID })
245 const comment: VideoComment = res.body.data[0] 239 const threadId2 = data[0].threadId
246 const threadId2 = comment.threadId
247 240
248 const text2 = 'a first answer to thread 4 by a third party' 241 const text2 = 'a first answer to thread 4 by a third party'
249 await addVideoCommentReply(server.url, userAccessTokenServer1, videoId, threadId2, text2) 242 await command.addReply({ token: userAccessTokenServer1, videoId, toCommentId: threadId2, text: text2 })
250 243
251 const text3 = 'my second answer to thread 4' 244 const text3 = 'my second answer to thread 4'
252 await addVideoCommentReply(server.url, server.accessToken, videoId, threadId2, text3) 245 await command.addReply({ videoId, toCommentId: threadId2, text: text3 })
253 246
254 res = await getVideoThreadComments(server.url, videoUUID, threadId2) 247 const tree = await command.getThread({ videoId: videoUUID, threadId: threadId2 })
255 const tree: VideoCommentThreadTree = res.body
256 expect(tree.comment.totalReplies).to.equal(tree.comment.totalRepliesFromVideoAuthor + 1) 248 expect(tree.comment.totalReplies).to.equal(tree.comment.totalRepliesFromVideoAuthor + 1)
257 }) 249 })
258 }) 250 })
259 251
260 describe('All instance comments', function () { 252 describe('All instance comments', function () {
261 async function getComments (options: any = {}) {
262 const res = await getAdminVideoComments(Object.assign({
263 url: server.url,
264 token: server.accessToken,
265 start: 0,
266 count: 10
267 }, options))
268
269 return { comments: res.body.data as VideoCommentAdmin[], total: res.body.total as number }
270 }
271 253
272 it('Should list instance comments as admin', async function () { 254 it('Should list instance comments as admin', async function () {
273 const { comments } = await getComments({ start: 0, count: 1 }) 255 const { data } = await command.listForAdmin({ start: 0, count: 1 })
274 256
275 expect(comments[0].text).to.equal('my second answer to thread 4') 257 expect(data[0].text).to.equal('my second answer to thread 4')
276 }) 258 })
277 259
278 it('Should filter instance comments by isLocal', async function () { 260 it('Should filter instance comments by isLocal', async function () {
279 const { total, comments } = await getComments({ isLocal: false }) 261 const { total, data } = await command.listForAdmin({ isLocal: false })
280 262
281 expect(comments).to.have.lengthOf(0) 263 expect(data).to.have.lengthOf(0)
282 expect(total).to.equal(0) 264 expect(total).to.equal(0)
283 }) 265 })
284 266
285 it('Should search instance comments by account', async function () { 267 it('Should search instance comments by account', async function () {
286 const { total, comments } = await getComments({ searchAccount: 'user' }) 268 const { total, data } = await command.listForAdmin({ searchAccount: 'user' })
287 269
288 expect(comments).to.have.lengthOf(1) 270 expect(data).to.have.lengthOf(1)
289 expect(total).to.equal(1) 271 expect(total).to.equal(1)
290 272
291 expect(comments[0].text).to.equal('a first answer to thread 4 by a third party') 273 expect(data[0].text).to.equal('a first answer to thread 4 by a third party')
292 }) 274 })
293 275
294 it('Should search instance comments by video', async function () { 276 it('Should search instance comments by video', async function () {
295 { 277 {
296 const { total, comments } = await getComments({ searchVideo: 'video' }) 278 const { total, data } = await command.listForAdmin({ searchVideo: 'video' })
297 279
298 expect(comments).to.have.lengthOf(7) 280 expect(data).to.have.lengthOf(7)
299 expect(total).to.equal(7) 281 expect(total).to.equal(7)
300 } 282 }
301 283
302 { 284 {
303 const { total, comments } = await getComments({ searchVideo: 'hello' }) 285 const { total, data } = await command.listForAdmin({ searchVideo: 'hello' })
304 286
305 expect(comments).to.have.lengthOf(0) 287 expect(data).to.have.lengthOf(0)
306 expect(total).to.equal(0) 288 expect(total).to.equal(0)
307 } 289 }
308 }) 290 })
309 291
310 it('Should search instance comments', async function () { 292 it('Should search instance comments', async function () {
311 const { total, comments } = await getComments({ search: 'super thread 3' }) 293 const { total, data } = await command.listForAdmin({ search: 'super thread 3' })
312 294
313 expect(comments).to.have.lengthOf(1)
314 expect(total).to.equal(1) 295 expect(total).to.equal(1)
315 expect(comments[0].text).to.equal('super thread 3') 296
297 expect(data).to.have.lengthOf(1)
298 expect(data[0].text).to.equal('super thread 3')
316 }) 299 })
317 }) 300 })
318 301