1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
3 import { expect } from 'chai'
4 import { HttpStatusCode } from '@shared/models'
9 setAccessTokensToServers,
10 setDefaultAccountAvatar,
11 setDefaultChannelAvatar,
13 } from '@shared/server-commands'
15 describe('Test user videos', function () {
16 let server: PeerTubeServer
20 let anotherUserToken: string
22 before(async function () {
25 server = await createSingleServer(1)
27 await setAccessTokensToServers([ server ])
28 await setDefaultChannelAvatar([ server ])
29 await setDefaultAccountAvatar([ server ])
31 await server.videos.quickUpload({ name: 'root video' })
32 await server.videos.quickUpload({ name: 'root video 2' })
34 token = await server.users.generateUserAndToken('user')
35 anotherUserToken = await server.users.generateUserAndToken('user2')
38 describe('List my videos', function () {
40 it('Should list my videos', async function () {
41 const { data, total } = await server.videos.listMyVideos()
43 expect(total).to.equal(2)
44 expect(data).to.have.lengthOf(2)
48 describe('Upload', function () {
50 it('Should upload the video with the correct token', async function () {
51 await server.videos.upload({ token })
52 const { data } = await server.videos.list()
55 expect(video.account.name).to.equal('user')
59 it('Should upload the video again with the correct token', async function () {
60 const { id } = await server.videos.upload({ token })
65 describe('Ratings', function () {
67 it('Should retrieve a video rating', async function () {
68 await server.videos.rate({ id: videoId, token, rating: 'like' })
69 const rating = await server.users.getMyRating({ token, videoId })
71 expect(rating.videoId).to.equal(videoId)
72 expect(rating.rating).to.equal('like')
75 it('Should retrieve ratings list', async function () {
76 await server.videos.rate({ id: videoId, token, rating: 'like' })
78 const body = await server.accounts.listRatings({ accountName: 'user', token })
80 expect(body.total).to.equal(1)
81 expect(body.data[0].video.id).to.equal(videoId)
82 expect(body.data[0].rating).to.equal('like')
85 it('Should retrieve ratings list by rating type', async function () {
87 const body = await server.accounts.listRatings({ accountName: 'user', token, rating: 'like' })
88 expect(body.data.length).to.equal(1)
92 const body = await server.accounts.listRatings({ accountName: 'user', token, rating: 'dislike' })
93 expect(body.data.length).to.equal(0)
98 describe('Remove video', function () {
100 it('Should not be able to remove the video with an incorrect token', async function () {
101 await server.videos.remove({ token: 'bad_token', id: videoId, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
104 it('Should not be able to remove the video with the token of another account', async function () {
105 await server.videos.remove({ token: anotherUserToken, id: videoId, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
108 it('Should be able to remove the video with the correct token', async function () {
109 await server.videos.remove({ token, id: videoId })
110 await server.videos.remove({ token, id: videoId2 })
114 describe('My videos & quotas', function () {
116 it('Should be able to upload a video with a user', async function () {
120 name: 'super user video',
121 fixture: 'video_short.webm'
123 await server.videos.upload({ token, attributes })
125 await server.channels.create({ token, attributes: { name: 'other_channel' } })
128 it('Should have video quota updated', async function () {
129 const quota = await server.users.getMyQuotaUsed({ token })
130 expect(quota.videoQuotaUsed).to.equal(218910)
131 expect(quota.videoQuotaUsedDaily).to.equal(218910)
133 const { data } = await server.users.list()
134 const tmpUser = data.find(u => u.username === 'user')
135 expect(tmpUser.videoQuotaUsed).to.equal(218910)
136 expect(tmpUser.videoQuotaUsedDaily).to.equal(218910)
139 it('Should be able to list my videos', async function () {
140 const { total, data } = await server.videos.listMyVideos({ token })
141 expect(total).to.equal(1)
142 expect(data).to.have.lengthOf(1)
144 const video = data[0]
145 expect(video.name).to.equal('super user video')
146 expect(video.thumbnailPath).to.not.be.null
147 expect(video.previewPath).to.not.be.null
150 it('Should be able to filter by channel in my videos', async function () {
151 const myInfo = await server.users.getMyInfo({ token })
152 const mainChannel = myInfo.videoChannels.find(c => c.name !== 'other_channel')
153 const otherChannel = myInfo.videoChannels.find(c => c.name === 'other_channel')
156 const { total, data } = await server.videos.listMyVideos({ token, channelId: mainChannel.id })
157 expect(total).to.equal(1)
158 expect(data).to.have.lengthOf(1)
160 const video = data[0]
161 expect(video.name).to.equal('super user video')
162 expect(video.thumbnailPath).to.not.be.null
163 expect(video.previewPath).to.not.be.null
167 const { total, data } = await server.videos.listMyVideos({ token, channelId: otherChannel.id })
168 expect(total).to.equal(0)
169 expect(data).to.have.lengthOf(0)
173 it('Should be able to search in my videos', async function () {
175 const { total, data } = await server.videos.listMyVideos({ token, sort: '-createdAt', search: 'user video' })
176 expect(total).to.equal(1)
177 expect(data).to.have.lengthOf(1)
181 const { total, data } = await server.videos.listMyVideos({ token, sort: '-createdAt', search: 'toto' })
182 expect(total).to.equal(0)
183 expect(data).to.have.lengthOf(0)
187 it('Should disable webtorrent, enable HLS, and update my quota', async function () {
191 const config = await server.config.getCustomConfig()
192 config.transcoding.webtorrent.enabled = false
193 config.transcoding.hls.enabled = true
194 config.transcoding.enabled = true
195 await server.config.updateCustomSubConfig({ newConfig: config })
200 name: 'super user video 2',
201 fixture: 'video_short.webm'
203 await server.videos.upload({ token, attributes })
205 await waitJobs([ server ])
209 const data = await server.users.getMyQuotaUsed({ token })
210 expect(data.videoQuotaUsed).to.be.greaterThan(220000)
211 expect(data.videoQuotaUsedDaily).to.be.greaterThan(220000)
216 after(async function () {
217 await cleanupTests([ server ])