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