aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/utils
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-01-18 10:53:54 +0100
committerChocobozzz <me@florianbigard.com>2018-01-18 15:42:20 +0100
commitf05a1c30c15d2ae35c11e241ca039a72eeb7d6ad (patch)
tree6d90c0de5dd3ad506e738d447e4f396951ed5624 /server/tests/utils
parent1174a8479ab9ee47b3305d668fe757435057a298 (diff)
downloadPeerTube-f05a1c30c15d2ae35c11e241ca039a72eeb7d6ad.tar.gz
PeerTube-f05a1c30c15d2ae35c11e241ca039a72eeb7d6ad.tar.zst
PeerTube-f05a1c30c15d2ae35c11e241ca039a72eeb7d6ad.zip
Don't show videos of remote instance after unfollow
Diffstat (limited to 'server/tests/utils')
-rw-r--r--server/tests/utils/miscs/miscs.ts9
-rw-r--r--server/tests/utils/users/accounts.ts25
-rw-r--r--server/tests/utils/users/users.ts2
-rw-r--r--server/tests/utils/videos/videos.ts31
4 files changed, 57 insertions, 10 deletions
diff --git a/server/tests/utils/miscs/miscs.ts b/server/tests/utils/miscs/miscs.ts
index 2aac37791..e6666619b 100644
--- a/server/tests/utils/miscs/miscs.ts
+++ b/server/tests/utils/miscs/miscs.ts
@@ -1,3 +1,4 @@
1import { join } from 'path'
1import * as WebTorrent from 'webtorrent' 2import * as WebTorrent from 'webtorrent'
2 3
3let webtorrent = new WebTorrent() 4let webtorrent = new WebTorrent()
@@ -24,11 +25,17 @@ function webtorrentAdd (torrent: string, refreshWebTorrent = false) {
24 return new Promise<WebTorrent.Torrent>(res => webtorrent.add(torrent, res)) 25 return new Promise<WebTorrent.Torrent>(res => webtorrent.add(torrent, res))
25} 26}
26 27
28function root () {
29 // We are in server/tests/utils/miscs
30 return join(__dirname, '..', '..', '..', '..')
31}
32
27// --------------------------------------------------------------------------- 33// ---------------------------------------------------------------------------
28 34
29export { 35export {
30 dateIsValid, 36 dateIsValid,
31 wait, 37 wait,
32 webtorrentAdd, 38 webtorrentAdd,
33 immutableAssign 39 immutableAssign,
40 root
34} 41}
diff --git a/server/tests/utils/users/accounts.ts b/server/tests/utils/users/accounts.ts
index 0ec7992b3..a5c13c319 100644
--- a/server/tests/utils/users/accounts.ts
+++ b/server/tests/utils/users/accounts.ts
@@ -1,5 +1,11 @@
1/* tslint:disable:no-unused-expression */
2
1import { expect } from 'chai' 3import { expect } from 'chai'
4import { existsSync } from 'fs'
5import { join } from 'path'
2import { Account } from '../../../../shared/models/actors' 6import { Account } from '../../../../shared/models/actors'
7import { readdirPromise } from '../../../helpers/core-utils'
8import { root } from '../index'
3import { makeGetRequest } from '../requests/requests' 9import { makeGetRequest } from '../requests/requests'
4 10
5function getAccountsList (url: string, sort = '-createdAt', statusCodeExpected = 200) { 11function getAccountsList (url: string, sort = '-createdAt', statusCodeExpected = 200) {
@@ -32,10 +38,27 @@ async function expectAccountFollows (url: string, nameWithDomain: string, follow
32 expect(account.followingCount).to.equal(followingCount, message) 38 expect(account.followingCount).to.equal(followingCount, message)
33} 39}
34 40
41async function checkActorFilesWereRemoved (actorUUID: string, serverNumber: number) {
42 const testDirectory = 'test' + serverNumber
43
44 for (const directory of [ 'avatars' ]) {
45 const directoryPath = join(root(), testDirectory, directory)
46
47 const directoryExists = existsSync(directoryPath)
48 expect(directoryExists).to.be.true
49
50 const files = await readdirPromise(directoryPath)
51 for (const file of files) {
52 expect(file).to.not.contain(actorUUID)
53 }
54 }
55}
56
35// --------------------------------------------------------------------------- 57// ---------------------------------------------------------------------------
36 58
37export { 59export {
38 getAccount, 60 getAccount,
39 expectAccountFollows, 61 expectAccountFollows,
40 getAccountsList 62 getAccountsList,
63 checkActorFilesWereRemoved
41} 64}
diff --git a/server/tests/utils/users/users.ts b/server/tests/utils/users/users.ts
index 12945a805..25351e2c7 100644
--- a/server/tests/utils/users/users.ts
+++ b/server/tests/utils/users/users.ts
@@ -11,7 +11,7 @@ function createUser (
11 password: string, 11 password: string,
12 videoQuota = 1000000, 12 videoQuota = 1000000,
13 role: UserRole = UserRole.USER, 13 role: UserRole = UserRole.USER,
14 specialStatus = 204 14 specialStatus = 200
15) { 15) {
16 const path = '/api/v1/users' 16 const path = '/api/v1/users'
17 const body = { 17 const body = {
diff --git a/server/tests/utils/videos/videos.ts b/server/tests/utils/videos/videos.ts
index 095d4e29d..270a6042b 100644
--- a/server/tests/utils/videos/videos.ts
+++ b/server/tests/utils/videos/videos.ts
@@ -1,13 +1,13 @@
1/* tslint:disable:no-unused-expression */ 1/* tslint:disable:no-unused-expression */
2 2
3import { expect } from 'chai' 3import { expect } from 'chai'
4import { readFile } from 'fs' 4import { existsSync, readFile } from 'fs'
5import * as parseTorrent from 'parse-torrent' 5import * as parseTorrent from 'parse-torrent'
6import { extname, isAbsolute, join } from 'path' 6import { extname, isAbsolute, join } from 'path'
7import * as request from 'supertest' 7import * as request from 'supertest'
8import { getMyUserInformation, makeGetRequest, ServerInfo } from '../' 8import { getMyUserInformation, makeGetRequest, root, ServerInfo } from '../'
9import { VideoPrivacy } from '../../../../shared/models/videos' 9import { VideoPrivacy } from '../../../../shared/models/videos'
10import { readFileBufferPromise } from '../../../helpers/core-utils' 10import { readdirPromise, readFileBufferPromise } from '../../../helpers/core-utils'
11import { VIDEO_CATEGORIES, VIDEO_LANGUAGES, VIDEO_LICENCES, VIDEO_PRIVACIES } from '../../../initializers' 11import { VIDEO_CATEGORIES, VIDEO_LANGUAGES, VIDEO_LICENCES, VIDEO_PRIVACIES } from '../../../initializers'
12import { dateIsValid, webtorrentAdd } from '../index' 12import { dateIsValid, webtorrentAdd } from '../index'
13 13
@@ -203,7 +203,23 @@ function searchVideoWithSort (url: string, search: string, sort: string) {
203 .expect('Content-Type', /json/) 203 .expect('Content-Type', /json/)
204} 204}
205 205
206async function testVideoImage (url: string, imageName: string, imagePath: string, extension = '.jpg') { 206async function checkVideoFilesWereRemoved (videoUUID: string, serverNumber: number) {
207 const testDirectory = 'test' + serverNumber
208
209 for (const directory of [ 'videos', 'thumbnails', 'torrents', 'previews' ]) {
210 const directoryPath = join(root(), testDirectory, directory)
211
212 const directoryExists = existsSync(directoryPath)
213 expect(directoryExists).to.be.true
214
215 const files = await readdirPromise(directoryPath)
216 for (const file of files) {
217 expect(file).to.not.contain(videoUUID)
218 }
219 }
220}
221
222async function testImage (url: string, imageName: string, imagePath: string, extension = '.jpg') {
207 // Don't test images if the node env is not set 223 // Don't test images if the node env is not set
208 // Because we need a special ffmpeg version for this test 224 // Because we need a special ffmpeg version for this test
209 if (process.env['NODE_TEST_IMAGE']) { 225 if (process.env['NODE_TEST_IMAGE']) {
@@ -409,7 +425,7 @@ async function completeVideoCheck (
409 const maxSize = attributeFile.size + ((10 * attributeFile.size) / 100) 425 const maxSize = attributeFile.size + ((10 * attributeFile.size) / 100)
410 expect(file.size).to.be.above(minSize).and.below(maxSize) 426 expect(file.size).to.be.above(minSize).and.below(maxSize)
411 427
412 const test = await testVideoImage(url, attributes.fixture, videoDetails.thumbnailPath) 428 const test = await testImage(url, attributes.fixture, videoDetails.thumbnailPath)
413 expect(test).to.equal(true) 429 expect(test).to.equal(true)
414 430
415 const torrent = await webtorrentAdd(magnetUri, true) 431 const torrent = await webtorrentAdd(magnetUri, true)
@@ -437,11 +453,12 @@ export {
437 searchVideo, 453 searchVideo,
438 searchVideoWithPagination, 454 searchVideoWithPagination,
439 searchVideoWithSort, 455 searchVideoWithSort,
440 testVideoImage, 456 testImage,
441 uploadVideo, 457 uploadVideo,
442 updateVideo, 458 updateVideo,
443 rateVideo, 459 rateVideo,
444 viewVideo, 460 viewVideo,
445 parseTorrentVideo, 461 parseTorrentVideo,
446 completeVideoCheck 462 completeVideoCheck,
463 checkVideoFilesWereRemoved
447} 464}