]>
Commit | Line | Data |
---|---|---|
a1587156 | 1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
2d3741d6 C |
2 | |
3 | import * as chai from 'chai' | |
4 | import 'mocha' | |
764a9657 | 5 | import { cleanupTests, flushAndRunServer, ServerInfo, setAccessTokensToServers, uploadVideo, wait } from '../../../../shared/extra-utils' |
94565d52 | 6 | import { getVideosOverview } from '../../../../shared/extra-utils/overviews/overviews' |
2d3741d6 C |
7 | import { VideosOverview } from '../../../../shared/models/overviews' |
8 | ||
9 | const expect = chai.expect | |
10 | ||
11 | describe('Test a videos overview', function () { | |
12 | let server: ServerInfo = null | |
13 | ||
14 | before(async function () { | |
15 | this.timeout(30000) | |
16 | ||
210feb6c | 17 | server = await flushAndRunServer(1) |
2d3741d6 C |
18 | |
19 | await setAccessTokensToServers([ server ]) | |
20 | }) | |
21 | ||
22 | it('Should send empty overview', async function () { | |
764a9657 | 23 | const res = await getVideosOverview(server.url, 1) |
2d3741d6 C |
24 | |
25 | const overview: VideosOverview = res.body | |
26 | expect(overview.tags).to.have.lengthOf(0) | |
27 | expect(overview.categories).to.have.lengthOf(0) | |
28 | expect(overview.channels).to.have.lengthOf(0) | |
29 | }) | |
30 | ||
9a629c6e C |
31 | it('Should upload 5 videos in a specific category, tag and channel but not include them in overview', async function () { |
32 | this.timeout(15000) | |
33 | ||
764a9657 C |
34 | await wait(3000) |
35 | ||
36 | await uploadVideo(server.url, server.accessToken, { | |
37 | name: 'video 0', | |
38 | category: 3, | |
39 | tags: [ 'coucou1', 'coucou2' ] | |
40 | }) | |
2d3741d6 | 41 | |
764a9657 | 42 | const res = await getVideosOverview(server.url, 1) |
2d3741d6 C |
43 | |
44 | const overview: VideosOverview = res.body | |
45 | expect(overview.tags).to.have.lengthOf(0) | |
46 | expect(overview.categories).to.have.lengthOf(0) | |
47 | expect(overview.channels).to.have.lengthOf(0) | |
48 | }) | |
49 | ||
50 | it('Should upload another video and include all videos in the overview', async function () { | |
764a9657 | 51 | this.timeout(15000) |
2d3741d6 | 52 | |
764a9657 C |
53 | for (let i = 1; i < 6; i++) { |
54 | await uploadVideo(server.url, server.accessToken, { | |
55 | name: 'video ' + i, | |
56 | category: 3, | |
57 | tags: [ 'coucou1', 'coucou2' ] | |
58 | }) | |
59 | } | |
2d3741d6 | 60 | |
764a9657 C |
61 | await wait(3000) |
62 | ||
63 | { | |
64 | const res = await getVideosOverview(server.url, 1) | |
65 | ||
66 | const overview: VideosOverview = res.body | |
67 | expect(overview.tags).to.have.lengthOf(1) | |
68 | expect(overview.categories).to.have.lengthOf(1) | |
69 | expect(overview.channels).to.have.lengthOf(1) | |
70 | } | |
71 | ||
72 | { | |
73 | const res = await getVideosOverview(server.url, 2) | |
74 | ||
75 | const overview: VideosOverview = res.body | |
76 | expect(overview.tags).to.have.lengthOf(1) | |
77 | expect(overview.categories).to.have.lengthOf(0) | |
78 | expect(overview.channels).to.have.lengthOf(0) | |
79 | } | |
2d3741d6 C |
80 | }) |
81 | ||
82 | it('Should have the correct overview', async function () { | |
764a9657 C |
83 | const res1 = await getVideosOverview(server.url, 1) |
84 | const res2 = await getVideosOverview(server.url, 2) | |
2d3741d6 | 85 | |
764a9657 C |
86 | const overview1: VideosOverview = res1.body |
87 | const overview2: VideosOverview = res2.body | |
88 | ||
89 | const tmp = [ | |
90 | overview1.tags, | |
91 | overview1.categories, | |
92 | overview1.channels, | |
93 | overview2.tags | |
94 | ] | |
95 | ||
96 | for (const arr of tmp) { | |
97 | expect(arr).to.have.lengthOf(1) | |
2d3741d6 | 98 | |
764a9657 | 99 | const obj = arr[0] |
2d3741d6 | 100 | |
9a629c6e C |
101 | expect(obj.videos).to.have.lengthOf(6) |
102 | expect(obj.videos[0].name).to.equal('video 5') | |
103 | expect(obj.videos[1].name).to.equal('video 4') | |
104 | expect(obj.videos[2].name).to.equal('video 3') | |
105 | expect(obj.videos[3].name).to.equal('video 2') | |
106 | expect(obj.videos[4].name).to.equal('video 1') | |
107 | expect(obj.videos[5].name).to.equal('video 0') | |
2d3741d6 C |
108 | } |
109 | ||
764a9657 C |
110 | const tags = [ overview1.tags[0].tag, overview2.tags[0].tag ] |
111 | expect(tags.find(t => t === 'coucou1')).to.not.be.undefined | |
112 | expect(tags.find(t => t === 'coucou2')).to.not.be.undefined | |
2d3741d6 | 113 | |
764a9657 | 114 | expect(overview1.categories[0].category.id).to.equal(3) |
2d3741d6 | 115 | |
764a9657 | 116 | expect(overview1.channels[0].channel.name).to.equal('root_channel') |
2d3741d6 C |
117 | }) |
118 | ||
7c3b7976 C |
119 | after(async function () { |
120 | await cleanupTests([ server ]) | |
2d3741d6 C |
121 | }) |
122 | }) |