]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/videos/video-channels.ts
Tests directories refractor
[github/Chocobozzz/PeerTube.git] / server / tests / api / videos / video-channels.ts
1 /* tslint:disable:no-unused-expression */
2
3 import 'mocha'
4 import * as chai from 'chai'
5 const expect = chai.expect
6
7 import {
8 ServerInfo,
9 flushTests,
10 runServer,
11 setAccessTokensToServers,
12 killallServers,
13 getMyUserInformation,
14 getVideoChannelsList,
15 addVideoChannel,
16 getAccountVideoChannelsList,
17 updateVideoChannel,
18 deleteVideoChannel,
19 getVideoChannel
20 } from '../../utils/index'
21 import { User } from '../../../../shared/index'
22
23 describe('Test a video channels', function () {
24 let server: ServerInfo
25 let userInfo: User
26 let videoChannelId: number
27
28 before(async function () {
29 this.timeout(10000)
30
31 await flushTests()
32
33 server = await runServer(1)
34
35 await setAccessTokensToServers([ server ])
36 })
37
38 it('Should have one video channel (created with root)', async () => {
39 const res = await getVideoChannelsList(server.url, 0, 2)
40
41 expect(res.body.total).to.equal(1)
42 expect(res.body.data).to.be.an('array')
43 expect(res.body.data).to.have.lengthOf(1)
44 })
45
46 it('Should create another video channel', async () => {
47 const videoChannel = {
48 name: 'second video channel',
49 description: 'super video channel description'
50 }
51 await addVideoChannel(server.url, server.accessToken, videoChannel)
52 })
53
54 it('Should have two video channels when getting my information', async () => {
55 const res = await getMyUserInformation(server.url, server.accessToken)
56 userInfo = res.body
57
58 expect(userInfo.videoChannels).to.be.an('array')
59 expect(userInfo.videoChannels).to.have.lengthOf(2)
60
61 const videoChannels = userInfo.videoChannels
62 expect(videoChannels[0].name).to.equal('Default root channel')
63 expect(videoChannels[1].name).to.equal('second video channel')
64 expect(videoChannels[1].description).to.equal('super video channel description')
65 })
66
67 it('Should have two video channels when getting account channels', async () => {
68 const res = await getAccountVideoChannelsList(server.url, userInfo.account.uuid)
69
70 expect(res.body.total).to.equal(2)
71 expect(res.body.data).to.be.an('array')
72 expect(res.body.data).to.have.lengthOf(2)
73
74 const videoChannels = res.body.data
75 expect(videoChannels[0].name).to.equal('Default root channel')
76 expect(videoChannels[1].name).to.equal('second video channel')
77 expect(videoChannels[1].description).to.equal('super video channel description')
78
79 videoChannelId = videoChannels[1].id
80 })
81
82 it('Should list video channels', async () => {
83 const res = await getVideoChannelsList(server.url, 1, 1, '-name')
84
85 expect(res.body.total).to.equal(2)
86 expect(res.body.data).to.be.an('array')
87 expect(res.body.data).to.have.lengthOf(1)
88 expect(res.body.data[0].name).to.equal('Default root channel')
89 })
90
91 it('Should update video channel', async () => {
92 const videoChannelAttributes = {
93 name: 'video channel updated',
94 description: 'video channel description updated'
95 }
96
97 await updateVideoChannel(server.url, server.accessToken, videoChannelId, videoChannelAttributes)
98 })
99
100 it('Should have video channel updated', async () => {
101 const res = await getVideoChannelsList(server.url, 0, 1, '-name')
102
103 expect(res.body.total).to.equal(2)
104 expect(res.body.data).to.be.an('array')
105 expect(res.body.data).to.have.lengthOf(1)
106 expect(res.body.data[0].name).to.equal('video channel updated')
107 expect(res.body.data[0].description).to.equal('video channel description updated')
108 })
109
110 it('Should get video channel', async () => {
111 const res = await getVideoChannel(server.url, videoChannelId)
112
113 const videoChannel = res.body
114 expect(videoChannel.name).to.equal('video channel updated')
115 expect(videoChannel.description).to.equal('video channel description updated')
116 })
117
118 it('Should delete video channel', async () => {
119 await deleteVideoChannel(server.url, server.accessToken, videoChannelId)
120 })
121
122 it('Should have video channel deleted', async () => {
123 const res = await getVideoChannelsList(server.url, 0, 10)
124
125 expect(res.body.total).to.equal(1)
126 expect(res.body.data).to.be.an('array')
127 expect(res.body.data).to.have.lengthOf(1)
128 expect(res.body.data[0].name).to.equal('Default root channel')
129 })
130
131 after(async function () {
132 killallServers([ server ])
133
134 // Keep the logs if the test failed
135 if (this['ok']) {
136 await flushTests()
137 }
138 })
139 })