diff options
-rw-r--r-- | client/src/app/videos/+video-watch/comment/video-comment-add.component.ts | 2 | ||||
-rw-r--r-- | server/lib/activitypub/videos.ts | 4 | ||||
-rw-r--r-- | server/lib/cache/videos-preview-cache.ts | 10 | ||||
-rw-r--r-- | server/middlewares/validators/video-channels.ts | 2 | ||||
-rw-r--r-- | server/models/video/video-comment.ts | 2 | ||||
-rw-r--r-- | server/tests/api/check-params/video-channels.ts | 10 | ||||
-rw-r--r-- | server/tests/api/check-params/video-comments.ts | 16 | ||||
-rw-r--r-- | server/tests/api/multiple-servers.ts | 135 | ||||
-rw-r--r-- | server/tests/api/video-comments.ts | 6 | ||||
-rw-r--r-- | server/tests/utils/video-comments.ts | 6 |
10 files changed, 136 insertions, 57 deletions
diff --git a/client/src/app/videos/+video-watch/comment/video-comment-add.component.ts b/client/src/app/videos/+video-watch/comment/video-comment-add.component.ts index 5ad83fc47..d05232202 100644 --- a/client/src/app/videos/+video-watch/comment/video-comment-add.component.ts +++ b/client/src/app/videos/+video-watch/comment/video-comment-add.component.ts | |||
@@ -66,7 +66,7 @@ export class VideoCommentAddComponent extends FormReactive implements OnInit { | |||
66 | 66 | ||
67 | err => this.notificationsService.error('Error', err.text) | 67 | err => this.notificationsService.error('Error', err.text) |
68 | ) | 68 | ) |
69 | } | 69 | } |
70 | 70 | ||
71 | isAddButtonDisplayed () { | 71 | isAddButtonDisplayed () { |
72 | return this.form.value['text'] | 72 | return this.form.value['text'] |
diff --git a/server/lib/activitypub/videos.ts b/server/lib/activitypub/videos.ts index fab43757a..ded854ee1 100644 --- a/server/lib/activitypub/videos.ts +++ b/server/lib/activitypub/videos.ts | |||
@@ -17,12 +17,12 @@ import { | |||
17 | sendUndoLikeToVideoFollowers | 17 | sendUndoLikeToVideoFollowers |
18 | } from './send' | 18 | } from './send' |
19 | 19 | ||
20 | function fetchRemoteVideoPreview (video: VideoModel) { | 20 | function fetchRemoteVideoPreview (video: VideoModel, reject: Function) { |
21 | // FIXME: use url | 21 | // FIXME: use url |
22 | const host = video.VideoChannel.Account.Actor.Server.host | 22 | const host = video.VideoChannel.Account.Actor.Server.host |
23 | const path = join(STATIC_PATHS.PREVIEWS, video.getPreviewName()) | 23 | const path = join(STATIC_PATHS.PREVIEWS, video.getPreviewName()) |
24 | 24 | ||
25 | return request.get(REMOTE_SCHEME.HTTP + '://' + host + path) | 25 | return request.get(REMOTE_SCHEME.HTTP + '://' + host + path, err => reject(err)) |
26 | } | 26 | } |
27 | 27 | ||
28 | async function fetchRemoteVideoDescription (video: VideoModel) { | 28 | async function fetchRemoteVideoDescription (video: VideoModel) { |
diff --git a/server/lib/cache/videos-preview-cache.ts b/server/lib/cache/videos-preview-cache.ts index 0eb43efcc..ea959076d 100644 --- a/server/lib/cache/videos-preview-cache.ts +++ b/server/lib/cache/videos-preview-cache.ts | |||
@@ -52,21 +52,19 @@ class VideosPreviewCache { | |||
52 | 52 | ||
53 | if (video.isOwned()) throw new Error('Cannot load preview of owned video.') | 53 | if (video.isOwned()) throw new Error('Cannot load preview of owned video.') |
54 | 54 | ||
55 | const res = await this.saveRemotePreviewAndReturnPath(video) | 55 | return this.saveRemotePreviewAndReturnPath(video) |
56 | |||
57 | return res | ||
58 | } | 56 | } |
59 | 57 | ||
60 | private saveRemotePreviewAndReturnPath (video: VideoModel) { | 58 | private saveRemotePreviewAndReturnPath (video: VideoModel) { |
61 | const req = fetchRemoteVideoPreview(video) | ||
62 | 59 | ||
63 | return new Promise<string>((res, rej) => { | 60 | return new Promise<string>((res, rej) => { |
61 | const req = fetchRemoteVideoPreview(video, rej) | ||
64 | const path = join(CACHE.DIRECTORIES.PREVIEWS, video.getPreviewName()) | 62 | const path = join(CACHE.DIRECTORIES.PREVIEWS, video.getPreviewName()) |
65 | const stream = createWriteStream(path) | 63 | const stream = createWriteStream(path) |
66 | 64 | ||
67 | req.pipe(stream) | 65 | req.pipe(stream) |
68 | .on('finish', () => res(path)) | 66 | .on('error', (err) => rej(err)) |
69 | .on('error', (err) => rej(err)) | 67 | .on('finish', () => res(path)) |
70 | }) | 68 | }) |
71 | } | 69 | } |
72 | } | 70 | } |
diff --git a/server/middlewares/validators/video-channels.ts b/server/middlewares/validators/video-channels.ts index cc7d54c06..0e6eff493 100644 --- a/server/middlewares/validators/video-channels.ts +++ b/server/middlewares/validators/video-channels.ts | |||
@@ -51,7 +51,7 @@ const videoChannelsUpdateValidator = [ | |||
51 | if (!await isVideoChannelExist(req.params.id, res)) return | 51 | if (!await isVideoChannelExist(req.params.id, res)) return |
52 | 52 | ||
53 | // We need to make additional checks | 53 | // We need to make additional checks |
54 | if (res.locals.videoChannel.isOwned() === false) { | 54 | if (res.locals.videoChannel.Actor.isOwned() === false) { |
55 | return res.status(403) | 55 | return res.status(403) |
56 | .json({ error: 'Cannot update video channel of another server' }) | 56 | .json({ error: 'Cannot update video channel of another server' }) |
57 | .end() | 57 | .end() |
diff --git a/server/models/video/video-comment.ts b/server/models/video/video-comment.ts index a3e8c48d4..8ceeb563a 100644 --- a/server/models/video/video-comment.ts +++ b/server/models/video/video-comment.ts | |||
@@ -212,7 +212,7 @@ export class VideoCommentModel extends Model<VideoCommentModel> { | |||
212 | url: this.url, | 212 | url: this.url, |
213 | text: this.text, | 213 | text: this.text, |
214 | threadId: this.originCommentId || this.id, | 214 | threadId: this.originCommentId || this.id, |
215 | inReplyToCommentId: this.inReplyToCommentId, | 215 | inReplyToCommentId: this.inReplyToCommentId || null, |
216 | videoId: this.videoId, | 216 | videoId: this.videoId, |
217 | createdAt: this.createdAt, | 217 | createdAt: this.createdAt, |
218 | updatedAt: this.updatedAt, | 218 | updatedAt: this.updatedAt, |
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 | ||
3 | import 'mocha' | 3 | import 'mocha' |
4 | import * as request from 'supertest' | 4 | import * as request from 'supertest' |
5 | import { | 5 | import { flushTests, killallServers, makePostBodyRequest, runServer, ServerInfo, setAccessTokensToServers, uploadVideo } from '../../utils' |
6 | createUser, flushTests, getUserAccessToken, killallServers, makePostBodyRequest, runServer, ServerInfo, setAccessTokensToServers, | ||
7 | uploadVideo | ||
8 | } from '../../utils' | ||
9 | import { addVideoCommentThread } from '../../utils/video-comments' | 6 | import { addVideoCommentThread } from '../../utils/video-comments' |
10 | 7 | ||
11 | describe('Test video comments API validator', function () { | 8 | describe('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 | ||
3 | import 'mocha' | ||
4 | import * as chai from 'chai' | 3 | import * as chai from 'chai' |
4 | import 'mocha' | ||
5 | import { join } from 'path' | 5 | import { join } from 'path' |
6 | import * as request from 'supertest' | 6 | import * as request from 'supertest' |
7 | import { VideoComment, VideoCommentThreadTree } from '../../../shared/models/videos/video-comment.model' | ||
7 | 8 | ||
8 | import { | 9 | import { |
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' |
29 | import { createUser } from '../utils/users' | 14 | import { createUser } from '../utils/users' |
15 | import { addVideoCommentReply, addVideoCommentThread, getVideoCommentThreads, getVideoThreadComments } from '../utils/video-comments' | ||
30 | import { viewVideo } from '../utils/videos' | 16 | import { viewVideo } from '../utils/videos' |
31 | 17 | ||
32 | const expect = chai.expect | 18 | const 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 @@ | |||
1 | import * as request from 'supertest' | 1 | import * as request from 'supertest' |
2 | 2 | ||
3 | function getVideoCommentThreads (url: string, videoId: number, start: number, count: number, sort?: string) { | 3 | function 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 | ||
18 | function getVideoThreadComments (url: string, videoId: number, threadId: number) { | 18 | function 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 | |||
39 | function addVideoCommentReply ( | 39 | function 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 |