diff options
author | Chocobozzz <me@florianbigard.com> | 2017-12-28 15:25:31 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2017-12-28 15:25:31 +0100 |
commit | 26d21b7867c225d99e0625af51da4643e351d86d (patch) | |
tree | 5fa3f0482749eb1001c8b6fad7d9710298c31724 /server/tests/utils/users/users.ts | |
parent | 331128ed3512aa2c1b632e25ac7ac0174bdb3789 (diff) | |
download | PeerTube-26d21b7867c225d99e0625af51da4643e351d86d.tar.gz PeerTube-26d21b7867c225d99e0625af51da4643e351d86d.tar.zst PeerTube-26d21b7867c225d99e0625af51da4643e351d86d.zip |
Improve check users parameters tests
Diffstat (limited to 'server/tests/utils/users/users.ts')
-rw-r--r-- | server/tests/utils/users/users.ts | 78 |
1 files changed, 47 insertions, 31 deletions
diff --git a/server/tests/utils/users/users.ts b/server/tests/utils/users/users.ts index bd8d7ab04..e0cca3f51 100644 --- a/server/tests/utils/users/users.ts +++ b/server/tests/utils/users/users.ts | |||
@@ -1,4 +1,5 @@ | |||
1 | import * as request from 'supertest' | 1 | import * as request from 'supertest' |
2 | import { makePutBodyRequest } from '../' | ||
2 | 3 | ||
3 | import { UserRole } from '../../../../shared/index' | 4 | import { UserRole } from '../../../../shared/index' |
4 | 5 | ||
@@ -43,14 +44,14 @@ function registerUser (url: string, username: string, password: string, specialS | |||
43 | .expect(specialStatus) | 44 | .expect(specialStatus) |
44 | } | 45 | } |
45 | 46 | ||
46 | function getMyUserInformation (url: string, accessToken: string) { | 47 | function getMyUserInformation (url: string, accessToken: string, specialStatus = 200) { |
47 | const path = '/api/v1/users/me' | 48 | const path = '/api/v1/users/me' |
48 | 49 | ||
49 | return request(url) | 50 | return request(url) |
50 | .get(path) | 51 | .get(path) |
51 | .set('Accept', 'application/json') | 52 | .set('Accept', 'application/json') |
52 | .set('Authorization', 'Bearer ' + accessToken) | 53 | .set('Authorization', 'Bearer ' + accessToken) |
53 | .expect(200) | 54 | .expect(specialStatus) |
54 | .expect('Content-Type', /json/) | 55 | .expect('Content-Type', /json/) |
55 | } | 56 | } |
56 | 57 | ||
@@ -65,14 +66,14 @@ function getUserInformation (url: string, accessToken: string, userId: number) { | |||
65 | .expect('Content-Type', /json/) | 66 | .expect('Content-Type', /json/) |
66 | } | 67 | } |
67 | 68 | ||
68 | function getUserVideoRating (url: string, accessToken: string, videoId: number) { | 69 | function getMyUserVideoRating (url: string, accessToken: string, videoId: number | string, specialStatus = 200) { |
69 | const path = '/api/v1/users/me/videos/' + videoId + '/rating' | 70 | const path = '/api/v1/users/me/videos/' + videoId + '/rating' |
70 | 71 | ||
71 | return request(url) | 72 | return request(url) |
72 | .get(path) | 73 | .get(path) |
73 | .set('Accept', 'application/json') | 74 | .set('Accept', 'application/json') |
74 | .set('Authorization', 'Bearer ' + accessToken) | 75 | .set('Authorization', 'Bearer ' + accessToken) |
75 | .expect(200) | 76 | .expect(specialStatus) |
76 | .expect('Content-Type', /json/) | 77 | .expect('Content-Type', /json/) |
77 | } | 78 | } |
78 | 79 | ||
@@ -101,7 +102,7 @@ function getUsersListPaginationAndSort (url: string, accessToken: string, start: | |||
101 | .expect('Content-Type', /json/) | 102 | .expect('Content-Type', /json/) |
102 | } | 103 | } |
103 | 104 | ||
104 | function removeUser (url: string, userId: number, accessToken: string, expectedStatus = 204) { | 105 | function removeUser (url: string, userId: number | string, accessToken: string, expectedStatus = 204) { |
105 | const path = '/api/v1/users' | 106 | const path = '/api/v1/users' |
106 | 107 | ||
107 | return request(url) | 108 | return request(url) |
@@ -111,38 +112,53 @@ function removeUser (url: string, userId: number, accessToken: string, expectedS | |||
111 | .expect(expectedStatus) | 112 | .expect(expectedStatus) |
112 | } | 113 | } |
113 | 114 | ||
114 | function updateMyUser (url: string, accessToken: string, newPassword: string, displayNSFW?: boolean, | 115 | function updateMyUser (options: { |
115 | email?: string, autoPlayVideo?: boolean) { | 116 | url: string |
117 | accessToken: string, | ||
118 | newPassword?: string, | ||
119 | displayNSFW?: boolean, | ||
120 | email?: string, | ||
121 | autoPlayVideo?: boolean | ||
122 | }) { | ||
116 | const path = '/api/v1/users/me' | 123 | const path = '/api/v1/users/me' |
117 | 124 | ||
118 | const toSend = {} | 125 | const toSend = {} |
119 | if (newPassword !== undefined && newPassword !== null) toSend['password'] = newPassword | 126 | if (options.newPassword !== undefined && options.newPassword !== null) toSend['password'] = options.newPassword |
120 | if (displayNSFW !== undefined && displayNSFW !== null) toSend['displayNSFW'] = displayNSFW | 127 | if (options.displayNSFW !== undefined && options.displayNSFW !== null) toSend['displayNSFW'] = options.displayNSFW |
121 | if (autoPlayVideo !== undefined && autoPlayVideo !== null) toSend['autoPlayVideo'] = autoPlayVideo | 128 | if (options.autoPlayVideo !== undefined && options.autoPlayVideo !== null) toSend['autoPlayVideo'] = options.autoPlayVideo |
122 | if (email !== undefined && email !== null) toSend['email'] = email | 129 | if (options.email !== undefined && options.email !== null) toSend['email'] = options.email |
123 | 130 | ||
124 | return request(url) | 131 | return makePutBodyRequest({ |
125 | .put(path) | 132 | url: options.url, |
126 | .set('Accept', 'application/json') | 133 | path, |
127 | .set('Authorization', 'Bearer ' + accessToken) | 134 | token: options.accessToken, |
128 | .send(toSend) | 135 | fields: toSend, |
129 | .expect(204) | 136 | statusCodeExpected: 204 |
137 | }) | ||
130 | } | 138 | } |
131 | 139 | ||
132 | function updateUser (url: string, userId: number, accessToken: string, email: string, videoQuota: number, role: UserRole) { | 140 | function updateUser (options: { |
133 | const path = '/api/v1/users/' + userId | 141 | url: string |
142 | userId: number, | ||
143 | accessToken: string, | ||
144 | email?: string, | ||
145 | videoQuota?: number, | ||
146 | role?: UserRole | ||
147 | }) { | ||
148 | const path = '/api/v1/users/' + options.userId | ||
134 | 149 | ||
135 | const toSend = {} | 150 | const toSend = {} |
136 | if (email !== undefined && email !== null) toSend['email'] = email | 151 | if (options.email !== undefined && options.email !== null) toSend['email'] = options.email |
137 | if (videoQuota !== undefined && videoQuota !== null) toSend['videoQuota'] = videoQuota | 152 | if (options.videoQuota !== undefined && options.videoQuota !== null) toSend['videoQuota'] = options.videoQuota |
138 | if (role !== undefined && role !== null) toSend['role'] = role | 153 | if (options.role !== undefined && options.role !== null) toSend['role'] = options.role |
139 | 154 | ||
140 | return request(url) | 155 | return makePutBodyRequest({ |
141 | .put(path) | 156 | url: options.url, |
142 | .set('Accept', 'application/json') | 157 | path, |
143 | .set('Authorization', 'Bearer ' + accessToken) | 158 | token: options.accessToken, |
144 | .send(toSend) | 159 | fields: toSend, |
145 | .expect(204) | 160 | statusCodeExpected: 204 |
161 | }) | ||
146 | } | 162 | } |
147 | 163 | ||
148 | // --------------------------------------------------------------------------- | 164 | // --------------------------------------------------------------------------- |
@@ -151,7 +167,7 @@ export { | |||
151 | createUser, | 167 | createUser, |
152 | registerUser, | 168 | registerUser, |
153 | getMyUserInformation, | 169 | getMyUserInformation, |
154 | getUserVideoRating, | 170 | getMyUserVideoRating, |
155 | getUsersList, | 171 | getUsersList, |
156 | getUsersListPaginationAndSort, | 172 | getUsersListPaginationAndSort, |
157 | removeUser, | 173 | removeUser, |