diff options
Diffstat (limited to 'server/tests/api/videos/videos-overview.ts')
-rw-r--r-- | server/tests/api/videos/videos-overview.ts | 96 |
1 files changed, 96 insertions, 0 deletions
diff --git a/server/tests/api/videos/videos-overview.ts b/server/tests/api/videos/videos-overview.ts new file mode 100644 index 000000000..1514d1bda --- /dev/null +++ b/server/tests/api/videos/videos-overview.ts | |||
@@ -0,0 +1,96 @@ | |||
1 | /* tslint:disable:no-unused-expression */ | ||
2 | |||
3 | import * as chai from 'chai' | ||
4 | import 'mocha' | ||
5 | import { flushTests, killallServers, runServer, ServerInfo, setAccessTokensToServers, uploadVideo } from '../../utils' | ||
6 | import { getVideosOverview } from '../../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 | await flushTests() | ||
18 | |||
19 | server = await runServer(1) | ||
20 | |||
21 | await setAccessTokensToServers([ server ]) | ||
22 | }) | ||
23 | |||
24 | it('Should send empty overview', async function () { | ||
25 | const res = await getVideosOverview(server.url) | ||
26 | |||
27 | const overview: VideosOverview = res.body | ||
28 | expect(overview.tags).to.have.lengthOf(0) | ||
29 | expect(overview.categories).to.have.lengthOf(0) | ||
30 | expect(overview.channels).to.have.lengthOf(0) | ||
31 | }) | ||
32 | |||
33 | it('Should upload 3 videos in a specific category, tag and channel but not include them in overview', async function () { | ||
34 | for (let i = 0; i < 3; i++) { | ||
35 | await uploadVideo(server.url, server.accessToken, { | ||
36 | name: 'video ' + i, | ||
37 | category: 3, | ||
38 | tags: [ 'coucou1', 'coucou2' ] | ||
39 | }) | ||
40 | } | ||
41 | |||
42 | const res = await getVideosOverview(server.url) | ||
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 | await uploadVideo(server.url, server.accessToken, { | ||
52 | name: 'video 3', | ||
53 | category: 3, | ||
54 | tags: [ 'coucou1', 'coucou2' ] | ||
55 | }) | ||
56 | |||
57 | const res = await getVideosOverview(server.url) | ||
58 | |||
59 | const overview: VideosOverview = res.body | ||
60 | expect(overview.tags).to.have.lengthOf(2) | ||
61 | expect(overview.categories).to.have.lengthOf(1) | ||
62 | expect(overview.channels).to.have.lengthOf(1) | ||
63 | }) | ||
64 | |||
65 | it('Should have the correct overview', async function () { | ||
66 | const res = await getVideosOverview(server.url) | ||
67 | |||
68 | const overview: VideosOverview = res.body | ||
69 | |||
70 | for (const attr of [ 'tags', 'categories', 'channels' ]) { | ||
71 | const obj = overview[attr][0] | ||
72 | |||
73 | expect(obj.videos).to.have.lengthOf(4) | ||
74 | expect(obj.videos[0].name).to.equal('video 3') | ||
75 | expect(obj.videos[1].name).to.equal('video 2') | ||
76 | expect(obj.videos[2].name).to.equal('video 1') | ||
77 | expect(obj.videos[3].name).to.equal('video 0') | ||
78 | } | ||
79 | |||
80 | expect(overview.tags.find(t => t.tag === 'coucou1')).to.not.be.undefined | ||
81 | expect(overview.tags.find(t => t.tag === 'coucou2')).to.not.be.undefined | ||
82 | |||
83 | expect(overview.categories[0].category.id).to.equal(3) | ||
84 | |||
85 | expect(overview.channels[0].channel.name).to.equal('root_channel') | ||
86 | }) | ||
87 | |||
88 | after(async function () { | ||
89 | killallServers([ server ]) | ||
90 | |||
91 | // Keep the logs if the test failed | ||
92 | if (this['ok']) { | ||
93 | await flushTests() | ||
94 | } | ||
95 | }) | ||
96 | }) | ||