diff options
author | Chocobozzz <me@florianbigard.com> | 2022-07-18 14:53:50 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2022-07-18 14:53:50 +0200 |
commit | 58c44687f748a3ea5feafe6335fe962aea8186bd (patch) | |
tree | 1d0a1846f439c15edfbf67327623fc3bcca4e92a /server/tests/api/users/user-videos.ts | |
parent | 1efad362ef0b65118d1d79d802ffc928994c0ef6 (diff) | |
download | PeerTube-58c44687f748a3ea5feafe6335fe962aea8186bd.tar.gz PeerTube-58c44687f748a3ea5feafe6335fe962aea8186bd.tar.zst PeerTube-58c44687f748a3ea5feafe6335fe962aea8186bd.zip |
Fix my videos counter
Diffstat (limited to 'server/tests/api/users/user-videos.ts')
-rw-r--r-- | server/tests/api/users/user-videos.ts | 222 |
1 files changed, 222 insertions, 0 deletions
diff --git a/server/tests/api/users/user-videos.ts b/server/tests/api/users/user-videos.ts new file mode 100644 index 000000000..2f5dd1c3e --- /dev/null +++ b/server/tests/api/users/user-videos.ts | |||
@@ -0,0 +1,222 @@ | |||
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | ||
2 | |||
3 | import 'mocha' | ||
4 | import * as chai from 'chai' | ||
5 | import { HttpStatusCode } from '@shared/models' | ||
6 | import { | ||
7 | cleanupTests, | ||
8 | createSingleServer, | ||
9 | PeerTubeServer, | ||
10 | setAccessTokensToServers, | ||
11 | setDefaultAccountAvatar, | ||
12 | setDefaultChannelAvatar, | ||
13 | waitJobs | ||
14 | } from '@shared/server-commands' | ||
15 | |||
16 | const expect = chai.expect | ||
17 | |||
18 | describe('Test user videos', function () { | ||
19 | let server: PeerTubeServer | ||
20 | let videoId: number | ||
21 | let videoId2: number | ||
22 | let token: string | ||
23 | let anotherUserToken: string | ||
24 | |||
25 | before(async function () { | ||
26 | this.timeout(30000) | ||
27 | |||
28 | server = await createSingleServer(1) | ||
29 | |||
30 | await setAccessTokensToServers([ server ]) | ||
31 | await setDefaultChannelAvatar([ server ]) | ||
32 | await setDefaultAccountAvatar([ server ]) | ||
33 | |||
34 | await server.videos.quickUpload({ name: 'root video' }) | ||
35 | await server.videos.quickUpload({ name: 'root video 2' }) | ||
36 | |||
37 | token = await server.users.generateUserAndToken('user') | ||
38 | anotherUserToken = await server.users.generateUserAndToken('user2') | ||
39 | }) | ||
40 | |||
41 | describe('List my videos', function () { | ||
42 | |||
43 | it('Should list my videos', async function () { | ||
44 | const { data, total } = await server.videos.listMyVideos() | ||
45 | |||
46 | expect(total).to.equal(2) | ||
47 | expect(data).to.have.lengthOf(2) | ||
48 | }) | ||
49 | }) | ||
50 | |||
51 | describe('Upload', function () { | ||
52 | |||
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() | ||
56 | const video = data[0] | ||
57 | |||
58 | expect(video.account.name).to.equal('user') | ||
59 | videoId = video.id | ||
60 | }) | ||
61 | |||
62 | it('Should upload the video again with the correct token', async function () { | ||
63 | const { id } = await server.videos.upload({ token }) | ||
64 | videoId2 = id | ||
65 | }) | ||
66 | }) | ||
67 | |||
68 | describe('Ratings', function () { | ||
69 | |||
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 }) | ||
73 | |||
74 | expect(rating.videoId).to.equal(videoId) | ||
75 | expect(rating.rating).to.equal('like') | ||
76 | }) | ||
77 | |||
78 | it('Should retrieve ratings list', async function () { | ||
79 | await server.videos.rate({ id: videoId, token, rating: 'like' }) | ||
80 | |||
81 | const body = await server.accounts.listRatings({ accountName: 'user', token }) | ||
82 | |||
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') | ||
86 | }) | ||
87 | |||
88 | it('Should retrieve ratings list by rating type', async function () { | ||
89 | { | ||
90 | const body = await server.accounts.listRatings({ accountName: 'user', token, rating: 'like' }) | ||
91 | expect(body.data.length).to.equal(1) | ||
92 | } | ||
93 | |||
94 | { | ||
95 | const body = await server.accounts.listRatings({ accountName: 'user', token, rating: 'dislike' }) | ||
96 | expect(body.data.length).to.equal(0) | ||
97 | } | ||
98 | }) | ||
99 | }) | ||
100 | |||
101 | describe('Remove video', function () { | ||
102 | |||
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 }) | ||
105 | }) | ||
106 | |||
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 }) | ||
109 | }) | ||
110 | |||
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 }) | ||
114 | }) | ||
115 | }) | ||
116 | |||
117 | describe('My videos & quotas', function () { | ||
118 | |||
119 | it('Should be able to upload a video with a user', async function () { | ||
120 | this.timeout(10000) | ||
121 | |||
122 | const attributes = { | ||
123 | name: 'super user video', | ||
124 | fixture: 'video_short.webm' | ||
125 | } | ||
126 | await server.videos.upload({ token, attributes }) | ||
127 | |||
128 | await server.channels.create({ token, attributes: { name: 'other_channel' } }) | ||
129 | }) | ||
130 | |||
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) | ||
135 | |||
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) | ||
140 | }) | ||
141 | |||
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) | ||
146 | |||
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 | ||
151 | }) | ||
152 | |||
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') | ||
157 | |||
158 | { | ||
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) | ||
162 | |||
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 | ||
167 | } | ||
168 | |||
169 | { | ||
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) | ||
173 | } | ||
174 | }) | ||
175 | |||
176 | it('Should be able to search in my videos', async function () { | ||
177 | { | ||
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) | ||
181 | } | ||
182 | |||
183 | { | ||
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) | ||
187 | } | ||
188 | }) | ||
189 | |||
190 | it('Should disable webtorrent, enable HLS, and update my quota', async function () { | ||
191 | this.timeout(160000) | ||
192 | |||
193 | { | ||
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 }) | ||
199 | } | ||
200 | |||
201 | { | ||
202 | const attributes = { | ||
203 | name: 'super user video 2', | ||
204 | fixture: 'video_short.webm' | ||
205 | } | ||
206 | await server.videos.upload({ token, attributes }) | ||
207 | |||
208 | await waitJobs([ server ]) | ||
209 | } | ||
210 | |||
211 | { | ||
212 | const data = await server.users.getMyQuotaUsed({ token }) | ||
213 | expect(data.videoQuotaUsed).to.be.greaterThan(220000) | ||
214 | expect(data.videoQuotaUsedDaily).to.be.greaterThan(220000) | ||
215 | } | ||
216 | }) | ||
217 | }) | ||
218 | |||
219 | after(async function () { | ||
220 | await cleanupTests([ server ]) | ||
221 | }) | ||
222 | }) | ||