diff options
author | Rigel Kent <sendmemail@rigelk.eu> | 2020-12-07 14:32:36 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-07 14:32:36 +0100 |
commit | 2d53be0267acc49cda46707b885096193a1f4e9c (patch) | |
tree | 887061a34bc67f40acbb96a6278f9544bf83caeb /server/tests/api/users/users.ts | |
parent | adc1f09c0dbd997f34028c1c82d1c118dc8ead80 (diff) | |
download | PeerTube-2d53be0267acc49cda46707b885096193a1f4e9c.tar.gz PeerTube-2d53be0267acc49cda46707b885096193a1f4e9c.tar.zst PeerTube-2d53be0267acc49cda46707b885096193a1f4e9c.zip |
replace numbers with typed http status codes (#3409)
Diffstat (limited to 'server/tests/api/users/users.ts')
-rw-r--r-- | server/tests/api/users/users.ts | 49 |
1 files changed, 25 insertions, 24 deletions
diff --git a/server/tests/api/users/users.ts b/server/tests/api/users/users.ts index fe83ca041..cd928b980 100644 --- a/server/tests/api/users/users.ts +++ b/server/tests/api/users/users.ts | |||
@@ -47,6 +47,7 @@ import { follow } from '../../../../shared/extra-utils/server/follows' | |||
47 | import { logout, serverLogin, setAccessTokensToServers } from '../../../../shared/extra-utils/users/login' | 47 | import { logout, serverLogin, setAccessTokensToServers } from '../../../../shared/extra-utils/users/login' |
48 | import { getMyVideos } from '../../../../shared/extra-utils/videos/videos' | 48 | import { getMyVideos } from '../../../../shared/extra-utils/videos/videos' |
49 | import { UserAdminFlag } from '../../../../shared/models/users/user-flag.model' | 49 | import { UserAdminFlag } from '../../../../shared/models/users/user-flag.model' |
50 | import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' | ||
50 | 51 | ||
51 | const expect = chai.expect | 52 | const expect = chai.expect |
52 | 53 | ||
@@ -86,14 +87,14 @@ describe('Test users', function () { | |||
86 | 87 | ||
87 | it('Should not login with an invalid client id', async function () { | 88 | it('Should not login with an invalid client id', async function () { |
88 | const client = { id: 'client', secret: server.client.secret } | 89 | const client = { id: 'client', secret: server.client.secret } |
89 | const res = await login(server.url, client, server.user, 400) | 90 | const res = await login(server.url, client, server.user, HttpStatusCode.BAD_REQUEST_400) |
90 | 91 | ||
91 | expect(res.body.error).to.contain('client is invalid') | 92 | expect(res.body.error).to.contain('client is invalid') |
92 | }) | 93 | }) |
93 | 94 | ||
94 | it('Should not login with an invalid client secret', async function () { | 95 | it('Should not login with an invalid client secret', async function () { |
95 | const client = { id: server.client.id, secret: 'coucou' } | 96 | const client = { id: server.client.id, secret: 'coucou' } |
96 | const res = await login(server.url, client, server.user, 400) | 97 | const res = await login(server.url, client, server.user, HttpStatusCode.BAD_REQUEST_400) |
97 | 98 | ||
98 | expect(res.body.error).to.contain('client is invalid') | 99 | expect(res.body.error).to.contain('client is invalid') |
99 | }) | 100 | }) |
@@ -103,14 +104,14 @@ describe('Test users', function () { | |||
103 | 104 | ||
104 | it('Should not login with an invalid username', async function () { | 105 | it('Should not login with an invalid username', async function () { |
105 | const user = { username: 'captain crochet', password: server.user.password } | 106 | const user = { username: 'captain crochet', password: server.user.password } |
106 | const res = await login(server.url, server.client, user, 400) | 107 | const res = await login(server.url, server.client, user, HttpStatusCode.BAD_REQUEST_400) |
107 | 108 | ||
108 | expect(res.body.error).to.contain('credentials are invalid') | 109 | expect(res.body.error).to.contain('credentials are invalid') |
109 | }) | 110 | }) |
110 | 111 | ||
111 | it('Should not login with an invalid password', async function () { | 112 | it('Should not login with an invalid password', async function () { |
112 | const user = { username: server.user.username, password: 'mew_three' } | 113 | const user = { username: server.user.username, password: 'mew_three' } |
113 | const res = await login(server.url, server.client, user, 400) | 114 | const res = await login(server.url, server.client, user, HttpStatusCode.BAD_REQUEST_400) |
114 | 115 | ||
115 | expect(res.body.error).to.contain('credentials are invalid') | 116 | expect(res.body.error).to.contain('credentials are invalid') |
116 | }) | 117 | }) |
@@ -119,31 +120,31 @@ describe('Test users', function () { | |||
119 | accessToken = 'my_super_token' | 120 | accessToken = 'my_super_token' |
120 | 121 | ||
121 | const videoAttributes = {} | 122 | const videoAttributes = {} |
122 | await uploadVideo(server.url, accessToken, videoAttributes, 401) | 123 | await uploadVideo(server.url, accessToken, videoAttributes, HttpStatusCode.UNAUTHORIZED_401) |
123 | }) | 124 | }) |
124 | 125 | ||
125 | it('Should not be able to follow', async function () { | 126 | it('Should not be able to follow', async function () { |
126 | accessToken = 'my_super_token' | 127 | accessToken = 'my_super_token' |
127 | await follow(server.url, [ 'http://example.com' ], accessToken, 401) | 128 | await follow(server.url, [ 'http://example.com' ], accessToken, HttpStatusCode.UNAUTHORIZED_401) |
128 | }) | 129 | }) |
129 | 130 | ||
130 | it('Should not be able to unfollow') | 131 | it('Should not be able to unfollow') |
131 | 132 | ||
132 | it('Should be able to login', async function () { | 133 | it('Should be able to login', async function () { |
133 | const res = await login(server.url, server.client, server.user, 200) | 134 | const res = await login(server.url, server.client, server.user, HttpStatusCode.OK_200) |
134 | 135 | ||
135 | accessToken = res.body.access_token | 136 | accessToken = res.body.access_token |
136 | }) | 137 | }) |
137 | 138 | ||
138 | it('Should be able to login with an insensitive username', async function () { | 139 | it('Should be able to login with an insensitive username', async function () { |
139 | const user = { username: 'RoOt', password: server.user.password } | 140 | const user = { username: 'RoOt', password: server.user.password } |
140 | await login(server.url, server.client, user, 200) | 141 | await login(server.url, server.client, user, HttpStatusCode.OK_200) |
141 | 142 | ||
142 | const user2 = { username: 'rOoT', password: server.user.password } | 143 | const user2 = { username: 'rOoT', password: server.user.password } |
143 | await login(server.url, server.client, user2, 200) | 144 | await login(server.url, server.client, user2, HttpStatusCode.OK_200) |
144 | 145 | ||
145 | const user3 = { username: 'ROOt', password: server.user.password } | 146 | const user3 = { username: 'ROOt', password: server.user.password } |
146 | await login(server.url, server.client, user3, 200) | 147 | await login(server.url, server.client, user3, HttpStatusCode.OK_200) |
147 | }) | 148 | }) |
148 | }) | 149 | }) |
149 | 150 | ||
@@ -179,7 +180,7 @@ describe('Test users', function () { | |||
179 | it('Should retrieve ratings list', async function () { | 180 | it('Should retrieve ratings list', async function () { |
180 | await rateVideo(server.url, accessToken, videoId, 'like') | 181 | await rateVideo(server.url, accessToken, videoId, 'like') |
181 | 182 | ||
182 | const res = await getAccountRatings(server.url, server.user.username, server.accessToken, null, 200) | 183 | const res = await getAccountRatings(server.url, server.user.username, server.accessToken, null, HttpStatusCode.OK_200) |
183 | const ratings = res.body | 184 | const ratings = res.body |
184 | 185 | ||
185 | expect(ratings.total).to.equal(1) | 186 | expect(ratings.total).to.equal(1) |
@@ -204,7 +205,7 @@ describe('Test users', function () { | |||
204 | 205 | ||
205 | describe('Remove video', function () { | 206 | describe('Remove video', function () { |
206 | it('Should not be able to remove the video with an incorrect token', async function () { | 207 | it('Should not be able to remove the video with an incorrect token', async function () { |
207 | await removeVideo(server.url, 'bad_token', videoId, 401) | 208 | await removeVideo(server.url, 'bad_token', videoId, HttpStatusCode.UNAUTHORIZED_401) |
208 | }) | 209 | }) |
209 | 210 | ||
210 | it('Should not be able to remove the video with the token of another account') | 211 | it('Should not be able to remove the video with the token of another account') |
@@ -220,11 +221,11 @@ describe('Test users', function () { | |||
220 | }) | 221 | }) |
221 | 222 | ||
222 | it('Should not be able to get the user information', async function () { | 223 | it('Should not be able to get the user information', async function () { |
223 | await getMyUserInformation(server.url, server.accessToken, 401) | 224 | await getMyUserInformation(server.url, server.accessToken, HttpStatusCode.UNAUTHORIZED_401) |
224 | }) | 225 | }) |
225 | 226 | ||
226 | it('Should not be able to upload a video', async function () { | 227 | it('Should not be able to upload a video', async function () { |
227 | await uploadVideo(server.url, server.accessToken, { name: 'video' }, 401) | 228 | await uploadVideo(server.url, server.accessToken, { name: 'video' }, HttpStatusCode.UNAUTHORIZED_401) |
228 | }) | 229 | }) |
229 | 230 | ||
230 | it('Should not be able to rate a video', async function () { | 231 | it('Should not be able to rate a video', async function () { |
@@ -238,7 +239,7 @@ describe('Test users', function () { | |||
238 | path: path + videoId, | 239 | path: path + videoId, |
239 | token: 'wrong token', | 240 | token: 'wrong token', |
240 | fields: data, | 241 | fields: data, |
241 | statusCodeExpected: 401 | 242 | statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 |
242 | } | 243 | } |
243 | await makePutBodyRequest(options) | 244 | await makePutBodyRequest(options) |
244 | }) | 245 | }) |
@@ -534,7 +535,7 @@ describe('Test users', function () { | |||
534 | }) | 535 | }) |
535 | user.password = 'new password' | 536 | user.password = 'new password' |
536 | 537 | ||
537 | await userLogin(server, user, 200) | 538 | await userLogin(server, user, HttpStatusCode.OK_200) |
538 | }) | 539 | }) |
539 | 540 | ||
540 | it('Should be able to change the NSFW display attribute', async function () { | 541 | it('Should be able to change the NSFW display attribute', async function () { |
@@ -732,7 +733,7 @@ describe('Test users', function () { | |||
732 | }) | 733 | }) |
733 | 734 | ||
734 | it('Should have removed the user token', async function () { | 735 | it('Should have removed the user token', async function () { |
735 | await getMyUserVideoQuotaUsed(server.url, accessTokenUser, 401) | 736 | await getMyUserVideoQuotaUsed(server.url, accessTokenUser, HttpStatusCode.UNAUTHORIZED_401) |
736 | 737 | ||
737 | accessTokenUser = await userLogin(server, user) | 738 | accessTokenUser = await userLogin(server, user) |
738 | }) | 739 | }) |
@@ -745,9 +746,9 @@ describe('Test users', function () { | |||
745 | password: 'password updated' | 746 | password: 'password updated' |
746 | }) | 747 | }) |
747 | 748 | ||
748 | await getMyUserVideoQuotaUsed(server.url, accessTokenUser, 401) | 749 | await getMyUserVideoQuotaUsed(server.url, accessTokenUser, HttpStatusCode.UNAUTHORIZED_401) |
749 | 750 | ||
750 | await userLogin(server, user, 400) | 751 | await userLogin(server, user, HttpStatusCode.BAD_REQUEST_400) |
751 | 752 | ||
752 | user.password = 'password updated' | 753 | user.password = 'password updated' |
753 | accessTokenUser = await userLogin(server, user) | 754 | accessTokenUser = await userLogin(server, user) |
@@ -766,7 +767,7 @@ describe('Test users', function () { | |||
766 | }) | 767 | }) |
767 | 768 | ||
768 | it('Should not be able to login with this user', async function () { | 769 | it('Should not be able to login with this user', async function () { |
769 | await userLogin(server, user, 400) | 770 | await userLogin(server, user, HttpStatusCode.BAD_REQUEST_400) |
770 | }) | 771 | }) |
771 | 772 | ||
772 | it('Should not have videos of this user', async function () { | 773 | it('Should not have videos of this user', async function () { |
@@ -852,11 +853,11 @@ describe('Test users', function () { | |||
852 | 853 | ||
853 | user16AccessToken = await userLogin(server, user16) | 854 | user16AccessToken = await userLogin(server, user16) |
854 | 855 | ||
855 | await getMyUserInformation(server.url, user16AccessToken, 200) | 856 | await getMyUserInformation(server.url, user16AccessToken, HttpStatusCode.OK_200) |
856 | await blockUser(server.url, user16Id, server.accessToken) | 857 | await blockUser(server.url, user16Id, server.accessToken) |
857 | 858 | ||
858 | await getMyUserInformation(server.url, user16AccessToken, 401) | 859 | await getMyUserInformation(server.url, user16AccessToken, HttpStatusCode.UNAUTHORIZED_401) |
859 | await userLogin(server, user16, 400) | 860 | await userLogin(server, user16, HttpStatusCode.BAD_REQUEST_400) |
860 | }) | 861 | }) |
861 | 862 | ||
862 | it('Should search user by banned status', async function () { | 863 | it('Should search user by banned status', async function () { |
@@ -884,7 +885,7 @@ describe('Test users', function () { | |||
884 | it('Should unblock a user', async function () { | 885 | it('Should unblock a user', async function () { |
885 | await unblockUser(server.url, user16Id, server.accessToken) | 886 | await unblockUser(server.url, user16Id, server.accessToken) |
886 | user16AccessToken = await userLogin(server, user16) | 887 | user16AccessToken = await userLogin(server, user16) |
887 | await getMyUserInformation(server.url, user16AccessToken, 200) | 888 | await getMyUserInformation(server.url, user16AccessToken, HttpStatusCode.OK_200) |
888 | }) | 889 | }) |
889 | }) | 890 | }) |
890 | 891 | ||