aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/object-storage/video-imports.ts
blob: 90988ea9a1d0c052f08c59b928cf268d30619f67 (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
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */

import { expect } from 'chai'
import { expectStartWith, FIXTURE_URLS } from '@server/tests/shared'
import { areObjectStorageTestsDisabled } from '@shared/core-utils'
import { HttpStatusCode, VideoPrivacy } from '@shared/models'
import {
  createSingleServer,
  killallServers,
  makeRawRequest,
  ObjectStorageCommand,
  PeerTubeServer,
  setAccessTokensToServers,
  setDefaultVideoChannel,
  waitJobs
} from '@shared/server-commands'

async function importVideo (server: PeerTubeServer) {
  const attributes = {
    name: 'import 2',
    privacy: VideoPrivacy.PUBLIC,
    channelId: server.store.channel.id,
    targetUrl: FIXTURE_URLS.goodVideo720
  }

  const { video: { uuid } } = await server.imports.importVideo({ attributes })

  return uuid
}

describe('Object storage for video import', function () {
  if (areObjectStorageTestsDisabled()) return

  let server: PeerTubeServer

  before(async function () {
    this.timeout(120000)

    await ObjectStorageCommand.prepareDefaultBuckets()

    server = await createSingleServer(1, ObjectStorageCommand.getDefaultConfig())

    await setAccessTokensToServers([ server ])
    await setDefaultVideoChannel([ server ])

    await server.config.enableImports()
  })

  describe('Without transcoding', async function () {

    before(async function () {
      await server.config.disableTranscoding()
    })

    it('Should import a video and have sent it to object storage', async function () {
      this.timeout(120000)

      const uuid = await importVideo(server)
      await waitJobs(server)

      const video = await server.videos.get({ id: uuid })

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

      const fileUrl = video.files[0].fileUrl
      expectStartWith(fileUrl, ObjectStorageCommand.getWebTorrentBaseUrl())

      await makeRawRequest({ url: fileUrl, expectedStatus: HttpStatusCode.OK_200 })
    })
  })

  describe('With transcoding', async function () {

    before(async function () {
      await server.config.enableTranscoding()
    })

    it('Should import a video and have sent it to object storage', async function () {
      this.timeout(120000)

      const uuid = await importVideo(server)
      await waitJobs(server)

      const video = await server.videos.get({ id: uuid })

      expect(video.files).to.have.lengthOf(5)
      expect(video.streamingPlaylists).to.have.lengthOf(1)
      expect(video.streamingPlaylists[0].files).to.have.lengthOf(5)

      for (const file of video.files) {
        expectStartWith(file.fileUrl, ObjectStorageCommand.getWebTorrentBaseUrl())

        await makeRawRequest({ url: file.fileUrl, expectedStatus: HttpStatusCode.OK_200 })
      }

      for (const file of video.streamingPlaylists[0].files) {
        expectStartWith(file.fileUrl, ObjectStorageCommand.getPlaylistBaseUrl())

        await makeRawRequest({ url: file.fileUrl, expectedStatus: HttpStatusCode.OK_200 })
      }
    })
  })

  after(async function () {
    await killallServers([ server ])
  })
})