diff options
author | Chocobozzz <me@florianbigard.com> | 2021-11-17 16:04:53 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2021-11-18 09:04:30 +0100 |
commit | b46cf4b920984492df598c1b61179acfc7f6f22e (patch) | |
tree | 21fda049c85be48ab3d37b537aafa98e94649ad7 /server/tests/api/check-params | |
parent | 3cfa817672657df18260ece5b354efa0f3b6e317 (diff) | |
download | PeerTube-b46cf4b920984492df598c1b61179acfc7f6f22e.tar.gz PeerTube-b46cf4b920984492df598c1b61179acfc7f6f22e.tar.zst PeerTube-b46cf4b920984492df598c1b61179acfc7f6f22e.zip |
Add ability to remove hls/webtorrent files
Diffstat (limited to 'server/tests/api/check-params')
-rw-r--r-- | server/tests/api/check-params/index.ts | 1 | ||||
-rw-r--r-- | server/tests/api/check-params/video-files.ts | 99 |
2 files changed, 100 insertions, 0 deletions
diff --git a/server/tests/api/check-params/index.ts b/server/tests/api/check-params/index.ts index 0882f8176..ff7dc4abb 100644 --- a/server/tests/api/check-params/index.ts +++ b/server/tests/api/check-params/index.ts | |||
@@ -28,5 +28,6 @@ import './video-imports' | |||
28 | import './video-playlists' | 28 | import './video-playlists' |
29 | import './videos' | 29 | import './videos' |
30 | import './videos-common-filters' | 30 | import './videos-common-filters' |
31 | import './video-files' | ||
31 | import './videos-history' | 32 | import './videos-history' |
32 | import './videos-overviews' | 33 | import './videos-overviews' |
diff --git a/server/tests/api/check-params/video-files.ts b/server/tests/api/check-params/video-files.ts new file mode 100644 index 000000000..48b10d2b5 --- /dev/null +++ b/server/tests/api/check-params/video-files.ts | |||
@@ -0,0 +1,99 @@ | |||
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | ||
2 | |||
3 | import 'mocha' | ||
4 | import { cleanupTests, createMultipleServers, PeerTubeServer, setAccessTokensToServers, waitJobs } from '@shared/extra-utils' | ||
5 | import { HttpStatusCode, UserRole } from '@shared/models' | ||
6 | |||
7 | describe('Test videos files', function () { | ||
8 | let servers: PeerTubeServer[] | ||
9 | let webtorrentId: string | ||
10 | let hlsId: string | ||
11 | let remoteId: string | ||
12 | let userToken: string | ||
13 | let moderatorToken: string | ||
14 | let validId1: string | ||
15 | let validId2: string | ||
16 | |||
17 | // --------------------------------------------------------------- | ||
18 | |||
19 | before(async function () { | ||
20 | this.timeout(150_000) | ||
21 | |||
22 | servers = await createMultipleServers(2) | ||
23 | await setAccessTokensToServers(servers) | ||
24 | |||
25 | userToken = await servers[0].users.generateUserAndToken('user', UserRole.USER) | ||
26 | moderatorToken = await servers[0].users.generateUserAndToken('moderator', UserRole.MODERATOR) | ||
27 | |||
28 | { | ||
29 | await servers[0].config.enableTranscoding(true, true) | ||
30 | |||
31 | { | ||
32 | const { uuid } = await servers[0].videos.quickUpload({ name: 'both 1' }) | ||
33 | validId1 = uuid | ||
34 | } | ||
35 | |||
36 | { | ||
37 | const { uuid } = await servers[0].videos.quickUpload({ name: 'both 2' }) | ||
38 | validId2 = uuid | ||
39 | } | ||
40 | } | ||
41 | |||
42 | await waitJobs(servers) | ||
43 | |||
44 | { | ||
45 | await servers[0].config.enableTranscoding(false, true) | ||
46 | const { uuid } = await servers[0].videos.quickUpload({ name: 'hls' }) | ||
47 | hlsId = uuid | ||
48 | } | ||
49 | |||
50 | await waitJobs(servers) | ||
51 | |||
52 | { | ||
53 | await servers[0].config.enableTranscoding(false, true) | ||
54 | const { uuid } = await servers[0].videos.quickUpload({ name: 'webtorrent' }) | ||
55 | webtorrentId = uuid | ||
56 | } | ||
57 | |||
58 | await waitJobs(servers) | ||
59 | }) | ||
60 | |||
61 | it('Should not delete files of a remote video', async function () { | ||
62 | await servers[0].videos.removeHLSFiles({ videoId: remoteId, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) | ||
63 | await servers[0].videos.removeWebTorrentFiles({ videoId: remoteId, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) | ||
64 | }) | ||
65 | |||
66 | it('Should not delete files by a non admin user', async function () { | ||
67 | const expectedStatus = HttpStatusCode.FORBIDDEN_403 | ||
68 | |||
69 | await servers[0].videos.removeHLSFiles({ videoId: validId1, token: userToken, expectedStatus }) | ||
70 | await servers[0].videos.removeHLSFiles({ videoId: validId1, token: moderatorToken, expectedStatus }) | ||
71 | |||
72 | await servers[0].videos.removeWebTorrentFiles({ videoId: validId1, token: userToken, expectedStatus }) | ||
73 | await servers[0].videos.removeWebTorrentFiles({ videoId: validId1, token: moderatorToken, expectedStatus }) | ||
74 | }) | ||
75 | |||
76 | it('Should not delete files if the files are not available', async function () { | ||
77 | await servers[0].videos.removeHLSFiles({ videoId: hlsId, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) | ||
78 | await servers[0].videos.removeWebTorrentFiles({ videoId: webtorrentId, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) | ||
79 | }) | ||
80 | |||
81 | it('Should not delete files if no both versions are available', async function () { | ||
82 | await servers[0].videos.removeHLSFiles({ videoId: hlsId, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) | ||
83 | await servers[0].videos.removeWebTorrentFiles({ videoId: webtorrentId, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) | ||
84 | }) | ||
85 | |||
86 | it('Should not delete files if no both versions are available', async function () { | ||
87 | await servers[0].videos.removeHLSFiles({ videoId: hlsId, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) | ||
88 | await servers[0].videos.removeWebTorrentFiles({ videoId: webtorrentId, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) | ||
89 | }) | ||
90 | |||
91 | it('Should delete files if both versions are available', async function () { | ||
92 | await servers[0].videos.removeHLSFiles({ videoId: validId1 }) | ||
93 | await servers[0].videos.removeWebTorrentFiles({ videoId: validId2 }) | ||
94 | }) | ||
95 | |||
96 | after(async function () { | ||
97 | await cleanupTests(servers) | ||
98 | }) | ||
99 | }) | ||