aboutsummaryrefslogtreecommitdiffhomepage
path: root/packages/tests/src/api/videos/videos-overview.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2023-08-17 08:59:21 +0200
committerChocobozzz <me@florianbigard.com>2023-08-17 08:59:21 +0200
commitc380e3928517eb5311b38cf257816642617d7a33 (patch)
tree2ea9b70ebca16b5d109bcce98fe7f944dad89319 /packages/tests/src/api/videos/videos-overview.ts
parenta8ca6190fb462bf6eb5685cfc1d8ae444164a487 (diff)
parent3a4992633ee62d5edfbb484d9c6bcb3cf158489d (diff)
downloadPeerTube-c380e3928517eb5311b38cf257816642617d7a33.tar.gz
PeerTube-c380e3928517eb5311b38cf257816642617d7a33.tar.zst
PeerTube-c380e3928517eb5311b38cf257816642617d7a33.zip
Merge branch 'feature/esm-and-nx' into develop
Diffstat (limited to 'packages/tests/src/api/videos/videos-overview.ts')
-rw-r--r--packages/tests/src/api/videos/videos-overview.ts129
1 files changed, 129 insertions, 0 deletions
diff --git a/packages/tests/src/api/videos/videos-overview.ts b/packages/tests/src/api/videos/videos-overview.ts
new file mode 100644
index 000000000..7d74d6db2
--- /dev/null
+++ b/packages/tests/src/api/videos/videos-overview.ts
@@ -0,0 +1,129 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3import { expect } from 'chai'
4import { wait } from '@peertube/peertube-core-utils'
5import { VideosOverview } from '@peertube/peertube-models'
6import { cleanupTests, createSingleServer, PeerTubeServer, setAccessTokensToServers } from '@peertube/peertube-server-commands'
7
8describe('Test a videos overview', function () {
9 let server: PeerTubeServer = null
10
11 function testOverviewCount (overview: VideosOverview, expected: number) {
12 expect(overview.tags).to.have.lengthOf(expected)
13 expect(overview.categories).to.have.lengthOf(expected)
14 expect(overview.channels).to.have.lengthOf(expected)
15 }
16
17 before(async function () {
18 this.timeout(30000)
19
20 server = await createSingleServer(1)
21
22 await setAccessTokensToServers([ server ])
23 })
24
25 it('Should send empty overview', async function () {
26 const body = await server.overviews.getVideos({ page: 1 })
27
28 testOverviewCount(body, 0)
29 })
30
31 it('Should upload 5 videos in a specific category, tag and channel but not include them in overview', async function () {
32 this.timeout(60000)
33
34 await wait(3000)
35
36 await server.videos.upload({
37 attributes: {
38 name: 'video 0',
39 category: 3,
40 tags: [ 'coucou1', 'coucou2' ]
41 }
42 })
43
44 const body = await server.overviews.getVideos({ page: 1 })
45
46 testOverviewCount(body, 0)
47 })
48
49 it('Should upload another video and include all videos in the overview', async function () {
50 this.timeout(120000)
51
52 {
53 for (let i = 1; i < 6; i++) {
54 await server.videos.upload({
55 attributes: {
56 name: 'video ' + i,
57 category: 3,
58 tags: [ 'coucou1', 'coucou2' ]
59 }
60 })
61 }
62
63 await wait(3000)
64 }
65
66 {
67 const body = await server.overviews.getVideos({ page: 1 })
68
69 testOverviewCount(body, 1)
70 }
71
72 {
73 const overview = await server.overviews.getVideos({ page: 2 })
74
75 expect(overview.tags).to.have.lengthOf(1)
76 expect(overview.categories).to.have.lengthOf(0)
77 expect(overview.channels).to.have.lengthOf(0)
78 }
79 })
80
81 it('Should have the correct overview', async function () {
82 const overview1 = await server.overviews.getVideos({ page: 1 })
83 const overview2 = await server.overviews.getVideos({ page: 2 })
84
85 for (const arr of [ overview1.tags, overview1.categories, overview1.channels, overview2.tags ]) {
86 expect(arr).to.have.lengthOf(1)
87
88 const obj = arr[0]
89
90 expect(obj.videos).to.have.lengthOf(6)
91 expect(obj.videos[0].name).to.equal('video 5')
92 expect(obj.videos[1].name).to.equal('video 4')
93 expect(obj.videos[2].name).to.equal('video 3')
94 expect(obj.videos[3].name).to.equal('video 2')
95 expect(obj.videos[4].name).to.equal('video 1')
96 expect(obj.videos[5].name).to.equal('video 0')
97 }
98
99 const tags = [ overview1.tags[0].tag, overview2.tags[0].tag ]
100 expect(tags.find(t => t === 'coucou1')).to.not.be.undefined
101 expect(tags.find(t => t === 'coucou2')).to.not.be.undefined
102
103 expect(overview1.categories[0].category.id).to.equal(3)
104
105 expect(overview1.channels[0].channel.name).to.equal('root_channel')
106 })
107
108 it('Should hide muted accounts', async function () {
109 const token = await server.users.generateUserAndToken('choco')
110
111 await server.blocklist.addToMyBlocklist({ token, account: 'root@' + server.host })
112
113 {
114 const body = await server.overviews.getVideos({ page: 1 })
115
116 testOverviewCount(body, 1)
117 }
118
119 {
120 const body = await server.overviews.getVideos({ page: 1, token })
121
122 testOverviewCount(body, 0)
123 }
124 })
125
126 after(async function () {
127 await cleanupTests([ server ])
128 })
129})