diff options
Diffstat (limited to 'server/tests')
-rw-r--r-- | server/tests/api/check-params/users.ts | 22 | ||||
-rw-r--r-- | server/tests/api/fixtures/avatar.png | bin | 0 -> 1674 bytes | |||
-rw-r--r-- | server/tests/api/users/users.ts | 18 | ||||
-rw-r--r-- | server/tests/utils/users/users.ts | 29 | ||||
-rw-r--r-- | server/tests/utils/videos/videos.ts | 4 |
5 files changed, 67 insertions, 6 deletions
diff --git a/server/tests/api/check-params/users.ts b/server/tests/api/check-params/users.ts index 0c126dbff..44412ad82 100644 --- a/server/tests/api/check-params/users.ts +++ b/server/tests/api/check-params/users.ts | |||
@@ -2,11 +2,13 @@ | |||
2 | 2 | ||
3 | import { omit } from 'lodash' | 3 | import { omit } from 'lodash' |
4 | import 'mocha' | 4 | import 'mocha' |
5 | import { join } from "path" | ||
5 | import { UserRole } from '../../../../shared' | 6 | import { UserRole } from '../../../../shared' |
6 | 7 | ||
7 | import { | 8 | import { |
8 | createUser, flushTests, getMyUserInformation, getMyUserVideoRating, getUsersList, immutableAssign, killallServers, makeGetRequest, | 9 | createUser, flushTests, getMyUserInformation, getMyUserVideoRating, getUsersList, immutableAssign, killallServers, makeGetRequest, |
9 | makePostBodyRequest, makePutBodyRequest, registerUser, removeUser, runServer, ServerInfo, setAccessTokensToServers, updateUser, | 10 | makePostBodyRequest, makePostUploadRequest, makePutBodyRequest, registerUser, removeUser, runServer, ServerInfo, setAccessTokensToServers, |
11 | updateUser, | ||
10 | uploadVideo, userLogin | 12 | uploadVideo, userLogin |
11 | } from '../../utils' | 13 | } from '../../utils' |
12 | import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../utils/requests/check-api-params' | 14 | import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../utils/requests/check-api-params' |
@@ -266,6 +268,24 @@ describe('Test users API validators', function () { | |||
266 | }) | 268 | }) |
267 | }) | 269 | }) |
268 | 270 | ||
271 | describe('When updating my avatar', function () { | ||
272 | it('Should fail without an incorrect input file', async function () { | ||
273 | const fields = {} | ||
274 | const attaches = { | ||
275 | 'avatarfile': join(__dirname, '..', 'fixtures', 'video_short.mp4') | ||
276 | } | ||
277 | await makePostUploadRequest({ url: server.url, path: path + '/me/avatar/pick', token: server.accessToken, fields, attaches }) | ||
278 | }) | ||
279 | |||
280 | it('Should succeed with the correct params', async function () { | ||
281 | const fields = {} | ||
282 | const attaches = { | ||
283 | 'avatarfile': join(__dirname, '..', 'fixtures', 'avatar.png') | ||
284 | } | ||
285 | await makePostUploadRequest({ url: server.url, path: path + '/me/avatar/pick', token: server.accessToken, fields, attaches }) | ||
286 | }) | ||
287 | }) | ||
288 | |||
269 | describe('When updating a user', function () { | 289 | describe('When updating a user', function () { |
270 | 290 | ||
271 | before(async function () { | 291 | before(async function () { |
diff --git a/server/tests/api/fixtures/avatar.png b/server/tests/api/fixtures/avatar.png new file mode 100644 index 000000000..4b7fd2c0a --- /dev/null +++ b/server/tests/api/fixtures/avatar.png | |||
Binary files differ | |||
diff --git a/server/tests/api/users/users.ts b/server/tests/api/users/users.ts index 19549acdd..3390b2d56 100644 --- a/server/tests/api/users/users.ts +++ b/server/tests/api/users/users.ts | |||
@@ -6,7 +6,7 @@ import { UserRole } from '../../../../shared/index' | |||
6 | import { | 6 | import { |
7 | createUser, flushTests, getBlacklistedVideosList, getMyUserInformation, getMyUserVideoRating, getUserInformation, getUsersList, | 7 | createUser, flushTests, getBlacklistedVideosList, getMyUserInformation, getMyUserVideoRating, getUserInformation, getUsersList, |
8 | getUsersListPaginationAndSort, getVideosList, killallServers, login, makePutBodyRequest, rateVideo, registerUser, removeUser, removeVideo, | 8 | getUsersListPaginationAndSort, getVideosList, killallServers, login, makePutBodyRequest, rateVideo, registerUser, removeUser, removeVideo, |
9 | runServer, ServerInfo, serverLogin, updateMyUser, updateUser, uploadVideo | 9 | runServer, ServerInfo, serverLogin, testVideoImage, updateMyAvatar, updateMyUser, updateUser, uploadVideo |
10 | } from '../../utils/index' | 10 | } from '../../utils/index' |
11 | import { follow } from '../../utils/server/follows' | 11 | import { follow } from '../../utils/server/follows' |
12 | import { setAccessTokensToServers } from '../../utils/users/login' | 12 | import { setAccessTokensToServers } from '../../utils/users/login' |
@@ -340,6 +340,22 @@ describe('Test users', function () { | |||
340 | expect(user.id).to.be.a('number') | 340 | expect(user.id).to.be.a('number') |
341 | }) | 341 | }) |
342 | 342 | ||
343 | it('Should be able to update my avatar', async function () { | ||
344 | const fixture = 'avatar.png' | ||
345 | |||
346 | await updateMyAvatar({ | ||
347 | url: server.url, | ||
348 | accessToken: accessTokenUser, | ||
349 | fixture | ||
350 | }) | ||
351 | |||
352 | const res = await getMyUserInformation(server.url, accessTokenUser) | ||
353 | const user = res.body | ||
354 | |||
355 | const test = await testVideoImage(server.url, 'avatar', user.account.avatar.path, '.png') | ||
356 | expect(test).to.equal(true) | ||
357 | }) | ||
358 | |||
343 | it('Should be able to update another user', async function () { | 359 | it('Should be able to update another user', async function () { |
344 | await updateUser({ | 360 | await updateUser({ |
345 | url: server.url, | 361 | url: server.url, |
diff --git a/server/tests/utils/users/users.ts b/server/tests/utils/users/users.ts index e0cca3f51..90b1ca0a6 100644 --- a/server/tests/utils/users/users.ts +++ b/server/tests/utils/users/users.ts | |||
@@ -1,5 +1,6 @@ | |||
1 | import { isAbsolute, join } from 'path' | ||
1 | import * as request from 'supertest' | 2 | import * as request from 'supertest' |
2 | import { makePutBodyRequest } from '../' | 3 | import { makePostUploadRequest, makePutBodyRequest } from '../' |
3 | 4 | ||
4 | import { UserRole } from '../../../../shared/index' | 5 | import { UserRole } from '../../../../shared/index' |
5 | 6 | ||
@@ -137,6 +138,29 @@ function updateMyUser (options: { | |||
137 | }) | 138 | }) |
138 | } | 139 | } |
139 | 140 | ||
141 | function updateMyAvatar (options: { | ||
142 | url: string, | ||
143 | accessToken: string, | ||
144 | fixture: string | ||
145 | }) { | ||
146 | const path = '/api/v1/users/me/avatar/pick' | ||
147 | let filePath = '' | ||
148 | if (isAbsolute(options.fixture)) { | ||
149 | filePath = options.fixture | ||
150 | } else { | ||
151 | filePath = join(__dirname, '..', '..', 'api', 'fixtures', options.fixture) | ||
152 | } | ||
153 | |||
154 | return makePostUploadRequest({ | ||
155 | url: options.url, | ||
156 | path, | ||
157 | token: options.accessToken, | ||
158 | fields: {}, | ||
159 | attaches: { avatarfile: filePath }, | ||
160 | statusCodeExpected: 200 | ||
161 | }) | ||
162 | } | ||
163 | |||
140 | function updateUser (options: { | 164 | function updateUser (options: { |
141 | url: string | 165 | url: string |
142 | userId: number, | 166 | userId: number, |
@@ -173,5 +197,6 @@ export { | |||
173 | removeUser, | 197 | removeUser, |
174 | updateUser, | 198 | updateUser, |
175 | updateMyUser, | 199 | updateMyUser, |
176 | getUserInformation | 200 | getUserInformation, |
201 | updateMyAvatar | ||
177 | } | 202 | } |
diff --git a/server/tests/utils/videos/videos.ts b/server/tests/utils/videos/videos.ts index d6bf27dc7..aca51ee5d 100644 --- a/server/tests/utils/videos/videos.ts +++ b/server/tests/utils/videos/videos.ts | |||
@@ -201,7 +201,7 @@ function searchVideoWithSort (url: string, search: string, sort: string) { | |||
201 | .expect('Content-Type', /json/) | 201 | .expect('Content-Type', /json/) |
202 | } | 202 | } |
203 | 203 | ||
204 | async function testVideoImage (url: string, imageName: string, imagePath: string) { | 204 | async function testVideoImage (url: string, imageName: string, imagePath: string, extension = '.jpg') { |
205 | // Don't test images if the node env is not set | 205 | // Don't test images if the node env is not set |
206 | // Because we need a special ffmpeg version for this test | 206 | // Because we need a special ffmpeg version for this test |
207 | if (process.env['NODE_TEST_IMAGE']) { | 207 | if (process.env['NODE_TEST_IMAGE']) { |
@@ -209,7 +209,7 @@ async function testVideoImage (url: string, imageName: string, imagePath: string | |||
209 | .get(imagePath) | 209 | .get(imagePath) |
210 | .expect(200) | 210 | .expect(200) |
211 | 211 | ||
212 | const data = await readFilePromise(join(__dirname, '..', '..', 'api', 'fixtures', imageName + '.jpg')) | 212 | const data = await readFilePromise(join(__dirname, '..', '..', 'api', 'fixtures', imageName + extension)) |
213 | 213 | ||
214 | return data.equals(res.body) | 214 | return data.equals(res.body) |
215 | } else { | 215 | } else { |