]>
Commit | Line | Data |
---|---|---|
b46cf4b9 C |
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
2 | ||
b46cf4b9 | 3 | import { expect } from 'chai' |
1bb4c9ab | 4 | import { HttpStatusCode } from '@shared/models' |
c55e3d72 C |
5 | import { |
6 | cleanupTests, | |
7 | createMultipleServers, | |
8 | doubleFollow, | |
1bb4c9ab | 9 | makeRawRequest, |
c55e3d72 C |
10 | PeerTubeServer, |
11 | setAccessTokensToServers, | |
12 | waitJobs | |
13 | } from '@shared/server-commands' | |
b46cf4b9 C |
14 | |
15 | describe('Test videos files', function () { | |
16 | let servers: PeerTubeServer[] | |
b46cf4b9 C |
17 | |
18 | // --------------------------------------------------------------- | |
19 | ||
20 | before(async function () { | |
21 | this.timeout(150_000) | |
22 | ||
23 | servers = await createMultipleServers(2) | |
24 | await setAccessTokensToServers(servers) | |
25 | ||
26 | await doubleFollow(servers[0], servers[1]) | |
27 | ||
28 | await servers[0].config.enableTranscoding(true, true) | |
1bb4c9ab | 29 | }) |
b46cf4b9 | 30 | |
1bb4c9ab C |
31 | describe('When deleting all files', function () { |
32 | let validId1: string | |
33 | let validId2: string | |
b46cf4b9 | 34 | |
1bb4c9ab | 35 | before(async function () { |
36305301 | 36 | this.timeout(360_000) |
ec240986 | 37 | |
1bb4c9ab C |
38 | { |
39 | const { uuid } = await servers[0].videos.quickUpload({ name: 'video 1' }) | |
40 | validId1 = uuid | |
41 | } | |
b46cf4b9 | 42 | |
1bb4c9ab C |
43 | { |
44 | const { uuid } = await servers[0].videos.quickUpload({ name: 'video 2' }) | |
45 | validId2 = uuid | |
46 | } | |
47 | ||
48 | await waitJobs(servers) | |
49 | }) | |
50 | ||
51 | it('Should delete webtorrent files', async function () { | |
52 | this.timeout(30_000) | |
53 | ||
54 | await servers[0].videos.removeAllWebTorrentFiles({ videoId: validId1 }) | |
55 | ||
56 | await waitJobs(servers) | |
57 | ||
58 | for (const server of servers) { | |
59 | const video = await server.videos.get({ id: validId1 }) | |
60 | ||
61 | expect(video.files).to.have.lengthOf(0) | |
62 | expect(video.streamingPlaylists).to.have.lengthOf(1) | |
63 | } | |
64 | }) | |
b46cf4b9 | 65 | |
1bb4c9ab C |
66 | it('Should delete HLS files', async function () { |
67 | this.timeout(30_000) | |
b46cf4b9 | 68 | |
1bb4c9ab | 69 | await servers[0].videos.removeHLSPlaylist({ videoId: validId2 }) |
b46cf4b9 | 70 | |
1bb4c9ab | 71 | await waitJobs(servers) |
b46cf4b9 | 72 | |
1bb4c9ab C |
73 | for (const server of servers) { |
74 | const video = await server.videos.get({ id: validId2 }) | |
b46cf4b9 | 75 | |
1bb4c9ab C |
76 | expect(video.files).to.have.length.above(0) |
77 | expect(video.streamingPlaylists).to.have.lengthOf(0) | |
78 | } | |
79 | }) | |
b46cf4b9 C |
80 | }) |
81 | ||
1bb4c9ab C |
82 | describe('When deleting a specific file', function () { |
83 | let webtorrentId: string | |
84 | let hlsId: string | |
85 | ||
86 | before(async function () { | |
ec240986 C |
87 | this.timeout(120_000) |
88 | ||
1bb4c9ab C |
89 | { |
90 | const { uuid } = await servers[0].videos.quickUpload({ name: 'webtorrent' }) | |
91 | webtorrentId = uuid | |
92 | } | |
93 | ||
94 | { | |
95 | const { uuid } = await servers[0].videos.quickUpload({ name: 'hls' }) | |
96 | hlsId = uuid | |
97 | } | |
98 | ||
99 | await waitJobs(servers) | |
100 | }) | |
101 | ||
102 | it('Shoulde delete a webtorrent file', async function () { | |
ec240986 C |
103 | this.timeout(30_000) |
104 | ||
1bb4c9ab C |
105 | const video = await servers[0].videos.get({ id: webtorrentId }) |
106 | const files = video.files | |
107 | ||
108 | await servers[0].videos.removeWebTorrentFile({ videoId: webtorrentId, fileId: files[0].id }) | |
109 | ||
110 | await waitJobs(servers) | |
111 | ||
112 | for (const server of servers) { | |
113 | const video = await server.videos.get({ id: webtorrentId }) | |
114 | ||
115 | expect(video.files).to.have.lengthOf(files.length - 1) | |
116 | expect(video.files.find(f => f.id === files[0].id)).to.not.exist | |
117 | } | |
118 | }) | |
119 | ||
120 | it('Should delete all webtorrent files', async function () { | |
ec240986 C |
121 | this.timeout(30_000) |
122 | ||
1bb4c9ab C |
123 | const video = await servers[0].videos.get({ id: webtorrentId }) |
124 | const files = video.files | |
125 | ||
126 | for (const file of files) { | |
127 | await servers[0].videos.removeWebTorrentFile({ videoId: webtorrentId, fileId: file.id }) | |
128 | } | |
129 | ||
130 | await waitJobs(servers) | |
131 | ||
132 | for (const server of servers) { | |
133 | const video = await server.videos.get({ id: webtorrentId }) | |
134 | ||
135 | expect(video.files).to.have.lengthOf(0) | |
136 | } | |
137 | }) | |
138 | ||
139 | it('Should delete a hls file', async function () { | |
ec240986 C |
140 | this.timeout(30_000) |
141 | ||
1bb4c9ab C |
142 | const video = await servers[0].videos.get({ id: hlsId }) |
143 | const files = video.streamingPlaylists[0].files | |
144 | const toDelete = files[0] | |
145 | ||
146 | await servers[0].videos.removeHLSFile({ videoId: hlsId, fileId: toDelete.id }) | |
147 | ||
148 | await waitJobs(servers) | |
149 | ||
150 | for (const server of servers) { | |
151 | const video = await server.videos.get({ id: hlsId }) | |
152 | ||
153 | expect(video.streamingPlaylists[0].files).to.have.lengthOf(files.length - 1) | |
154 | expect(video.streamingPlaylists[0].files.find(f => f.id === toDelete.id)).to.not.exist | |
155 | ||
3545e72c | 156 | const { text } = await makeRawRequest({ url: video.streamingPlaylists[0].playlistUrl, expectedStatus: HttpStatusCode.OK_200 }) |
1bb4c9ab C |
157 | |
158 | expect(text.includes(`-${toDelete.resolution.id}.m3u8`)).to.be.false | |
159 | expect(text.includes(`-${video.streamingPlaylists[0].files[0].resolution.id}.m3u8`)).to.be.true | |
160 | } | |
161 | }) | |
162 | ||
163 | it('Should delete all hls files', async function () { | |
ec240986 C |
164 | this.timeout(30_000) |
165 | ||
1bb4c9ab C |
166 | const video = await servers[0].videos.get({ id: hlsId }) |
167 | const files = video.streamingPlaylists[0].files | |
168 | ||
169 | for (const file of files) { | |
170 | await servers[0].videos.removeHLSFile({ videoId: hlsId, fileId: file.id }) | |
171 | } | |
172 | ||
173 | await waitJobs(servers) | |
174 | ||
175 | for (const server of servers) { | |
176 | const video = await server.videos.get({ id: hlsId }) | |
b46cf4b9 | 177 | |
1bb4c9ab C |
178 | expect(video.streamingPlaylists).to.have.lengthOf(0) |
179 | } | |
180 | }) | |
b46cf4b9 | 181 | |
1bb4c9ab | 182 | it('Should not delete last file of a video', async function () { |
ec240986 C |
183 | this.timeout(60_000) |
184 | ||
1bb4c9ab C |
185 | const webtorrentOnly = await servers[0].videos.get({ id: hlsId }) |
186 | const hlsOnly = await servers[0].videos.get({ id: webtorrentId }) | |
b46cf4b9 | 187 | |
1bb4c9ab C |
188 | for (let i = 0; i < 4; i++) { |
189 | await servers[0].videos.removeWebTorrentFile({ videoId: webtorrentOnly.id, fileId: webtorrentOnly.files[i].id }) | |
190 | await servers[0].videos.removeHLSFile({ videoId: hlsOnly.id, fileId: hlsOnly.streamingPlaylists[0].files[i].id }) | |
191 | } | |
b46cf4b9 | 192 | |
1bb4c9ab C |
193 | const expectedStatus = HttpStatusCode.BAD_REQUEST_400 |
194 | await servers[0].videos.removeWebTorrentFile({ videoId: webtorrentOnly.id, fileId: webtorrentOnly.files[4].id, expectedStatus }) | |
195 | await servers[0].videos.removeHLSFile({ videoId: hlsOnly.id, fileId: hlsOnly.streamingPlaylists[0].files[4].id, expectedStatus }) | |
196 | }) | |
b46cf4b9 C |
197 | }) |
198 | ||
199 | after(async function () { | |
200 | await cleanupTests(servers) | |
201 | }) | |
202 | }) |