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