diff options
Diffstat (limited to 'server/tests/api/videos/multiple-servers.ts')
-rw-r--r-- | server/tests/api/videos/multiple-servers.ts | 99 |
1 files changed, 44 insertions, 55 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 @@ | |||
3 | import 'mocha' | 3 | import 'mocha' |
4 | import * as chai from 'chai' | 4 | import * as chai from 'chai' |
5 | import * as request from 'supertest' | 5 | import * as request from 'supertest' |
6 | import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' | 6 | import { HttpStatusCode } from '@shared/core-utils' |
7 | import { | 7 | import { |
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' |
32 | import { waitJobs } from '../../../../shared/extra-utils/server/jobs' | 33 | import { VideoCommentThreadTree, VideoPrivacy } from '@shared/models' |
33 | import { | ||
34 | addVideoCommentReply, | ||
35 | addVideoCommentThread, | ||
36 | deleteVideoComment, | ||
37 | findCommentId, | ||
38 | getVideoCommentThreads, | ||
39 | getVideoThreadComments | ||
40 | } from '../../../../shared/extra-utils/videos/video-comments' | ||
41 | import { VideoComment, VideoCommentThreadTree, VideoPrivacy } from '../../../../shared/models/videos' | ||
42 | 34 | ||
43 | const expect = chai.expect | 35 | const 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 | }) |