1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import * as chai from 'chai'
5 import { HttpStatusCode } from '@shared/models'
10 setAccessTokensToServers,
11 setDefaultAccountAvatar,
12 setDefaultChannelAvatar,
14 } from '@shared/server-commands'
16 const expect = chai.expect
18 describe('Test user videos', function () {
19 let server: PeerTubeServer
23 let anotherUserToken: string
25 before(async function () {
28 server = await createSingleServer(1)
30 await setAccessTokensToServers([ server ])
31 await setDefaultChannelAvatar([ server ])
32 await setDefaultAccountAvatar([ server ])
34 await server.videos.quickUpload({ name: 'root video' })
35 await server.videos.quickUpload({ name: 'root video 2' })
37 token = await server.users.generateUserAndToken('user')
38 anotherUserToken = await server.users.generateUserAndToken('user2')
41 describe('List my videos', function () {
43 it('Should list my videos', async function () {
44 const { data, total } = await server.videos.listMyVideos()
46 expect(total).to.equal(2)
47 expect(data).to.have.lengthOf(2)
51 describe('Upload', function () {
53 it('Should upload the video with the correct token', async function () {
54 await server.videos.upload({ token })
55 const { data } = await server.videos.list()
58 expect(video.account.name).to.equal('user')
62 it('Should upload the video again with the correct token', async function () {
63 const { id } = await server.videos.upload({ token })
68 describe('Ratings', function () {
70 it('Should retrieve a video rating', async function () {
71 await server.videos.rate({ id: videoId, token, rating: 'like' })
72 const rating = await server.users.getMyRating({ token, videoId })
74 expect(rating.videoId).to.equal(videoId)
75 expect(rating.rating).to.equal('like')
78 it('Should retrieve ratings list', async function () {
79 await server.videos.rate({ id: videoId, token, rating: 'like' })
81 const body = await server.accounts.listRatings({ accountName: 'user', token })
83 expect(body.total).to.equal(1)
84 expect(body.data[0].video.id).to.equal(videoId)
85 expect(body.data[0].rating).to.equal('like')
88 it('Should retrieve ratings list by rating type', async function () {
90 const body = await server.accounts.listRatings({ accountName: 'user', token, rating: 'like' })
91 expect(body.data.length).to.equal(1)
95 const body = await server.accounts.listRatings({ accountName: 'user', token, rating: 'dislike' })
96 expect(body.data.length).to.equal(0)
101 describe('Remove video', function () {
103 it('Should not be able to remove the video with an incorrect token', async function () {
104 await server.videos.remove({ token: 'bad_token', id: videoId, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
107 it('Should not be able to remove the video with the token of another account', async function () {
108 await server.videos.remove({ token: anotherUserToken, id: videoId, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
111 it('Should be able to remove the video with the correct token', async function () {
112 await server.videos.remove({ token, id: videoId })
113 await server.videos.remove({ token, id: videoId2 })
117 describe('My videos & quotas', function () {
119 it('Should be able to upload a video with a user', async function () {
123 name: 'super user video',
124 fixture: 'video_short.webm'
126 await server.videos.upload({ token, attributes })
128 await server.channels.create({ token, attributes: { name: 'other_channel' } })
131 it('Should have video quota updated', async function () {
132 const quota = await server.users.getMyQuotaUsed({ token })
133 expect(quota.videoQuotaUsed).to.equal(218910)
134 expect(quota.videoQuotaUsedDaily).to.equal(218910)
136 const { data } = await server.users.list()
137 const tmpUser = data.find(u => u.username === 'user')
138 expect(tmpUser.videoQuotaUsed).to.equal(218910)
139 expect(tmpUser.videoQuotaUsedDaily).to.equal(218910)
142 it('Should be able to list my videos', async function () {
143 const { total, data } = await server.videos.listMyVideos({ token })
144 expect(total).to.equal(1)
145 expect(data).to.have.lengthOf(1)
147 const video = data[0]
148 expect(video.name).to.equal('super user video')
149 expect(video.thumbnailPath).to.not.be.null
150 expect(video.previewPath).to.not.be.null
153 it('Should be able to filter by channel in my videos', async function () {
154 const myInfo = await server.users.getMyInfo({ token })
155 const mainChannel = myInfo.videoChannels.find(c => c.name !== 'other_channel')
156 const otherChannel = myInfo.videoChannels.find(c => c.name === 'other_channel')
159 const { total, data } = await server.videos.listMyVideos({ token, channelId: mainChannel.id })
160 expect(total).to.equal(1)
161 expect(data).to.have.lengthOf(1)
163 const video = data[0]
164 expect(video.name).to.equal('super user video')
165 expect(video.thumbnailPath).to.not.be.null
166 expect(video.previewPath).to.not.be.null
170 const { total, data } = await server.videos.listMyVideos({ token, channelId: otherChannel.id })
171 expect(total).to.equal(0)
172 expect(data).to.have.lengthOf(0)
176 it('Should be able to search in my videos', async function () {
178 const { total, data } = await server.videos.listMyVideos({ token, sort: '-createdAt', search: 'user video' })
179 expect(total).to.equal(1)
180 expect(data).to.have.lengthOf(1)
184 const { total, data } = await server.videos.listMyVideos({ token, sort: '-createdAt', search: 'toto' })
185 expect(total).to.equal(0)
186 expect(data).to.have.lengthOf(0)
190 it('Should disable webtorrent, enable HLS, and update my quota', async function () {
194 const config = await server.config.getCustomConfig()
195 config.transcoding.webtorrent.enabled = false
196 config.transcoding.hls.enabled = true
197 config.transcoding.enabled = true
198 await server.config.updateCustomSubConfig({ newConfig: config })
203 name: 'super user video 2',
204 fixture: 'video_short.webm'
206 await server.videos.upload({ token, attributes })
208 await waitJobs([ server ])
212 const data = await server.users.getMyQuotaUsed({ token })
213 expect(data.videoQuotaUsed).to.be.greaterThan(220000)
214 expect(data.videoQuotaUsedDaily).to.be.greaterThan(220000)
219 after(async function () {
220 await cleanupTests([ server ])