aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests')
-rw-r--r--server/tests/api/check-params/video-channels.ts10
-rw-r--r--server/tests/api/check-params/video-comments.ts16
-rw-r--r--server/tests/api/multiple-servers.ts135
-rw-r--r--server/tests/api/video-comments.ts6
-rw-r--r--server/tests/utils/video-comments.ts6
5 files changed, 127 insertions, 46 deletions
diff --git a/server/tests/api/check-params/video-channels.ts b/server/tests/api/check-params/video-channels.ts
index e72b2cb6c..7103aec25 100644
--- a/server/tests/api/check-params/video-channels.ts
+++ b/server/tests/api/check-params/video-channels.ts
@@ -69,9 +69,9 @@ describe('Test videos API validator', function () {
69 }) 69 })
70 }) 70 })
71 71
72 describe('When listing author video channels', function () { 72 describe('When listing account video channels', function () {
73 it('Should fail with bad author', async function () { 73 it('Should fail with bad account', async function () {
74 const path = '/api/v1/videos/authors/hello/channels' 74 const path = '/api/v1/videos/accounts/hello/channels'
75 75
76 await request(server.url) 76 await request(server.url)
77 .get(path) 77 .get(path)
@@ -79,8 +79,8 @@ describe('Test videos API validator', function () {
79 .expect(400) 79 .expect(400)
80 }) 80 })
81 81
82 it('Should fail with a unknown author', async function () { 82 it('Should fail with a unknown account', async function () {
83 const path = '/api/v1/videos/authors/156/channels' 83 const path = '/api/v1/videos/accounts/156/channels'
84 84
85 await request(server.url) 85 await request(server.url)
86 .get(path) 86 .get(path)
diff --git a/server/tests/api/check-params/video-comments.ts b/server/tests/api/check-params/video-comments.ts
index 5112274f0..e8d7ddf38 100644
--- a/server/tests/api/check-params/video-comments.ts
+++ b/server/tests/api/check-params/video-comments.ts
@@ -2,17 +2,13 @@
2 2
3import 'mocha' 3import 'mocha'
4import * as request from 'supertest' 4import * as request from 'supertest'
5import { 5import { flushTests, killallServers, makePostBodyRequest, runServer, ServerInfo, setAccessTokensToServers, uploadVideo } from '../../utils'
6 createUser, flushTests, getUserAccessToken, killallServers, makePostBodyRequest, runServer, ServerInfo, setAccessTokensToServers,
7 uploadVideo
8} from '../../utils'
9import { addVideoCommentThread } from '../../utils/video-comments' 6import { addVideoCommentThread } from '../../utils/video-comments'
10 7
11describe('Test video comments API validator', function () { 8describe('Test video comments API validator', function () {
12 let pathThread: string 9 let pathThread: string
13 let pathComment: string 10 let pathComment: string
14 let server: ServerInfo 11 let server: ServerInfo
15 let accessTokenUser: string
16 let videoUUID: string 12 let videoUUID: string
17 let commentId: number 13 let commentId: number
18 14
@@ -28,16 +24,6 @@ describe('Test video comments API validator', function () {
28 await setAccessTokensToServers([ server ]) 24 await setAccessTokensToServers([ server ])
29 25
30 { 26 {
31 const user = {
32 username: 'fake',
33 password: 'fake_password'
34 }
35 await createUser(server.url, server.accessToken, user.username, user.password)
36
37 accessTokenUser = await getUserAccessToken(server, user)
38 }
39
40 {
41 const res = await uploadVideo(server.url, server.accessToken, {}) 27 const res = await uploadVideo(server.url, server.accessToken, {})
42 videoUUID = res.body.video.uuid 28 videoUUID = res.body.video.uuid
43 pathThread = '/api/v1/videos/' + videoUUID + '/comment-threads' 29 pathThread = '/api/v1/videos/' + videoUUID + '/comment-threads'
diff --git a/server/tests/api/multiple-servers.ts b/server/tests/api/multiple-servers.ts
index 6fe1fb651..06274d4cc 100644
--- a/server/tests/api/multiple-servers.ts
+++ b/server/tests/api/multiple-servers.ts
@@ -1,32 +1,18 @@
1/* tslint:disable:no-unused-expression */ 1/* tslint:disable:no-unused-expression */
2 2
3import 'mocha'
4import * as chai from 'chai' 3import * as chai from 'chai'
4import 'mocha'
5import { join } from 'path' 5import { join } from 'path'
6import * as request from 'supertest' 6import * as request from 'supertest'
7import { VideoComment, VideoCommentThreadTree } from '../../../shared/models/videos/video-comment.model'
7 8
8import { 9import {
9 dateIsValid, 10 addVideoChannel, dateIsValid, doubleFollow, flushAndRunMultipleServers, flushTests, getUserAccessToken, getVideo,
10 flushAndRunMultipleServers, 11 getVideoChannelsList, getVideosList, killallServers, rateVideo, removeVideo, ServerInfo, setAccessTokensToServers, testVideoImage,
11 flushTests, 12 updateVideo, uploadVideo, wait, webtorrentAdd
12 getVideo,
13 getVideosList,
14 killallServers,
15 rateVideo,
16 removeVideo,
17 ServerInfo,
18 setAccessTokensToServers,
19 testVideoImage,
20 updateVideo,
21 uploadVideo,
22 wait,
23 webtorrentAdd,
24 addVideoChannel,
25 getVideoChannelsList,
26 getUserAccessToken,
27 doubleFollow
28} from '../utils' 13} from '../utils'
29import { createUser } from '../utils/users' 14import { createUser } from '../utils/users'
15import { addVideoCommentReply, addVideoCommentThread, getVideoCommentThreads, getVideoThreadComments } from '../utils/video-comments'
30import { viewVideo } from '../utils/videos' 16import { viewVideo } from '../utils/videos'
31 17
32const expect = chai.expect 18const expect = chai.expect
@@ -709,6 +695,115 @@ describe('Test multiple servers', function () {
709 }) 695 })
710 }) 696 })
711 697
698 describe('Should comment these videos', function () {
699 it('Should add comment (threads and replies)', async function () {
700 this.timeout(25000)
701
702 {
703 const text = 'my super first comment'
704 await addVideoCommentThread(servers[ 0 ].url, servers[ 0 ].accessToken, videoUUID, text)
705 }
706
707 {
708 const text = 'my super second comment'
709 await addVideoCommentThread(servers[ 2 ].url, servers[ 2 ].accessToken, videoUUID, text)
710 }
711
712 await wait(5000)
713
714 {
715 const res = await getVideoCommentThreads(servers[1].url, videoUUID, 0, 5)
716 const threadId = res.body.data.find(c => c.text === 'my super first comment').id
717
718 const text = 'my super answer to thread 1'
719 await addVideoCommentReply(servers[ 1 ].url, servers[ 1 ].accessToken, videoUUID, threadId, text)
720 }
721
722 await wait(5000)
723
724 {
725 const res1 = await getVideoCommentThreads(servers[2].url, videoUUID, 0, 5)
726 const threadId = res1.body.data.find(c => c.text === 'my super first comment').id
727
728 const res2 = await getVideoThreadComments(servers[2].url, videoUUID, threadId)
729 const childCommentId = res2.body.children[0].comment.id
730
731 const text3 = 'my second answer to thread 1'
732 await addVideoCommentReply(servers[ 2 ].url, servers[ 2 ].accessToken, videoUUID, threadId, text3)
733
734 const text2 = 'my super answer to answer of thread 1'
735 await addVideoCommentReply(servers[ 2 ].url, servers[ 2 ].accessToken, videoUUID, childCommentId, text2)
736 }
737
738 await wait(5000)
739 })
740
741 it('Should have these threads', async function () {
742 for (const server of servers) {
743 const res = await getVideoCommentThreads(server.url, videoUUID, 0, 5)
744
745 expect(res.body.total).to.equal(2)
746 expect(res.body.data).to.be.an('array')
747 expect(res.body.data).to.have.lengthOf(2)
748
749 {
750 const comment: VideoComment = res.body.data.find(c => c.text === 'my super first comment')
751 expect(comment).to.not.be.undefined
752 expect(comment.inReplyToCommentId).to.be.null
753 expect(comment.account.name).to.equal('root')
754 expect(comment.account.host).to.equal('localhost:9001')
755 expect(comment.totalReplies).to.equal(3)
756 expect(dateIsValid(comment.createdAt as string)).to.be.true
757 expect(dateIsValid(comment.updatedAt as string)).to.be.true
758 }
759
760 {
761 const comment: VideoComment = res.body.data.find(c => c.text === 'my super second comment')
762 expect(comment).to.not.be.undefined
763 expect(comment.inReplyToCommentId).to.be.null
764 expect(comment.account.name).to.equal('root')
765 expect(comment.account.host).to.equal('localhost:9003')
766 expect(comment.totalReplies).to.equal(0)
767 expect(dateIsValid(comment.createdAt as string)).to.be.true
768 expect(dateIsValid(comment.updatedAt as string)).to.be.true
769 }
770 }
771 })
772
773 it('Should have these comments', async function () {
774 for (const server of servers) {
775 const res1 = await getVideoCommentThreads(server.url, videoUUID, 0, 5)
776 const threadId = res1.body.data.find(c => c.text === 'my super first comment').id
777
778 const res2 = await getVideoThreadComments(server.url, videoUUID, threadId)
779
780 const tree: VideoCommentThreadTree = res2.body
781 expect(tree.comment.text).equal('my super first comment')
782 expect(tree.comment.account.name).equal('root')
783 expect(tree.comment.account.host).equal('localhost:9001')
784 expect(tree.children).to.have.lengthOf(2)
785
786 const firstChild = tree.children[0]
787 expect(firstChild.comment.text).to.equal('my super answer to thread 1')
788 expect(firstChild.comment.account.name).equal('root')
789 expect(firstChild.comment.account.host).equal('localhost:9002')
790 expect(firstChild.children).to.have.lengthOf(1)
791
792 const childOfFirstChild = firstChild.children[0]
793 expect(childOfFirstChild.comment.text).to.equal('my super answer to answer of thread 1')
794 expect(childOfFirstChild.comment.account.name).equal('root')
795 expect(childOfFirstChild.comment.account.host).equal('localhost:9003')
796 expect(childOfFirstChild.children).to.have.lengthOf(0)
797
798 const secondChild = tree.children[1]
799 expect(secondChild.comment.text).to.equal('my second answer to thread 1')
800 expect(secondChild.comment.account.name).equal('root')
801 expect(secondChild.comment.account.host).equal('localhost:9003')
802 expect(secondChild.children).to.have.lengthOf(0)
803 }
804 })
805 })
806
712 describe('With minimum parameters', function () { 807 describe('With minimum parameters', function () {
713 it('Should upload and propagate the video', async function () { 808 it('Should upload and propagate the video', async function () {
714 this.timeout(50000) 809 this.timeout(50000)
diff --git a/server/tests/api/video-comments.ts b/server/tests/api/video-comments.ts
index 2c7d1c6e2..f05ca5e81 100644
--- a/server/tests/api/video-comments.ts
+++ b/server/tests/api/video-comments.ts
@@ -40,7 +40,7 @@ describe('Test video comments', function () {
40 const text = 'my super first comment' 40 const text = 'my super first comment'
41 41
42 const res = await addVideoCommentThread(server.url, server.accessToken, videoUUID, text) 42 const res = await addVideoCommentThread(server.url, server.accessToken, videoUUID, text)
43 const comment = res.body 43 const comment = res.body.comment
44 44
45 expect(comment.inReplyToCommentId).to.be.null 45 expect(comment.inReplyToCommentId).to.be.null
46 expect(comment.text).equal('my super first comment') 46 expect(comment.text).equal('my super first comment')
@@ -133,9 +133,9 @@ describe('Test video comments', function () {
133 expect(res.body.data).to.have.lengthOf(3) 133 expect(res.body.data).to.have.lengthOf(3)
134 134
135 expect(res.body.data[0].text).to.equal('my super first comment') 135 expect(res.body.data[0].text).to.equal('my super first comment')
136 expect(res.body.data[0].totalReplies).to.equal(2) 136 expect(res.body.data[0].totalReplies).to.equal(3)
137 expect(res.body.data[1].text).to.equal('super thread 2') 137 expect(res.body.data[1].text).to.equal('super thread 2')
138 expect(res.body.data[1].totalReplies).to.equal(1) 138 expect(res.body.data[1].totalReplies).to.equal(0)
139 expect(res.body.data[2].text).to.equal('super thread 3') 139 expect(res.body.data[2].text).to.equal('super thread 3')
140 expect(res.body.data[2].totalReplies).to.equal(0) 140 expect(res.body.data[2].totalReplies).to.equal(0)
141 }) 141 })
diff --git a/server/tests/utils/video-comments.ts b/server/tests/utils/video-comments.ts
index 6a6e225f3..878147049 100644
--- a/server/tests/utils/video-comments.ts
+++ b/server/tests/utils/video-comments.ts
@@ -1,6 +1,6 @@
1import * as request from 'supertest' 1import * as request from 'supertest'
2 2
3function getVideoCommentThreads (url: string, videoId: number, start: number, count: number, sort?: string) { 3function getVideoCommentThreads (url: string, videoId: number | string, start: number, count: number, sort?: string) {
4 const path = '/api/v1/videos/' + videoId + '/comment-threads' 4 const path = '/api/v1/videos/' + videoId + '/comment-threads'
5 5
6 const req = request(url) 6 const req = request(url)
@@ -15,7 +15,7 @@ function getVideoCommentThreads (url: string, videoId: number, start: number, co
15 .expect('Content-Type', /json/) 15 .expect('Content-Type', /json/)
16} 16}
17 17
18function getVideoThreadComments (url: string, videoId: number, threadId: number) { 18function getVideoThreadComments (url: string, videoId: number | string, threadId: number) {
19 const path = '/api/v1/videos/' + videoId + '/comment-threads/' + threadId 19 const path = '/api/v1/videos/' + videoId + '/comment-threads/' + threadId
20 20
21 return request(url) 21 return request(url)
@@ -39,7 +39,7 @@ function addVideoCommentThread (url: string, token: string, videoId: number | st
39function addVideoCommentReply ( 39function addVideoCommentReply (
40 url: string, 40 url: string,
41 token: string, 41 token: string,
42 videoId: number, 42 videoId: number | string,
43 inReplyToCommentId: number, 43 inReplyToCommentId: number,
44 text: string, 44 text: string,
45 expectedStatus = 200 45 expectedStatus = 200