]>
Commit | Line | Data |
---|---|---|
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | |
2 | ||
3 | import * as chai from 'chai' | |
4 | import 'mocha' | |
5 | import { cleanupTests, flushAndRunServer, ServerInfo, setAccessTokensToServers, uploadVideo, wait } from '../../../../shared/extra-utils' | |
6 | import { getVideosOverview } from '../../../../shared/extra-utils/overviews/overviews' | |
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 | ||
17 | server = await flushAndRunServer(1) | |
18 | ||
19 | await setAccessTokensToServers([ server ]) | |
20 | }) | |
21 | ||
22 | it('Should send empty overview', async function () { | |
23 | const res = await getVideosOverview(server.url, 1) | |
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 | ||
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 | ||
34 | await wait(3000) | |
35 | ||
36 | await uploadVideo(server.url, server.accessToken, { | |
37 | name: 'video 0', | |
38 | category: 3, | |
39 | tags: [ 'coucou1', 'coucou2' ] | |
40 | }) | |
41 | ||
42 | const res = await getVideosOverview(server.url, 1) | |
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 () { | |
51 | this.timeout(15000) | |
52 | ||
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 | } | |
60 | ||
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 | } | |
80 | }) | |
81 | ||
82 | it('Should have the correct overview', async function () { | |
83 | const res1 = await getVideosOverview(server.url, 1) | |
84 | const res2 = await getVideosOverview(server.url, 2) | |
85 | ||
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) | |
98 | ||
99 | const obj = arr[0] | |
100 | ||
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') | |
108 | } | |
109 | ||
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 | |
113 | ||
114 | expect(overview1.categories[0].category.id).to.equal(3) | |
115 | ||
116 | expect(overview1.channels[0].channel.name).to.equal('root_channel') | |
117 | }) | |
118 | ||
119 | after(async function () { | |
120 | await cleanupTests([ server ]) | |
121 | }) | |
122 | }) |