diff options
Diffstat (limited to 'server/tests/api/users/users.ts')
-rw-r--r-- | server/tests/api/users/users.ts | 122 |
1 files changed, 108 insertions, 14 deletions
diff --git a/server/tests/api/users/users.ts b/server/tests/api/users/users.ts index 502eac0bb..3e1a0c19b 100644 --- a/server/tests/api/users/users.ts +++ b/server/tests/api/users/users.ts | |||
@@ -2,7 +2,7 @@ | |||
2 | 2 | ||
3 | import * as chai from 'chai' | 3 | import * as chai from 'chai' |
4 | import 'mocha' | 4 | import 'mocha' |
5 | import { MyUser, User, UserRole, Video, VideoPlaylistType } from '../../../../shared/index' | 5 | import { MyUser, User, UserRole, Video, VideoPlaylistType, VideoAbuseState, VideoAbuseUpdate } from '../../../../shared/index' |
6 | import { | 6 | import { |
7 | blockUser, | 7 | blockUser, |
8 | cleanupTests, | 8 | cleanupTests, |
@@ -33,7 +33,11 @@ import { | |||
33 | updateMyUser, | 33 | updateMyUser, |
34 | updateUser, | 34 | updateUser, |
35 | uploadVideo, | 35 | uploadVideo, |
36 | userLogin | 36 | userLogin, |
37 | reportVideoAbuse, | ||
38 | addVideoCommentThread, | ||
39 | updateVideoAbuse, | ||
40 | getVideoAbusesList | ||
37 | } from '../../../../shared/extra-utils' | 41 | } from '../../../../shared/extra-utils' |
38 | import { follow } from '../../../../shared/extra-utils/server/follows' | 42 | import { follow } from '../../../../shared/extra-utils/server/follows' |
39 | import { setAccessTokensToServers } from '../../../../shared/extra-utils/users/login' | 43 | import { setAccessTokensToServers } from '../../../../shared/extra-utils/users/login' |
@@ -254,7 +258,7 @@ describe('Test users', function () { | |||
254 | const res1 = await getMyUserInformation(server.url, accessTokenUser) | 258 | const res1 = await getMyUserInformation(server.url, accessTokenUser) |
255 | const userMe: MyUser = res1.body | 259 | const userMe: MyUser = res1.body |
256 | 260 | ||
257 | const res2 = await getUserInformation(server.url, server.accessToken, userMe.id) | 261 | const res2 = await getUserInformation(server.url, server.accessToken, userMe.id, true) |
258 | const userGet: User = res2.body | 262 | const userGet: User = res2.body |
259 | 263 | ||
260 | for (const user of [ userMe, userGet ]) { | 264 | for (const user of [ userMe, userGet ]) { |
@@ -273,6 +277,16 @@ describe('Test users', function () { | |||
273 | 277 | ||
274 | expect(userMe.specialPlaylists).to.have.lengthOf(1) | 278 | expect(userMe.specialPlaylists).to.have.lengthOf(1) |
275 | expect(userMe.specialPlaylists[0].type).to.equal(VideoPlaylistType.WATCH_LATER) | 279 | expect(userMe.specialPlaylists[0].type).to.equal(VideoPlaylistType.WATCH_LATER) |
280 | |||
281 | // Check stats are included with withStats | ||
282 | expect(userGet.videosCount).to.be.a('number') | ||
283 | expect(userGet.videosCount).to.equal(0) | ||
284 | expect(userGet.videoCommentsCount).to.be.a('number') | ||
285 | expect(userGet.videoCommentsCount).to.equal(0) | ||
286 | expect(userGet.videoAbusesCount).to.be.a('number') | ||
287 | expect(userGet.videoAbusesCount).to.equal(0) | ||
288 | expect(userGet.videoAbusesAcceptedCount).to.be.a('number') | ||
289 | expect(userGet.videoAbusesAcceptedCount).to.equal(0) | ||
276 | }) | 290 | }) |
277 | }) | 291 | }) |
278 | 292 | ||
@@ -623,7 +637,6 @@ describe('Test users', function () { | |||
623 | }) | 637 | }) |
624 | 638 | ||
625 | describe('Updating another user', function () { | 639 | describe('Updating another user', function () { |
626 | |||
627 | it('Should be able to update another user', async function () { | 640 | it('Should be able to update another user', async function () { |
628 | await updateUser({ | 641 | await updateUser({ |
629 | url: server.url, | 642 | url: server.url, |
@@ -698,6 +711,8 @@ describe('Test users', function () { | |||
698 | }) | 711 | }) |
699 | 712 | ||
700 | describe('Registering a new user', function () { | 713 | describe('Registering a new user', function () { |
714 | let user15AccessToken | ||
715 | |||
701 | it('Should register a new user', async function () { | 716 | it('Should register a new user', async function () { |
702 | const user = { displayName: 'super user 15', username: 'user_15', password: 'my super password' } | 717 | const user = { displayName: 'super user 15', username: 'user_15', password: 'my super password' } |
703 | const channel = { name: 'my_user_15_channel', displayName: 'my channel rocks' } | 718 | const channel = { name: 'my_user_15_channel', displayName: 'my channel rocks' } |
@@ -711,18 +726,18 @@ describe('Test users', function () { | |||
711 | password: 'my super password' | 726 | password: 'my super password' |
712 | } | 727 | } |
713 | 728 | ||
714 | accessToken = await userLogin(server, user15) | 729 | user15AccessToken = await userLogin(server, user15) |
715 | }) | 730 | }) |
716 | 731 | ||
717 | it('Should have the correct display name', async function () { | 732 | it('Should have the correct display name', async function () { |
718 | const res = await getMyUserInformation(server.url, accessToken) | 733 | const res = await getMyUserInformation(server.url, user15AccessToken) |
719 | const user: User = res.body | 734 | const user: User = res.body |
720 | 735 | ||
721 | expect(user.account.displayName).to.equal('super user 15') | 736 | expect(user.account.displayName).to.equal('super user 15') |
722 | }) | 737 | }) |
723 | 738 | ||
724 | it('Should have the correct video quota', async function () { | 739 | it('Should have the correct video quota', async function () { |
725 | const res = await getMyUserInformation(server.url, accessToken) | 740 | const res = await getMyUserInformation(server.url, user15AccessToken) |
726 | const user = res.body | 741 | const user = res.body |
727 | 742 | ||
728 | expect(user.videoQuota).to.equal(5 * 1024 * 1024) | 743 | expect(user.videoQuota).to.equal(5 * 1024 * 1024) |
@@ -740,7 +755,7 @@ describe('Test users', function () { | |||
740 | expect(res.body.data.find(u => u.username === 'user_15')).to.not.be.undefined | 755 | expect(res.body.data.find(u => u.username === 'user_15')).to.not.be.undefined |
741 | } | 756 | } |
742 | 757 | ||
743 | await deleteMe(server.url, accessToken) | 758 | await deleteMe(server.url, user15AccessToken) |
744 | 759 | ||
745 | { | 760 | { |
746 | const res = await getUsersList(server.url, server.accessToken) | 761 | const res = await getUsersList(server.url, server.accessToken) |
@@ -750,6 +765,9 @@ describe('Test users', function () { | |||
750 | }) | 765 | }) |
751 | 766 | ||
752 | describe('User blocking', function () { | 767 | describe('User blocking', function () { |
768 | let user16Id | ||
769 | let user16AccessToken | ||
770 | |||
753 | it('Should block and unblock a user', async function () { | 771 | it('Should block and unblock a user', async function () { |
754 | const user16 = { | 772 | const user16 = { |
755 | username: 'user_16', | 773 | username: 'user_16', |
@@ -761,19 +779,95 @@ describe('Test users', function () { | |||
761 | username: user16.username, | 779 | username: user16.username, |
762 | password: user16.password | 780 | password: user16.password |
763 | }) | 781 | }) |
764 | const user16Id = resUser.body.user.id | 782 | user16Id = resUser.body.user.id |
765 | 783 | ||
766 | accessToken = await userLogin(server, user16) | 784 | user16AccessToken = await userLogin(server, user16) |
767 | 785 | ||
768 | await getMyUserInformation(server.url, accessToken, 200) | 786 | await getMyUserInformation(server.url, user16AccessToken, 200) |
769 | await blockUser(server.url, user16Id, server.accessToken) | 787 | await blockUser(server.url, user16Id, server.accessToken) |
770 | 788 | ||
771 | await getMyUserInformation(server.url, accessToken, 401) | 789 | await getMyUserInformation(server.url, user16AccessToken, 401) |
772 | await userLogin(server, user16, 400) | 790 | await userLogin(server, user16, 400) |
773 | 791 | ||
774 | await unblockUser(server.url, user16Id, server.accessToken) | 792 | await unblockUser(server.url, user16Id, server.accessToken) |
775 | accessToken = await userLogin(server, user16) | 793 | user16AccessToken = await userLogin(server, user16) |
776 | await getMyUserInformation(server.url, accessToken, 200) | 794 | await getMyUserInformation(server.url, user16AccessToken, 200) |
795 | }) | ||
796 | }) | ||
797 | |||
798 | describe('User stats', function () { | ||
799 | let user17Id | ||
800 | let user17AccessToken | ||
801 | |||
802 | it('Should report correct initial statistics about a user', async function () { | ||
803 | const user17 = { | ||
804 | username: 'user_17', | ||
805 | password: 'my super password' | ||
806 | } | ||
807 | const resUser = await createUser({ | ||
808 | url: server.url, | ||
809 | accessToken: server.accessToken, | ||
810 | username: user17.username, | ||
811 | password: user17.password | ||
812 | }) | ||
813 | |||
814 | user17Id = resUser.body.user.id | ||
815 | user17AccessToken = await userLogin(server, user17) | ||
816 | |||
817 | const res = await getUserInformation(server.url, server.accessToken, user17Id, true) | ||
818 | const user: User = res.body | ||
819 | |||
820 | expect(user.videosCount).to.equal(0) | ||
821 | expect(user.videoCommentsCount).to.equal(0) | ||
822 | expect(user.videoAbusesCount).to.equal(0) | ||
823 | expect(user.videoAbusesCreatedCount).to.equal(0) | ||
824 | expect(user.videoAbusesAcceptedCount).to.equal(0) | ||
825 | }) | ||
826 | |||
827 | it('Should report correct videos count', async function () { | ||
828 | const videoAttributes = { | ||
829 | name: 'video to test user stats' | ||
830 | } | ||
831 | await uploadVideo(server.url, user17AccessToken, videoAttributes) | ||
832 | const res1 = await getVideosList(server.url) | ||
833 | videoId = res1.body.data.find(video => video.name === videoAttributes.name).id | ||
834 | |||
835 | const res2 = await getUserInformation(server.url, server.accessToken, user17Id, true) | ||
836 | const user: User = res2.body | ||
837 | |||
838 | expect(user.videosCount).to.equal(1) | ||
839 | }) | ||
840 | |||
841 | it('Should report correct video comments for user', async function () { | ||
842 | const text = 'super comment' | ||
843 | await addVideoCommentThread(server.url, user17AccessToken, videoId, text) | ||
844 | |||
845 | const res = await getUserInformation(server.url, server.accessToken, user17Id, true) | ||
846 | const user: User = res.body | ||
847 | |||
848 | expect(user.videoCommentsCount).to.equal(1) | ||
849 | }) | ||
850 | |||
851 | it('Should report correct video abuses counts', async function () { | ||
852 | const reason = 'my super bad reason' | ||
853 | await reportVideoAbuse(server.url, user17AccessToken, videoId, reason) | ||
854 | |||
855 | const res1 = await getVideoAbusesList(server.url, server.accessToken) | ||
856 | const abuseId = res1.body.data[0].id | ||
857 | |||
858 | const res2 = await getUserInformation(server.url, server.accessToken, user17Id, true) | ||
859 | const user2: User = res2.body | ||
860 | |||
861 | expect(user2.videoAbusesCount).to.equal(1) // number of incriminations | ||
862 | expect(user2.videoAbusesCreatedCount).to.equal(1) // number of reports created | ||
863 | |||
864 | const body: VideoAbuseUpdate = { state: VideoAbuseState.ACCEPTED } | ||
865 | await updateVideoAbuse(server.url, server.accessToken, videoId, abuseId, body) | ||
866 | |||
867 | const res3 = await getUserInformation(server.url, server.accessToken, user17Id, true) | ||
868 | const user3: User = res3.body | ||
869 | |||
870 | expect(user3.videoAbusesAcceptedCount).to.equal(1) // number of reports created accepted | ||
777 | }) | 871 | }) |
778 | }) | 872 | }) |
779 | 873 | ||