aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/check-params
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests/api/check-params')
-rw-r--r--server/tests/api/check-params/follows.ts1
-rw-r--r--server/tests/api/check-params/jobs.ts3
-rw-r--r--server/tests/api/check-params/video-abuses.ts84
-rw-r--r--server/tests/api/check-params/video-blacklist.ts109
-rw-r--r--server/tests/api/check-params/video-channels.ts206
-rw-r--r--server/tests/api/check-params/video-comments.ts64
-rw-r--r--server/tests/api/check-params/videos.ts374
7 files changed, 296 insertions, 545 deletions
diff --git a/server/tests/api/check-params/follows.ts b/server/tests/api/check-params/follows.ts
index d5fcb7477..e54f139f0 100644
--- a/server/tests/api/check-params/follows.ts
+++ b/server/tests/api/check-params/follows.ts
@@ -1,7 +1,6 @@
1/* tslint:disable:no-unused-expression */ 1/* tslint:disable:no-unused-expression */
2 2
3import 'mocha' 3import 'mocha'
4import * as request from 'supertest'
5 4
6import { 5import {
7 createUser, flushTests, killallServers, makeDeleteRequest, makePostBodyRequest, runServer, ServerInfo, setAccessTokensToServers, 6 createUser, flushTests, killallServers, makeDeleteRequest, makePostBodyRequest, runServer, ServerInfo, setAccessTokensToServers,
diff --git a/server/tests/api/check-params/jobs.ts b/server/tests/api/check-params/jobs.ts
index 46b05cb4e..b12818bb1 100644
--- a/server/tests/api/check-params/jobs.ts
+++ b/server/tests/api/check-params/jobs.ts
@@ -1,9 +1,8 @@
1/* tslint:disable:no-unused-expression */ 1/* tslint:disable:no-unused-expression */
2 2
3import 'mocha' 3import 'mocha'
4import * as request from 'supertest'
5 4
6import { createUser, flushTests, userLogin, killallServers, runServer, ServerInfo, setAccessTokensToServers } from '../../utils' 5import { createUser, flushTests, killallServers, runServer, ServerInfo, setAccessTokensToServers, userLogin } from '../../utils'
7import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../utils/requests/check-api-params' 6import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../utils/requests/check-api-params'
8import { makeGetRequest } from '../../utils/requests/requests' 7import { makeGetRequest } from '../../utils/requests/requests'
9 8
diff --git a/server/tests/api/check-params/video-abuses.ts b/server/tests/api/check-params/video-abuses.ts
index e994ccd49..68e2ce786 100644
--- a/server/tests/api/check-params/video-abuses.ts
+++ b/server/tests/api/check-params/video-abuses.ts
@@ -1,20 +1,12 @@
1/* tslint:disable:no-unused-expression */ 1/* tslint:disable:no-unused-expression */
2 2
3import * as request from 'supertest'
4import 'mocha' 3import 'mocha'
5 4
6import { 5import {
7 ServerInfo, 6 createUser, flushTests, killallServers, makeGetRequest, makePostBodyRequest, runServer, ServerInfo, setAccessTokensToServers,
8 flushTests, 7 uploadVideo, userLogin
9 runServer,
10 uploadVideo,
11 getVideosList,
12 createUser,
13 setAccessTokensToServers,
14 killallServers,
15 makePostBodyRequest,
16 userLogin
17} from '../../utils' 8} from '../../utils'
9import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../utils/requests/check-api-params'
18 10
19describe('Test video abuses API validators', function () { 11describe('Test video abuses API validators', function () {
20 let server: ServerInfo 12 let server: ServerInfo
@@ -34,63 +26,42 @@ describe('Test video abuses API validators', function () {
34 const username = 'user1' 26 const username = 'user1'
35 const password = 'my super password' 27 const password = 'my super password'
36 await createUser(server.url, server.accessToken, username, password) 28 await createUser(server.url, server.accessToken, username, password)
37
38 userAccessToken = await userLogin(server, { username, password }) 29 userAccessToken = await userLogin(server, { username, password })
39 30
40 // Upload a video 31 const res = await uploadVideo(server.url, server.accessToken, {})
41 const videoAttributes = {} 32 server.video = res.body.video
42 await uploadVideo(server.url, server.accessToken, videoAttributes)
43
44 const res = await getVideosList(server.url)
45 const videos = res.body.data
46 server.video = videos[0]
47 }) 33 })
48 34
49 describe('When listing video abuses', function () { 35 describe('When listing video abuses', function () {
50 const path = '/api/v1/videos/abuse' 36 const path = '/api/v1/videos/abuse'
51 37
52 it('Should fail with a bad start pagination', async function () { 38 it('Should fail with a bad start pagination', async function () {
53 await request(server.url) 39 await checkBadStartPagination(server.url, path, server.accessToken)
54 .get(path)
55 .query({ start: 'hello' })
56 .set('Authorization', 'Bearer ' + server.accessToken)
57 .set('Accept', 'application/json')
58 .expect(400)
59 }) 40 })
60 41
61 it('Should fail with a bad count pagination', async function () { 42 it('Should fail with a bad count pagination', async function () {
62 await request(server.url) 43 await checkBadCountPagination(server.url, path, server.accessToken)
63 .get(path)
64 .query({ count: 'hello' })
65 .set('Accept', 'application/json')
66 .set('Authorization', 'Bearer ' + server.accessToken)
67 .expect(400)
68 }) 44 })
69 45
70 it('Should fail with an incorrect sort', async function () { 46 it('Should fail with an incorrect sort', async function () {
71 await request(server.url) 47 await checkBadSortPagination(server.url, path, server.accessToken)
72 .get(path)
73 .query({ sort: 'hello' })
74 .set('Accept', 'application/json')
75 .set('Authorization', 'Bearer ' + server.accessToken)
76 .expect(400)
77 }) 48 })
78 49
79 it('Should fail with a non authenticated user', async function () { 50 it('Should fail with a non authenticated user', async function () {
80 await request(server.url) 51 await makeGetRequest({
81 .get(path) 52 url: server.url,
82 .query({ sort: 'hello' }) 53 path,
83 .set('Accept', 'application/json') 54 statusCodeExpected: 401
84 .expect(401) 55 })
85 }) 56 })
86 57
87 it('Should fail with a non admin user', async function () { 58 it('Should fail with a non admin user', async function () {
88 await request(server.url) 59 await makeGetRequest({
89 .get(path) 60 url: server.url,
90 .query({ sort: 'hello' }) 61 path,
91 .set('Accept', 'application/json') 62 token: userAccessToken,
92 .set('Authorization', 'Bearer ' + userAccessToken) 63 statusCodeExpected: 403
93 .expect(403) 64 })
94 }) 65 })
95 }) 66 })
96 67
@@ -105,32 +76,33 @@ describe('Test video abuses API validators', function () {
105 76
106 it('Should fail with a wrong video', async function () { 77 it('Should fail with a wrong video', async function () {
107 const wrongPath = '/api/v1/videos/blabla/abuse' 78 const wrongPath = '/api/v1/videos/blabla/abuse'
108 const fields = {} 79 const fields = {
80 reason: 'my super reason'
81 }
109 await makePostBodyRequest({ url: server.url, path: wrongPath, token: server.accessToken, fields }) 82 await makePostBodyRequest({ url: server.url, path: wrongPath, token: server.accessToken, fields })
110 }) 83 })
111 84
112 it('Should fail with a non authenticated user', async function () { 85 it('Should fail with a non authenticated user', async function () {
113 const fields = {}
114 const path = basePath + server.video.id + '/abuse' 86 const path = basePath + server.video.id + '/abuse'
87 const fields = {
88 reason: 'my super reason'
89 }
115 await makePostBodyRequest({ url: server.url, path, token: 'hello', fields, statusCodeExpected: 401 }) 90 await makePostBodyRequest({ url: server.url, path, token: 'hello', fields, statusCodeExpected: 401 })
116 }) 91 })
117 92
118 it('Should fail with a reason too short', async function () { 93 it('Should fail with a reason too short', async function () {
94 const path = basePath + server.video.id + '/abuse'
119 const fields = { 95 const fields = {
120 reason: 'h' 96 reason: 'h'
121 } 97 }
122 const path = basePath + server.video.id + '/abuse'
123 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) 98 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
124 }) 99 })
125 100
126 it('Should fail with a reason too big', async function () { 101 it('Should fail with a reason too big', async function () {
102 const path = basePath + server.video.id + '/abuse'
127 const fields = { 103 const fields = {
128 reason: '0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef' + 104 reason: 'super'.repeat(61)
129 '0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef' +
130 '0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef' +
131 '0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef'
132 } 105 }
133 const path = basePath + server.video.id + '/abuse'
134 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) 106 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
135 }) 107 })
136 }) 108 })
diff --git a/server/tests/api/check-params/video-blacklist.ts b/server/tests/api/check-params/video-blacklist.ts
index c8b457182..6cd13d23f 100644
--- a/server/tests/api/check-params/video-blacklist.ts
+++ b/server/tests/api/check-params/video-blacklist.ts
@@ -1,20 +1,12 @@
1/* tslint:disable:no-unused-expression */ 1/* tslint:disable:no-unused-expression */
2 2
3import 'mocha' 3import 'mocha'
4import * as request from 'supertest'
5 4
6import { 5import {
7 ServerInfo, 6 createUser, flushTests, getBlacklistedVideosList, killallServers, makePostBodyRequest, removeVideoFromBlacklist, runServer,
8 flushTests, 7 ServerInfo, setAccessTokensToServers, uploadVideo, userLogin
9 runServer,
10 uploadVideo,
11 getVideosList,
12 createUser,
13 setAccessTokensToServers,
14 killallServers,
15 makePostBodyRequest,
16 userLogin
17} from '../../utils' 8} from '../../utils'
9import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../utils/requests/check-api-params'
18 10
19describe('Test video blacklist API validators', function () { 11describe('Test video blacklist API validators', function () {
20 let server: ServerInfo 12 let server: ServerInfo
@@ -36,14 +28,8 @@ describe('Test video blacklist API validators', function () {
36 await createUser(server.url, server.accessToken, username, password) 28 await createUser(server.url, server.accessToken, username, password)
37 userAccessToken = await userLogin(server, { username, password }) 29 userAccessToken = await userLogin(server, { username, password })
38 30
39 // Upload a video 31 const res = await uploadVideo(server.url, server.accessToken, {})
40 const videoAttributes = {} 32 server.video = res.body.video
41 await uploadVideo(server.url, server.accessToken, videoAttributes)
42
43 const res = await getVideosList(server.url)
44
45 const videos = res.body.data
46 server.video = videos[0]
47 }) 33 })
48 34
49 describe('When adding a video in blacklist', function () { 35 describe('When adding a video in blacklist', function () {
@@ -62,66 +48,40 @@ describe('Test video blacklist API validators', function () {
62 }) 48 })
63 49
64 it('Should fail with a non authenticated user', async function () { 50 it('Should fail with a non authenticated user', async function () {
65 const fields = {}
66 const path = basePath + server.video + '/blacklist' 51 const path = basePath + server.video + '/blacklist'
52 const fields = {}
67 await makePostBodyRequest({ url: server.url, path, token: 'hello', fields, statusCodeExpected: 401 }) 53 await makePostBodyRequest({ url: server.url, path, token: 'hello', fields, statusCodeExpected: 401 })
68 }) 54 })
69 55
70 it('Should fail with a non admin user', async function () { 56 it('Should fail with a non admin user', async function () {
71 const fields = {}
72 const path = basePath + server.video + '/blacklist' 57 const path = basePath + server.video + '/blacklist'
58 const fields = {}
73 await makePostBodyRequest({ url: server.url, path, token: userAccessToken, fields, statusCodeExpected: 403 }) 59 await makePostBodyRequest({ url: server.url, path, token: userAccessToken, fields, statusCodeExpected: 403 })
74 }) 60 })
75 61
76 it('Should fail with a local video', async function () { 62 it('Should fail with a local video', async function () {
77 const fields = {}
78 const path = basePath + server.video.id + '/blacklist' 63 const path = basePath + server.video.id + '/blacklist'
64 const fields = {}
79 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 403 }) 65 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 403 })
80 }) 66 })
81 }) 67 })
82 68
83 describe('When removing a video in blacklist', function () { 69 describe('When removing a video in blacklist', function () {
84 const basePath = '/api/v1/videos/'
85
86 it('Should fail with a non authenticated user', async function () { 70 it('Should fail with a non authenticated user', async function () {
87 const path = basePath + server.video.id + '/blacklist' 71 await removeVideoFromBlacklist(server.url, 'fake token', server.video.id, 401)
88
89 await request(server.url)
90 .delete(path)
91 .set('Authorization', 'Bearer ' + 'fake token')
92 .set('Accept', 'application/json')
93 .expect(401)
94 }) 72 })
95 73
96 it('Should fail with a non admin user', async function () { 74 it('Should fail with a non admin user', async function () {
97 const path = basePath + server.video.id + '/blacklist' 75 await removeVideoFromBlacklist(server.url, userAccessToken, server.video.id, 403)
98
99 await request(server.url)
100 .delete(path)
101 .set('Authorization', 'Bearer ' + userAccessToken)
102 .set('Accept', 'application/json')
103 .expect(403)
104 }) 76 })
105 77
106 it('Should fail with an incorrect id', async function () { 78 it('Should fail with an incorrect id', async function () {
107 const path = basePath + 'foobar/blacklist' 79 await removeVideoFromBlacklist(server.url, server.accessToken, 'hello', 400)
108
109 await request(server.url)
110 .delete(path)
111 .set('Authorization', 'Bearer ' + server.accessToken)
112 .set('Accept', 'application/json')
113 .expect(400)
114 }) 80 })
115 81
116 it('Should fail with a not blacklisted video', async function () { 82 it('Should fail with a not blacklisted video', async function () {
117 // The video was not added to the blacklist so it should fail 83 // The video was not added to the blacklist so it should fail
118 const path = basePath + server.video.id + '/blacklist' 84 await removeVideoFromBlacklist(server.url, server.accessToken, server.video.id, 404)
119
120 await request(server.url)
121 .delete(path)
122 .set('Authorization', 'Bearer ' + server.accessToken)
123 .set('Accept', 'application/json')
124 .expect(404)
125 }) 85 })
126 }) 86 })
127 87
@@ -129,58 +89,23 @@ describe('Test video blacklist API validators', function () {
129 const basePath = '/api/v1/videos/blacklist/' 89 const basePath = '/api/v1/videos/blacklist/'
130 90
131 it('Should fail with a non authenticated user', async function () { 91 it('Should fail with a non authenticated user', async function () {
132 const path = basePath 92 await getBlacklistedVideosList(server.url, 'fake token', 401)
133
134 await request(server.url)
135 .get(path)
136 .query({ sort: 'createdAt' })
137 .set('Accept', 'application/json')
138 .set('Authorization', 'Bearer ' + 'fake token')
139 .expect(401)
140 }) 93 })
141 94
142 it('Should fail with a non admin user', async function () { 95 it('Should fail with a non admin user', async function () {
143 const path = basePath 96 await getBlacklistedVideosList(server.url, userAccessToken, 403)
144
145 await request(server.url)
146 .get(path)
147 .query({ sort: 'createdAt' })
148 .set('Authorization', 'Bearer ' + userAccessToken)
149 .set('Accept', 'application/json')
150 .expect(403)
151 }) 97 })
152 98
153 it('Should fail with a bad start pagination', async function () { 99 it('Should fail with a bad start pagination', async function () {
154 const path = basePath 100 await checkBadStartPagination(server.url, basePath, server.accessToken)
155
156 await request(server.url)
157 .get(path)
158 .query({ start: 'foobar' })
159 .set('Accept', 'application/json')
160 .set('Authorization', 'Bearer ' + server.accessToken)
161 .expect(400)
162 }) 101 })
163 102
164 it('Should fail with a bad count pagination', async function () { 103 it('Should fail with a bad count pagination', async function () {
165 const path = basePath 104 await checkBadCountPagination(server.url, basePath, server.accessToken)
166
167 await request(server.url)
168 .get(path)
169 .query({ count: 'foobar' })
170 .set('Accept', 'application/json')
171 .set('Authorization', 'Bearer ' + server.accessToken)
172 .expect(400)
173 }) 105 })
174 106
175 it('Should fail with an incorrect sort', async function () { 107 it('Should fail with an incorrect sort', async function () {
176 const path = basePath 108 await checkBadSortPagination(server.url, basePath, server.accessToken)
177
178 await request(server.url)
179 .get(path)
180 .query({ sort: 'foobar' })
181 .set('Accept', 'application/json')
182 .set('Authorization', 'Bearer ' + server.accessToken)
183 .expect(400)
184 }) 109 })
185 }) 110 })
186 111
diff --git a/server/tests/api/check-params/video-channels.ts b/server/tests/api/check-params/video-channels.ts
index bf464152b..22e98d110 100644
--- a/server/tests/api/check-params/video-channels.ts
+++ b/server/tests/api/check-params/video-channels.ts
@@ -1,22 +1,15 @@
1/* tslint:disable:no-unused-expression */ 1/* tslint:disable:no-unused-expression */
2 2
3import * as request from 'supertest'
4import 'mocha'
5import * as chai from 'chai' 3import * as chai from 'chai'
6const expect = chai.expect 4import { omit } from 'lodash'
7 5import 'mocha'
8import { 6import {
9 ServerInfo, 7 createUser, deleteVideoChannel, flushTests, getAccountVideoChannelsList, getVideoChannelsList, immutableAssign, killallServers,
10 flushTests, 8 makeGetRequest, makePostBodyRequest, makePutBodyRequest, runServer, ServerInfo, setAccessTokensToServers, userLogin
11 runServer,
12 makePutBodyRequest,
13 setAccessTokensToServers,
14 killallServers,
15 makePostBodyRequest,
16 getVideoChannelsList,
17 createUser,
18 userLogin
19} from '../../utils' 9} from '../../utils'
10import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../utils/requests/check-api-params'
11
12const expect = chai.expect
20 13
21describe('Test videos API validator', function () { 14describe('Test videos API validator', function () {
22 const path = '/api/v1/videos/channels' 15 const path = '/api/v1/videos/channels'
@@ -39,64 +32,41 @@ describe('Test videos API validator', function () {
39 password: 'fake_password' 32 password: 'fake_password'
40 } 33 }
41 await createUser(server.url, server.accessToken, user.username, user.password) 34 await createUser(server.url, server.accessToken, user.username, user.password)
42
43 accessTokenUser = await userLogin(server, user) 35 accessTokenUser = await userLogin(server, user)
44 }) 36 })
45 37
46 describe('When listing a video channels', function () { 38 describe('When listing a video channels', function () {
47 it('Should fail with a bad start pagination', async function () { 39 it('Should fail with a bad start pagination', async function () {
48 await request(server.url) 40 await checkBadStartPagination(server.url, path, server.accessToken)
49 .get(path)
50 .query({ start: 'hello' })
51 .set('Accept', 'application/json')
52 .expect(400)
53 }) 41 })
54 42
55 it('Should fail with a bad count pagination', async function () { 43 it('Should fail with a bad count pagination', async function () {
56 await request(server.url) 44 await checkBadCountPagination(server.url, path, server.accessToken)
57 .get(path)
58 .query({ count: 'hello' })
59 .set('Accept', 'application/json')
60 .expect(400)
61 }) 45 })
62 46
63 it('Should fail with an incorrect sort', async function () { 47 it('Should fail with an incorrect sort', async function () {
64 await request(server.url) 48 await checkBadSortPagination(server.url, path, server.accessToken)
65 .get(path)
66 .query({ sort: 'hello' })
67 .set('Accept', 'application/json')
68 .expect(400)
69 }) 49 })
70 }) 50 })
71 51
72 describe('When listing account video channels', function () { 52 describe('When listing account video channels', function () {
73 it('Should fail with bad account', async function () { 53 it('Should fail with bad account', async function () {
74 const path = '/api/v1/videos/accounts/hello/channels' 54 await getAccountVideoChannelsList(server.url, 'hello', 400)
75
76 await request(server.url)
77 .get(path)
78 .set('Accept', 'application/json')
79 .expect(400)
80 }) 55 })
81 56
82 it('Should fail with a unknown account', async function () { 57 it('Should fail with a unknown account', async function () {
83 const path = '/api/v1/videos/accounts/156/channels' 58 await getAccountVideoChannelsList(server.url, 154, 404)
84
85 await request(server.url)
86 .get(path)
87 .set('Accept', 'application/json')
88 .expect(404)
89 }) 59 })
90 }) 60 })
91 61
92 describe('When adding a video channel', function () { 62 describe('When adding a video channel', function () {
63 const baseCorrectParams = {
64 name: 'hello',
65 description: 'super description'
66 }
93 67
94 it('Should fail with a non authenticated user', async function () { 68 it('Should fail with a non authenticated user', async function () {
95 const fields = { 69 await makePostBodyRequest({ url: server.url, path, token: 'none', fields: baseCorrectParams, statusCodeExpected: 401 })
96 name: 'hello',
97 description: 'super description'
98 }
99 await makePostBodyRequest({ url: server.url, path, token: 'none', fields, statusCodeExpected: 401 })
100 }) 70 })
101 71
102 it('Should fail with nothing', async function () { 72 it('Should fail with nothing', async function () {
@@ -105,45 +75,37 @@ describe('Test videos API validator', function () {
105 }) 75 })
106 76
107 it('Should fail without name', async function () { 77 it('Should fail without name', async function () {
108 const fields = { 78 const fields = omit(baseCorrectParams, 'name')
109 description: 'super description'
110 }
111 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) 79 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
112 }) 80 })
113 81
114 it('Should fail with a long name', async function () { 82 it('Should fail with a long name', async function () {
115 const fields = { 83 const fields = immutableAssign(baseCorrectParams, { name: 'super'.repeat(25) })
116 name: 'hello tooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo' +
117 'oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo' +
118 'oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo' +
119 'oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo' +
120 'oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo long',
121 description: 'super description'
122 }
123 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) 84 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
124 }) 85 })
125 86
126 it('Should fail with a long description', async function () { 87 it('Should fail with a long description', async function () {
127 const fields = { 88 const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(60) })
128 name: 'hello',
129 description: 'super toooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo' +
130 'oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo0' +
131 'ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo' +
132 'oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo long description'
133 }
134 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) 89 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
135 }) 90 })
136 91
137 it('Should succeed with the correct parameters', async function () { 92 it('Should succeed with the correct parameters', async function () {
138 const fields = { 93 await makePostBodyRequest({
139 name: 'hello', 94 url: server.url,
140 description: 'super description' 95 path,
141 } 96 token: server.accessToken,
142 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 204 }) 97 fields: baseCorrectParams,
98 statusCodeExpected: 204
99 })
143 }) 100 })
144 }) 101 })
145 102
146 describe('When updating a video channel', function () { 103 describe('When updating a video channel', function () {
104 const baseCorrectParams = {
105 name: 'hello',
106 description: 'super description'
107 }
108
147 let videoChannelId 109 let videoChannelId
148 110
149 before(async function () { 111 before(async function () {
@@ -152,60 +114,41 @@ describe('Test videos API validator', function () {
152 }) 114 })
153 115
154 it('Should fail with a non authenticated user', async function () { 116 it('Should fail with a non authenticated user', async function () {
155 const fields = { 117 await makePutBodyRequest({
156 name: 'hello', 118 url: server.url,
157 description: 'super description' 119 path: path + '/' + videoChannelId,
158 } 120 token: 'hi',
159 await makePutBodyRequest({ url: server.url, path: path + '/' + videoChannelId, token: 'hi', fields, statusCodeExpected: 401 }) 121 fields: baseCorrectParams,
122 statusCodeExpected: 401
123 })
160 }) 124 })
161 125
162 it('Should fail with another authenticated user', async function () { 126 it('Should fail with another authenticated user', async function () {
163 const fields = {
164 name: 'hello',
165 description: 'super description'
166 }
167 await makePutBodyRequest({ 127 await makePutBodyRequest({
168 url: server.url, 128 url: server.url,
169 path: path + '/' + videoChannelId, 129 path: path + '/' + videoChannelId,
170 token: accessTokenUser, 130 token: accessTokenUser,
171 fields, 131 fields: baseCorrectParams,
172 statusCodeExpected: 403 132 statusCodeExpected: 403
173 }) 133 })
174 }) 134 })
175 135
176 it('Should fail with a long name', async function () { 136 it('Should fail with a long name', async function () {
177 const fields = { 137 const fields = immutableAssign(baseCorrectParams, { name: 'super'.repeat(25) })
178 name: 'hello tooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo' +
179 'oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo' +
180 'oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo' +
181 'oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo' +
182 'oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo long',
183 description: 'super description'
184 }
185 await makePutBodyRequest({ url: server.url, path: path + '/' + videoChannelId, token: server.accessToken, fields }) 138 await makePutBodyRequest({ url: server.url, path: path + '/' + videoChannelId, token: server.accessToken, fields })
186 }) 139 })
187 140
188 it('Should fail with a long description', async function () { 141 it('Should fail with a long description', async function () {
189 const fields = { 142 const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(60) })
190 name: 'hello',
191 description: 'super toooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo' +
192 'oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo0' +
193 'ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo' +
194 'oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo long description'
195 }
196 await makePutBodyRequest({ url: server.url, path: path + '/' + videoChannelId, token: server.accessToken, fields }) 143 await makePutBodyRequest({ url: server.url, path: path + '/' + videoChannelId, token: server.accessToken, fields })
197 }) 144 })
198 145
199 it('Should succeed with the correct parameters', async function () { 146 it('Should succeed with the correct parameters', async function () {
200 const fields = {
201 name: 'hello 2',
202 description: 'super description 2'
203 }
204 await makePutBodyRequest({ 147 await makePutBodyRequest({
205 url: server.url, 148 url: server.url,
206 path: path + '/' + videoChannelId, 149 path: path + '/' + videoChannelId,
207 token: server.accessToken, 150 token: server.accessToken,
208 fields, 151 fields: baseCorrectParams,
209 statusCodeExpected: 204 152 statusCodeExpected: 204
210 }) 153 })
211 }) 154 })
@@ -220,34 +163,37 @@ describe('Test videos API validator', function () {
220 }) 163 })
221 164
222 it('Should return the list of the video channels with nothing', async function () { 165 it('Should return the list of the video channels with nothing', async function () {
223 const res = await request(server.url) 166 const res = await makeGetRequest({
224 .get(path) 167 url: server.url,
225 .set('Accept', 'application/json') 168 path,
226 .expect(200) 169 statusCodeExpected: 200
227 .expect('Content-Type', /json/) 170 })
228 171
229 expect(res.body.data).to.be.an('array') 172 expect(res.body.data).to.be.an('array')
230 }) 173 })
231 174
232 it('Should fail without a correct uuid', async function () { 175 it('Should fail without a correct uuid', async function () {
233 await request(server.url) 176 await makeGetRequest({
234 .get(path + '/coucou') 177 url: server.url,
235 .set('Accept', 'application/json') 178 path: path + '/coucou',
236 .expect(400) 179 statusCodeExpected: 400
180 })
237 }) 181 })
238 182
239 it('Should return 404 with an incorrect video channel', async function () { 183 it('Should return 404 with an incorrect video channel', async function () {
240 await request(server.url) 184 await makeGetRequest({
241 .get(path + '/4da6fde3-88f7-4d16-b119-108df5630b06') 185 url: server.url,
242 .set('Accept', 'application/json') 186 path: path + '/4da6fde3-88f7-4d16-b119-108df5630b06',
243 .expect(404) 187 statusCodeExpected: 404
188 })
244 }) 189 })
245 190
246 it('Should succeed with the correct parameters', async function () { 191 it('Should succeed with the correct parameters', async function () {
247 await request(server.url) 192 await makeGetRequest({
248 .get(path + '/' + videoChannelId) 193 url: server.url,
249 .set('Accept', 'application/json') 194 path: path + '/' + videoChannelId,
250 .expect(200) 195 statusCodeExpected: 200
196 })
251 }) 197 })
252 }) 198 })
253 199
@@ -260,42 +206,26 @@ describe('Test videos API validator', function () {
260 }) 206 })
261 207
262 it('Should fail with a non authenticated user', async function () { 208 it('Should fail with a non authenticated user', async function () {
263 await request(server.url) 209 await deleteVideoChannel(server.url, 'coucou', videoChannelId, 401)
264 .delete(path + '/' + videoChannelId)
265 .set('Authorization', 'Bearer coucou')
266 .expect(401)
267 }) 210 })
268 211
269 it('Should fail with another authenticated user', async function () { 212 it('Should fail with another authenticated user', async function () {
270 await request(server.url) 213 await deleteVideoChannel(server.url, accessTokenUser, videoChannelId, 403)
271 .delete(path + '/' + videoChannelId)
272 .set('Authorization', 'Bearer ' + accessTokenUser)
273 .expect(403)
274 }) 214 })
275 215
276 it('Should fail with an unknown id', async function () { 216 it('Should fail with an unknown id', async function () {
277 await request(server.url) 217 await deleteVideoChannel(server.url, server.accessToken, 454554, 404)
278 .delete(path + '/454554')
279 .set('Authorization', 'Bearer ' + server.accessToken)
280 .expect(404)
281 }) 218 })
282 219
283 it('Should succeed with the correct parameters', async function () { 220 it('Should succeed with the correct parameters', async function () {
284 await request(server.url) 221 await deleteVideoChannel(server.url, server.accessToken, videoChannelId)
285 .delete(path + '/' + videoChannelId)
286 .set('Authorization', 'Bearer ' + server.accessToken)
287 .expect(204)
288 }) 222 })
289 223
290 it('Should fail to delete the last user video channel', async function () { 224 it('Should fail to delete the last user video channel', async function () {
291 const res = await getVideoChannelsList(server.url, 0, 1) 225 const res = await getVideoChannelsList(server.url, 0, 1)
292 videoChannelId = res.body.data[0].id 226 videoChannelId = res.body.data[0].id
293 227
294 await request(server.url) 228 await deleteVideoChannel(server.url, server.accessToken, videoChannelId, 409)
295 .delete(path + '/' + videoChannelId)
296 .set('Authorization', 'Bearer ' + server.accessToken)
297 .expect(409
298 )
299 }) 229 })
300 }) 230 })
301 231
diff --git a/server/tests/api/check-params/video-comments.ts b/server/tests/api/check-params/video-comments.ts
index f3832bd2c..cdb48a276 100644
--- a/server/tests/api/check-params/video-comments.ts
+++ b/server/tests/api/check-params/video-comments.ts
@@ -1,8 +1,11 @@
1/* tslint:disable:no-unused-expression */ 1/* tslint:disable:no-unused-expression */
2 2
3import 'mocha' 3import 'mocha'
4import * as request from 'supertest' 4import {
5import { flushTests, killallServers, makePostBodyRequest, runServer, ServerInfo, setAccessTokensToServers, uploadVideo } from '../../utils' 5 flushTests, killallServers, makeGetRequest, makePostBodyRequest, runServer, ServerInfo, setAccessTokensToServers,
6 uploadVideo
7} from '../../utils'
8import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../utils/requests/check-api-params'
6import { addVideoCommentThread } from '../../utils/videos/video-comments' 9import { addVideoCommentThread } from '../../utils/videos/video-comments'
7 10
8describe('Test video comments API validator', function () { 11describe('Test video comments API validator', function () {
@@ -38,57 +41,52 @@ describe('Test video comments API validator', function () {
38 41
39 describe('When listing video comment threads', function () { 42 describe('When listing video comment threads', function () {
40 it('Should fail with a bad start pagination', async function () { 43 it('Should fail with a bad start pagination', async function () {
41 await request(server.url) 44 await checkBadStartPagination(server.url, pathThread, server.accessToken)
42 .get(pathThread) 45
43 .query({ start: 'hello' })
44 .set('Accept', 'application/json')
45 .expect(400)
46 }) 46 })
47 47
48 it('Should fail with a bad count pagination', async function () { 48 it('Should fail with a bad count pagination', async function () {
49 await request(server.url) 49 await checkBadCountPagination(server.url, pathThread, server.accessToken)
50 .get(pathThread) 50
51 .query({ count: 'hello' })
52 .set('Accept', 'application/json')
53 .expect(400)
54 }) 51 })
55 52
56 it('Should fail with an incorrect sort', async function () { 53 it('Should fail with an incorrect sort', async function () {
57 await request(server.url) 54 await checkBadSortPagination(server.url, pathThread, server.accessToken)
58 .get(pathThread) 55
59 .query({ sort: 'hello' })
60 .set('Accept', 'application/json')
61 .expect(400)
62 }) 56 })
63 57
64 it('Should fail with an incorrect video', async function () { 58 it('Should fail with an incorrect video', async function () {
65 await request(server.url) 59 await makeGetRequest({
66 .get('/api/v1/videos/ba708d62-e3d7-45d9-9d73-41b9097cc02d/comment-threads') 60 url: server.url,
67 .set('Accept', 'application/json') 61 path: '/api/v1/videos/ba708d62-e3d7-45d9-9d73-41b9097cc02d/comment-threads',
68 .expect(404) 62 statusCodeExpected: 404
63 })
69 }) 64 })
70 }) 65 })
71 66
72 describe('When listing comments of a thread', function () { 67 describe('When listing comments of a thread', function () {
73 it('Should fail with an incorrect video', async function () { 68 it('Should fail with an incorrect video', async function () {
74 await request(server.url) 69 await makeGetRequest({
75 .get('/api/v1/videos/ba708d62-e3d7-45d9-9d73-41b9097cc02d/comment-threads/' + commentId) 70 url: server.url,
76 .set('Accept', 'application/json') 71 path: '/api/v1/videos/ba708d62-e3d7-45d9-9d73-41b9097cc02d/comment-threads/' + commentId,
77 .expect(404) 72 statusCodeExpected: 404
73 })
78 }) 74 })
79 75
80 it('Should fail with an incorrect thread id', async function () { 76 it('Should fail with an incorrect thread id', async function () {
81 await request(server.url) 77 await makeGetRequest({
82 .get('/api/v1/videos/' + videoUUID + '/comment-threads/156') 78 url: server.url,
83 .set('Accept', 'application/json') 79 path: '/api/v1/videos/' + videoUUID + '/comment-threads/156',
84 .expect(404) 80 statusCodeExpected: 404
81 })
85 }) 82 })
86 83
87 it('Should success with the correct params', async function () { 84 it('Should success with the correct params', async function () {
88 await request(server.url) 85 await makeGetRequest({
89 .get('/api/v1/videos/' + videoUUID + '/comment-threads/' + commentId) 86 url: server.url,
90 .set('Accept', 'application/json') 87 path: '/api/v1/videos/' + videoUUID + '/comment-threads/' + commentId,
91 .expect(200) 88 statusCodeExpected: 200
89 })
92 }) 90 })
93 }) 91 })
94 92
diff --git a/server/tests/api/check-params/videos.ts b/server/tests/api/check-params/videos.ts
index b0c850f0c..b9484afc4 100644
--- a/server/tests/api/check-params/videos.ts
+++ b/server/tests/api/check-params/videos.ts
@@ -1,64 +1,23 @@
1/* tslint:disable:no-unused-expression */ 1/* tslint:disable:no-unused-expression */
2 2
3import * as request from 'supertest'
4import { join } from 'path'
5import 'mocha'
6import * as chai from 'chai' 3import * as chai from 'chai'
7const expect = chai.expect 4import { omit } from 'lodash'
8 5import 'mocha'
6import { join } from 'path'
7import { VideoPrivacy } from '../../../../shared/models/videos/video-privacy.enum'
9import { 8import {
10 ServerInfo, 9 createUser, flushTests, getMyUserInformation, getVideo, getVideosList, immutableAssign, killallServers, makeDeleteRequest,
11 flushTests, 10 makeGetRequest, makePostUploadRequest, makePutBodyRequest, removeVideo, runServer, ServerInfo, setAccessTokensToServers, userLogin
12 runServer,
13 getVideosList,
14 makePutBodyRequest,
15 setAccessTokensToServers,
16 killallServers,
17 makePostUploadRequest,
18 getMyUserInformation,
19 createUser,
20 userLogin
21} from '../../utils' 11} from '../../utils'
22import { VideoPrivacy } from '../../../../shared/models/videos/video-privacy.enum' 12import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../utils/requests/check-api-params'
13
14const expect = chai.expect
23 15
24describe('Test videos API validator', function () { 16describe('Test videos API validator', function () {
25 const path = '/api/v1/videos/' 17 const path = '/api/v1/videos/'
26 let server: ServerInfo 18 let server: ServerInfo
27 let channelId: number 19 let channelId: number
28 20
29 function getCompleteVideoUploadAttributes () {
30 return {
31 name: 'my super name',
32 category: 5,
33 licence: 1,
34 language: 6,
35 nsfw: false,
36 description: 'my super description',
37 tags: [ 'tag1', 'tag2' ],
38 privacy: VideoPrivacy.PUBLIC,
39 channelId
40 }
41 }
42
43 function getCompleteVideoUpdateAttributes () {
44 return {
45 name: 'my super name',
46 category: 5,
47 licence: 2,
48 language: 6,
49 nsfw: false,
50 description: 'my super description',
51 privacy: VideoPrivacy.PUBLIC,
52 tags: [ 'tag1', 'tag2' ]
53 }
54 }
55
56 function getVideoUploadAttaches () {
57 return {
58 'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm')
59 }
60 }
61
62 // --------------------------------------------------------------- 21 // ---------------------------------------------------------------
63 22
64 before(async function () { 23 before(async function () {
@@ -76,60 +35,38 @@ describe('Test videos API validator', function () {
76 35
77 describe('When listing a video', function () { 36 describe('When listing a video', function () {
78 it('Should fail with a bad start pagination', async function () { 37 it('Should fail with a bad start pagination', async function () {
79 await request(server.url) 38 await checkBadStartPagination(server.url, path)
80 .get(path)
81 .query({ start: 'hello' })
82 .set('Accept', 'application/json')
83 .expect(400)
84 }) 39 })
85 40
86 it('Should fail with a bad count pagination', async function () { 41 it('Should fail with a bad count pagination', async function () {
87 await request(server.url) 42 await checkBadCountPagination(server.url, path)
88 .get(path)
89 .query({ count: 'hello' })
90 .set('Accept', 'application/json')
91 .expect(400)
92 }) 43 })
93 44
94 it('Should fail with an incorrect sort', async function () { 45 it('Should fail with an incorrect sort', async function () {
95 await request(server.url) 46 await checkBadSortPagination(server.url, path)
96 .get(path)
97 .query({ sort: 'hello' })
98 .set('Accept', 'application/json')
99 .expect(400)
100 }) 47 })
101 }) 48 })
102 49
103 describe('When searching a video', function () { 50 describe('When searching a video', function () {
51
104 it('Should fail with nothing', async function () { 52 it('Should fail with nothing', async function () {
105 await request(server.url) 53 await makeGetRequest({
106 .get(join(path, 'search')) 54 url: server.url,
107 .set('Accept', 'application/json') 55 path: join(path, 'search'),
108 .expect(400) 56 statusCodeExpected: 400
57 })
109 }) 58 })
110 59
111 it('Should fail with a bad start pagination', async function () { 60 it('Should fail with a bad start pagination', async function () {
112 await request(server.url) 61 await checkBadStartPagination(server.url, join(path, 'search', 'test'))
113 .get(join(path, 'search', 'test'))
114 .query({ start: 'hello' })
115 .set('Accept', 'application/json')
116 .expect(400)
117 }) 62 })
118 63
119 it('Should fail with a bad count pagination', async function () { 64 it('Should fail with a bad count pagination', async function () {
120 await request(server.url) 65 await checkBadCountPagination(server.url, join(path, 'search', 'test'))
121 .get(join(path, 'search', 'test'))
122 .query({ count: 'hello' })
123 .set('Accept', 'application/json')
124 .expect(400)
125 }) 66 })
126 67
127 it('Should fail with an incorrect sort', async function () { 68 it('Should fail with an incorrect sort', async function () {
128 await request(server.url) 69 await checkBadSortPagination(server.url, join(path, 'search', 'test'))
129 .get(join(path, 'search', 'test'))
130 .query({ sort: 'hello' })
131 .set('Accept', 'application/json')
132 .expect(400)
133 }) 70 })
134 }) 71 })
135 72
@@ -137,34 +74,39 @@ describe('Test videos API validator', function () {
137 const path = '/api/v1/users/me/videos' 74 const path = '/api/v1/users/me/videos'
138 75
139 it('Should fail with a bad start pagination', async function () { 76 it('Should fail with a bad start pagination', async function () {
140 await request(server.url) 77 await checkBadStartPagination(server.url, path, server.accessToken)
141 .get(path)
142 .set('Authorization', 'Bearer ' + server.accessToken)
143 .query({ start: 'hello' })
144 .set('Accept', 'application/json')
145 .expect(400)
146 }) 78 })
147 79
148 it('Should fail with a bad count pagination', async function () { 80 it('Should fail with a bad count pagination', async function () {
149 await request(server.url) 81 await checkBadCountPagination(server.url, path, server.accessToken)
150 .get(path)
151 .set('Authorization', 'Bearer ' + server.accessToken)
152 .query({ count: 'hello' })
153 .set('Accept', 'application/json')
154 .expect(400)
155 }) 82 })
156 83
157 it('Should fail with an incorrect sort', async function () { 84 it('Should fail with an incorrect sort', async function () {
158 await request(server.url) 85 await checkBadSortPagination(server.url, path, server.accessToken)
159 .get(path)
160 .set('Authorization', 'Bearer ' + server.accessToken)
161 .query({ sort: 'hello' })
162 .set('Accept', 'application/json')
163 .expect(400)
164 }) 86 })
165 }) 87 })
166 88
167 describe('When adding a video', function () { 89 describe('When adding a video', function () {
90 let baseCorrectParams
91 const baseCorrectAttaches = {
92 'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm')
93 }
94
95 before(function () {
96 // Put in before to have channelId
97 baseCorrectParams = {
98 name: 'my super name',
99 category: 5,
100 licence: 1,
101 language: 6,
102 nsfw: false,
103 description: 'my super description',
104 tags: [ 'tag1', 'tag2' ],
105 privacy: VideoPrivacy.PUBLIC,
106 channelId
107 }
108 })
109
168 it('Should fail with nothing', async function () { 110 it('Should fail with nothing', async function () {
169 const fields = {} 111 const fields = {}
170 const attaches = {} 112 const attaches = {}
@@ -172,84 +114,72 @@ describe('Test videos API validator', function () {
172 }) 114 })
173 115
174 it('Should fail without name', async function () { 116 it('Should fail without name', async function () {
175 const fields = getCompleteVideoUploadAttributes() 117 const fields = omit(baseCorrectParams, 'name')
176 delete fields.name 118 const attaches = baseCorrectAttaches
177 119
178 const attaches = getVideoUploadAttaches()
179 await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) 120 await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
180 }) 121 })
181 122
182 it('Should fail with a long name', async function () { 123 it('Should fail with a long name', async function () {
183 const fields = getCompleteVideoUploadAttributes() 124 const fields = immutableAssign(baseCorrectParams, { name: 'super'.repeat(65) })
184 fields.name = 'My very very very very very very very very very very very very very very very very very ' + 125 const attaches = baseCorrectAttaches
185 'very very very very very very very very very very very very very very very very long long' +
186 'very very very very very very very very very very very very very very very very long name'
187 126
188 const attaches = getVideoUploadAttaches
189 await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) 127 await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
190 }) 128 })
191 129
192 it('Should fail with a bad category', async function () { 130 it('Should fail with a bad category', async function () {
193 const fields = getCompleteVideoUploadAttributes() 131 const fields = immutableAssign(baseCorrectParams, { category: 125 })
194 fields.category = 125 132 const attaches = baseCorrectAttaches
195 133
196 const attaches = getVideoUploadAttaches
197 await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) 134 await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
198 }) 135 })
199 136
200 it('Should fail with a bad licence', async function () { 137 it('Should fail with a bad licence', async function () {
201 const fields = getCompleteVideoUploadAttributes() 138 const fields = immutableAssign(baseCorrectParams, { licence: 125 })
202 fields.licence = 125 139 const attaches = baseCorrectAttaches
203 140
204 const attaches = getVideoUploadAttaches()
205 await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) 141 await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
206 }) 142 })
207 143
208 it('Should fail with a bad language', async function () { 144 it('Should fail with a bad language', async function () {
209 const fields = getCompleteVideoUploadAttributes() 145 const fields = immutableAssign(baseCorrectParams, { language: 125 })
210 fields.language = 563 146 const attaches = baseCorrectAttaches
211 147
212 const attaches = getVideoUploadAttaches()
213 await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) 148 await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
214 }) 149 })
215 150
216 it('Should fail without nsfw attribute', async function () { 151 it('Should fail without nsfw attribute', async function () {
217 const fields = getCompleteVideoUploadAttributes() 152 const fields = omit(baseCorrectParams, 'nsfw')
218 delete fields.nsfw 153 const attaches = baseCorrectAttaches
219 154
220 const attaches = getVideoUploadAttaches()
221 await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) 155 await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
222 }) 156 })
223 157
224 it('Should fail with a bad nsfw attribute', async function () { 158 it('Should fail with a bad nsfw attribute', async function () {
225 const fields = getCompleteVideoUploadAttributes() 159 const fields = immutableAssign(baseCorrectParams, { nsfw: 2 })
226 fields.nsfw = 2 as any 160 const attaches = baseCorrectAttaches
227 161
228 const attaches = getVideoUploadAttaches()
229 await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) 162 await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
230 }) 163 })
231 164
232 it('Should fail with a long description', async function () { 165 it('Should fail with a long description', async function () {
233 const fields = getCompleteVideoUploadAttributes() 166 const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(1500) })
234 fields.description = 'my super description which is very very very very very very very very very very very very long'.repeat(35) 167 const attaches = baseCorrectAttaches
235 168
236 const attaches = getVideoUploadAttaches()
237 await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) 169 await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
238 }) 170 })
239 171
240 it('Should fail without a channel', async function () { 172 it('Should fail without a channel', async function () {
241 const fields = getCompleteVideoUploadAttributes() 173 const fields = omit(baseCorrectParams, 'channelId')
242 delete fields.channelId 174 const attaches = baseCorrectAttaches
243 175
244 const attaches = getVideoUploadAttaches()
245 await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) 176 await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
246 }) 177 })
247 178
248 it('Should fail with a bad channel', async function () { 179 it('Should fail with a bad channel', async function () {
249 const fields = getCompleteVideoUploadAttributes() 180 const fields = immutableAssign(baseCorrectParams, { channelId: 545454 })
250 fields.channelId = 545454 181 const attaches = baseCorrectAttaches
251 182
252 const attaches = getVideoUploadAttaches()
253 await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) 183 await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
254 }) 184 })
255 185
@@ -264,45 +194,41 @@ describe('Test videos API validator', function () {
264 const res = await getMyUserInformation(server.url, accessTokenUser) 194 const res = await getMyUserInformation(server.url, accessTokenUser)
265 const customChannelId = res.body.videoChannels[0].id 195 const customChannelId = res.body.videoChannels[0].id
266 196
267 const fields = getCompleteVideoUploadAttributes() 197 const fields = immutableAssign(baseCorrectParams, { channelId: customChannelId })
268 fields.channelId = customChannelId 198 const attaches = baseCorrectAttaches
269 199
270 const attaches = getVideoUploadAttaches()
271 await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) 200 await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
272 }) 201 })
273 202
274 it('Should fail with too many tags', async function () { 203 it('Should fail with too many tags', async function () {
275 const fields = getCompleteVideoUploadAttributes() 204 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'tag2', 'tag3', 'tag4', 'tag5', 'tag6' ] })
276 fields.tags = [ 'tag1', 'tag2', 'tag3', 'tag4', 'tag5', 'tag6' ] 205 const attaches = baseCorrectAttaches
277 206
278 const attaches = getVideoUploadAttaches()
279 await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) 207 await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
280 }) 208 })
281 209
282 it('Should fail with a tag length too low', async function () { 210 it('Should fail with a tag length too low', async function () {
283 const fields = getCompleteVideoUploadAttributes() 211 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 't' ] })
284 fields.tags = [ 'tag1', 't' ] 212 const attaches = baseCorrectAttaches
285 213
286 const attaches = getVideoUploadAttaches()
287 await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) 214 await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
288 }) 215 })
289 216
290 it('Should fail with a tag length too big', async function () { 217 it('Should fail with a tag length too big', async function () {
291 const fields = getCompleteVideoUploadAttributes() 218 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'my_super_tag_too_long_long_long_long_long_long' ] })
292 fields.tags = [ 'my_super_tag_too_long_long_long_long_long_long', 'tag1' ] 219 const attaches = baseCorrectAttaches
293 220
294 const attaches = getVideoUploadAttaches()
295 await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) 221 await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
296 }) 222 })
297 223
298 it('Should fail without an input file', async function () { 224 it('Should fail without an input file', async function () {
299 const fields = getCompleteVideoUploadAttributes() 225 const fields = baseCorrectParams
300 const attaches = {} 226 const attaches = {}
301 await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) 227 await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
302 }) 228 })
303 229
304 it('Should fail without an incorrect input file', async function () { 230 it('Should fail without an incorrect input file', async function () {
305 const fields = getCompleteVideoUploadAttributes() 231 const fields = baseCorrectParams
306 const attaches = { 232 const attaches = {
307 'videofile': join(__dirname, '..', 'fixtures', 'video_short_fake.webm') 233 'videofile': join(__dirname, '..', 'fixtures', 'video_short_fake.webm')
308 } 234 }
@@ -312,41 +238,63 @@ describe('Test videos API validator', function () {
312 it('Should succeed with the correct parameters', async function () { 238 it('Should succeed with the correct parameters', async function () {
313 this.timeout(10000) 239 this.timeout(10000)
314 240
315 const fields = getCompleteVideoUploadAttributes() 241 const fields = baseCorrectParams
316 const attaches = getVideoUploadAttaches() 242
317 243 {
318 await makePostUploadRequest({ 244 const attaches = baseCorrectAttaches
319 url: server.url, 245 await makePostUploadRequest({
320 path: path + '/upload', 246 url: server.url,
321 token: server.accessToken, 247 path: path + '/upload',
322 fields, 248 token: server.accessToken,
323 attaches, 249 fields,
324 statusCodeExpected: 200 250 attaches,
325 }) 251 statusCodeExpected: 200
252 })
253 }
326 254
327 attaches.videofile = join(__dirname, '..', 'fixtures', 'video_short.mp4') 255 {
328 await makePostUploadRequest({ 256 const attaches = immutableAssign(baseCorrectAttaches, {
329 url: server.url, 257 videofile: join(__dirname, '..', 'fixtures', 'video_short.mp4')
330 path: path + '/upload', 258 })
331 token: server.accessToken, 259
332 fields, 260 await makePostUploadRequest({
333 attaches, 261 url: server.url,
334 statusCodeExpected: 200 262 path: path + '/upload',
335 }) 263 token: server.accessToken,
264 fields,
265 attaches,
266 statusCodeExpected: 200
267 })
268 }
336 269
337 attaches.videofile = join(__dirname, '..', 'fixtures', 'video_short.ogv') 270 {
338 await makePostUploadRequest({ 271 const attaches = immutableAssign(baseCorrectAttaches, {
339 url: server.url, 272 videofile: join(__dirname, '..', 'fixtures', 'video_short.ogv')
340 path: path + '/upload', 273 })
341 token: server.accessToken, 274
342 fields, 275 await makePostUploadRequest({
343 attaches, 276 url: server.url,
344 statusCodeExpected: 200 277 path: path + '/upload',
345 }) 278 token: server.accessToken,
279 fields,
280 attaches,
281 statusCodeExpected: 200
282 })
283 }
346 }) 284 })
347 }) 285 })
348 286
349 describe('When updating a video', function () { 287 describe('When updating a video', function () {
288 const baseCorrectParams = {
289 name: 'my super name',
290 category: 5,
291 licence: 2,
292 language: 6,
293 nsfw: false,
294 description: 'my super description',
295 privacy: VideoPrivacy.PUBLIC,
296 tags: [ 'tag1', 'tag2' ]
297 }
350 let videoId 298 let videoId
351 299
352 before(async function () { 300 before(async function () {
@@ -360,12 +308,12 @@ describe('Test videos API validator', function () {
360 }) 308 })
361 309
362 it('Should fail without a valid uuid', async function () { 310 it('Should fail without a valid uuid', async function () {
363 const fields = getCompleteVideoUpdateAttributes() 311 const fields = baseCorrectParams
364 await makePutBodyRequest({ url: server.url, path: path + 'blabla', token: server.accessToken, fields }) 312 await makePutBodyRequest({ url: server.url, path: path + 'blabla', token: server.accessToken, fields })
365 }) 313 })
366 314
367 it('Should fail with an unknown id', async function () { 315 it('Should fail with an unknown id', async function () {
368 const fields = getCompleteVideoUpdateAttributes() 316 const fields = baseCorrectParams
369 317
370 await makePutBodyRequest({ 318 await makePutBodyRequest({
371 url: server.url, 319 url: server.url,
@@ -377,64 +325,55 @@ describe('Test videos API validator', function () {
377 }) 325 })
378 326
379 it('Should fail with a long name', async function () { 327 it('Should fail with a long name', async function () {
380 const fields = getCompleteVideoUpdateAttributes() 328 const fields = immutableAssign(baseCorrectParams, { name: 'super'.repeat(65) })
381 fields.name = 'My very very very very very very very very very very very very very very very very long'.repeat(3)
382 329
383 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields }) 330 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
384 }) 331 })
385 332
386 it('Should fail with a bad category', async function () { 333 it('Should fail with a bad category', async function () {
387 const fields = getCompleteVideoUpdateAttributes() 334 const fields = immutableAssign(baseCorrectParams, { category: 125 })
388 fields.category = 128
389 335
390 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields }) 336 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
391 }) 337 })
392 338
393 it('Should fail with a bad licence', async function () { 339 it('Should fail with a bad licence', async function () {
394 const fields = getCompleteVideoUpdateAttributes() 340 const fields = immutableAssign(baseCorrectParams, { licence: 125 })
395 fields.licence = 128
396 341
397 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields }) 342 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
398 }) 343 })
399 344
400 it('Should fail with a bad language', async function () { 345 it('Should fail with a bad language', async function () {
401 const fields = getCompleteVideoUpdateAttributes() 346 const fields = immutableAssign(baseCorrectParams, { language: 125 })
402 fields.language = 896
403 347
404 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields }) 348 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
405 }) 349 })
406 350
407 it('Should fail with a bad nsfw attribute', async function () { 351 it('Should fail with a bad nsfw attribute', async function () {
408 const fields = getCompleteVideoUpdateAttributes() 352 const fields = immutableAssign(baseCorrectParams, { nsfw: 2 })
409 fields.nsfw = (-4 as any)
410 353
411 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields }) 354 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
412 }) 355 })
413 356
414 it('Should fail with a long description', async function () { 357 it('Should fail with a long description', async function () {
415 const fields = getCompleteVideoUpdateAttributes() 358 const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(1500) })
416 fields.description = 'my super description which is very very very very very very very very very very very very very long'.repeat(35)
417 359
418 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields }) 360 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
419 }) 361 })
420 362
421 it('Should fail with too many tags', async function () { 363 it('Should fail with too many tags', async function () {
422 const fields = getCompleteVideoUpdateAttributes() 364 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'tag2', 'tag3', 'tag4', 'tag5', 'tag6' ] })
423 fields.tags = [ 'tag1', 'tag2', 'tag3', 'tag4', 'tag5', 'tag6' ]
424 365
425 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields }) 366 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
426 }) 367 })
427 368
428 it('Should fail with a tag length too low', async function () { 369 it('Should fail with a tag length too low', async function () {
429 const fields = getCompleteVideoUpdateAttributes() 370 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 't' ] })
430 fields.tags = [ 'tag1', 't' ]
431 371
432 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields }) 372 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
433 }) 373 })
434 374
435 it('Should fail with a tag length too big', async function () { 375 it('Should fail with a tag length too big', async function () {
436 const fields = getCompleteVideoUpdateAttributes() 376 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'my_super_tag_too_long_long_long_long_long_long' ] })
437 fields.tags = [ 'my_super_tag_too_long_long_long_long', 'tag1' ]
438 377
439 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields }) 378 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
440 }) 379 })
@@ -444,7 +383,7 @@ describe('Test videos API validator', function () {
444 it('Should fail with a video of another server') 383 it('Should fail with a video of another server')
445 384
446 it('Should succeed with the correct parameters', async function () { 385 it('Should succeed with the correct parameters', async function () {
447 const fields = getCompleteVideoUpdateAttributes() 386 const fields = baseCorrectParams
448 387
449 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields, statusCodeExpected: 204 }) 388 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields, statusCodeExpected: 204 })
450 }) 389 })
@@ -452,28 +391,22 @@ describe('Test videos API validator', function () {
452 391
453 describe('When getting a video', function () { 392 describe('When getting a video', function () {
454 it('Should return the list of the videos with nothing', async function () { 393 it('Should return the list of the videos with nothing', async function () {
455 const res = await request(server.url) 394 const res = await makeGetRequest({
456 .get(path) 395 url: server.url,
457 .set('Accept', 'application/json') 396 path,
458 .expect(200) 397 statusCodeExpected: 200
459 .expect('Content-Type', /json/) 398 })
460 399
461 expect(res.body.data).to.be.an('array') 400 expect(res.body.data).to.be.an('array')
462 expect(res.body.data.length).to.equal(3) 401 expect(res.body.data.length).to.equal(3)
463 }) 402 })
464 403
465 it('Should fail without a correct uuid', async function () { 404 it('Should fail without a correct uuid', async function () {
466 await request(server.url) 405 await getVideo(server.url, 'coucou', 400)
467 .get(path + 'coucou')
468 .set('Accept', 'application/json')
469 .expect(400)
470 }) 406 })
471 407
472 it('Should return 404 with an incorrect video', async function () { 408 it('Should return 404 with an incorrect video', async function () {
473 await request(server.url) 409 await getVideo(server.url, '4da6fde3-88f7-4d16-b119-108df5630b06', 404)
474 .get(path + '4da6fde3-88f7-4d16-b119-108df5630b06')
475 .set('Accept', 'application/json')
476 .expect(404)
477 }) 410 })
478 411
479 it('Should succeed with the correct parameters') 412 it('Should succeed with the correct parameters')
@@ -530,24 +463,19 @@ describe('Test videos API validator', function () {
530 463
531 describe('When removing a video', function () { 464 describe('When removing a video', function () {
532 it('Should have 404 with nothing', async function () { 465 it('Should have 404 with nothing', async function () {
533 await request(server.url) 466 await makeDeleteRequest({
534 .delete(path) 467 url: server.url,
535 .set('Authorization', 'Bearer ' + server.accessToken) 468 path,
536 .expect(400) 469 statusCodeExpected: 400
470 })
537 }) 471 })
538 472
539 it('Should fail without a correct uuid', async function () { 473 it('Should fail without a correct uuid', async function () {
540 await request(server.url) 474 await removeVideo(server.url, server.accessToken, 'hello', 400)
541 .delete(path + 'hello')
542 .set('Authorization', 'Bearer ' + server.accessToken)
543 .expect(400)
544 }) 475 })
545 476
546 it('Should fail with a video which does not exist', async function () { 477 it('Should fail with a video which does not exist', async function () {
547 await request(server.url) 478 await removeVideo(server.url, server.accessToken, '4da6fde3-88f7-4d16-b119-108df5630b06', 404)
548 .delete(path + '4da6fde3-88f7-4d16-b119-108df5630b06')
549 .set('Authorization', 'Bearer ' + server.accessToken)
550 .expect(404)
551 }) 479 })
552 480
553 it('Should fail with a video of another user') 481 it('Should fail with a video of another user')