1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
3 import * as chai from 'chai'
4 import { HttpStatusCode } from '@shared/models'
9 setAccessTokensToServers,
10 setDefaultAccountAvatar,
11 setDefaultChannelAvatar,
13 } from '@shared/server-commands'
15 const expect = chai.expect
17 describe('Test user videos', function () {
18 let server: PeerTubeServer
22 let anotherUserToken: string
24 before(async function () {
27 server = await createSingleServer(1)
29 await setAccessTokensToServers([ server ])
30 await setDefaultChannelAvatar([ server ])
31 await setDefaultAccountAvatar([ server ])
33 await server.videos.quickUpload({ name: 'root video' })
34 await server.videos.quickUpload({ name: 'root video 2' })
36 token = await server.users.generateUserAndToken('user')
37 anotherUserToken = await server.users.generateUserAndToken('user2')
40 describe('List my videos', function () {
42 it('Should list my videos', async function () {
43 const { data, total } = await server.videos.listMyVideos()
45 expect(total).to.equal(2)
46 expect(data).to.have.lengthOf(2)
50 describe('Upload', function () {
52 it('Should upload the video with the correct token', async function () {
53 await server.videos.upload({ token })
54 const { data } = await server.videos.list()
57 expect(video.account.name).to.equal('user')
61 it('Should upload the video again with the correct token', async function () {
62 const { id } = await server.videos.upload({ token })
67 describe('Ratings', function () {
69 it('Should retrieve a video rating', async function () {
70 await server.videos.rate({ id: videoId, token, rating: 'like' })
71 const rating = await server.users.getMyRating({ token, videoId })
73 expect(rating.videoId).to.equal(videoId)
74 expect(rating.rating).to.equal('like')
77 it('Should retrieve ratings list', async function () {
78 await server.videos.rate({ id: videoId, token, rating: 'like' })
80 const body = await server.accounts.listRatings({ accountName: 'user', token })
82 expect(body.total).to.equal(1)
83 expect(body.data[0].video.id).to.equal(videoId)
84 expect(body.data[0].rating).to.equal('like')
87 it('Should retrieve ratings list by rating type', async function () {
89 const body = await server.accounts.listRatings({ accountName: 'user', token, rating: 'like' })
90 expect(body.data.length).to.equal(1)
94 const body = await server.accounts.listRatings({ accountName: 'user', token, rating: 'dislike' })
95 expect(body.data.length).to.equal(0)
100 describe('Remove video', function () {
102 it('Should not be able to remove the video with an incorrect token', async function () {
103 await server.videos.remove({ token: 'bad_token', id: videoId, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
106 it('Should not be able to remove the video with the token of another account', async function () {
107 await server.videos.remove({ token: anotherUserToken, id: videoId, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
110 it('Should be able to remove the video with the correct token', async function () {
111 await server.videos.remove({ token, id: videoId })
112 await server.videos.remove({ token, id: videoId2 })
116 describe('My videos & quotas', function () {
118 it('Should be able to upload a video with a user', async function () {
122 name: 'super user video',
123 fixture: 'video_short.webm'
125 await server.videos.upload({ token, attributes })
127 await server.channels.create({ token, attributes: { name: 'other_channel' } })
130 it('Should have video quota updated', async function () {
131 const quota = await server.users.getMyQuotaUsed({ token })
132 expect(quota.videoQuotaUsed).to.equal(218910)
133 expect(quota.videoQuotaUsedDaily).to.equal(218910)
135 const { data } = await server.users.list()
136 const tmpUser = data.find(u => u.username === 'user')
137 expect(tmpUser.videoQuotaUsed).to.equal(218910)
138 expect(tmpUser.videoQuotaUsedDaily).to.equal(218910)
141 it('Should be able to list my videos', async function () {
142 const { total, data } = await server.videos.listMyVideos({ token })
143 expect(total).to.equal(1)
144 expect(data).to.have.lengthOf(1)
146 const video = data[0]
147 expect(video.name).to.equal('super user video')
148 expect(video.thumbnailPath).to.not.be.null
149 expect(video.previewPath).to.not.be.null
152 it('Should be able to filter by channel in my videos', async function () {
153 const myInfo = await server.users.getMyInfo({ token })
154 const mainChannel = myInfo.videoChannels.find(c => c.name !== 'other_channel')
155 const otherChannel = myInfo.videoChannels.find(c => c.name === 'other_channel')
158 const { total, data } = await server.videos.listMyVideos({ token, channelId: mainChannel.id })
159 expect(total).to.equal(1)
160 expect(data).to.have.lengthOf(1)
162 const video = data[0]
163 expect(video.name).to.equal('super user video')
164 expect(video.thumbnailPath).to.not.be.null
165 expect(video.previewPath).to.not.be.null
169 const { total, data } = await server.videos.listMyVideos({ token, channelId: otherChannel.id })
170 expect(total).to.equal(0)
171 expect(data).to.have.lengthOf(0)
175 it('Should be able to search in my videos', async function () {
177 const { total, data } = await server.videos.listMyVideos({ token, sort: '-createdAt', search: 'user video' })
178 expect(total).to.equal(1)
179 expect(data).to.have.lengthOf(1)
183 const { total, data } = await server.videos.listMyVideos({ token, sort: '-createdAt', search: 'toto' })
184 expect(total).to.equal(0)
185 expect(data).to.have.lengthOf(0)
189 it('Should disable webtorrent, enable HLS, and update my quota', async function () {
193 const config = await server.config.getCustomConfig()
194 config.transcoding.webtorrent.enabled = false
195 config.transcoding.hls.enabled = true
196 config.transcoding.enabled = true
197 await server.config.updateCustomSubConfig({ newConfig: config })
202 name: 'super user video 2',
203 fixture: 'video_short.webm'
205 await server.videos.upload({ token, attributes })
207 await waitJobs([ server ])
211 const data = await server.users.getMyQuotaUsed({ token })
212 expect(data.videoQuotaUsed).to.be.greaterThan(220000)
213 expect(data.videoQuotaUsedDaily).to.be.greaterThan(220000)
218 after(async function () {
219 await cleanupTests([ server ])