]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/videos/video-files.ts
Add ability to delete a specific video file
[github/Chocobozzz/PeerTube.git] / server / tests / api / videos / video-files.ts
CommitLineData
b46cf4b9
C
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3import 'mocha'
4import { expect } from 'chai'
1bb4c9ab 5import { HttpStatusCode } from '@shared/models'
c55e3d72
C
6import {
7 cleanupTests,
8 createMultipleServers,
9 doubleFollow,
1bb4c9ab 10 makeRawRequest,
c55e3d72
C
11 PeerTubeServer,
12 setAccessTokensToServers,
13 waitJobs
14} from '@shared/server-commands'
b46cf4b9
C
15
16describe('Test videos files', function () {
17 let servers: PeerTubeServer[]
b46cf4b9
C
18
19 // ---------------------------------------------------------------
20
21 before(async function () {
22 this.timeout(150_000)
23
24 servers = await createMultipleServers(2)
25 await setAccessTokensToServers(servers)
26
27 await doubleFollow(servers[0], servers[1])
28
29 await servers[0].config.enableTranscoding(true, true)
1bb4c9ab 30 })
b46cf4b9 31
1bb4c9ab
C
32 describe('When deleting all files', function () {
33 let validId1: string
34 let validId2: string
b46cf4b9 35
1bb4c9ab
C
36 before(async function () {
37 {
38 const { uuid } = await servers[0].videos.quickUpload({ name: 'video 1' })
39 validId1 = uuid
40 }
b46cf4b9 41
1bb4c9ab
C
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 })
b46cf4b9 64
1bb4c9ab
C
65 it('Should delete HLS files', async function () {
66 this.timeout(30_000)
b46cf4b9 67
1bb4c9ab 68 await servers[0].videos.removeHLSPlaylist({ videoId: validId2 })
b46cf4b9 69
1bb4c9ab 70 await waitJobs(servers)
b46cf4b9 71
1bb4c9ab
C
72 for (const server of servers) {
73 const video = await server.videos.get({ id: validId2 })
b46cf4b9 74
1bb4c9ab
C
75 expect(video.files).to.have.length.above(0)
76 expect(video.streamingPlaylists).to.have.lengthOf(0)
77 }
78 })
b46cf4b9
C
79 })
80
1bb4c9ab
C
81 describe('When deleting a specific file', function () {
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 })
b46cf4b9 166
1bb4c9ab
C
167 expect(video.streamingPlaylists).to.have.lengthOf(0)
168 }
169 })
b46cf4b9 170
1bb4c9ab
C
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 })
b46cf4b9 174
1bb4c9ab
C
175 for (let i = 0; i < 4; i++) {
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 }
b46cf4b9 179
1bb4c9ab
C
180 const expectedStatus = HttpStatusCode.BAD_REQUEST_400
181 await servers[0].videos.removeWebTorrentFile({ videoId: webtorrentOnly.id, fileId: webtorrentOnly.files[4].id, expectedStatus })
182 await servers[0].videos.removeHLSFile({ videoId: hlsOnly.id, fileId: hlsOnly.streamingPlaylists[0].files[4].id, expectedStatus })
183 })
b46cf4b9
C
184 })
185
186 after(async function () {
187 await cleanupTests(servers)
188 })
189})