diff options
Diffstat (limited to 'server/tests')
-rw-r--r-- | server/tests/api/check-params/index.ts | 6 | ||||
-rw-r--r-- | server/tests/api/check-params/video-comments.ts | 212 | ||||
-rw-r--r-- | server/tests/api/video-comments.ts | 2 | ||||
-rw-r--r-- | server/tests/utils/video-comments.ts | 2 |
4 files changed, 218 insertions, 4 deletions
diff --git a/server/tests/api/check-params/index.ts b/server/tests/api/check-params/index.ts index b22bf054a..ab0aa1580 100644 --- a/server/tests/api/check-params/index.ts +++ b/server/tests/api/check-params/index.ts | |||
@@ -1,8 +1,10 @@ | |||
1 | // Order of the tests we want to execute | 1 | // Order of the tests we want to execute |
2 | import './follows' | 2 | import './follows' |
3 | import './jobs' | 3 | import './jobs' |
4 | import './users' | ||
5 | import './services' | 4 | import './services' |
6 | import './videos' | 5 | import './users' |
7 | import './video-abuses' | 6 | import './video-abuses' |
8 | import './video-blacklist' | 7 | import './video-blacklist' |
8 | import './video-channels' | ||
9 | import './video-comments' | ||
10 | import './videos' | ||
diff --git a/server/tests/api/check-params/video-comments.ts b/server/tests/api/check-params/video-comments.ts new file mode 100644 index 000000000..5112274f0 --- /dev/null +++ b/server/tests/api/check-params/video-comments.ts | |||
@@ -0,0 +1,212 @@ | |||
1 | /* tslint:disable:no-unused-expression */ | ||
2 | |||
3 | import 'mocha' | ||
4 | import * as request from 'supertest' | ||
5 | import { | ||
6 | createUser, flushTests, getUserAccessToken, killallServers, makePostBodyRequest, runServer, ServerInfo, setAccessTokensToServers, | ||
7 | uploadVideo | ||
8 | } from '../../utils' | ||
9 | import { addVideoCommentThread } from '../../utils/video-comments' | ||
10 | |||
11 | describe('Test video comments API validator', function () { | ||
12 | let pathThread: string | ||
13 | let pathComment: string | ||
14 | let server: ServerInfo | ||
15 | let accessTokenUser: string | ||
16 | let videoUUID: string | ||
17 | let commentId: number | ||
18 | |||
19 | // --------------------------------------------------------------- | ||
20 | |||
21 | before(async function () { | ||
22 | this.timeout(20000) | ||
23 | |||
24 | await flushTests() | ||
25 | |||
26 | server = await runServer(1) | ||
27 | |||
28 | await setAccessTokensToServers([ server ]) | ||
29 | |||
30 | { | ||
31 | const user = { | ||
32 | username: 'fake', | ||
33 | password: 'fake_password' | ||
34 | } | ||
35 | await createUser(server.url, server.accessToken, user.username, user.password) | ||
36 | |||
37 | accessTokenUser = await getUserAccessToken(server, user) | ||
38 | } | ||
39 | |||
40 | { | ||
41 | const res = await uploadVideo(server.url, server.accessToken, {}) | ||
42 | videoUUID = res.body.video.uuid | ||
43 | pathThread = '/api/v1/videos/' + videoUUID + '/comment-threads' | ||
44 | } | ||
45 | |||
46 | { | ||
47 | const res = await addVideoCommentThread(server.url, server.accessToken, videoUUID, 'coucou') | ||
48 | commentId = res.body.comment.id | ||
49 | pathComment = '/api/v1/videos/' + videoUUID + '/comments/' + commentId | ||
50 | } | ||
51 | }) | ||
52 | |||
53 | describe('When listing video comment threads', function () { | ||
54 | it('Should fail with a bad start pagination', async function () { | ||
55 | await request(server.url) | ||
56 | .get(pathThread) | ||
57 | .query({ start: 'hello' }) | ||
58 | .set('Accept', 'application/json') | ||
59 | .expect(400) | ||
60 | }) | ||
61 | |||
62 | it('Should fail with a bad count pagination', async function () { | ||
63 | await request(server.url) | ||
64 | .get(pathThread) | ||
65 | .query({ count: 'hello' }) | ||
66 | .set('Accept', 'application/json') | ||
67 | .expect(400) | ||
68 | }) | ||
69 | |||
70 | it('Should fail with an incorrect sort', async function () { | ||
71 | await request(server.url) | ||
72 | .get(pathThread) | ||
73 | .query({ sort: 'hello' }) | ||
74 | .set('Accept', 'application/json') | ||
75 | .expect(400) | ||
76 | }) | ||
77 | |||
78 | it('Should fail with an incorrect video', async function () { | ||
79 | await request(server.url) | ||
80 | .get('/api/v1/videos/ba708d62-e3d7-45d9-9d73-41b9097cc02d/comment-threads') | ||
81 | .set('Accept', 'application/json') | ||
82 | .expect(404) | ||
83 | }) | ||
84 | }) | ||
85 | |||
86 | describe('When listing comments of a thread', function () { | ||
87 | it('Should fail with an incorrect video', async function () { | ||
88 | await request(server.url) | ||
89 | .get('/api/v1/videos/ba708d62-e3d7-45d9-9d73-41b9097cc02d/comment-threads/' + commentId) | ||
90 | .set('Accept', 'application/json') | ||
91 | .expect(404) | ||
92 | }) | ||
93 | |||
94 | it('Should fail with an incorrect thread id', async function () { | ||
95 | await request(server.url) | ||
96 | .get('/api/v1/videos/' + videoUUID + '/comment-threads/156') | ||
97 | .set('Accept', 'application/json') | ||
98 | .expect(404) | ||
99 | }) | ||
100 | |||
101 | it('Should success with the correct params', async function () { | ||
102 | await request(server.url) | ||
103 | .get('/api/v1/videos/' + videoUUID + '/comment-threads/' + commentId) | ||
104 | .set('Accept', 'application/json') | ||
105 | .expect(200) | ||
106 | }) | ||
107 | }) | ||
108 | |||
109 | describe('When adding a video thread', function () { | ||
110 | |||
111 | it('Should fail with a non authenticated user', async function () { | ||
112 | const fields = { | ||
113 | text: 'text' | ||
114 | } | ||
115 | await makePostBodyRequest({ url: server.url, path: pathThread, token: 'none', fields, statusCodeExpected: 401 }) | ||
116 | }) | ||
117 | |||
118 | it('Should fail with nothing', async function () { | ||
119 | const fields = {} | ||
120 | await makePostBodyRequest({ url: server.url, path: pathThread, token: server.accessToken, fields }) | ||
121 | }) | ||
122 | |||
123 | it('Should fail with a short comment', async function () { | ||
124 | const fields = { | ||
125 | text: 'h'.repeat(3001) | ||
126 | } | ||
127 | await makePostBodyRequest({ url: server.url, path: pathThread, token: server.accessToken, fields }) | ||
128 | }) | ||
129 | |||
130 | it('Should fail with a long comment', async function () { | ||
131 | const fields = { | ||
132 | text: 'h'.repeat(3001) | ||
133 | } | ||
134 | await makePostBodyRequest({ url: server.url, path: pathThread, token: server.accessToken, fields }) | ||
135 | }) | ||
136 | |||
137 | it('Should fail with an incorrect video', async function () { | ||
138 | const path = '/api/v1/videos/ba708d62-e3d7-45d9-9d73-41b9097cc02d/comment-threads' | ||
139 | const fields = { | ||
140 | text: 'super comment' | ||
141 | } | ||
142 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 404 }) | ||
143 | }) | ||
144 | |||
145 | it('Should succeed with the correct parameters', async function () { | ||
146 | const fields = { | ||
147 | text: 'super comment' | ||
148 | } | ||
149 | await makePostBodyRequest({ url: server.url, path: pathThread, token: server.accessToken, fields, statusCodeExpected: 200 }) | ||
150 | }) | ||
151 | }) | ||
152 | |||
153 | describe('When adding a comment to a thread', function () { | ||
154 | it('Should fail with a non authenticated user', async function () { | ||
155 | const fields = { | ||
156 | text: 'text' | ||
157 | } | ||
158 | await makePostBodyRequest({ url: server.url, path: pathComment, token: 'none', fields, statusCodeExpected: 401 }) | ||
159 | }) | ||
160 | |||
161 | it('Should fail with nothing', async function () { | ||
162 | const fields = {} | ||
163 | await makePostBodyRequest({ url: server.url, path: pathComment, token: server.accessToken, fields }) | ||
164 | }) | ||
165 | |||
166 | it('Should fail with a short comment', async function () { | ||
167 | const fields = { | ||
168 | text: 'h'.repeat(3001) | ||
169 | } | ||
170 | await makePostBodyRequest({ url: server.url, path: pathComment, token: server.accessToken, fields }) | ||
171 | }) | ||
172 | |||
173 | it('Should fail with a long comment', async function () { | ||
174 | const fields = { | ||
175 | text: 'h'.repeat(3001) | ||
176 | } | ||
177 | await makePostBodyRequest({ url: server.url, path: pathComment, token: server.accessToken, fields }) | ||
178 | }) | ||
179 | |||
180 | it('Should fail with an incorrect video', async function () { | ||
181 | const path = '/api/v1/videos/ba708d62-e3d7-45d9-9d73-41b9097cc02d/comments/' + commentId | ||
182 | const fields = { | ||
183 | text: 'super comment' | ||
184 | } | ||
185 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 404 }) | ||
186 | }) | ||
187 | |||
188 | it('Should fail with an incorrect comment', async function () { | ||
189 | const path = '/api/v1/videos/' + videoUUID + '/comments/124' | ||
190 | const fields = { | ||
191 | text: 'super comment' | ||
192 | } | ||
193 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 404 }) | ||
194 | }) | ||
195 | |||
196 | it('Should succeed with the correct parameters', async function () { | ||
197 | const fields = { | ||
198 | text: 'super comment' | ||
199 | } | ||
200 | await makePostBodyRequest({ url: server.url, path: pathComment, token: server.accessToken, fields, statusCodeExpected: 200 }) | ||
201 | }) | ||
202 | }) | ||
203 | |||
204 | after(async function () { | ||
205 | killallServers([ server ]) | ||
206 | |||
207 | // Keep the logs if the test failed | ||
208 | if (this['ok']) { | ||
209 | await flushTests() | ||
210 | } | ||
211 | }) | ||
212 | }) | ||
diff --git a/server/tests/api/video-comments.ts b/server/tests/api/video-comments.ts index fbc1a0a20..2f1e6260a 100644 --- a/server/tests/api/video-comments.ts +++ b/server/tests/api/video-comments.ts | |||
@@ -8,7 +8,7 @@ import { addVideoCommentReply, addVideoCommentThread, getVideoCommentThreads, ge | |||
8 | 8 | ||
9 | const expect = chai.expect | 9 | const expect = chai.expect |
10 | 10 | ||
11 | describe('Test a video comments', function () { | 11 | describe('Test video comments', function () { |
12 | let server: ServerInfo | 12 | let server: ServerInfo |
13 | let videoId | 13 | let videoId |
14 | let videoUUID | 14 | let videoUUID |
diff --git a/server/tests/utils/video-comments.ts b/server/tests/utils/video-comments.ts index be062f815..6a6e225f3 100644 --- a/server/tests/utils/video-comments.ts +++ b/server/tests/utils/video-comments.ts | |||
@@ -25,7 +25,7 @@ function getVideoThreadComments (url: string, videoId: number, threadId: number) | |||
25 | .expect('Content-Type', /json/) | 25 | .expect('Content-Type', /json/) |
26 | } | 26 | } |
27 | 27 | ||
28 | function addVideoCommentThread (url: string, token: string, videoId: number, text: string, expectedStatus = 200) { | 28 | function addVideoCommentThread (url: string, token: string, videoId: number | string, text: string, expectedStatus = 200) { |
29 | const path = '/api/v1/videos/' + videoId + '/comment-threads' | 29 | const path = '/api/v1/videos/' + videoId + '/comment-threads' |
30 | 30 | ||
31 | return request(url) | 31 | return request(url) |