X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Ftests%2Fapi%2Fusers%2Fuser-subscriptions.ts;h=48811e647d172606b4db54aee8fce30270dd8212;hb=97567dd81f508dd6295ac4d73d849aa2ce0a6549;hp=2ba6cdfafee443daa7c4c3124a3dbf1fd2fa1bcd;hpb=06a05d5f4784a7cbb27aa1188385b5679845dad8;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/tests/api/users/user-subscriptions.ts b/server/tests/api/users/user-subscriptions.ts index 2ba6cdfaf..48811e647 100644 --- a/server/tests/api/users/user-subscriptions.ts +++ b/server/tests/api/users/user-subscriptions.ts @@ -2,24 +2,35 @@ import * as chai from 'chai' import 'mocha' -import { createUser, doubleFollow, flushAndRunMultipleServers, follow, getVideosList, unfollow, userLogin } from '../../utils' -import { getMyUserInformation, killallServers, ServerInfo, uploadVideo } from '../../utils/index' -import { setAccessTokensToServers } from '../../utils/users/login' +import { + cleanupTests, + createUser, + doubleFollow, + flushAndRunMultipleServers, + follow, + getVideosList, + unfollow, + updateVideo, + userLogin +} from '../../../../shared/extra-utils' +import { killallServers, ServerInfo, uploadVideo } from '../../../../shared/extra-utils/index' +import { setAccessTokensToServers } from '../../../../shared/extra-utils/users/login' import { Video, VideoChannel } from '../../../../shared/models/videos' -import { waitJobs } from '../../utils/server/jobs' +import { waitJobs } from '../../../../shared/extra-utils/server/jobs' import { addUserSubscription, listUserSubscriptions, listUserSubscriptionVideos, - removeUserSubscription -} from '../../utils/users/user-subscriptions' + removeUserSubscription, + getUserSubscription, areSubscriptionsExist +} from '../../../../shared/extra-utils/users/user-subscriptions' const expect = chai.expect describe('Test users subscriptions', function () { let servers: ServerInfo[] = [] - const users: { accessToken: string, videoChannelName: string }[] = [] - let rootChannelNameServer1: string + const users: { accessToken: string }[] = [] + let video3UUID: string before(async function () { this.timeout(120000) @@ -32,19 +43,13 @@ describe('Test users subscriptions', function () { // Server 1 and server 2 follow each other await doubleFollow(servers[0], servers[1]) - const res = await getMyUserInformation(servers[0].url, servers[0].accessToken) - rootChannelNameServer1 = res.body.videoChannels[0].name - { for (const server of servers) { const user = { username: 'user' + server.serverNumber, password: 'password' } - await createUser(server.url, server.accessToken, user.username, user.password) + await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) const accessToken = await userLogin(server, user) - const res = await getMyUserInformation(server.url, accessToken) - const videoChannels: VideoChannel[] = res.body.videoChannels - - users.push({ accessToken, videoChannelName: videoChannels[0].name }) + users.push({ accessToken }) const videoName1 = 'video 1-' + server.serverNumber await uploadVideo(server.url, accessToken, { name: videoName1 }) @@ -64,14 +69,15 @@ describe('Test users subscriptions', function () { }) it('User of server 1 should follow user of server 3 and root of server 1', async function () { - this.timeout(30000) + this.timeout(60000) - await addUserSubscription(servers[0].url, users[0].accessToken, users[2].videoChannelName + '@localhost:9003') - await addUserSubscription(servers[0].url, users[0].accessToken, rootChannelNameServer1 + '@localhost:9001') + await addUserSubscription(servers[0].url, users[0].accessToken, 'user3_channel@localhost:9003') + await addUserSubscription(servers[0].url, users[0].accessToken, 'root_channel@localhost:9001') await waitJobs(servers) - await uploadVideo(servers[2].url, users[2].accessToken, { name: 'video server 3 added after follow' }) + const res = await uploadVideo(servers[2].url, users[2].accessToken, { name: 'video server 3 added after follow' }) + video3UUID = res.body.video.uuid await waitJobs(servers) }) @@ -103,11 +109,52 @@ describe('Test users subscriptions', function () { expect(subscriptions).to.be.an('array') expect(subscriptions).to.have.lengthOf(2) - expect(subscriptions[0].name).to.equal(users[2].videoChannelName) - expect(subscriptions[1].name).to.equal(rootChannelNameServer1) + expect(subscriptions[0].name).to.equal('user3_channel') + expect(subscriptions[1].name).to.equal('root_channel') + } + }) + + it('Should get subscription', async function () { + { + const res = await getUserSubscription(servers[ 0 ].url, users[ 0 ].accessToken, 'user3_channel@localhost:9003') + const videoChannel: VideoChannel = res.body + + expect(videoChannel.name).to.equal('user3_channel') + expect(videoChannel.host).to.equal('localhost:9003') + expect(videoChannel.displayName).to.equal('Main user3 channel') + expect(videoChannel.followingCount).to.equal(0) + expect(videoChannel.followersCount).to.equal(1) + } + + { + const res = await getUserSubscription(servers[ 0 ].url, users[ 0 ].accessToken, 'root_channel@localhost:9001') + const videoChannel: VideoChannel = res.body + + expect(videoChannel.name).to.equal('root_channel') + expect(videoChannel.host).to.equal('localhost:9001') + expect(videoChannel.displayName).to.equal('Main root channel') + expect(videoChannel.followingCount).to.equal(0) + expect(videoChannel.followersCount).to.equal(1) } }) + it('Should return the existing subscriptions', async function () { + const uris = [ + 'user3_channel@localhost:9003', + 'root2_channel@localhost:9001', + 'root_channel@localhost:9001', + 'user3_channel@localhost:9001' + ] + + const res = await areSubscriptionsExist(servers[ 0 ].url, users[ 0 ].accessToken, uris) + const body = res.body + + expect(body['user3_channel@localhost:9003']).to.be.true + expect(body['root2_channel@localhost:9001']).to.be.false + expect(body['root_channel@localhost:9001']).to.be.true + expect(body['user3_channel@localhost:9001']).to.be.false + }) + it('Should list subscription videos', async function () { { const res = await listUserSubscriptionVideos(servers[0].url, servers[0].accessToken) @@ -131,7 +178,7 @@ describe('Test users subscriptions', function () { }) it('Should upload a video by root on server 1 and see it in the subscription videos', async function () { - this.timeout(30000) + this.timeout(60000) const videoName = 'video server 1 added after follow' await uploadVideo(servers[0].url, servers[0].accessToken, { name: videoName }) @@ -172,7 +219,7 @@ describe('Test users subscriptions', function () { }) it('Should have server 1 follow server 3 and display server 3 videos', async function () { - this.timeout(30000) + this.timeout(60000) await follow(servers[0].url, [ servers[2].url ], servers[0].accessToken) @@ -190,7 +237,7 @@ describe('Test users subscriptions', function () { }) it('Should remove follow server 1 -> server 3 and hide server 3 videos', async function () { - this.timeout(30000) + this.timeout(60000) await unfollow(servers[0].url, servers[0].accessToken, servers[2]) @@ -229,8 +276,22 @@ describe('Test users subscriptions', function () { } }) + it('Should update a video of server 3 and see the updated video on server 1', async function () { + this.timeout(30000) + + await updateVideo(servers[2].url, users[2].accessToken, video3UUID, { name: 'video server 3 added after follow updated' }) + + await waitJobs(servers) + + const res = await listUserSubscriptionVideos(servers[0].url, users[0].accessToken, 'createdAt') + const videos: Video[] = res.body.data + expect(videos[2].name).to.equal('video server 3 added after follow updated') + }) + it('Should remove user of server 3 subscription', async function () { - await removeUserSubscription(servers[0].url, users[0].accessToken, users[2].videoChannelName + '@localhost:9003') + this.timeout(30000) + + await removeUserSubscription(servers[0].url, users[0].accessToken, 'user3_channel@localhost:9003') await waitJobs(servers) }) @@ -249,7 +310,9 @@ describe('Test users subscriptions', function () { }) it('Should remove the root subscription and not display the videos anymore', async function () { - await removeUserSubscription(servers[0].url, users[0].accessToken, rootChannelNameServer1 + '@localhost:9001') + this.timeout(30000) + + await removeUserSubscription(servers[0].url, users[0].accessToken, 'root_channel@localhost:9001') await waitJobs(servers) @@ -270,14 +333,14 @@ describe('Test users subscriptions', function () { for (const video of res.body.data) { expect(video.name).to.not.contain('1-3') expect(video.name).to.not.contain('2-3') - expect(video.name).to.not.contain('video server 3 added after follow') + expect(video.name).to.not.contain('video server 3 added after follow updated') } }) it('Should follow user of server 3 again', async function () { - this.timeout(30000) + this.timeout(60000) - await addUserSubscription(servers[0].url, users[0].accessToken, users[2].videoChannelName + '@localhost:9003') + await addUserSubscription(servers[0].url, users[0].accessToken, 'user3_channel@localhost:9003') await waitJobs(servers) @@ -291,7 +354,7 @@ describe('Test users subscriptions', function () { expect(videos[0].name).to.equal('video 1-3') expect(videos[1].name).to.equal('video 2-3') - expect(videos[2].name).to.equal('video server 3 added after follow') + expect(videos[2].name).to.equal('video server 3 added after follow updated') } { @@ -301,12 +364,12 @@ describe('Test users subscriptions', function () { for (const video of res.body.data) { expect(video.name).to.not.contain('1-3') expect(video.name).to.not.contain('2-3') - expect(video.name).to.not.contain('video server 3 added after follow') + expect(video.name).to.not.contain('video server 3 added after follow updated') } } }) after(async function () { - killallServers(servers) + await cleanupTests(servers) }) })