diff options
Diffstat (limited to 'server/tests/utils')
-rw-r--r-- | server/tests/utils/miscs/miscs.ts | 9 | ||||
-rw-r--r-- | server/tests/utils/users/accounts.ts | 25 | ||||
-rw-r--r-- | server/tests/utils/users/users.ts | 2 | ||||
-rw-r--r-- | server/tests/utils/videos/videos.ts | 31 |
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 @@ | |||
1 | import { join } from 'path' | ||
1 | import * as WebTorrent from 'webtorrent' | 2 | import * as WebTorrent from 'webtorrent' |
2 | 3 | ||
3 | let webtorrent = new WebTorrent() | 4 | let 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 | ||
28 | function root () { | ||
29 | // We are in server/tests/utils/miscs | ||
30 | return join(__dirname, '..', '..', '..', '..') | ||
31 | } | ||
32 | |||
27 | // --------------------------------------------------------------------------- | 33 | // --------------------------------------------------------------------------- |
28 | 34 | ||
29 | export { | 35 | export { |
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 | |||
1 | import { expect } from 'chai' | 3 | import { expect } from 'chai' |
4 | import { existsSync } from 'fs' | ||
5 | import { join } from 'path' | ||
2 | import { Account } from '../../../../shared/models/actors' | 6 | import { Account } from '../../../../shared/models/actors' |
7 | import { readdirPromise } from '../../../helpers/core-utils' | ||
8 | import { root } from '../index' | ||
3 | import { makeGetRequest } from '../requests/requests' | 9 | import { makeGetRequest } from '../requests/requests' |
4 | 10 | ||
5 | function getAccountsList (url: string, sort = '-createdAt', statusCodeExpected = 200) { | 11 | function 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 | ||
41 | async 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 | ||
37 | export { | 59 | export { |
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 | ||
3 | import { expect } from 'chai' | 3 | import { expect } from 'chai' |
4 | import { readFile } from 'fs' | 4 | import { existsSync, readFile } from 'fs' |
5 | import * as parseTorrent from 'parse-torrent' | 5 | import * as parseTorrent from 'parse-torrent' |
6 | import { extname, isAbsolute, join } from 'path' | 6 | import { extname, isAbsolute, join } from 'path' |
7 | import * as request from 'supertest' | 7 | import * as request from 'supertest' |
8 | import { getMyUserInformation, makeGetRequest, ServerInfo } from '../' | 8 | import { getMyUserInformation, makeGetRequest, root, ServerInfo } from '../' |
9 | import { VideoPrivacy } from '../../../../shared/models/videos' | 9 | import { VideoPrivacy } from '../../../../shared/models/videos' |
10 | import { readFileBufferPromise } from '../../../helpers/core-utils' | 10 | import { readdirPromise, readFileBufferPromise } from '../../../helpers/core-utils' |
11 | import { VIDEO_CATEGORIES, VIDEO_LANGUAGES, VIDEO_LICENCES, VIDEO_PRIVACIES } from '../../../initializers' | 11 | import { VIDEO_CATEGORIES, VIDEO_LANGUAGES, VIDEO_LICENCES, VIDEO_PRIVACIES } from '../../../initializers' |
12 | import { dateIsValid, webtorrentAdd } from '../index' | 12 | import { 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 | ||
206 | async function testVideoImage (url: string, imageName: string, imagePath: string, extension = '.jpg') { | 206 | async 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 | |||
222 | async 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 | } |