]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/check-params/video-comments.ts
Add comments federation tests
[github/Chocobozzz/PeerTube.git] / server / tests / api / check-params / video-comments.ts
CommitLineData
e2e22e40
C
1/* tslint:disable:no-unused-expression */
2
3import 'mocha'
4import * as request from 'supertest'
d50acfab 5import { flushTests, killallServers, makePostBodyRequest, runServer, ServerInfo, setAccessTokensToServers, uploadVideo } from '../../utils'
e2e22e40
C
6import { addVideoCommentThread } from '../../utils/video-comments'
7
8describe('Test video comments API validator', function () {
9 let pathThread: string
10 let pathComment: string
11 let server: ServerInfo
e2e22e40
C
12 let videoUUID: string
13 let commentId: number
14
15 // ---------------------------------------------------------------
16
17 before(async function () {
18 this.timeout(20000)
19
20 await flushTests()
21
22 server = await runServer(1)
23
24 await setAccessTokensToServers([ server ])
25
e2e22e40
C
26 {
27 const res = await uploadVideo(server.url, server.accessToken, {})
28 videoUUID = res.body.video.uuid
29 pathThread = '/api/v1/videos/' + videoUUID + '/comment-threads'
30 }
31
32 {
33 const res = await addVideoCommentThread(server.url, server.accessToken, videoUUID, 'coucou')
34 commentId = res.body.comment.id
35 pathComment = '/api/v1/videos/' + videoUUID + '/comments/' + commentId
36 }
37 })
38
39 describe('When listing video comment threads', function () {
40 it('Should fail with a bad start pagination', async function () {
41 await request(server.url)
42 .get(pathThread)
43 .query({ start: 'hello' })
44 .set('Accept', 'application/json')
45 .expect(400)
46 })
47
48 it('Should fail with a bad count pagination', async function () {
49 await request(server.url)
50 .get(pathThread)
51 .query({ count: 'hello' })
52 .set('Accept', 'application/json')
53 .expect(400)
54 })
55
56 it('Should fail with an incorrect sort', async function () {
57 await request(server.url)
58 .get(pathThread)
59 .query({ sort: 'hello' })
60 .set('Accept', 'application/json')
61 .expect(400)
62 })
63
64 it('Should fail with an incorrect video', async function () {
65 await request(server.url)
66 .get('/api/v1/videos/ba708d62-e3d7-45d9-9d73-41b9097cc02d/comment-threads')
67 .set('Accept', 'application/json')
68 .expect(404)
69 })
70 })
71
72 describe('When listing comments of a thread', function () {
73 it('Should fail with an incorrect video', async function () {
74 await request(server.url)
75 .get('/api/v1/videos/ba708d62-e3d7-45d9-9d73-41b9097cc02d/comment-threads/' + commentId)
76 .set('Accept', 'application/json')
77 .expect(404)
78 })
79
80 it('Should fail with an incorrect thread id', async function () {
81 await request(server.url)
82 .get('/api/v1/videos/' + videoUUID + '/comment-threads/156')
83 .set('Accept', 'application/json')
84 .expect(404)
85 })
86
87 it('Should success with the correct params', async function () {
88 await request(server.url)
89 .get('/api/v1/videos/' + videoUUID + '/comment-threads/' + commentId)
90 .set('Accept', 'application/json')
91 .expect(200)
92 })
93 })
94
95 describe('When adding a video thread', function () {
96
97 it('Should fail with a non authenticated user', async function () {
98 const fields = {
99 text: 'text'
100 }
101 await makePostBodyRequest({ url: server.url, path: pathThread, token: 'none', fields, statusCodeExpected: 401 })
102 })
103
104 it('Should fail with nothing', async function () {
105 const fields = {}
106 await makePostBodyRequest({ url: server.url, path: pathThread, token: server.accessToken, fields })
107 })
108
109 it('Should fail with a short comment', async function () {
110 const fields = {
111 text: 'h'.repeat(3001)
112 }
113 await makePostBodyRequest({ url: server.url, path: pathThread, token: server.accessToken, fields })
114 })
115
116 it('Should fail with a long comment', async function () {
117 const fields = {
118 text: 'h'.repeat(3001)
119 }
120 await makePostBodyRequest({ url: server.url, path: pathThread, token: server.accessToken, fields })
121 })
122
123 it('Should fail with an incorrect video', async function () {
124 const path = '/api/v1/videos/ba708d62-e3d7-45d9-9d73-41b9097cc02d/comment-threads'
125 const fields = {
126 text: 'super comment'
127 }
128 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 404 })
129 })
130
131 it('Should succeed with the correct parameters', async function () {
132 const fields = {
133 text: 'super comment'
134 }
135 await makePostBodyRequest({ url: server.url, path: pathThread, token: server.accessToken, fields, statusCodeExpected: 200 })
136 })
137 })
138
139 describe('When adding a comment to a thread', function () {
140 it('Should fail with a non authenticated user', async function () {
141 const fields = {
142 text: 'text'
143 }
144 await makePostBodyRequest({ url: server.url, path: pathComment, token: 'none', fields, statusCodeExpected: 401 })
145 })
146
147 it('Should fail with nothing', async function () {
148 const fields = {}
149 await makePostBodyRequest({ url: server.url, path: pathComment, token: server.accessToken, fields })
150 })
151
152 it('Should fail with a short comment', async function () {
153 const fields = {
154 text: 'h'.repeat(3001)
155 }
156 await makePostBodyRequest({ url: server.url, path: pathComment, token: server.accessToken, fields })
157 })
158
159 it('Should fail with a long comment', async function () {
160 const fields = {
161 text: 'h'.repeat(3001)
162 }
163 await makePostBodyRequest({ url: server.url, path: pathComment, token: server.accessToken, fields })
164 })
165
166 it('Should fail with an incorrect video', async function () {
167 const path = '/api/v1/videos/ba708d62-e3d7-45d9-9d73-41b9097cc02d/comments/' + commentId
168 const fields = {
169 text: 'super comment'
170 }
171 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 404 })
172 })
173
174 it('Should fail with an incorrect comment', async function () {
175 const path = '/api/v1/videos/' + videoUUID + '/comments/124'
176 const fields = {
177 text: 'super comment'
178 }
179 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 404 })
180 })
181
182 it('Should succeed with the correct parameters', async function () {
183 const fields = {
184 text: 'super comment'
185 }
186 await makePostBodyRequest({ url: server.url, path: pathComment, token: server.accessToken, fields, statusCodeExpected: 200 })
187 })
188 })
189
190 after(async function () {
191 killallServers([ server ])
192
193 // Keep the logs if the test failed
194 if (this['ok']) {
195 await flushTests()
196 }
197 })
198})