aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/videos/video-files.ts
blob: 0a183c44d8d4c0a0c5564a6177b91683e5d807bf (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */

import { expect } from 'chai'
import { HttpStatusCode } from '@shared/models'
import {
  cleanupTests,
  createMultipleServers,
  doubleFollow,
  makeRawRequest,
  PeerTubeServer,
  setAccessTokensToServers,
  waitJobs
} from '@shared/server-commands'

describe('Test videos files', function () {
  let servers: PeerTubeServer[]

  // ---------------------------------------------------------------

  before(async function () {
    this.timeout(150_000)

    servers = await createMultipleServers(2)
    await setAccessTokensToServers(servers)

    await doubleFollow(servers[0], servers[1])

    await servers[0].config.enableTranscoding(true, true)
  })

  describe('When deleting all files', function () {
    let validId1: string
    let validId2: string

    before(async function () {
      this.timeout(360_000)

      {
        const { uuid } = await servers[0].videos.quickUpload({ name: 'video 1' })
        validId1 = uuid
      }

      {
        const { uuid } = await servers[0].videos.quickUpload({ name: 'video 2' })
        validId2 = uuid
      }

      await waitJobs(servers)
    })

    it('Should delete web video files', async function () {
      this.timeout(30_000)

      await servers[0].videos.removeAllWebVideoFiles({ videoId: validId1 })

      await waitJobs(servers)

      for (const server of servers) {
        const video = await server.videos.get({ id: validId1 })

        expect(video.files).to.have.lengthOf(0)
        expect(video.streamingPlaylists).to.have.lengthOf(1)
      }
    })

    it('Should delete HLS files', async function () {
      this.timeout(30_000)

      await servers[0].videos.removeHLSPlaylist({ videoId: validId2 })

      await waitJobs(servers)

      for (const server of servers) {
        const video = await server.videos.get({ id: validId2 })

        expect(video.files).to.have.length.above(0)
        expect(video.streamingPlaylists).to.have.lengthOf(0)
      }
    })
  })

  describe('When deleting a specific file', function () {
    let webVideoId: string
    let hlsId: string

    before(async function () {
      this.timeout(120_000)

      {
        const { uuid } = await servers[0].videos.quickUpload({ name: 'web-video' })
        webVideoId = uuid
      }

      {
        const { uuid } = await servers[0].videos.quickUpload({ name: 'hls' })
        hlsId = uuid
      }

      await waitJobs(servers)
    })

    it('Shoulde delete a web video file', async function () {
      this.timeout(30_000)

      const video = await servers[0].videos.get({ id: webVideoId })
      const files = video.files

      await servers[0].videos.removeWebVideoFile({ videoId: webVideoId, fileId: files[0].id })

      await waitJobs(servers)

      for (const server of servers) {
        const video = await server.videos.get({ id: webVideoId })

        expect(video.files).to.have.lengthOf(files.length - 1)
        expect(video.files.find(f => f.id === files[0].id)).to.not.exist
      }
    })

    it('Should delete all web video files', async function () {
      this.timeout(30_000)

      const video = await servers[0].videos.get({ id: webVideoId })
      const files = video.files

      for (const file of files) {
        await servers[0].videos.removeWebVideoFile({ videoId: webVideoId, fileId: file.id })
      }

      await waitJobs(servers)

      for (const server of servers) {
        const video = await server.videos.get({ id: webVideoId })

        expect(video.files).to.have.lengthOf(0)
      }
    })

    it('Should delete a hls file', async function () {
      this.timeout(30_000)

      const video = await servers[0].videos.get({ id: hlsId })
      const files = video.streamingPlaylists[0].files
      const toDelete = files[0]

      await servers[0].videos.removeHLSFile({ videoId: hlsId, fileId: toDelete.id })

      await waitJobs(servers)

      for (const server of servers) {
        const video = await server.videos.get({ id: hlsId })

        expect(video.streamingPlaylists[0].files).to.have.lengthOf(files.length - 1)
        expect(video.streamingPlaylists[0].files.find(f => f.id === toDelete.id)).to.not.exist

        const { text } = await makeRawRequest({ url: video.streamingPlaylists[0].playlistUrl, expectedStatus: HttpStatusCode.OK_200 })

        expect(text.includes(`-${toDelete.resolution.id}.m3u8`)).to.be.false
        expect(text.includes(`-${video.streamingPlaylists[0].files[0].resolution.id}.m3u8`)).to.be.true
      }
    })

    it('Should delete all hls files', async function () {
      this.timeout(30_000)

      const video = await servers[0].videos.get({ id: hlsId })
      const files = video.streamingPlaylists[0].files

      for (const file of files) {
        await servers[0].videos.removeHLSFile({ videoId: hlsId, fileId: file.id })
      }

      await waitJobs(servers)

      for (const server of servers) {
        const video = await server.videos.get({ id: hlsId })

        expect(video.streamingPlaylists).to.have.lengthOf(0)
      }
    })

    it('Should not delete last file of a video', async function () {
      this.timeout(60_000)

      const webVideoOnly = await servers[0].videos.get({ id: hlsId })
      const hlsOnly = await servers[0].videos.get({ id: webVideoId })

      for (let i = 0; i < 4; i++) {
        await servers[0].videos.removeWebVideoFile({ videoId: webVideoOnly.id, fileId: webVideoOnly.files[i].id })
        await servers[0].videos.removeHLSFile({ videoId: hlsOnly.id, fileId: hlsOnly.streamingPlaylists[0].files[i].id })
      }

      const expectedStatus = HttpStatusCode.BAD_REQUEST_400
      await servers[0].videos.removeWebVideoFile({ videoId: webVideoOnly.id, fileId: webVideoOnly.files[4].id, expectedStatus })
      await servers[0].videos.removeHLSFile({ videoId: hlsOnly.id, fileId: hlsOnly.streamingPlaylists[0].files[4].id, expectedStatus })
    })
  })

  after(async function () {
    await cleanupTests(servers)
  })
})