From f05a1c30c15d2ae35c11e241ca039a72eeb7d6ad Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 18 Jan 2018 10:53:54 +0100 Subject: Don't show videos of remote instance after unfollow --- server/tests/api/check-params/users.ts | 2 +- server/tests/api/server/follows.ts | 24 ++++++++- server/tests/api/users/users-multiple-servers.ts | 66 ++++++++++++++++++++---- server/tests/api/users/users.ts | 4 +- server/tests/api/videos/multiple-servers.ts | 14 +++-- server/tests/api/videos/single-server.ts | 17 +++--- server/tests/api/videos/video-comments.ts | 4 +- 7 files changed, 101 insertions(+), 30 deletions(-) (limited to 'server/tests/api') diff --git a/server/tests/api/check-params/users.ts b/server/tests/api/check-params/users.ts index 14fcf8703..0c9d933a7 100644 --- a/server/tests/api/check-params/users.ts +++ b/server/tests/api/check-params/users.ts @@ -185,7 +185,7 @@ describe('Test users API validators', function () { path, token: server.accessToken, fields: baseCorrectParams, - statusCodeExpected: 204 + statusCodeExpected: 200 }) }) diff --git a/server/tests/api/server/follows.ts b/server/tests/api/server/follows.ts index fad58e840..ac614d605 100644 --- a/server/tests/api/server/follows.ts +++ b/server/tests/api/server/follows.ts @@ -4,7 +4,7 @@ import * as chai from 'chai' import 'mocha' import { Video, VideoPrivacy } from '../../../../shared/models/videos' import { VideoComment, VideoCommentThreadTree } from '../../../../shared/models/videos/video-comment.model' -import { completeVideoCheck } from '../../utils' +import { checkVideoFilesWereRemoved, completeVideoCheck, getVideoChannelsList } from '../../utils' import { flushAndRunMultipleServers, flushTests, getVideosList, killallServers, ServerInfo, setAccessTokensToServers, uploadVideo, @@ -12,7 +12,7 @@ import { } from '../../utils/index' import { dateIsValid } from '../../utils/miscs/miscs' import { follow, getFollowersListPaginationAndSort, getFollowingListPaginationAndSort, unfollow } from '../../utils/server/follows' -import { expectAccountFollows } from '../../utils/users/accounts' +import { expectAccountFollows, getAccountsList } from '../../utils/users/accounts' import { userLogin } from '../../utils/users/login' import { createUser } from '../../utils/users/users' import { @@ -343,6 +343,26 @@ describe('Test follows', function () { expect(secondChild.comment.text).to.equal('my second answer to thread 1') expect(secondChild.children).to.have.lengthOf(0) }) + + it('Should unfollow server 3 on server 1 and does not list server 3 videos', async function () { + this.timeout(5000) + + await unfollow(servers[0].url, servers[0].accessToken, servers[2]) + + await wait(3000) + + let res = await getVideosList(servers[ 0 ].url) + expect(res.body.total).to.equal(1) + + res = await getVideoChannelsList(servers[0].url, 0, 1) + expect(res.body.total).to.equal(2) + + res = await getAccountsList(servers[0].url) + expect(res.body.total).to.equal(2) + + await checkVideoFilesWereRemoved(video4.uuid, servers[0].serverNumber) + }) + }) after(async function () { diff --git a/server/tests/api/users/users-multiple-servers.ts b/server/tests/api/users/users-multiple-servers.ts index 1c7f011a8..0483b9c3d 100644 --- a/server/tests/api/users/users-multiple-servers.ts +++ b/server/tests/api/users/users-multiple-servers.ts @@ -3,18 +3,20 @@ import * as chai from 'chai' import 'mocha' import { Account } from '../../../../shared/models/actors' -import { doubleFollow, flushAndRunMultipleServers, wait } from '../../utils' -import { - flushTests, getMyUserInformation, killallServers, ServerInfo, testVideoImage, updateMyAvatar, - uploadVideo -} from '../../utils/index' -import { getAccount, getAccountsList } from '../../utils/users/accounts' +import { checkVideoFilesWereRemoved, createUser, doubleFollow, flushAndRunMultipleServers, removeUser, userLogin, wait } from '../../utils' +import { flushTests, getMyUserInformation, killallServers, ServerInfo, testImage, updateMyAvatar, uploadVideo } from '../../utils/index' +import { checkActorFilesWereRemoved, getAccount, getAccountsList } from '../../utils/users/accounts' import { setAccessTokensToServers } from '../../utils/users/login' const expect = chai.expect describe('Test users with multiple servers', function () { let servers: ServerInfo[] = [] + let user + let userUUID + let userId + let videoUUID + let userAccessToken before(async function () { this.timeout(120000) @@ -34,6 +36,18 @@ describe('Test users with multiple servers', function () { // The root user of server 1 is propagated to servers 2 and 3 await uploadVideo(servers[0].url, servers[0].accessToken, {}) + const user = { + username: 'user1', + password: 'password' + } + const resUser = await createUser(servers[0].url, servers[0].accessToken, user.username, user.password) + userUUID = resUser.body.user.uuid + userId = resUser.body.user.id + userAccessToken = await userLogin(servers[0], user) + + const resVideo = await uploadVideo(servers[0].url, userAccessToken, {}) + videoUUID = resVideo.body.uuid + await wait(5000) }) @@ -49,9 +63,9 @@ describe('Test users with multiple servers', function () { }) const res = await getMyUserInformation(servers[0].url, servers[0].accessToken) - const user = res.body + user = res.body - const test = await testVideoImage(servers[0].url, 'avatar2-resized', user.account.avatar.path, '.png') + const test = await testImage(servers[0].url, 'avatar2-resized', user.account.avatar.path, '.png') expect(test).to.equal(true) await wait(5000) @@ -69,11 +83,45 @@ describe('Test users with multiple servers', function () { expect(rootServer1Get.name).to.equal('root') expect(rootServer1Get.host).to.equal('localhost:9001') - const test = await testVideoImage(server.url, 'avatar2-resized', rootServer1Get.avatar.path, '.png') + const test = await testImage(server.url, 'avatar2-resized', rootServer1Get.avatar.path, '.png') expect(test).to.equal(true) } }) + it('Should remove the user', async function () { + this.timeout(10000) + + for (const server of servers) { + const resAccounts = await getAccountsList(server.url, '-createdAt') + + const userServer1List = resAccounts.body.data.find(a => a.name === 'user1' && a.host === 'localhost:9001') as Account + expect(userServer1List).not.to.be.undefined + } + + await removeUser(servers[0].url, userId, servers[0].accessToken) + + await wait(5000) + + for (const server of servers) { + const resAccounts = await getAccountsList(server.url, '-createdAt') + + const userServer1List = resAccounts.body.data.find(a => a.name === 'user1' && a.host === 'localhost:9001') as Account + expect(userServer1List).to.be.undefined + } + }) + + it('Should not have actor files', async () => { + for (const server of servers) { + await checkActorFilesWereRemoved(userUUID, server.serverNumber) + } + }) + + it('Should not have video files', async () => { + for (const server of servers) { + await checkVideoFilesWereRemoved(videoUUID, server.serverNumber) + } + }) + after(async function () { killallServers(servers) diff --git a/server/tests/api/users/users.ts b/server/tests/api/users/users.ts index b788637e7..d8004ff24 100644 --- a/server/tests/api/users/users.ts +++ b/server/tests/api/users/users.ts @@ -7,7 +7,7 @@ import { createUser, flushTests, getBlacklistedVideosList, getMyUserInformation, getMyUserVideoQuotaUsed, getMyUserVideoRating, getUserInformation, getUsersList, getUsersListPaginationAndSort, getVideosList, killallServers, login, makePutBodyRequest, rateVideo, registerUser, removeUser, removeVideo, - runServer, ServerInfo, serverLogin, testVideoImage, updateMyAvatar, updateMyUser, updateUser, uploadVideo + runServer, ServerInfo, serverLogin, testImage, updateMyAvatar, updateMyUser, updateUser, uploadVideo } from '../../utils/index' import { follow } from '../../utils/server/follows' import { setAccessTokensToServers } from '../../utils/users/login' @@ -361,7 +361,7 @@ describe('Test users', function () { const res = await getMyUserInformation(server.url, accessTokenUser) const user = res.body - const test = await testVideoImage(server.url, 'avatar-resized', user.account.avatar.path, '.png') + const test = await testImage(server.url, 'avatar-resized', user.account.avatar.path, '.png') expect(test).to.equal(true) }) diff --git a/server/tests/api/videos/multiple-servers.ts b/server/tests/api/videos/multiple-servers.ts index 6712829d4..4c4b5123d 100644 --- a/server/tests/api/videos/multiple-servers.ts +++ b/server/tests/api/videos/multiple-servers.ts @@ -8,8 +8,9 @@ import { VideoPrivacy } from '../../../../shared/models/videos' import { VideoComment, VideoCommentThreadTree } from '../../../../shared/models/videos/video-comment.model' import { - addVideoChannel, completeVideoCheck, createUser, dateIsValid, doubleFollow, flushAndRunMultipleServers, flushTests, getVideo, - getVideoChannelsList, getVideosList, killallServers, rateVideo, removeVideo, ServerInfo, setAccessTokensToServers, testVideoImage, + addVideoChannel, checkVideoFilesWereRemoved, completeVideoCheck, createUser, dateIsValid, doubleFollow, flushAndRunMultipleServers, + flushTests, getVideo, + getVideoChannelsList, getVideosList, killallServers, rateVideo, removeVideo, ServerInfo, setAccessTokensToServers, testImage, updateVideo, uploadVideo, userLogin, viewVideo, wait, webtorrentAdd } from '../../utils' import { @@ -578,6 +579,13 @@ describe('Test multiple servers', function () { await wait(5000) }) + it('Should not have files of videos 3 and 3-2 on each server', async function () { + for (const server of servers) { + await checkVideoFilesWereRemoved(toRemove[0].uuid, server.serverNumber) + await checkVideoFilesWereRemoved(toRemove[1].uuid, server.serverNumber) + } + }) + it('Should have videos 1 and 3 on each server', async function () { for (const server of servers) { const res = await getVideosList(server.url) @@ -624,7 +632,7 @@ describe('Test multiple servers', function () { const res = await getVideo(server.url, videoUUID) const video = res.body - const test = await testVideoImage(server.url, 'video_short1-preview.webm', video.previewPath) + const test = await testImage(server.url, 'video_short1-preview.webm', video.previewPath) expect(test).to.equal(true) } }) diff --git a/server/tests/api/videos/single-server.ts b/server/tests/api/videos/single-server.ts index ca20f39a0..76d265ec5 100644 --- a/server/tests/api/videos/single-server.ts +++ b/server/tests/api/videos/single-server.ts @@ -3,13 +3,12 @@ import * as chai from 'chai' import { keyBy } from 'lodash' import 'mocha' -import { join } from 'path' import { VideoPrivacy } from '../../../../shared/models/videos' -import { readdirPromise } from '../../../helpers/core-utils' import { - completeVideoCheck, flushTests, getVideo, getVideoCategories, getVideoLanguages, getVideoLicences, getVideoPrivacies, - getVideosList, getVideosListPagination, getVideosListSort, killallServers, rateVideo, removeVideo, runServer, searchVideo, - searchVideoWithPagination, searchVideoWithSort, ServerInfo, setAccessTokensToServers, testVideoImage, updateVideo, uploadVideo, viewVideo + checkVideoFilesWereRemoved, completeVideoCheck, flushTests, getVideo, getVideoCategories, getVideoLanguages, getVideoLicences, + getVideoPrivacies, getVideosList, getVideosListPagination, getVideosListSort, killallServers, rateVideo, removeVideo, runServer, + searchVideo, searchVideoWithPagination, searchVideoWithSort, ServerInfo, setAccessTokensToServers, testImage, updateVideo, uploadVideo, + viewVideo } from '../../utils' const expect = chai.expect @@ -277,11 +276,7 @@ describe('Test a single server', function () { it('Should remove the video', async function () { await removeVideo(server.url, server.accessToken, videoId) - const files1 = await readdirPromise(join(__dirname, '..', '..', '..', '..', 'test1', 'videos')) - expect(files1).to.have.lengthOf(0) - - const files2 = await readdirPromise(join(__dirname, '..', '..', '..', '..', 'test1', 'thumbnails')) - expect(files2).to.have.lengthOf(0) + await checkVideoFilesWereRemoved(videoUUID, 1) }) it('Should not have videos', async function () { @@ -346,7 +341,7 @@ describe('Test a single server', function () { for (const video of videos) { const videoName = video.name.replace(' name', '') - const test = await testVideoImage(server.url, videoName, video.thumbnailPath) + const test = await testImage(server.url, videoName, video.thumbnailPath) expect(test).to.equal(true) } diff --git a/server/tests/api/videos/video-comments.ts b/server/tests/api/videos/video-comments.ts index 18d484ccf..0eddac35b 100644 --- a/server/tests/api/videos/video-comments.ts +++ b/server/tests/api/videos/video-comments.ts @@ -3,7 +3,7 @@ import * as chai from 'chai' import 'mocha' import { VideoComment, VideoCommentThreadTree } from '../../../../shared/models/videos/video-comment.model' -import { testVideoImage } from '../../utils' +import { testImage } from '../../utils' import { dateIsValid, flushTests, killallServers, runServer, ServerInfo, setAccessTokensToServers, updateMyAvatar, uploadVideo @@ -83,7 +83,7 @@ describe('Test video comments', function () { expect(comment.account.name).to.equal('root') expect(comment.account.host).to.equal('localhost:9001') - const test = await testVideoImage(server.url, 'avatar-resized', comment.account.avatar.path, '.png') + const test = await testImage(server.url, 'avatar-resized', comment.account.avatar.path, '.png') expect(test).to.equal(true) expect(comment.totalReplies).to.equal(0) -- cgit v1.2.3