aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests')
-rw-r--r--server/tests/api/check-params/video-files.ts80
-rw-r--r--server/tests/api/transcoding/create-transcoding.ts4
-rw-r--r--server/tests/api/videos/video-files.ts172
3 files changed, 204 insertions, 52 deletions
diff --git a/server/tests/api/check-params/video-files.ts b/server/tests/api/check-params/video-files.ts
index 8c0795092..c698bea82 100644
--- a/server/tests/api/check-params/video-files.ts
+++ b/server/tests/api/check-params/video-files.ts
@@ -24,6 +24,12 @@ describe('Test videos files', function () {
24 let validId1: string 24 let validId1: string
25 let validId2: string 25 let validId2: string
26 26
27 let hlsFileId: number
28 let webtorrentFileId: number
29
30 let remoteHLSFileId: number
31 let remoteWebtorrentFileId: number
32
27 // --------------------------------------------------------------- 33 // ---------------------------------------------------------------
28 34
29 before(async function () { 35 before(async function () {
@@ -39,7 +45,12 @@ describe('Test videos files', function () {
39 45
40 { 46 {
41 const { uuid } = await servers[1].videos.quickUpload({ name: 'remote video' }) 47 const { uuid } = await servers[1].videos.quickUpload({ name: 'remote video' })
42 remoteId = uuid 48 await waitJobs(servers)
49
50 const video = await servers[1].videos.get({ id: uuid })
51 remoteId = video.uuid
52 remoteHLSFileId = video.streamingPlaylists[0].files[0].id
53 remoteWebtorrentFileId = video.files[0].id
43 } 54 }
44 55
45 { 56 {
@@ -47,7 +58,12 @@ describe('Test videos files', function () {
47 58
48 { 59 {
49 const { uuid } = await servers[0].videos.quickUpload({ name: 'both 1' }) 60 const { uuid } = await servers[0].videos.quickUpload({ name: 'both 1' })
50 validId1 = uuid 61 await waitJobs(servers)
62
63 const video = await servers[0].videos.get({ id: uuid })
64 validId1 = video.uuid
65 hlsFileId = video.streamingPlaylists[0].files[0].id
66 webtorrentFileId = video.files[0].id
51 } 67 }
52 68
53 { 69 {
@@ -76,43 +92,67 @@ describe('Test videos files', function () {
76 }) 92 })
77 93
78 it('Should not delete files of a unknown video', async function () { 94 it('Should not delete files of a unknown video', async function () {
79 await servers[0].videos.removeHLSFiles({ videoId: 404, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) 95 const expectedStatus = HttpStatusCode.NOT_FOUND_404
80 await servers[0].videos.removeWebTorrentFiles({ videoId: 404, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) 96
97 await servers[0].videos.removeHLSPlaylist({ videoId: 404, expectedStatus })
98 await servers[0].videos.removeAllWebTorrentFiles({ videoId: 404, expectedStatus })
99
100 await servers[0].videos.removeHLSFile({ videoId: 404, fileId: hlsFileId, expectedStatus })
101 await servers[0].videos.removeWebTorrentFile({ videoId: 404, fileId: webtorrentFileId, expectedStatus })
102 })
103
104 it('Should not delete unknown files', async function () {
105 const expectedStatus = HttpStatusCode.NOT_FOUND_404
106
107 await servers[0].videos.removeHLSFile({ videoId: validId1, fileId: webtorrentFileId, expectedStatus })
108 await servers[0].videos.removeWebTorrentFile({ videoId: validId1, fileId: hlsFileId, expectedStatus })
81 }) 109 })
82 110
83 it('Should not delete files of a remote video', async function () { 111 it('Should not delete files of a remote video', async function () {
84 await servers[0].videos.removeHLSFiles({ videoId: remoteId, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) 112 const expectedStatus = HttpStatusCode.BAD_REQUEST_400
85 await servers[0].videos.removeWebTorrentFiles({ videoId: remoteId, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) 113
114 await servers[0].videos.removeHLSPlaylist({ videoId: remoteId, expectedStatus })
115 await servers[0].videos.removeAllWebTorrentFiles({ videoId: remoteId, expectedStatus })
116
117 await servers[0].videos.removeHLSFile({ videoId: remoteId, fileId: remoteHLSFileId, expectedStatus })
118 await servers[0].videos.removeWebTorrentFile({ videoId: remoteId, fileId: remoteWebtorrentFileId, expectedStatus })
86 }) 119 })
87 120
88 it('Should not delete files by a non admin user', async function () { 121 it('Should not delete files by a non admin user', async function () {
89 const expectedStatus = HttpStatusCode.FORBIDDEN_403 122 const expectedStatus = HttpStatusCode.FORBIDDEN_403
90 123
91 await servers[0].videos.removeHLSFiles({ videoId: validId1, token: userToken, expectedStatus }) 124 await servers[0].videos.removeHLSPlaylist({ videoId: validId1, token: userToken, expectedStatus })
92 await servers[0].videos.removeHLSFiles({ videoId: validId1, token: moderatorToken, expectedStatus }) 125 await servers[0].videos.removeHLSPlaylist({ videoId: validId1, token: moderatorToken, expectedStatus })
126
127 await servers[0].videos.removeAllWebTorrentFiles({ videoId: validId1, token: userToken, expectedStatus })
128 await servers[0].videos.removeAllWebTorrentFiles({ videoId: validId1, token: moderatorToken, expectedStatus })
93 129
94 await servers[0].videos.removeWebTorrentFiles({ videoId: validId1, token: userToken, expectedStatus }) 130 await servers[0].videos.removeHLSFile({ videoId: validId1, fileId: hlsFileId, token: userToken, expectedStatus })
95 await servers[0].videos.removeWebTorrentFiles({ videoId: validId1, token: moderatorToken, expectedStatus }) 131 await servers[0].videos.removeHLSFile({ videoId: validId1, fileId: hlsFileId, token: moderatorToken, expectedStatus })
132
133 await servers[0].videos.removeWebTorrentFile({ videoId: validId1, fileId: webtorrentFileId, token: userToken, expectedStatus })
134 await servers[0].videos.removeWebTorrentFile({ videoId: validId1, fileId: webtorrentFileId, token: moderatorToken, expectedStatus })
96 }) 135 })
97 136
98 it('Should not delete files if the files are not available', async function () { 137 it('Should not delete files if the files are not available', async function () {
99 await servers[0].videos.removeHLSFiles({ videoId: hlsId, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) 138 await servers[0].videos.removeHLSPlaylist({ videoId: hlsId, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
100 await servers[0].videos.removeWebTorrentFiles({ videoId: webtorrentId, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) 139 await servers[0].videos.removeAllWebTorrentFiles({ videoId: webtorrentId, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
101 })
102 140
103 it('Should not delete files if no both versions are available', async function () { 141 await servers[0].videos.removeHLSFile({ videoId: hlsId, fileId: 404, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
104 await servers[0].videos.removeHLSFiles({ videoId: hlsId, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) 142 await servers[0].videos.removeWebTorrentFile({ videoId: webtorrentId, fileId: 404, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
105 await servers[0].videos.removeWebTorrentFiles({ videoId: webtorrentId, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
106 }) 143 })
107 144
108 it('Should not delete files if no both versions are available', async function () { 145 it('Should not delete files if no both versions are available', async function () {
109 await servers[0].videos.removeHLSFiles({ videoId: hlsId, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) 146 await servers[0].videos.removeHLSPlaylist({ videoId: hlsId, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
110 await servers[0].videos.removeWebTorrentFiles({ videoId: webtorrentId, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) 147 await servers[0].videos.removeAllWebTorrentFiles({ videoId: webtorrentId, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
111 }) 148 })
112 149
113 it('Should delete files if both versions are available', async function () { 150 it('Should delete files if both versions are available', async function () {
114 await servers[0].videos.removeHLSFiles({ videoId: validId1 }) 151 await servers[0].videos.removeHLSFile({ videoId: validId1, fileId: hlsFileId })
115 await servers[0].videos.removeWebTorrentFiles({ videoId: validId2 }) 152 await servers[0].videos.removeWebTorrentFile({ videoId: validId1, fileId: webtorrentFileId })
153
154 await servers[0].videos.removeHLSPlaylist({ videoId: validId1 })
155 await servers[0].videos.removeAllWebTorrentFiles({ videoId: validId2 })
116 }) 156 })
117 157
118 after(async function () { 158 after(async function () {
diff --git a/server/tests/api/transcoding/create-transcoding.ts b/server/tests/api/transcoding/create-transcoding.ts
index e3867fdad..b59bef772 100644
--- a/server/tests/api/transcoding/create-transcoding.ts
+++ b/server/tests/api/transcoding/create-transcoding.ts
@@ -122,7 +122,7 @@ function runTests (objectStorage: boolean) {
122 it('Should generate WebTorrent from HLS only video', async function () { 122 it('Should generate WebTorrent from HLS only video', async function () {
123 this.timeout(60000) 123 this.timeout(60000)
124 124
125 await servers[0].videos.removeWebTorrentFiles({ videoId: videoUUID }) 125 await servers[0].videos.removeAllWebTorrentFiles({ videoId: videoUUID })
126 await waitJobs(servers) 126 await waitJobs(servers)
127 127
128 await servers[0].videos.runTranscoding({ videoId: videoUUID, transcodingType: 'webtorrent' }) 128 await servers[0].videos.runTranscoding({ videoId: videoUUID, transcodingType: 'webtorrent' })
@@ -142,7 +142,7 @@ function runTests (objectStorage: boolean) {
142 it('Should only generate WebTorrent', async function () { 142 it('Should only generate WebTorrent', async function () {
143 this.timeout(60000) 143 this.timeout(60000)
144 144
145 await servers[0].videos.removeHLSFiles({ videoId: videoUUID }) 145 await servers[0].videos.removeHLSPlaylist({ videoId: videoUUID })
146 await waitJobs(servers) 146 await waitJobs(servers)
147 147
148 await servers[0].videos.runTranscoding({ videoId: videoUUID, transcodingType: 'webtorrent' }) 148 await servers[0].videos.runTranscoding({ videoId: videoUUID, transcodingType: 'webtorrent' })
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
3import 'mocha' 3import 'mocha'
4import { expect } from 'chai' 4import { expect } from 'chai'
5import { HttpStatusCode } from '@shared/models'
5import { 6import {
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
14describe('Test videos files', function () { 16describe('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 () {