diff options
author | Chocobozzz <me@florianbigard.com> | 2022-07-29 14:50:41 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2022-08-01 14:55:10 +0200 |
commit | 1bb4c9ab2e8b3b3022351b33a82a5e527fa5d4d7 (patch) | |
tree | a6554ee0a3ccc2ae402665b2ecf57bb38fd0ed72 /server/tests/api/videos | |
parent | 12d84abeca4917d2f1e3f308010bfcd56d37cb7c (diff) | |
download | PeerTube-1bb4c9ab2e8b3b3022351b33a82a5e527fa5d4d7.tar.gz PeerTube-1bb4c9ab2e8b3b3022351b33a82a5e527fa5d4d7.tar.zst PeerTube-1bb4c9ab2e8b3b3022351b33a82a5e527fa5d4d7.zip |
Add ability to delete a specific video file
Diffstat (limited to 'server/tests/api/videos')
-rw-r--r-- | server/tests/api/videos/video-files.ts | 172 |
1 files changed, 142 insertions, 30 deletions
diff --git a/server/tests/api/videos/video-files.ts b/server/tests/api/videos/video-files.ts index b0ef4a2e9..313f020e9 100644 --- a/server/tests/api/videos/video-files.ts +++ b/server/tests/api/videos/video-files.ts | |||
@@ -2,10 +2,12 @@ | |||
2 | 2 | ||
3 | import 'mocha' | 3 | import 'mocha' |
4 | import { expect } from 'chai' | 4 | import { expect } from 'chai' |
5 | import { HttpStatusCode } from '@shared/models' | ||
5 | import { | 6 | import { |
6 | cleanupTests, | 7 | cleanupTests, |
7 | createMultipleServers, | 8 | createMultipleServers, |
8 | doubleFollow, | 9 | doubleFollow, |
10 | makeRawRequest, | ||
9 | PeerTubeServer, | 11 | PeerTubeServer, |
10 | setAccessTokensToServers, | 12 | setAccessTokensToServers, |
11 | waitJobs | 13 | waitJobs |
@@ -13,8 +15,6 @@ import { | |||
13 | 15 | ||
14 | describe('Test videos files', function () { | 16 | describe('Test videos files', function () { |
15 | let servers: PeerTubeServer[] | 17 | let servers: PeerTubeServer[] |
16 | let validId1: string | ||
17 | let validId2: string | ||
18 | 18 | ||
19 | // --------------------------------------------------------------- | 19 | // --------------------------------------------------------------- |
20 | 20 | ||
@@ -27,48 +27,160 @@ describe('Test videos files', function () { | |||
27 | await doubleFollow(servers[0], servers[1]) | 27 | await doubleFollow(servers[0], servers[1]) |
28 | 28 | ||
29 | await servers[0].config.enableTranscoding(true, true) | 29 | await servers[0].config.enableTranscoding(true, true) |
30 | }) | ||
30 | 31 | ||
31 | { | 32 | describe('When deleting all files', function () { |
32 | const { uuid } = await servers[0].videos.quickUpload({ name: 'video 1' }) | 33 | let validId1: string |
33 | validId1 = uuid | 34 | let validId2: string |
34 | } | ||
35 | 35 | ||
36 | { | 36 | before(async function () { |
37 | const { uuid } = await servers[0].videos.quickUpload({ name: 'video 2' }) | 37 | { |
38 | validId2 = uuid | 38 | const { uuid } = await servers[0].videos.quickUpload({ name: 'video 1' }) |
39 | } | 39 | validId1 = uuid |
40 | } | ||
40 | 41 | ||
41 | await waitJobs(servers) | 42 | { |
42 | }) | 43 | const { uuid } = await servers[0].videos.quickUpload({ name: 'video 2' }) |
44 | validId2 = uuid | ||
45 | } | ||
46 | |||
47 | await waitJobs(servers) | ||
48 | }) | ||
49 | |||
50 | it('Should delete webtorrent files', async function () { | ||
51 | this.timeout(30_000) | ||
52 | |||
53 | await servers[0].videos.removeAllWebTorrentFiles({ videoId: validId1 }) | ||
54 | |||
55 | await waitJobs(servers) | ||
56 | |||
57 | for (const server of servers) { | ||
58 | const video = await server.videos.get({ id: validId1 }) | ||
59 | |||
60 | expect(video.files).to.have.lengthOf(0) | ||
61 | expect(video.streamingPlaylists).to.have.lengthOf(1) | ||
62 | } | ||
63 | }) | ||
43 | 64 | ||
44 | it('Should delete webtorrent files', async function () { | 65 | it('Should delete HLS files', async function () { |
45 | this.timeout(30_000) | 66 | this.timeout(30_000) |
46 | 67 | ||
47 | await servers[0].videos.removeWebTorrentFiles({ videoId: validId1 }) | 68 | await servers[0].videos.removeHLSPlaylist({ videoId: validId2 }) |
48 | 69 | ||
49 | await waitJobs(servers) | 70 | await waitJobs(servers) |
50 | 71 | ||
51 | for (const server of servers) { | 72 | for (const server of servers) { |
52 | const video = await server.videos.get({ id: validId1 }) | 73 | const video = await server.videos.get({ id: validId2 }) |
53 | 74 | ||
54 | expect(video.files).to.have.lengthOf(0) | 75 | expect(video.files).to.have.length.above(0) |
55 | expect(video.streamingPlaylists).to.have.lengthOf(1) | 76 | expect(video.streamingPlaylists).to.have.lengthOf(0) |
56 | } | 77 | } |
78 | }) | ||
57 | }) | 79 | }) |
58 | 80 | ||
59 | it('Should delete HLS files', async function () { | 81 | describe('When deleting a specific file', function () { |
60 | this.timeout(30_000) | 82 | let webtorrentId: string |
83 | let hlsId: string | ||
84 | |||
85 | before(async function () { | ||
86 | { | ||
87 | const { uuid } = await servers[0].videos.quickUpload({ name: 'webtorrent' }) | ||
88 | webtorrentId = uuid | ||
89 | } | ||
90 | |||
91 | { | ||
92 | const { uuid } = await servers[0].videos.quickUpload({ name: 'hls' }) | ||
93 | hlsId = uuid | ||
94 | } | ||
95 | |||
96 | await waitJobs(servers) | ||
97 | }) | ||
98 | |||
99 | it('Shoulde delete a webtorrent file', async function () { | ||
100 | const video = await servers[0].videos.get({ id: webtorrentId }) | ||
101 | const files = video.files | ||
102 | |||
103 | await servers[0].videos.removeWebTorrentFile({ videoId: webtorrentId, fileId: files[0].id }) | ||
104 | |||
105 | await waitJobs(servers) | ||
106 | |||
107 | for (const server of servers) { | ||
108 | const video = await server.videos.get({ id: webtorrentId }) | ||
109 | |||
110 | expect(video.files).to.have.lengthOf(files.length - 1) | ||
111 | expect(video.files.find(f => f.id === files[0].id)).to.not.exist | ||
112 | } | ||
113 | }) | ||
114 | |||
115 | it('Should delete all webtorrent files', async function () { | ||
116 | const video = await servers[0].videos.get({ id: webtorrentId }) | ||
117 | const files = video.files | ||
118 | |||
119 | for (const file of files) { | ||
120 | await servers[0].videos.removeWebTorrentFile({ videoId: webtorrentId, fileId: file.id }) | ||
121 | } | ||
122 | |||
123 | await waitJobs(servers) | ||
124 | |||
125 | for (const server of servers) { | ||
126 | const video = await server.videos.get({ id: webtorrentId }) | ||
127 | |||
128 | expect(video.files).to.have.lengthOf(0) | ||
129 | } | ||
130 | }) | ||
131 | |||
132 | it('Should delete a hls file', async function () { | ||
133 | const video = await servers[0].videos.get({ id: hlsId }) | ||
134 | const files = video.streamingPlaylists[0].files | ||
135 | const toDelete = files[0] | ||
136 | |||
137 | await servers[0].videos.removeHLSFile({ videoId: hlsId, fileId: toDelete.id }) | ||
138 | |||
139 | await waitJobs(servers) | ||
140 | |||
141 | for (const server of servers) { | ||
142 | const video = await server.videos.get({ id: hlsId }) | ||
143 | |||
144 | expect(video.streamingPlaylists[0].files).to.have.lengthOf(files.length - 1) | ||
145 | expect(video.streamingPlaylists[0].files.find(f => f.id === toDelete.id)).to.not.exist | ||
146 | |||
147 | const { text } = await makeRawRequest(video.streamingPlaylists[0].playlistUrl) | ||
148 | |||
149 | expect(text.includes(`-${toDelete.resolution.id}.m3u8`)).to.be.false | ||
150 | expect(text.includes(`-${video.streamingPlaylists[0].files[0].resolution.id}.m3u8`)).to.be.true | ||
151 | } | ||
152 | }) | ||
153 | |||
154 | it('Should delete all hls files', async function () { | ||
155 | const video = await servers[0].videos.get({ id: hlsId }) | ||
156 | const files = video.streamingPlaylists[0].files | ||
157 | |||
158 | for (const file of files) { | ||
159 | await servers[0].videos.removeHLSFile({ videoId: hlsId, fileId: file.id }) | ||
160 | } | ||
161 | |||
162 | await waitJobs(servers) | ||
163 | |||
164 | for (const server of servers) { | ||
165 | const video = await server.videos.get({ id: hlsId }) | ||
61 | 166 | ||
62 | await servers[0].videos.removeHLSFiles({ videoId: validId2 }) | 167 | expect(video.streamingPlaylists).to.have.lengthOf(0) |
168 | } | ||
169 | }) | ||
63 | 170 | ||
64 | await waitJobs(servers) | 171 | it('Should not delete last file of a video', async function () { |
172 | const webtorrentOnly = await servers[0].videos.get({ id: hlsId }) | ||
173 | const hlsOnly = await servers[0].videos.get({ id: webtorrentId }) | ||
65 | 174 | ||
66 | for (const server of servers) { | 175 | for (let i = 0; i < 4; i++) { |
67 | const video = await server.videos.get({ id: validId2 }) | 176 | await servers[0].videos.removeWebTorrentFile({ videoId: webtorrentOnly.id, fileId: webtorrentOnly.files[i].id }) |
177 | await servers[0].videos.removeHLSFile({ videoId: hlsOnly.id, fileId: hlsOnly.streamingPlaylists[0].files[i].id }) | ||
178 | } | ||
68 | 179 | ||
69 | expect(video.files).to.have.length.above(0) | 180 | const expectedStatus = HttpStatusCode.BAD_REQUEST_400 |
70 | expect(video.streamingPlaylists).to.have.lengthOf(0) | 181 | await servers[0].videos.removeWebTorrentFile({ videoId: webtorrentOnly.id, fileId: webtorrentOnly.files[4].id, expectedStatus }) |
71 | } | 182 | await servers[0].videos.removeHLSFile({ videoId: hlsOnly.id, fileId: hlsOnly.streamingPlaylists[0].files[4].id, expectedStatus }) |
183 | }) | ||
72 | }) | 184 | }) |
73 | 185 | ||
74 | after(async function () { | 186 | after(async function () { |