aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/videos/resumable-upload.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-07-21 15:51:30 +0200
committerChocobozzz <me@florianbigard.com>2021-07-21 15:51:30 +0200
commita24bd1ed41b43790bab6ba789580bb4e85f07d85 (patch)
treea54b0f6c921ba83a6e909cd0ced325b2d4b8863c /server/tests/api/videos/resumable-upload.ts
parent5f26f13b3c16ac5ae0a3b0a7142d84a9528cf565 (diff)
parentc63830f15403ac4e750829f27d8bbbdc9a59282c (diff)
downloadPeerTube-a24bd1ed41b43790bab6ba789580bb4e85f07d85.tar.gz
PeerTube-a24bd1ed41b43790bab6ba789580bb4e85f07d85.tar.zst
PeerTube-a24bd1ed41b43790bab6ba789580bb4e85f07d85.zip
Merge branch 'next' into develop
Diffstat (limited to 'server/tests/api/videos/resumable-upload.ts')
-rw-r--r--server/tests/api/videos/resumable-upload.ts48
1 files changed, 17 insertions, 31 deletions
diff --git a/server/tests/api/videos/resumable-upload.ts b/server/tests/api/videos/resumable-upload.ts
index 4fc3317df..13e47c85e 100644
--- a/server/tests/api/videos/resumable-upload.ts
+++ b/server/tests/api/videos/resumable-upload.ts
@@ -4,22 +4,15 @@ import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { pathExists, readdir, stat } from 'fs-extra' 5import { pathExists, readdir, stat } from 'fs-extra'
6import { join } from 'path' 6import { join } from 'path'
7import { HttpStatusCode } from '@shared/core-utils'
8import { 7import {
9 buildAbsoluteFixturePath, 8 buildAbsoluteFixturePath,
10 buildServerDirectory,
11 cleanupTests, 9 cleanupTests,
12 flushAndRunServer, 10 createSingleServer,
13 getMyUserInformation, 11 PeerTubeServer,
14 prepareResumableUpload,
15 sendDebugCommand,
16 sendResumableChunks,
17 ServerInfo,
18 setAccessTokensToServers, 12 setAccessTokensToServers,
19 setDefaultVideoChannel, 13 setDefaultVideoChannel
20 updateUser
21} from '@shared/extra-utils' 14} from '@shared/extra-utils'
22import { MyUser, VideoPrivacy } from '@shared/models' 15import { HttpStatusCode, VideoPrivacy } from '@shared/models'
23 16
24const expect = chai.expect 17const expect = chai.expect
25 18
@@ -27,7 +20,7 @@ const expect = chai.expect
27 20
28describe('Test resumable upload', function () { 21describe('Test resumable upload', function () {
29 const defaultFixture = 'video_short.mp4' 22 const defaultFixture = 'video_short.mp4'
30 let server: ServerInfo 23 let server: PeerTubeServer
31 let rootId: number 24 let rootId: number
32 25
33 async function buildSize (fixture: string, size?: number) { 26 async function buildSize (fixture: string, size?: number) {
@@ -42,14 +35,14 @@ describe('Test resumable upload', function () {
42 35
43 const attributes = { 36 const attributes = {
44 name: 'video', 37 name: 'video',
45 channelId: server.videoChannel.id, 38 channelId: server.store.channel.id,
46 privacy: VideoPrivacy.PUBLIC, 39 privacy: VideoPrivacy.PUBLIC,
47 fixture: defaultFixture 40 fixture: defaultFixture
48 } 41 }
49 42
50 const mimetype = 'video/mp4' 43 const mimetype = 'video/mp4'
51 44
52 const res = await prepareResumableUpload({ url: server.url, token: server.accessToken, attributes, size, mimetype }) 45 const res = await server.videos.prepareResumableUpload({ attributes, size, mimetype })
53 46
54 return res.header['location'].split('?')[1] 47 return res.header['location'].split('?')[1]
55 } 48 }
@@ -67,15 +60,13 @@ describe('Test resumable upload', function () {
67 const size = await buildSize(defaultFixture, options.size) 60 const size = await buildSize(defaultFixture, options.size)
68 const absoluteFilePath = buildAbsoluteFixturePath(defaultFixture) 61 const absoluteFilePath = buildAbsoluteFixturePath(defaultFixture)
69 62
70 return sendResumableChunks({ 63 return server.videos.sendResumableChunks({
71 url: server.url,
72 token: server.accessToken,
73 pathUploadId, 64 pathUploadId,
74 videoFilePath: absoluteFilePath, 65 videoFilePath: absoluteFilePath,
75 size, 66 size,
76 contentLength, 67 contentLength,
77 contentRangeBuilder, 68 contentRangeBuilder,
78 specialStatus: expectedStatus 69 expectedStatus
79 }) 70 })
80 } 71 }
81 72
@@ -83,7 +74,7 @@ describe('Test resumable upload', function () {
83 const uploadId = uploadIdArg.replace(/^upload_id=/, '') 74 const uploadId = uploadIdArg.replace(/^upload_id=/, '')
84 75
85 const subPath = join('tmp', 'resumable-uploads', uploadId) 76 const subPath = join('tmp', 'resumable-uploads', uploadId)
86 const filePath = buildServerDirectory(server, subPath) 77 const filePath = server.servers.buildDirectory(subPath)
87 const exists = await pathExists(filePath) 78 const exists = await pathExists(filePath)
88 79
89 if (expectedSize === null) { 80 if (expectedSize === null) {
@@ -98,7 +89,7 @@ describe('Test resumable upload', function () {
98 89
99 async function countResumableUploads () { 90 async function countResumableUploads () {
100 const subPath = join('tmp', 'resumable-uploads') 91 const subPath = join('tmp', 'resumable-uploads')
101 const filePath = buildServerDirectory(server, subPath) 92 const filePath = server.servers.buildDirectory(subPath)
102 93
103 const files = await readdir(filePath) 94 const files = await readdir(filePath)
104 return files.length 95 return files.length
@@ -107,19 +98,14 @@ describe('Test resumable upload', function () {
107 before(async function () { 98 before(async function () {
108 this.timeout(30000) 99 this.timeout(30000)
109 100
110 server = await flushAndRunServer(1) 101 server = await createSingleServer(1)
111 await setAccessTokensToServers([ server ]) 102 await setAccessTokensToServers([ server ])
112 await setDefaultVideoChannel([ server ]) 103 await setDefaultVideoChannel([ server ])
113 104
114 const res = await getMyUserInformation(server.url, server.accessToken) 105 const body = await server.users.getMyInfo()
115 rootId = (res.body as MyUser).id 106 rootId = body.id
116 107
117 await updateUser({ 108 await server.users.update({ userId: rootId, videoQuota: 10_000_000 })
118 url: server.url,
119 userId: rootId,
120 accessToken: server.accessToken,
121 videoQuota: 10_000_000
122 })
123 }) 109 })
124 110
125 describe('Directory cleaning', function () { 111 describe('Directory cleaning', function () {
@@ -138,13 +124,13 @@ describe('Test resumable upload', function () {
138 }) 124 })
139 125
140 it('Should not delete recent uploads', async function () { 126 it('Should not delete recent uploads', async function () {
141 await sendDebugCommand(server.url, server.accessToken, { command: 'remove-dandling-resumable-uploads' }) 127 await server.debug.sendCommand({ body: { command: 'remove-dandling-resumable-uploads' } })
142 128
143 expect(await countResumableUploads()).to.equal(2) 129 expect(await countResumableUploads()).to.equal(2)
144 }) 130 })
145 131
146 it('Should delete old uploads', async function () { 132 it('Should delete old uploads', async function () {
147 await sendDebugCommand(server.url, server.accessToken, { command: 'remove-dandling-resumable-uploads' }) 133 await server.debug.sendCommand({ body: { command: 'remove-dandling-resumable-uploads' } })
148 134
149 expect(await countResumableUploads()).to.equal(0) 135 expect(await countResumableUploads()).to.equal(0)
150 }) 136 })