diff options
author | Chocobozzz <me@florianbigard.com> | 2021-07-16 09:04:35 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2021-07-20 15:27:18 +0200 |
commit | 89d241a79c262b9775c233b73cff080043ebb5e6 (patch) | |
tree | cb3b6cb431d25d891ef4e02f66c61d252d17048f /server/tests/api/users | |
parent | d23dd9fbfc4d26026352c10f81d2795ceaf2908a (diff) | |
download | PeerTube-89d241a79c262b9775c233b73cff080043ebb5e6.tar.gz PeerTube-89d241a79c262b9775c233b73cff080043ebb5e6.tar.zst PeerTube-89d241a79c262b9775c233b73cff080043ebb5e6.zip |
Shorter server command names
Diffstat (limited to 'server/tests/api/users')
-rw-r--r-- | server/tests/api/users/user-subscriptions.ts | 34 | ||||
-rw-r--r-- | server/tests/api/users/users-multiple-servers.ts | 40 | ||||
-rw-r--r-- | server/tests/api/users/users-verification.ts | 34 | ||||
-rw-r--r-- | server/tests/api/users/users.ts | 262 |
4 files changed, 185 insertions, 185 deletions
diff --git a/server/tests/api/users/user-subscriptions.ts b/server/tests/api/users/user-subscriptions.ts index 622cddb7d..1b15a98dc 100644 --- a/server/tests/api/users/user-subscriptions.ts +++ b/server/tests/api/users/user-subscriptions.ts | |||
@@ -35,26 +35,26 @@ describe('Test users subscriptions', function () { | |||
35 | { | 35 | { |
36 | for (const server of servers) { | 36 | for (const server of servers) { |
37 | const user = { username: 'user' + server.serverNumber, password: 'password' } | 37 | const user = { username: 'user' + server.serverNumber, password: 'password' } |
38 | await server.usersCommand.create({ username: user.username, password: user.password }) | 38 | await server.users.create({ username: user.username, password: user.password }) |
39 | 39 | ||
40 | const accessToken = await server.loginCommand.getAccessToken(user) | 40 | const accessToken = await server.login.getAccessToken(user) |
41 | users.push({ accessToken }) | 41 | users.push({ accessToken }) |
42 | 42 | ||
43 | const videoName1 = 'video 1-' + server.serverNumber | 43 | const videoName1 = 'video 1-' + server.serverNumber |
44 | await server.videosCommand.upload({ token: accessToken, attributes: { name: videoName1 } }) | 44 | await server.videos.upload({ token: accessToken, attributes: { name: videoName1 } }) |
45 | 45 | ||
46 | const videoName2 = 'video 2-' + server.serverNumber | 46 | const videoName2 = 'video 2-' + server.serverNumber |
47 | await server.videosCommand.upload({ token: accessToken, attributes: { name: videoName2 } }) | 47 | await server.videos.upload({ token: accessToken, attributes: { name: videoName2 } }) |
48 | } | 48 | } |
49 | } | 49 | } |
50 | 50 | ||
51 | await waitJobs(servers) | 51 | await waitJobs(servers) |
52 | 52 | ||
53 | command = servers[0].subscriptionsCommand | 53 | command = servers[0].subscriptions |
54 | }) | 54 | }) |
55 | 55 | ||
56 | it('Should display videos of server 2 on server 1', async function () { | 56 | it('Should display videos of server 2 on server 1', async function () { |
57 | const { total } = await servers[0].videosCommand.list() | 57 | const { total } = await servers[0].videos.list() |
58 | 58 | ||
59 | expect(total).to.equal(4) | 59 | expect(total).to.equal(4) |
60 | }) | 60 | }) |
@@ -67,14 +67,14 @@ describe('Test users subscriptions', function () { | |||
67 | 67 | ||
68 | await waitJobs(servers) | 68 | await waitJobs(servers) |
69 | 69 | ||
70 | const { uuid } = await servers[2].videosCommand.upload({ attributes: { name: 'video server 3 added after follow' } }) | 70 | const { uuid } = await servers[2].videos.upload({ attributes: { name: 'video server 3 added after follow' } }) |
71 | video3UUID = uuid | 71 | video3UUID = uuid |
72 | 72 | ||
73 | await waitJobs(servers) | 73 | await waitJobs(servers) |
74 | }) | 74 | }) |
75 | 75 | ||
76 | it('Should not display videos of server 3 on server 1', async function () { | 76 | it('Should not display videos of server 3 on server 1', async function () { |
77 | const { total, data } = await servers[0].videosCommand.list() | 77 | const { total, data } = await servers[0].videos.list() |
78 | expect(total).to.equal(4) | 78 | expect(total).to.equal(4) |
79 | 79 | ||
80 | for (const video of data) { | 80 | for (const video of data) { |
@@ -183,7 +183,7 @@ describe('Test users subscriptions', function () { | |||
183 | this.timeout(60000) | 183 | this.timeout(60000) |
184 | 184 | ||
185 | const videoName = 'video server 1 added after follow' | 185 | const videoName = 'video server 1 added after follow' |
186 | await servers[0].videosCommand.upload({ attributes: { name: videoName } }) | 186 | await servers[0].videos.upload({ attributes: { name: videoName } }) |
187 | 187 | ||
188 | await waitJobs(servers) | 188 | await waitJobs(servers) |
189 | 189 | ||
@@ -209,7 +209,7 @@ describe('Test users subscriptions', function () { | |||
209 | } | 209 | } |
210 | 210 | ||
211 | { | 211 | { |
212 | const { data, total } = await servers[0].videosCommand.list() | 212 | const { data, total } = await servers[0].videos.list() |
213 | expect(total).to.equal(5) | 213 | expect(total).to.equal(5) |
214 | 214 | ||
215 | for (const video of data) { | 215 | for (const video of data) { |
@@ -223,11 +223,11 @@ describe('Test users subscriptions', function () { | |||
223 | it('Should have server 1 follow server 3 and display server 3 videos', async function () { | 223 | it('Should have server 1 follow server 3 and display server 3 videos', async function () { |
224 | this.timeout(60000) | 224 | this.timeout(60000) |
225 | 225 | ||
226 | await servers[0].followsCommand.follow({ targets: [ servers[2].url ] }) | 226 | await servers[0].follows.follow({ targets: [ servers[2].url ] }) |
227 | 227 | ||
228 | await waitJobs(servers) | 228 | await waitJobs(servers) |
229 | 229 | ||
230 | const { data, total } = await servers[0].videosCommand.list() | 230 | const { data, total } = await servers[0].videos.list() |
231 | expect(total).to.equal(8) | 231 | expect(total).to.equal(8) |
232 | 232 | ||
233 | const names = [ '1-3', '2-3', 'video server 3 added after follow' ] | 233 | const names = [ '1-3', '2-3', 'video server 3 added after follow' ] |
@@ -240,11 +240,11 @@ describe('Test users subscriptions', function () { | |||
240 | it('Should remove follow server 1 -> server 3 and hide server 3 videos', async function () { | 240 | it('Should remove follow server 1 -> server 3 and hide server 3 videos', async function () { |
241 | this.timeout(60000) | 241 | this.timeout(60000) |
242 | 242 | ||
243 | await servers[0].followsCommand.unfollow({ target: servers[2] }) | 243 | await servers[0].follows.unfollow({ target: servers[2] }) |
244 | 244 | ||
245 | await waitJobs(servers) | 245 | await waitJobs(servers) |
246 | 246 | ||
247 | const { total, data } = await servers[0].videosCommand.list() | 247 | const { total, data } = await servers[0].videos.list() |
248 | expect(total).to.equal(5) | 248 | expect(total).to.equal(5) |
249 | 249 | ||
250 | for (const video of data) { | 250 | for (const video of data) { |
@@ -280,7 +280,7 @@ describe('Test users subscriptions', function () { | |||
280 | it('Should update a video of server 3 and see the updated video on server 1', async function () { | 280 | it('Should update a video of server 3 and see the updated video on server 1', async function () { |
281 | this.timeout(30000) | 281 | this.timeout(30000) |
282 | 282 | ||
283 | await servers[2].videosCommand.update({ id: video3UUID, attributes: { name: 'video server 3 added after follow updated' } }) | 283 | await servers[2].videos.update({ id: video3UUID, attributes: { name: 'video server 3 added after follow updated' } }) |
284 | 284 | ||
285 | await waitJobs(servers) | 285 | await waitJobs(servers) |
286 | 286 | ||
@@ -325,7 +325,7 @@ describe('Test users subscriptions', function () { | |||
325 | }) | 325 | }) |
326 | 326 | ||
327 | it('Should correctly display public videos on server 1', async function () { | 327 | it('Should correctly display public videos on server 1', async function () { |
328 | const { total, data } = await servers[0].videosCommand.list() | 328 | const { total, data } = await servers[0].videos.list() |
329 | expect(total).to.equal(5) | 329 | expect(total).to.equal(5) |
330 | 330 | ||
331 | for (const video of data) { | 331 | for (const video of data) { |
@@ -356,7 +356,7 @@ describe('Test users subscriptions', function () { | |||
356 | } | 356 | } |
357 | 357 | ||
358 | { | 358 | { |
359 | const { total, data } = await servers[0].videosCommand.list() | 359 | const { total, data } = await servers[0].videos.list() |
360 | expect(total).to.equal(5) | 360 | expect(total).to.equal(5) |
361 | 361 | ||
362 | for (const video of data) { | 362 | for (const video of data) { |
diff --git a/server/tests/api/users/users-multiple-servers.ts b/server/tests/api/users/users-multiple-servers.ts index 3ae105008..f8d7ae88e 100644 --- a/server/tests/api/users/users-multiple-servers.ts +++ b/server/tests/api/users/users-multiple-servers.ts | |||
@@ -42,20 +42,20 @@ describe('Test users with multiple servers', function () { | |||
42 | await doubleFollow(servers[1], servers[2]) | 42 | await doubleFollow(servers[1], servers[2]) |
43 | 43 | ||
44 | // The root user of server 1 is propagated to servers 2 and 3 | 44 | // The root user of server 1 is propagated to servers 2 and 3 |
45 | await servers[0].videosCommand.upload() | 45 | await servers[0].videos.upload() |
46 | 46 | ||
47 | { | 47 | { |
48 | const user = { | 48 | const user = { |
49 | username: 'user1', | 49 | username: 'user1', |
50 | password: 'password' | 50 | password: 'password' |
51 | } | 51 | } |
52 | const created = await servers[0].usersCommand.create(user) | 52 | const created = await servers[0].users.create(user) |
53 | userId = created.id | 53 | userId = created.id |
54 | userAccessToken = await servers[0].loginCommand.getAccessToken(user) | 54 | userAccessToken = await servers[0].login.getAccessToken(user) |
55 | } | 55 | } |
56 | 56 | ||
57 | { | 57 | { |
58 | const { uuid } = await servers[0].videosCommand.upload({ token: userAccessToken }) | 58 | const { uuid } = await servers[0].videos.upload({ token: userAccessToken }) |
59 | videoUUID = uuid | 59 | videoUUID = uuid |
60 | } | 60 | } |
61 | 61 | ||
@@ -65,9 +65,9 @@ describe('Test users with multiple servers', function () { | |||
65 | it('Should be able to update my display name', async function () { | 65 | it('Should be able to update my display name', async function () { |
66 | this.timeout(10000) | 66 | this.timeout(10000) |
67 | 67 | ||
68 | await servers[0].usersCommand.updateMe({ displayName: 'my super display name' }) | 68 | await servers[0].users.updateMe({ displayName: 'my super display name' }) |
69 | 69 | ||
70 | user = await servers[0].usersCommand.getMyInfo() | 70 | user = await servers[0].users.getMyInfo() |
71 | expect(user.account.displayName).to.equal('my super display name') | 71 | expect(user.account.displayName).to.equal('my super display name') |
72 | 72 | ||
73 | await waitJobs(servers) | 73 | await waitJobs(servers) |
@@ -76,9 +76,9 @@ describe('Test users with multiple servers', function () { | |||
76 | it('Should be able to update my description', async function () { | 76 | it('Should be able to update my description', async function () { |
77 | this.timeout(10_000) | 77 | this.timeout(10_000) |
78 | 78 | ||
79 | await servers[0].usersCommand.updateMe({ description: 'my super description updated' }) | 79 | await servers[0].users.updateMe({ description: 'my super description updated' }) |
80 | 80 | ||
81 | user = await servers[0].usersCommand.getMyInfo() | 81 | user = await servers[0].users.getMyInfo() |
82 | expect(user.account.displayName).to.equal('my super display name') | 82 | expect(user.account.displayName).to.equal('my super display name') |
83 | expect(user.account.description).to.equal('my super description updated') | 83 | expect(user.account.description).to.equal('my super description updated') |
84 | 84 | ||
@@ -90,9 +90,9 @@ describe('Test users with multiple servers', function () { | |||
90 | 90 | ||
91 | const fixture = 'avatar2.png' | 91 | const fixture = 'avatar2.png' |
92 | 92 | ||
93 | await servers[0].usersCommand.updateMyAvatar({ fixture }) | 93 | await servers[0].users.updateMyAvatar({ fixture }) |
94 | 94 | ||
95 | user = await servers[0].usersCommand.getMyInfo() | 95 | user = await servers[0].users.getMyInfo() |
96 | userAvatarFilename = user.account.avatar.path | 96 | userAvatarFilename = user.account.avatar.path |
97 | 97 | ||
98 | await testImage(servers[0].url, 'avatar2-resized', userAvatarFilename, '.png') | 98 | await testImage(servers[0].url, 'avatar2-resized', userAvatarFilename, '.png') |
@@ -104,12 +104,12 @@ describe('Test users with multiple servers', function () { | |||
104 | let createdAt: string | Date | 104 | let createdAt: string | Date |
105 | 105 | ||
106 | for (const server of servers) { | 106 | for (const server of servers) { |
107 | const body = await server.accountsCommand.list({ sort: '-createdAt' }) | 107 | const body = await server.accounts.list({ sort: '-createdAt' }) |
108 | 108 | ||
109 | const resList = body.data.find(a => a.name === 'root' && a.host === 'localhost:' + servers[0].port) | 109 | const resList = body.data.find(a => a.name === 'root' && a.host === 'localhost:' + servers[0].port) |
110 | expect(resList).not.to.be.undefined | 110 | expect(resList).not.to.be.undefined |
111 | 111 | ||
112 | const account = await server.accountsCommand.get({ accountName: resList.name + '@' + resList.host }) | 112 | const account = await server.accounts.get({ accountName: resList.name + '@' + resList.host }) |
113 | 113 | ||
114 | if (!createdAt) createdAt = account.createdAt | 114 | if (!createdAt) createdAt = account.createdAt |
115 | 115 | ||
@@ -131,7 +131,7 @@ describe('Test users with multiple servers', function () { | |||
131 | 131 | ||
132 | it('Should list account videos', async function () { | 132 | it('Should list account videos', async function () { |
133 | for (const server of servers) { | 133 | for (const server of servers) { |
134 | const { total, data } = await server.videosCommand.listByAccount({ accountName: 'user1@localhost:' + servers[0].port }) | 134 | const { total, data } = await server.videos.listByAccount({ accountName: 'user1@localhost:' + servers[0].port }) |
135 | 135 | ||
136 | expect(total).to.equal(1) | 136 | expect(total).to.equal(1) |
137 | expect(data).to.be.an('array') | 137 | expect(data).to.be.an('array') |
@@ -143,12 +143,12 @@ describe('Test users with multiple servers', function () { | |||
143 | it('Should search through account videos', async function () { | 143 | it('Should search through account videos', async function () { |
144 | this.timeout(10_000) | 144 | this.timeout(10_000) |
145 | 145 | ||
146 | const created = await servers[0].videosCommand.upload({ token: userAccessToken, attributes: { name: 'Kami no chikara' } }) | 146 | const created = await servers[0].videos.upload({ token: userAccessToken, attributes: { name: 'Kami no chikara' } }) |
147 | 147 | ||
148 | await waitJobs(servers) | 148 | await waitJobs(servers) |
149 | 149 | ||
150 | for (const server of servers) { | 150 | for (const server of servers) { |
151 | const { total, data } = await server.videosCommand.listByAccount({ accountName: 'user1@localhost:' + servers[0].port, search: 'Kami' }) | 151 | const { total, data } = await server.videos.listByAccount({ accountName: 'user1@localhost:' + servers[0].port, search: 'Kami' }) |
152 | 152 | ||
153 | expect(total).to.equal(1) | 153 | expect(total).to.equal(1) |
154 | expect(data).to.be.an('array') | 154 | expect(data).to.be.an('array') |
@@ -161,27 +161,27 @@ describe('Test users with multiple servers', function () { | |||
161 | this.timeout(10_000) | 161 | this.timeout(10_000) |
162 | 162 | ||
163 | for (const server of servers) { | 163 | for (const server of servers) { |
164 | const body = await server.accountsCommand.list({ sort: '-createdAt' }) | 164 | const body = await server.accounts.list({ sort: '-createdAt' }) |
165 | 165 | ||
166 | const accountDeleted = body.data.find(a => a.name === 'user1' && a.host === 'localhost:' + servers[0].port) | 166 | const accountDeleted = body.data.find(a => a.name === 'user1' && a.host === 'localhost:' + servers[0].port) |
167 | expect(accountDeleted).not.to.be.undefined | 167 | expect(accountDeleted).not.to.be.undefined |
168 | 168 | ||
169 | const { data } = await server.channelsCommand.list() | 169 | const { data } = await server.channels.list() |
170 | const videoChannelDeleted = data.find(a => a.displayName === 'Main user1 channel' && a.host === 'localhost:' + servers[0].port) | 170 | const videoChannelDeleted = data.find(a => a.displayName === 'Main user1 channel' && a.host === 'localhost:' + servers[0].port) |
171 | expect(videoChannelDeleted).not.to.be.undefined | 171 | expect(videoChannelDeleted).not.to.be.undefined |
172 | } | 172 | } |
173 | 173 | ||
174 | await servers[0].usersCommand.remove({ userId }) | 174 | await servers[0].users.remove({ userId }) |
175 | 175 | ||
176 | await waitJobs(servers) | 176 | await waitJobs(servers) |
177 | 177 | ||
178 | for (const server of servers) { | 178 | for (const server of servers) { |
179 | const body = await server.accountsCommand.list({ sort: '-createdAt' }) | 179 | const body = await server.accounts.list({ sort: '-createdAt' }) |
180 | 180 | ||
181 | const accountDeleted = body.data.find(a => a.name === 'user1' && a.host === 'localhost:' + servers[0].port) | 181 | const accountDeleted = body.data.find(a => a.name === 'user1' && a.host === 'localhost:' + servers[0].port) |
182 | expect(accountDeleted).to.be.undefined | 182 | expect(accountDeleted).to.be.undefined |
183 | 183 | ||
184 | const { data } = await server.channelsCommand.list() | 184 | const { data } = await server.channels.list() |
185 | const videoChannelDeleted = data.find(a => a.name === 'Main user1 channel' && a.host === 'localhost:' + servers[0].port) | 185 | const videoChannelDeleted = data.find(a => a.name === 'Main user1 channel' && a.host === 'localhost:' + servers[0].port) |
186 | expect(videoChannelDeleted).to.be.undefined | 186 | expect(videoChannelDeleted).to.be.undefined |
187 | } | 187 | } |
diff --git a/server/tests/api/users/users-verification.ts b/server/tests/api/users/users-verification.ts index 271aa3c7a..c8c226fa8 100644 --- a/server/tests/api/users/users-verification.ts +++ b/server/tests/api/users/users-verification.ts | |||
@@ -42,7 +42,7 @@ describe('Test users account verification', function () { | |||
42 | it('Should register user and send verification email if verification required', async function () { | 42 | it('Should register user and send verification email if verification required', async function () { |
43 | this.timeout(30000) | 43 | this.timeout(30000) |
44 | 44 | ||
45 | await server.configCommand.updateCustomSubConfig({ | 45 | await server.config.updateCustomSubConfig({ |
46 | newConfig: { | 46 | newConfig: { |
47 | signup: { | 47 | signup: { |
48 | enabled: true, | 48 | enabled: true, |
@@ -52,7 +52,7 @@ describe('Test users account verification', function () { | |||
52 | } | 52 | } |
53 | }) | 53 | }) |
54 | 54 | ||
55 | await server.usersCommand.register(user1) | 55 | await server.users.register(user1) |
56 | 56 | ||
57 | await waitJobs(server) | 57 | await waitJobs(server) |
58 | expectedEmailsLength++ | 58 | expectedEmailsLength++ |
@@ -71,22 +71,22 @@ describe('Test users account verification', function () { | |||
71 | 71 | ||
72 | userId = parseInt(userIdMatches[1], 10) | 72 | userId = parseInt(userIdMatches[1], 10) |
73 | 73 | ||
74 | const body = await server.usersCommand.get({ userId }) | 74 | const body = await server.users.get({ userId }) |
75 | expect(body.emailVerified).to.be.false | 75 | expect(body.emailVerified).to.be.false |
76 | }) | 76 | }) |
77 | 77 | ||
78 | it('Should not allow login for user with unverified email', async function () { | 78 | it('Should not allow login for user with unverified email', async function () { |
79 | const { detail } = await server.loginCommand.login({ user: user1, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) | 79 | const { detail } = await server.login.login({ user: user1, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) |
80 | expect(detail).to.contain('User email is not verified.') | 80 | expect(detail).to.contain('User email is not verified.') |
81 | }) | 81 | }) |
82 | 82 | ||
83 | it('Should verify the user via email and allow login', async function () { | 83 | it('Should verify the user via email and allow login', async function () { |
84 | await server.usersCommand.verifyEmail({ userId, verificationString }) | 84 | await server.users.verifyEmail({ userId, verificationString }) |
85 | 85 | ||
86 | const body = await server.loginCommand.login({ user: user1 }) | 86 | const body = await server.login.login({ user: user1 }) |
87 | userAccessToken = body.access_token | 87 | userAccessToken = body.access_token |
88 | 88 | ||
89 | const user = await server.usersCommand.get({ userId }) | 89 | const user = await server.users.get({ userId }) |
90 | expect(user.emailVerified).to.be.true | 90 | expect(user.emailVerified).to.be.true |
91 | }) | 91 | }) |
92 | 92 | ||
@@ -96,7 +96,7 @@ describe('Test users account verification', function () { | |||
96 | let updateVerificationString: string | 96 | let updateVerificationString: string |
97 | 97 | ||
98 | { | 98 | { |
99 | await server.usersCommand.updateMe({ | 99 | await server.users.updateMe({ |
100 | token: userAccessToken, | 100 | token: userAccessToken, |
101 | email: 'updated@example.com', | 101 | email: 'updated@example.com', |
102 | currentPassword: user1.password | 102 | currentPassword: user1.password |
@@ -113,15 +113,15 @@ describe('Test users account verification', function () { | |||
113 | } | 113 | } |
114 | 114 | ||
115 | { | 115 | { |
116 | const me = await server.usersCommand.getMyInfo({ token: userAccessToken }) | 116 | const me = await server.users.getMyInfo({ token: userAccessToken }) |
117 | expect(me.email).to.equal('user_1@example.com') | 117 | expect(me.email).to.equal('user_1@example.com') |
118 | expect(me.pendingEmail).to.equal('updated@example.com') | 118 | expect(me.pendingEmail).to.equal('updated@example.com') |
119 | } | 119 | } |
120 | 120 | ||
121 | { | 121 | { |
122 | await server.usersCommand.verifyEmail({ userId, verificationString: updateVerificationString, isPendingEmail: true }) | 122 | await server.users.verifyEmail({ userId, verificationString: updateVerificationString, isPendingEmail: true }) |
123 | 123 | ||
124 | const me = await server.usersCommand.getMyInfo({ token: userAccessToken }) | 124 | const me = await server.users.getMyInfo({ token: userAccessToken }) |
125 | expect(me.email).to.equal('updated@example.com') | 125 | expect(me.email).to.equal('updated@example.com') |
126 | expect(me.pendingEmail).to.be.null | 126 | expect(me.pendingEmail).to.be.null |
127 | } | 127 | } |
@@ -129,7 +129,7 @@ describe('Test users account verification', function () { | |||
129 | 129 | ||
130 | it('Should register user not requiring email verification if setting not enabled', async function () { | 130 | it('Should register user not requiring email verification if setting not enabled', async function () { |
131 | this.timeout(5000) | 131 | this.timeout(5000) |
132 | await server.configCommand.updateCustomSubConfig({ | 132 | await server.config.updateCustomSubConfig({ |
133 | newConfig: { | 133 | newConfig: { |
134 | signup: { | 134 | signup: { |
135 | enabled: true, | 135 | enabled: true, |
@@ -139,19 +139,19 @@ describe('Test users account verification', function () { | |||
139 | } | 139 | } |
140 | }) | 140 | }) |
141 | 141 | ||
142 | await server.usersCommand.register(user2) | 142 | await server.users.register(user2) |
143 | 143 | ||
144 | await waitJobs(server) | 144 | await waitJobs(server) |
145 | expect(emails).to.have.lengthOf(expectedEmailsLength) | 145 | expect(emails).to.have.lengthOf(expectedEmailsLength) |
146 | 146 | ||
147 | const accessToken = await server.loginCommand.getAccessToken(user2) | 147 | const accessToken = await server.login.getAccessToken(user2) |
148 | 148 | ||
149 | const user = await server.usersCommand.getMyInfo({ token: accessToken }) | 149 | const user = await server.users.getMyInfo({ token: accessToken }) |
150 | expect(user.emailVerified).to.be.null | 150 | expect(user.emailVerified).to.be.null |
151 | }) | 151 | }) |
152 | 152 | ||
153 | it('Should allow login for user with unverified email when setting later enabled', async function () { | 153 | it('Should allow login for user with unverified email when setting later enabled', async function () { |
154 | await server.configCommand.updateCustomSubConfig({ | 154 | await server.config.updateCustomSubConfig({ |
155 | newConfig: { | 155 | newConfig: { |
156 | signup: { | 156 | signup: { |
157 | enabled: true, | 157 | enabled: true, |
@@ -161,7 +161,7 @@ describe('Test users account verification', function () { | |||
161 | } | 161 | } |
162 | }) | 162 | }) |
163 | 163 | ||
164 | await server.loginCommand.getAccessToken(user2) | 164 | await server.login.getAccessToken(user2) |
165 | }) | 165 | }) |
166 | 166 | ||
167 | after(async function () { | 167 | after(async function () { |
diff --git a/server/tests/api/users/users.ts b/server/tests/api/users/users.ts index 6f3873939..310136a37 100644 --- a/server/tests/api/users/users.ts +++ b/server/tests/api/users/users.ts | |||
@@ -42,7 +42,7 @@ describe('Test users', function () { | |||
42 | 42 | ||
43 | await setAccessTokensToServers([ server ]) | 43 | await setAccessTokensToServers([ server ]) |
44 | 44 | ||
45 | await server.pluginsCommand.install({ npmName: 'peertube-theme-background-red' }) | 45 | await server.plugins.install({ npmName: 'peertube-theme-background-red' }) |
46 | }) | 46 | }) |
47 | 47 | ||
48 | describe('OAuth client', function () { | 48 | describe('OAuth client', function () { |
@@ -53,8 +53,8 @@ describe('Test users', function () { | |||
53 | it('Should remove the last client') | 53 | it('Should remove the last client') |
54 | 54 | ||
55 | it('Should not login with an invalid client id', async function () { | 55 | it('Should not login with an invalid client id', async function () { |
56 | const client = { id: 'client', secret: server.client.secret } | 56 | const client = { id: 'client', secret: server.store.client.secret } |
57 | const body = await server.loginCommand.login({ client, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) | 57 | const body = await server.login.login({ client, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) |
58 | 58 | ||
59 | expect(body.code).to.equal(OAuth2ErrorCode.INVALID_CLIENT) | 59 | expect(body.code).to.equal(OAuth2ErrorCode.INVALID_CLIENT) |
60 | expect(body.error).to.contain('client is invalid') | 60 | expect(body.error).to.contain('client is invalid') |
@@ -63,8 +63,8 @@ describe('Test users', function () { | |||
63 | }) | 63 | }) |
64 | 64 | ||
65 | it('Should not login with an invalid client secret', async function () { | 65 | it('Should not login with an invalid client secret', async function () { |
66 | const client = { id: server.client.id, secret: 'coucou' } | 66 | const client = { id: server.store.client.id, secret: 'coucou' } |
67 | const body = await server.loginCommand.login({ client, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) | 67 | const body = await server.login.login({ client, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) |
68 | 68 | ||
69 | expect(body.code).to.equal(OAuth2ErrorCode.INVALID_CLIENT) | 69 | expect(body.code).to.equal(OAuth2ErrorCode.INVALID_CLIENT) |
70 | expect(body.error).to.contain('client is invalid') | 70 | expect(body.error).to.contain('client is invalid') |
@@ -76,8 +76,8 @@ describe('Test users', function () { | |||
76 | describe('Login', function () { | 76 | describe('Login', function () { |
77 | 77 | ||
78 | it('Should not login with an invalid username', async function () { | 78 | it('Should not login with an invalid username', async function () { |
79 | const user = { username: 'captain crochet', password: server.user.password } | 79 | const user = { username: 'captain crochet', password: server.store.user.password } |
80 | const body = await server.loginCommand.login({ user, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) | 80 | const body = await server.login.login({ user, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) |
81 | 81 | ||
82 | expect(body.code).to.equal(OAuth2ErrorCode.INVALID_GRANT) | 82 | expect(body.code).to.equal(OAuth2ErrorCode.INVALID_GRANT) |
83 | expect(body.error).to.contain('credentials are invalid') | 83 | expect(body.error).to.contain('credentials are invalid') |
@@ -86,8 +86,8 @@ describe('Test users', function () { | |||
86 | }) | 86 | }) |
87 | 87 | ||
88 | it('Should not login with an invalid password', async function () { | 88 | it('Should not login with an invalid password', async function () { |
89 | const user = { username: server.user.username, password: 'mew_three' } | 89 | const user = { username: server.store.user.username, password: 'mew_three' } |
90 | const body = await server.loginCommand.login({ user, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) | 90 | const body = await server.login.login({ user, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) |
91 | 91 | ||
92 | expect(body.code).to.equal(OAuth2ErrorCode.INVALID_GRANT) | 92 | expect(body.code).to.equal(OAuth2ErrorCode.INVALID_GRANT) |
93 | expect(body.error).to.contain('credentials are invalid') | 93 | expect(body.error).to.contain('credentials are invalid') |
@@ -98,13 +98,13 @@ describe('Test users', function () { | |||
98 | it('Should not be able to upload a video', async function () { | 98 | it('Should not be able to upload a video', async function () { |
99 | token = 'my_super_token' | 99 | token = 'my_super_token' |
100 | 100 | ||
101 | await server.videosCommand.upload({ token, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) | 101 | await server.videos.upload({ token, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) |
102 | }) | 102 | }) |
103 | 103 | ||
104 | it('Should not be able to follow', async function () { | 104 | it('Should not be able to follow', async function () { |
105 | token = 'my_super_token' | 105 | token = 'my_super_token' |
106 | 106 | ||
107 | await server.followsCommand.follow({ | 107 | await server.follows.follow({ |
108 | targets: [ 'http://example.com' ], | 108 | targets: [ 'http://example.com' ], |
109 | token, | 109 | token, |
110 | expectedStatus: HttpStatusCode.UNAUTHORIZED_401 | 110 | expectedStatus: HttpStatusCode.UNAUTHORIZED_401 |
@@ -114,28 +114,28 @@ describe('Test users', function () { | |||
114 | it('Should not be able to unfollow') | 114 | it('Should not be able to unfollow') |
115 | 115 | ||
116 | it('Should be able to login', async function () { | 116 | it('Should be able to login', async function () { |
117 | const body = await server.loginCommand.login({ expectedStatus: HttpStatusCode.OK_200 }) | 117 | const body = await server.login.login({ expectedStatus: HttpStatusCode.OK_200 }) |
118 | 118 | ||
119 | token = body.access_token | 119 | token = body.access_token |
120 | }) | 120 | }) |
121 | 121 | ||
122 | it('Should be able to login with an insensitive username', async function () { | 122 | it('Should be able to login with an insensitive username', async function () { |
123 | const user = { username: 'RoOt', password: server.user.password } | 123 | const user = { username: 'RoOt', password: server.store.user.password } |
124 | await server.loginCommand.login({ user, expectedStatus: HttpStatusCode.OK_200 }) | 124 | await server.login.login({ user, expectedStatus: HttpStatusCode.OK_200 }) |
125 | 125 | ||
126 | const user2 = { username: 'rOoT', password: server.user.password } | 126 | const user2 = { username: 'rOoT', password: server.store.user.password } |
127 | await server.loginCommand.login({ user: user2, expectedStatus: HttpStatusCode.OK_200 }) | 127 | await server.login.login({ user: user2, expectedStatus: HttpStatusCode.OK_200 }) |
128 | 128 | ||
129 | const user3 = { username: 'ROOt', password: server.user.password } | 129 | const user3 = { username: 'ROOt', password: server.store.user.password } |
130 | await server.loginCommand.login({ user: user3, expectedStatus: HttpStatusCode.OK_200 }) | 130 | await server.login.login({ user: user3, expectedStatus: HttpStatusCode.OK_200 }) |
131 | }) | 131 | }) |
132 | }) | 132 | }) |
133 | 133 | ||
134 | describe('Upload', function () { | 134 | describe('Upload', function () { |
135 | 135 | ||
136 | it('Should upload the video with the correct token', async function () { | 136 | it('Should upload the video with the correct token', async function () { |
137 | await server.videosCommand.upload({ token }) | 137 | await server.videos.upload({ token }) |
138 | const { data } = await server.videosCommand.list() | 138 | const { data } = await server.videos.list() |
139 | const video = data[0] | 139 | const video = data[0] |
140 | 140 | ||
141 | expect(video.account.name).to.equal('root') | 141 | expect(video.account.name).to.equal('root') |
@@ -143,24 +143,24 @@ describe('Test users', function () { | |||
143 | }) | 143 | }) |
144 | 144 | ||
145 | it('Should upload the video again with the correct token', async function () { | 145 | it('Should upload the video again with the correct token', async function () { |
146 | await server.videosCommand.upload({ token }) | 146 | await server.videos.upload({ token }) |
147 | }) | 147 | }) |
148 | }) | 148 | }) |
149 | 149 | ||
150 | describe('Ratings', function () { | 150 | describe('Ratings', function () { |
151 | 151 | ||
152 | it('Should retrieve a video rating', async function () { | 152 | it('Should retrieve a video rating', async function () { |
153 | await server.videosCommand.rate({ id: videoId, rating: 'like' }) | 153 | await server.videos.rate({ id: videoId, rating: 'like' }) |
154 | const rating = await server.usersCommand.getMyRating({ token, videoId }) | 154 | const rating = await server.users.getMyRating({ token, videoId }) |
155 | 155 | ||
156 | expect(rating.videoId).to.equal(videoId) | 156 | expect(rating.videoId).to.equal(videoId) |
157 | expect(rating.rating).to.equal('like') | 157 | expect(rating.rating).to.equal('like') |
158 | }) | 158 | }) |
159 | 159 | ||
160 | it('Should retrieve ratings list', async function () { | 160 | it('Should retrieve ratings list', async function () { |
161 | await server.videosCommand.rate({ id: videoId, rating: 'like' }) | 161 | await server.videos.rate({ id: videoId, rating: 'like' }) |
162 | 162 | ||
163 | const body = await server.accountsCommand.listRatings({ accountName: server.user.username }) | 163 | const body = await server.accounts.listRatings({ accountName: server.store.user.username }) |
164 | 164 | ||
165 | expect(body.total).to.equal(1) | 165 | expect(body.total).to.equal(1) |
166 | expect(body.data[0].video.id).to.equal(videoId) | 166 | expect(body.data[0].video.id).to.equal(videoId) |
@@ -169,12 +169,12 @@ describe('Test users', function () { | |||
169 | 169 | ||
170 | it('Should retrieve ratings list by rating type', async function () { | 170 | it('Should retrieve ratings list by rating type', async function () { |
171 | { | 171 | { |
172 | const body = await server.accountsCommand.listRatings({ accountName: server.user.username, rating: 'like' }) | 172 | const body = await server.accounts.listRatings({ accountName: server.store.user.username, rating: 'like' }) |
173 | expect(body.data.length).to.equal(1) | 173 | expect(body.data.length).to.equal(1) |
174 | } | 174 | } |
175 | 175 | ||
176 | { | 176 | { |
177 | const body = await server.accountsCommand.listRatings({ accountName: server.user.username, rating: 'dislike' }) | 177 | const body = await server.accounts.listRatings({ accountName: server.store.user.username, rating: 'dislike' }) |
178 | expect(body.data.length).to.equal(0) | 178 | expect(body.data.length).to.equal(0) |
179 | } | 179 | } |
180 | }) | 180 | }) |
@@ -182,27 +182,27 @@ describe('Test users', function () { | |||
182 | 182 | ||
183 | describe('Remove video', function () { | 183 | describe('Remove video', function () { |
184 | it('Should not be able to remove the video with an incorrect token', async function () { | 184 | it('Should not be able to remove the video with an incorrect token', async function () { |
185 | await server.videosCommand.remove({ token: 'bad_token', id: videoId, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) | 185 | await server.videos.remove({ token: 'bad_token', id: videoId, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) |
186 | }) | 186 | }) |
187 | 187 | ||
188 | it('Should not be able to remove the video with the token of another account') | 188 | it('Should not be able to remove the video with the token of another account') |
189 | 189 | ||
190 | it('Should be able to remove the video with the correct token', async function () { | 190 | it('Should be able to remove the video with the correct token', async function () { |
191 | await server.videosCommand.remove({ token, id: videoId }) | 191 | await server.videos.remove({ token, id: videoId }) |
192 | }) | 192 | }) |
193 | }) | 193 | }) |
194 | 194 | ||
195 | describe('Logout', function () { | 195 | describe('Logout', function () { |
196 | it('Should logout (revoke token)', async function () { | 196 | it('Should logout (revoke token)', async function () { |
197 | await server.loginCommand.logout({ token: server.accessToken }) | 197 | await server.login.logout({ token: server.accessToken }) |
198 | }) | 198 | }) |
199 | 199 | ||
200 | it('Should not be able to get the user information', async function () { | 200 | it('Should not be able to get the user information', async function () { |
201 | await server.usersCommand.getMyInfo({ expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) | 201 | await server.users.getMyInfo({ expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) |
202 | }) | 202 | }) |
203 | 203 | ||
204 | it('Should not be able to upload a video', async function () { | 204 | it('Should not be able to upload a video', async function () { |
205 | await server.videosCommand.upload({ attributes: { name: 'video' }, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) | 205 | await server.videos.upload({ attributes: { name: 'video' }, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) |
206 | }) | 206 | }) |
207 | 207 | ||
208 | it('Should not be able to rate a video', async function () { | 208 | it('Should not be able to rate a video', async function () { |
@@ -222,64 +222,64 @@ describe('Test users', function () { | |||
222 | }) | 222 | }) |
223 | 223 | ||
224 | it('Should be able to login again', async function () { | 224 | it('Should be able to login again', async function () { |
225 | const body = await server.loginCommand.login() | 225 | const body = await server.login.login() |
226 | server.accessToken = body.access_token | 226 | server.accessToken = body.access_token |
227 | server.refreshToken = body.refresh_token | 227 | server.refreshToken = body.refresh_token |
228 | }) | 228 | }) |
229 | 229 | ||
230 | it('Should be able to get my user information again', async function () { | 230 | it('Should be able to get my user information again', async function () { |
231 | await server.usersCommand.getMyInfo() | 231 | await server.users.getMyInfo() |
232 | }) | 232 | }) |
233 | 233 | ||
234 | it('Should have an expired access token', async function () { | 234 | it('Should have an expired access token', async function () { |
235 | this.timeout(15000) | 235 | this.timeout(15000) |
236 | 236 | ||
237 | await server.sqlCommand.setTokenField(server.accessToken, 'accessTokenExpiresAt', new Date().toISOString()) | 237 | await server.sql.setTokenField(server.accessToken, 'accessTokenExpiresAt', new Date().toISOString()) |
238 | await server.sqlCommand.setTokenField(server.accessToken, 'refreshTokenExpiresAt', new Date().toISOString()) | 238 | await server.sql.setTokenField(server.accessToken, 'refreshTokenExpiresAt', new Date().toISOString()) |
239 | 239 | ||
240 | await killallServers([ server ]) | 240 | await killallServers([ server ]) |
241 | await reRunServer(server) | 241 | await reRunServer(server) |
242 | 242 | ||
243 | await server.usersCommand.getMyInfo({ expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) | 243 | await server.users.getMyInfo({ expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) |
244 | }) | 244 | }) |
245 | 245 | ||
246 | it('Should not be able to refresh an access token with an expired refresh token', async function () { | 246 | it('Should not be able to refresh an access token with an expired refresh token', async function () { |
247 | await server.loginCommand.refreshToken({ refreshToken: server.refreshToken, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) | 247 | await server.login.refreshToken({ refreshToken: server.refreshToken, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) |
248 | }) | 248 | }) |
249 | 249 | ||
250 | it('Should refresh the token', async function () { | 250 | it('Should refresh the token', async function () { |
251 | this.timeout(15000) | 251 | this.timeout(15000) |
252 | 252 | ||
253 | const futureDate = new Date(new Date().getTime() + 1000 * 60).toISOString() | 253 | const futureDate = new Date(new Date().getTime() + 1000 * 60).toISOString() |
254 | await server.sqlCommand.setTokenField(server.accessToken, 'refreshTokenExpiresAt', futureDate) | 254 | await server.sql.setTokenField(server.accessToken, 'refreshTokenExpiresAt', futureDate) |
255 | 255 | ||
256 | await killallServers([ server ]) | 256 | await killallServers([ server ]) |
257 | await reRunServer(server) | 257 | await reRunServer(server) |
258 | 258 | ||
259 | const res = await server.loginCommand.refreshToken({ refreshToken: server.refreshToken }) | 259 | const res = await server.login.refreshToken({ refreshToken: server.refreshToken }) |
260 | server.accessToken = res.body.access_token | 260 | server.accessToken = res.body.access_token |
261 | server.refreshToken = res.body.refresh_token | 261 | server.refreshToken = res.body.refresh_token |
262 | }) | 262 | }) |
263 | 263 | ||
264 | it('Should be able to get my user information again', async function () { | 264 | it('Should be able to get my user information again', async function () { |
265 | await server.usersCommand.getMyInfo() | 265 | await server.users.getMyInfo() |
266 | }) | 266 | }) |
267 | }) | 267 | }) |
268 | 268 | ||
269 | describe('Creating a user', function () { | 269 | describe('Creating a user', function () { |
270 | 270 | ||
271 | it('Should be able to create a new user', async function () { | 271 | it('Should be able to create a new user', async function () { |
272 | await server.usersCommand.create({ ...user, videoQuota: 2 * 1024 * 1024, adminFlags: UserAdminFlag.BYPASS_VIDEO_AUTO_BLACKLIST }) | 272 | await server.users.create({ ...user, videoQuota: 2 * 1024 * 1024, adminFlags: UserAdminFlag.BYPASS_VIDEO_AUTO_BLACKLIST }) |
273 | }) | 273 | }) |
274 | 274 | ||
275 | it('Should be able to login with this user', async function () { | 275 | it('Should be able to login with this user', async function () { |
276 | userToken = await server.loginCommand.getAccessToken(user) | 276 | userToken = await server.login.getAccessToken(user) |
277 | }) | 277 | }) |
278 | 278 | ||
279 | it('Should be able to get user information', async function () { | 279 | it('Should be able to get user information', async function () { |
280 | const userMe = await server.usersCommand.getMyInfo({ token: userToken }) | 280 | const userMe = await server.users.getMyInfo({ token: userToken }) |
281 | 281 | ||
282 | const userGet = await server.usersCommand.get({ userId: userMe.id, withStats: true }) | 282 | const userGet = await server.users.get({ userId: userMe.id, withStats: true }) |
283 | 283 | ||
284 | for (const user of [ userMe, userGet ]) { | 284 | for (const user of [ userMe, userGet ]) { |
285 | expect(user.username).to.equal('user_1') | 285 | expect(user.username).to.equal('user_1') |
@@ -319,20 +319,20 @@ describe('Test users', function () { | |||
319 | name: 'super user video', | 319 | name: 'super user video', |
320 | fixture: 'video_short.webm' | 320 | fixture: 'video_short.webm' |
321 | } | 321 | } |
322 | await server.videosCommand.upload({ token: userToken, attributes }) | 322 | await server.videos.upload({ token: userToken, attributes }) |
323 | }) | 323 | }) |
324 | 324 | ||
325 | it('Should have video quota updated', async function () { | 325 | it('Should have video quota updated', async function () { |
326 | const quota = await server.usersCommand.getMyQuotaUsed({ token: userToken }) | 326 | const quota = await server.users.getMyQuotaUsed({ token: userToken }) |
327 | expect(quota.videoQuotaUsed).to.equal(218910) | 327 | expect(quota.videoQuotaUsed).to.equal(218910) |
328 | 328 | ||
329 | const { data } = await server.usersCommand.list() | 329 | const { data } = await server.users.list() |
330 | const tmpUser = data.find(u => u.username === user.username) | 330 | const tmpUser = data.find(u => u.username === user.username) |
331 | expect(tmpUser.videoQuotaUsed).to.equal(218910) | 331 | expect(tmpUser.videoQuotaUsed).to.equal(218910) |
332 | }) | 332 | }) |
333 | 333 | ||
334 | it('Should be able to list my videos', async function () { | 334 | it('Should be able to list my videos', async function () { |
335 | const { total, data } = await server.videosCommand.listMyVideos({ token: userToken }) | 335 | const { total, data } = await server.videos.listMyVideos({ token: userToken }) |
336 | expect(total).to.equal(1) | 336 | expect(total).to.equal(1) |
337 | expect(data).to.have.lengthOf(1) | 337 | expect(data).to.have.lengthOf(1) |
338 | 338 | ||
@@ -344,13 +344,13 @@ describe('Test users', function () { | |||
344 | 344 | ||
345 | it('Should be able to search in my videos', async function () { | 345 | it('Should be able to search in my videos', async function () { |
346 | { | 346 | { |
347 | const { total, data } = await server.videosCommand.listMyVideos({ token: userToken, sort: '-createdAt', search: 'user video' }) | 347 | const { total, data } = await server.videos.listMyVideos({ token: userToken, sort: '-createdAt', search: 'user video' }) |
348 | expect(total).to.equal(1) | 348 | expect(total).to.equal(1) |
349 | expect(data).to.have.lengthOf(1) | 349 | expect(data).to.have.lengthOf(1) |
350 | } | 350 | } |
351 | 351 | ||
352 | { | 352 | { |
353 | const { total, data } = await server.videosCommand.listMyVideos({ token: userToken, sort: '-createdAt', search: 'toto' }) | 353 | const { total, data } = await server.videos.listMyVideos({ token: userToken, sort: '-createdAt', search: 'toto' }) |
354 | expect(total).to.equal(0) | 354 | expect(total).to.equal(0) |
355 | expect(data).to.have.lengthOf(0) | 355 | expect(data).to.have.lengthOf(0) |
356 | } | 356 | } |
@@ -360,11 +360,11 @@ describe('Test users', function () { | |||
360 | this.timeout(60000) | 360 | this.timeout(60000) |
361 | 361 | ||
362 | { | 362 | { |
363 | const config = await server.configCommand.getCustomConfig() | 363 | const config = await server.config.getCustomConfig() |
364 | config.transcoding.webtorrent.enabled = false | 364 | config.transcoding.webtorrent.enabled = false |
365 | config.transcoding.hls.enabled = true | 365 | config.transcoding.hls.enabled = true |
366 | config.transcoding.enabled = true | 366 | config.transcoding.enabled = true |
367 | await server.configCommand.updateCustomSubConfig({ newConfig: config }) | 367 | await server.config.updateCustomSubConfig({ newConfig: config }) |
368 | } | 368 | } |
369 | 369 | ||
370 | { | 370 | { |
@@ -372,13 +372,13 @@ describe('Test users', function () { | |||
372 | name: 'super user video 2', | 372 | name: 'super user video 2', |
373 | fixture: 'video_short.webm' | 373 | fixture: 'video_short.webm' |
374 | } | 374 | } |
375 | await server.videosCommand.upload({ token: userToken, attributes }) | 375 | await server.videos.upload({ token: userToken, attributes }) |
376 | 376 | ||
377 | await waitJobs([ server ]) | 377 | await waitJobs([ server ]) |
378 | } | 378 | } |
379 | 379 | ||
380 | { | 380 | { |
381 | const data = await server.usersCommand.getMyQuotaUsed({ token: userToken }) | 381 | const data = await server.users.getMyQuotaUsed({ token: userToken }) |
382 | expect(data.videoQuotaUsed).to.be.greaterThan(220000) | 382 | expect(data.videoQuotaUsed).to.be.greaterThan(220000) |
383 | } | 383 | } |
384 | }) | 384 | }) |
@@ -387,7 +387,7 @@ describe('Test users', function () { | |||
387 | describe('Users listing', function () { | 387 | describe('Users listing', function () { |
388 | 388 | ||
389 | it('Should list all the users', async function () { | 389 | it('Should list all the users', async function () { |
390 | const { data, total } = await server.usersCommand.list() | 390 | const { data, total } = await server.users.list() |
391 | 391 | ||
392 | expect(total).to.equal(2) | 392 | expect(total).to.equal(2) |
393 | expect(data).to.be.an('array') | 393 | expect(data).to.be.an('array') |
@@ -410,7 +410,7 @@ describe('Test users', function () { | |||
410 | }) | 410 | }) |
411 | 411 | ||
412 | it('Should list only the first user by username asc', async function () { | 412 | it('Should list only the first user by username asc', async function () { |
413 | const { total, data } = await server.usersCommand.list({ start: 0, count: 1, sort: 'username' }) | 413 | const { total, data } = await server.users.list({ start: 0, count: 1, sort: 'username' }) |
414 | 414 | ||
415 | expect(total).to.equal(2) | 415 | expect(total).to.equal(2) |
416 | expect(data.length).to.equal(1) | 416 | expect(data.length).to.equal(1) |
@@ -423,7 +423,7 @@ describe('Test users', function () { | |||
423 | }) | 423 | }) |
424 | 424 | ||
425 | it('Should list only the first user by username desc', async function () { | 425 | it('Should list only the first user by username desc', async function () { |
426 | const { total, data } = await server.usersCommand.list({ start: 0, count: 1, sort: '-username' }) | 426 | const { total, data } = await server.users.list({ start: 0, count: 1, sort: '-username' }) |
427 | 427 | ||
428 | expect(total).to.equal(2) | 428 | expect(total).to.equal(2) |
429 | expect(data.length).to.equal(1) | 429 | expect(data.length).to.equal(1) |
@@ -435,7 +435,7 @@ describe('Test users', function () { | |||
435 | }) | 435 | }) |
436 | 436 | ||
437 | it('Should list only the second user by createdAt desc', async function () { | 437 | it('Should list only the second user by createdAt desc', async function () { |
438 | const { data, total } = await server.usersCommand.list({ start: 0, count: 1, sort: '-createdAt' }) | 438 | const { data, total } = await server.users.list({ start: 0, count: 1, sort: '-createdAt' }) |
439 | expect(total).to.equal(2) | 439 | expect(total).to.equal(2) |
440 | 440 | ||
441 | expect(data.length).to.equal(1) | 441 | expect(data.length).to.equal(1) |
@@ -447,7 +447,7 @@ describe('Test users', function () { | |||
447 | }) | 447 | }) |
448 | 448 | ||
449 | it('Should list all the users by createdAt asc', async function () { | 449 | it('Should list all the users by createdAt asc', async function () { |
450 | const { data, total } = await server.usersCommand.list({ start: 0, count: 2, sort: 'createdAt' }) | 450 | const { data, total } = await server.users.list({ start: 0, count: 2, sort: 'createdAt' }) |
451 | 451 | ||
452 | expect(total).to.equal(2) | 452 | expect(total).to.equal(2) |
453 | expect(data.length).to.equal(2) | 453 | expect(data.length).to.equal(2) |
@@ -462,7 +462,7 @@ describe('Test users', function () { | |||
462 | }) | 462 | }) |
463 | 463 | ||
464 | it('Should search user by username', async function () { | 464 | it('Should search user by username', async function () { |
465 | const { data, total } = await server.usersCommand.list({ start: 0, count: 2, sort: 'createdAt', search: 'oot' }) | 465 | const { data, total } = await server.users.list({ start: 0, count: 2, sort: 'createdAt', search: 'oot' }) |
466 | expect(total).to.equal(1) | 466 | expect(total).to.equal(1) |
467 | expect(data.length).to.equal(1) | 467 | expect(data.length).to.equal(1) |
468 | expect(data[0].username).to.equal('root') | 468 | expect(data[0].username).to.equal('root') |
@@ -470,7 +470,7 @@ describe('Test users', function () { | |||
470 | 470 | ||
471 | it('Should search user by email', async function () { | 471 | it('Should search user by email', async function () { |
472 | { | 472 | { |
473 | const { total, data } = await server.usersCommand.list({ start: 0, count: 2, sort: 'createdAt', search: 'r_1@exam' }) | 473 | const { total, data } = await server.users.list({ start: 0, count: 2, sort: 'createdAt', search: 'r_1@exam' }) |
474 | expect(total).to.equal(1) | 474 | expect(total).to.equal(1) |
475 | expect(data.length).to.equal(1) | 475 | expect(data.length).to.equal(1) |
476 | expect(data[0].username).to.equal('user_1') | 476 | expect(data[0].username).to.equal('user_1') |
@@ -478,7 +478,7 @@ describe('Test users', function () { | |||
478 | } | 478 | } |
479 | 479 | ||
480 | { | 480 | { |
481 | const { total, data } = await server.usersCommand.list({ start: 0, count: 2, sort: 'createdAt', search: 'example' }) | 481 | const { total, data } = await server.users.list({ start: 0, count: 2, sort: 'createdAt', search: 'example' }) |
482 | expect(total).to.equal(2) | 482 | expect(total).to.equal(2) |
483 | expect(data.length).to.equal(2) | 483 | expect(data.length).to.equal(2) |
484 | expect(data[0].username).to.equal('root') | 484 | expect(data[0].username).to.equal('root') |
@@ -490,23 +490,23 @@ describe('Test users', function () { | |||
490 | describe('Update my account', function () { | 490 | describe('Update my account', function () { |
491 | 491 | ||
492 | it('Should update my password', async function () { | 492 | it('Should update my password', async function () { |
493 | await server.usersCommand.updateMe({ | 493 | await server.users.updateMe({ |
494 | token: userToken, | 494 | token: userToken, |
495 | currentPassword: 'super password', | 495 | currentPassword: 'super password', |
496 | password: 'new password' | 496 | password: 'new password' |
497 | }) | 497 | }) |
498 | user.password = 'new password' | 498 | user.password = 'new password' |
499 | 499 | ||
500 | await server.loginCommand.login({ user }) | 500 | await server.login.login({ user }) |
501 | }) | 501 | }) |
502 | 502 | ||
503 | it('Should be able to change the NSFW display attribute', async function () { | 503 | it('Should be able to change the NSFW display attribute', async function () { |
504 | await server.usersCommand.updateMe({ | 504 | await server.users.updateMe({ |
505 | token: userToken, | 505 | token: userToken, |
506 | nsfwPolicy: 'do_not_list' | 506 | nsfwPolicy: 'do_not_list' |
507 | }) | 507 | }) |
508 | 508 | ||
509 | const user = await server.usersCommand.getMyInfo({ token: userToken }) | 509 | const user = await server.users.getMyInfo({ token: userToken }) |
510 | expect(user.username).to.equal('user_1') | 510 | expect(user.username).to.equal('user_1') |
511 | expect(user.email).to.equal('user_1@example.com') | 511 | expect(user.email).to.equal('user_1@example.com') |
512 | expect(user.nsfwPolicy).to.equal('do_not_list') | 512 | expect(user.nsfwPolicy).to.equal('do_not_list') |
@@ -517,33 +517,33 @@ describe('Test users', function () { | |||
517 | }) | 517 | }) |
518 | 518 | ||
519 | it('Should be able to change the autoPlayVideo attribute', async function () { | 519 | it('Should be able to change the autoPlayVideo attribute', async function () { |
520 | await server.usersCommand.updateMe({ | 520 | await server.users.updateMe({ |
521 | token: userToken, | 521 | token: userToken, |
522 | autoPlayVideo: false | 522 | autoPlayVideo: false |
523 | }) | 523 | }) |
524 | 524 | ||
525 | const user = await server.usersCommand.getMyInfo({ token: userToken }) | 525 | const user = await server.users.getMyInfo({ token: userToken }) |
526 | expect(user.autoPlayVideo).to.be.false | 526 | expect(user.autoPlayVideo).to.be.false |
527 | }) | 527 | }) |
528 | 528 | ||
529 | it('Should be able to change the autoPlayNextVideo attribute', async function () { | 529 | it('Should be able to change the autoPlayNextVideo attribute', async function () { |
530 | await server.usersCommand.updateMe({ | 530 | await server.users.updateMe({ |
531 | token: userToken, | 531 | token: userToken, |
532 | autoPlayNextVideo: true | 532 | autoPlayNextVideo: true |
533 | }) | 533 | }) |
534 | 534 | ||
535 | const user = await server.usersCommand.getMyInfo({ token: userToken }) | 535 | const user = await server.users.getMyInfo({ token: userToken }) |
536 | expect(user.autoPlayNextVideo).to.be.true | 536 | expect(user.autoPlayNextVideo).to.be.true |
537 | }) | 537 | }) |
538 | 538 | ||
539 | it('Should be able to change the email attribute', async function () { | 539 | it('Should be able to change the email attribute', async function () { |
540 | await server.usersCommand.updateMe({ | 540 | await server.users.updateMe({ |
541 | token: userToken, | 541 | token: userToken, |
542 | currentPassword: 'new password', | 542 | currentPassword: 'new password', |
543 | email: 'updated@example.com' | 543 | email: 'updated@example.com' |
544 | }) | 544 | }) |
545 | 545 | ||
546 | const user = await server.usersCommand.getMyInfo({ token: userToken }) | 546 | const user = await server.users.getMyInfo({ token: userToken }) |
547 | expect(user.username).to.equal('user_1') | 547 | expect(user.username).to.equal('user_1') |
548 | expect(user.email).to.equal('updated@example.com') | 548 | expect(user.email).to.equal('updated@example.com') |
549 | expect(user.nsfwPolicy).to.equal('do_not_list') | 549 | expect(user.nsfwPolicy).to.equal('do_not_list') |
@@ -556,9 +556,9 @@ describe('Test users', function () { | |||
556 | it('Should be able to update my avatar with a gif', async function () { | 556 | it('Should be able to update my avatar with a gif', async function () { |
557 | const fixture = 'avatar.gif' | 557 | const fixture = 'avatar.gif' |
558 | 558 | ||
559 | await server.usersCommand.updateMyAvatar({ token: userToken, fixture }) | 559 | await server.users.updateMyAvatar({ token: userToken, fixture }) |
560 | 560 | ||
561 | const user = await server.usersCommand.getMyInfo({ token: userToken }) | 561 | const user = await server.users.getMyInfo({ token: userToken }) |
562 | await testImage(server.url, 'avatar-resized', user.account.avatar.path, '.gif') | 562 | await testImage(server.url, 'avatar-resized', user.account.avatar.path, '.gif') |
563 | }) | 563 | }) |
564 | 564 | ||
@@ -566,17 +566,17 @@ describe('Test users', function () { | |||
566 | for (const extension of [ '.png', '.gif' ]) { | 566 | for (const extension of [ '.png', '.gif' ]) { |
567 | const fixture = 'avatar' + extension | 567 | const fixture = 'avatar' + extension |
568 | 568 | ||
569 | await server.usersCommand.updateMyAvatar({ token: userToken, fixture }) | 569 | await server.users.updateMyAvatar({ token: userToken, fixture }) |
570 | 570 | ||
571 | const user = await server.usersCommand.getMyInfo({ token: userToken }) | 571 | const user = await server.users.getMyInfo({ token: userToken }) |
572 | await testImage(server.url, 'avatar-resized', user.account.avatar.path, extension) | 572 | await testImage(server.url, 'avatar-resized', user.account.avatar.path, extension) |
573 | } | 573 | } |
574 | }) | 574 | }) |
575 | 575 | ||
576 | it('Should be able to update my display name', async function () { | 576 | it('Should be able to update my display name', async function () { |
577 | await server.usersCommand.updateMe({ token: userToken, displayName: 'new display name' }) | 577 | await server.users.updateMe({ token: userToken, displayName: 'new display name' }) |
578 | 578 | ||
579 | const user = await server.usersCommand.getMyInfo({ token: userToken }) | 579 | const user = await server.users.getMyInfo({ token: userToken }) |
580 | expect(user.username).to.equal('user_1') | 580 | expect(user.username).to.equal('user_1') |
581 | expect(user.email).to.equal('updated@example.com') | 581 | expect(user.email).to.equal('updated@example.com') |
582 | expect(user.nsfwPolicy).to.equal('do_not_list') | 582 | expect(user.nsfwPolicy).to.equal('do_not_list') |
@@ -587,9 +587,9 @@ describe('Test users', function () { | |||
587 | }) | 587 | }) |
588 | 588 | ||
589 | it('Should be able to update my description', async function () { | 589 | it('Should be able to update my description', async function () { |
590 | await server.usersCommand.updateMe({ token: userToken, description: 'my super description updated' }) | 590 | await server.users.updateMe({ token: userToken, description: 'my super description updated' }) |
591 | 591 | ||
592 | const user = await server.usersCommand.getMyInfo({ token: userToken }) | 592 | const user = await server.users.getMyInfo({ token: userToken }) |
593 | expect(user.username).to.equal('user_1') | 593 | expect(user.username).to.equal('user_1') |
594 | expect(user.email).to.equal('updated@example.com') | 594 | expect(user.email).to.equal('updated@example.com') |
595 | expect(user.nsfwPolicy).to.equal('do_not_list') | 595 | expect(user.nsfwPolicy).to.equal('do_not_list') |
@@ -603,21 +603,21 @@ describe('Test users', function () { | |||
603 | 603 | ||
604 | it('Should be able to update my theme', async function () { | 604 | it('Should be able to update my theme', async function () { |
605 | for (const theme of [ 'background-red', 'default', 'instance-default' ]) { | 605 | for (const theme of [ 'background-red', 'default', 'instance-default' ]) { |
606 | await server.usersCommand.updateMe({ token: userToken, theme }) | 606 | await server.users.updateMe({ token: userToken, theme }) |
607 | 607 | ||
608 | const user = await server.usersCommand.getMyInfo({ token: userToken }) | 608 | const user = await server.users.getMyInfo({ token: userToken }) |
609 | expect(user.theme).to.equal(theme) | 609 | expect(user.theme).to.equal(theme) |
610 | } | 610 | } |
611 | }) | 611 | }) |
612 | 612 | ||
613 | it('Should be able to update my modal preferences', async function () { | 613 | it('Should be able to update my modal preferences', async function () { |
614 | await server.usersCommand.updateMe({ | 614 | await server.users.updateMe({ |
615 | token: userToken, | 615 | token: userToken, |
616 | noInstanceConfigWarningModal: true, | 616 | noInstanceConfigWarningModal: true, |
617 | noWelcomeModal: true | 617 | noWelcomeModal: true |
618 | }) | 618 | }) |
619 | 619 | ||
620 | const user = await server.usersCommand.getMyInfo({ token: userToken }) | 620 | const user = await server.users.getMyInfo({ token: userToken }) |
621 | expect(user.noWelcomeModal).to.be.true | 621 | expect(user.noWelcomeModal).to.be.true |
622 | expect(user.noInstanceConfigWarningModal).to.be.true | 622 | expect(user.noInstanceConfigWarningModal).to.be.true |
623 | }) | 623 | }) |
@@ -625,7 +625,7 @@ describe('Test users', function () { | |||
625 | 625 | ||
626 | describe('Updating another user', function () { | 626 | describe('Updating another user', function () { |
627 | it('Should be able to update another user', async function () { | 627 | it('Should be able to update another user', async function () { |
628 | await server.usersCommand.update({ | 628 | await server.users.update({ |
629 | userId, | 629 | userId, |
630 | token, | 630 | token, |
631 | email: 'updated2@example.com', | 631 | email: 'updated2@example.com', |
@@ -636,7 +636,7 @@ describe('Test users', function () { | |||
636 | pluginAuth: 'toto' | 636 | pluginAuth: 'toto' |
637 | }) | 637 | }) |
638 | 638 | ||
639 | const user = await server.usersCommand.get({ token, userId }) | 639 | const user = await server.users.get({ token, userId }) |
640 | 640 | ||
641 | expect(user.username).to.equal('user_1') | 641 | expect(user.username).to.equal('user_1') |
642 | expect(user.email).to.equal('updated2@example.com') | 642 | expect(user.email).to.equal('updated2@example.com') |
@@ -650,47 +650,47 @@ describe('Test users', function () { | |||
650 | }) | 650 | }) |
651 | 651 | ||
652 | it('Should reset the auth plugin', async function () { | 652 | it('Should reset the auth plugin', async function () { |
653 | await server.usersCommand.update({ userId, token, pluginAuth: null }) | 653 | await server.users.update({ userId, token, pluginAuth: null }) |
654 | 654 | ||
655 | const user = await server.usersCommand.get({ token, userId }) | 655 | const user = await server.users.get({ token, userId }) |
656 | expect(user.pluginAuth).to.be.null | 656 | expect(user.pluginAuth).to.be.null |
657 | }) | 657 | }) |
658 | 658 | ||
659 | it('Should have removed the user token', async function () { | 659 | it('Should have removed the user token', async function () { |
660 | await server.usersCommand.getMyQuotaUsed({ token: userToken, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) | 660 | await server.users.getMyQuotaUsed({ token: userToken, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) |
661 | 661 | ||
662 | userToken = await server.loginCommand.getAccessToken(user) | 662 | userToken = await server.login.getAccessToken(user) |
663 | }) | 663 | }) |
664 | 664 | ||
665 | it('Should be able to update another user password', async function () { | 665 | it('Should be able to update another user password', async function () { |
666 | await server.usersCommand.update({ userId, token, password: 'password updated' }) | 666 | await server.users.update({ userId, token, password: 'password updated' }) |
667 | 667 | ||
668 | await server.usersCommand.getMyQuotaUsed({ token: userToken, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) | 668 | await server.users.getMyQuotaUsed({ token: userToken, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) |
669 | 669 | ||
670 | await server.loginCommand.login({ user, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) | 670 | await server.login.login({ user, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) |
671 | 671 | ||
672 | user.password = 'password updated' | 672 | user.password = 'password updated' |
673 | userToken = await server.loginCommand.getAccessToken(user) | 673 | userToken = await server.login.getAccessToken(user) |
674 | }) | 674 | }) |
675 | }) | 675 | }) |
676 | 676 | ||
677 | describe('Video blacklists', function () { | 677 | describe('Video blacklists', function () { |
678 | it('Should be able to list video blacklist by a moderator', async function () { | 678 | it('Should be able to list video blacklist by a moderator', async function () { |
679 | await server.blacklistCommand.list({ token: userToken }) | 679 | await server.blacklist.list({ token: userToken }) |
680 | }) | 680 | }) |
681 | }) | 681 | }) |
682 | 682 | ||
683 | describe('Remove a user', function () { | 683 | describe('Remove a user', function () { |
684 | it('Should be able to remove this user', async function () { | 684 | it('Should be able to remove this user', async function () { |
685 | await server.usersCommand.remove({ userId, token }) | 685 | await server.users.remove({ userId, token }) |
686 | }) | 686 | }) |
687 | 687 | ||
688 | it('Should not be able to login with this user', async function () { | 688 | it('Should not be able to login with this user', async function () { |
689 | await server.loginCommand.login({ user, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) | 689 | await server.login.login({ user, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) |
690 | }) | 690 | }) |
691 | 691 | ||
692 | it('Should not have videos of this user', async function () { | 692 | it('Should not have videos of this user', async function () { |
693 | const { data, total } = await server.videosCommand.list() | 693 | const { data, total } = await server.videos.list() |
694 | expect(total).to.equal(1) | 694 | expect(total).to.equal(1) |
695 | 695 | ||
696 | const video = data[0] | 696 | const video = data[0] |
@@ -705,7 +705,7 @@ describe('Test users', function () { | |||
705 | const user = { displayName: 'super user 15', username: 'user_15', password: 'my super password' } | 705 | const user = { displayName: 'super user 15', username: 'user_15', password: 'my super password' } |
706 | const channel = { name: 'my_user_15_channel', displayName: 'my channel rocks' } | 706 | const channel = { name: 'my_user_15_channel', displayName: 'my channel rocks' } |
707 | 707 | ||
708 | await server.usersCommand.register({ ...user, channel }) | 708 | await server.users.register({ ...user, channel }) |
709 | }) | 709 | }) |
710 | 710 | ||
711 | it('Should be able to login with this registered user', async function () { | 711 | it('Should be able to login with this registered user', async function () { |
@@ -714,35 +714,35 @@ describe('Test users', function () { | |||
714 | password: 'my super password' | 714 | password: 'my super password' |
715 | } | 715 | } |
716 | 716 | ||
717 | user15AccessToken = await server.loginCommand.getAccessToken(user15) | 717 | user15AccessToken = await server.login.getAccessToken(user15) |
718 | }) | 718 | }) |
719 | 719 | ||
720 | it('Should have the correct display name', async function () { | 720 | it('Should have the correct display name', async function () { |
721 | const user = await server.usersCommand.getMyInfo({ token: user15AccessToken }) | 721 | const user = await server.users.getMyInfo({ token: user15AccessToken }) |
722 | expect(user.account.displayName).to.equal('super user 15') | 722 | expect(user.account.displayName).to.equal('super user 15') |
723 | }) | 723 | }) |
724 | 724 | ||
725 | it('Should have the correct video quota', async function () { | 725 | it('Should have the correct video quota', async function () { |
726 | const user = await server.usersCommand.getMyInfo({ token: user15AccessToken }) | 726 | const user = await server.users.getMyInfo({ token: user15AccessToken }) |
727 | expect(user.videoQuota).to.equal(5 * 1024 * 1024) | 727 | expect(user.videoQuota).to.equal(5 * 1024 * 1024) |
728 | }) | 728 | }) |
729 | 729 | ||
730 | it('Should have created the channel', async function () { | 730 | it('Should have created the channel', async function () { |
731 | const { displayName } = await server.channelsCommand.get({ channelName: 'my_user_15_channel' }) | 731 | const { displayName } = await server.channels.get({ channelName: 'my_user_15_channel' }) |
732 | 732 | ||
733 | expect(displayName).to.equal('my channel rocks') | 733 | expect(displayName).to.equal('my channel rocks') |
734 | }) | 734 | }) |
735 | 735 | ||
736 | it('Should remove me', async function () { | 736 | it('Should remove me', async function () { |
737 | { | 737 | { |
738 | const { data } = await server.usersCommand.list() | 738 | const { data } = await server.users.list() |
739 | expect(data.find(u => u.username === 'user_15')).to.not.be.undefined | 739 | expect(data.find(u => u.username === 'user_15')).to.not.be.undefined |
740 | } | 740 | } |
741 | 741 | ||
742 | await server.usersCommand.deleteMe({ token: user15AccessToken }) | 742 | await server.users.deleteMe({ token: user15AccessToken }) |
743 | 743 | ||
744 | { | 744 | { |
745 | const { data } = await server.usersCommand.list() | 745 | const { data } = await server.users.list() |
746 | expect(data.find(u => u.username === 'user_15')).to.be.undefined | 746 | expect(data.find(u => u.username === 'user_15')).to.be.undefined |
747 | } | 747 | } |
748 | }) | 748 | }) |
@@ -757,21 +757,21 @@ describe('Test users', function () { | |||
757 | } | 757 | } |
758 | 758 | ||
759 | it('Should block a user', async function () { | 759 | it('Should block a user', async function () { |
760 | const user = await server.usersCommand.create({ ...user16 }) | 760 | const user = await server.users.create({ ...user16 }) |
761 | user16Id = user.id | 761 | user16Id = user.id |
762 | 762 | ||
763 | user16AccessToken = await server.loginCommand.getAccessToken(user16) | 763 | user16AccessToken = await server.login.getAccessToken(user16) |
764 | 764 | ||
765 | await server.usersCommand.getMyInfo({ token: user16AccessToken, expectedStatus: HttpStatusCode.OK_200 }) | 765 | await server.users.getMyInfo({ token: user16AccessToken, expectedStatus: HttpStatusCode.OK_200 }) |
766 | await server.usersCommand.banUser({ userId: user16Id }) | 766 | await server.users.banUser({ userId: user16Id }) |
767 | 767 | ||
768 | await server.usersCommand.getMyInfo({ token: user16AccessToken, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) | 768 | await server.users.getMyInfo({ token: user16AccessToken, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) |
769 | await server.loginCommand.login({ user: user16, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) | 769 | await server.login.login({ user: user16, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) |
770 | }) | 770 | }) |
771 | 771 | ||
772 | it('Should search user by banned status', async function () { | 772 | it('Should search user by banned status', async function () { |
773 | { | 773 | { |
774 | const { data, total } = await server.usersCommand.list({ start: 0, count: 2, sort: 'createdAt', blocked: true }) | 774 | const { data, total } = await server.users.list({ start: 0, count: 2, sort: 'createdAt', blocked: true }) |
775 | expect(total).to.equal(1) | 775 | expect(total).to.equal(1) |
776 | expect(data.length).to.equal(1) | 776 | expect(data.length).to.equal(1) |
777 | 777 | ||
@@ -779,7 +779,7 @@ describe('Test users', function () { | |||
779 | } | 779 | } |
780 | 780 | ||
781 | { | 781 | { |
782 | const { data, total } = await server.usersCommand.list({ start: 0, count: 2, sort: 'createdAt', blocked: false }) | 782 | const { data, total } = await server.users.list({ start: 0, count: 2, sort: 'createdAt', blocked: false }) |
783 | expect(total).to.equal(1) | 783 | expect(total).to.equal(1) |
784 | expect(data.length).to.equal(1) | 784 | expect(data.length).to.equal(1) |
785 | 785 | ||
@@ -788,9 +788,9 @@ describe('Test users', function () { | |||
788 | }) | 788 | }) |
789 | 789 | ||
790 | it('Should unblock a user', async function () { | 790 | it('Should unblock a user', async function () { |
791 | await server.usersCommand.unbanUser({ userId: user16Id }) | 791 | await server.users.unbanUser({ userId: user16Id }) |
792 | user16AccessToken = await server.loginCommand.getAccessToken(user16) | 792 | user16AccessToken = await server.login.getAccessToken(user16) |
793 | await server.usersCommand.getMyInfo({ token: user16AccessToken, expectedStatus: HttpStatusCode.OK_200 }) | 793 | await server.users.getMyInfo({ token: user16AccessToken, expectedStatus: HttpStatusCode.OK_200 }) |
794 | }) | 794 | }) |
795 | }) | 795 | }) |
796 | 796 | ||
@@ -803,12 +803,12 @@ describe('Test users', function () { | |||
803 | username: 'user_17', | 803 | username: 'user_17', |
804 | password: 'my super password' | 804 | password: 'my super password' |
805 | } | 805 | } |
806 | const created = await server.usersCommand.create({ ...user17 }) | 806 | const created = await server.users.create({ ...user17 }) |
807 | 807 | ||
808 | user17Id = created.id | 808 | user17Id = created.id |
809 | user17AccessToken = await server.loginCommand.getAccessToken(user17) | 809 | user17AccessToken = await server.login.getAccessToken(user17) |
810 | 810 | ||
811 | const user = await server.usersCommand.get({ userId: user17Id, withStats: true }) | 811 | const user = await server.users.get({ userId: user17Id, withStats: true }) |
812 | expect(user.videosCount).to.equal(0) | 812 | expect(user.videosCount).to.equal(0) |
813 | expect(user.videoCommentsCount).to.equal(0) | 813 | expect(user.videoCommentsCount).to.equal(0) |
814 | expect(user.abusesCount).to.equal(0) | 814 | expect(user.abusesCount).to.equal(0) |
@@ -818,37 +818,37 @@ describe('Test users', function () { | |||
818 | 818 | ||
819 | it('Should report correct videos count', async function () { | 819 | it('Should report correct videos count', async function () { |
820 | const attributes = { name: 'video to test user stats' } | 820 | const attributes = { name: 'video to test user stats' } |
821 | await server.videosCommand.upload({ token: user17AccessToken, attributes }) | 821 | await server.videos.upload({ token: user17AccessToken, attributes }) |
822 | 822 | ||
823 | const { data } = await server.videosCommand.list() | 823 | const { data } = await server.videos.list() |
824 | videoId = data.find(video => video.name === attributes.name).id | 824 | videoId = data.find(video => video.name === attributes.name).id |
825 | 825 | ||
826 | const user = await server.usersCommand.get({ userId: user17Id, withStats: true }) | 826 | const user = await server.users.get({ userId: user17Id, withStats: true }) |
827 | expect(user.videosCount).to.equal(1) | 827 | expect(user.videosCount).to.equal(1) |
828 | }) | 828 | }) |
829 | 829 | ||
830 | it('Should report correct video comments for user', async function () { | 830 | it('Should report correct video comments for user', async function () { |
831 | const text = 'super comment' | 831 | const text = 'super comment' |
832 | await server.commentsCommand.createThread({ token: user17AccessToken, videoId, text }) | 832 | await server.comments.createThread({ token: user17AccessToken, videoId, text }) |
833 | 833 | ||
834 | const user = await server.usersCommand.get({ userId: user17Id, withStats: true }) | 834 | const user = await server.users.get({ userId: user17Id, withStats: true }) |
835 | expect(user.videoCommentsCount).to.equal(1) | 835 | expect(user.videoCommentsCount).to.equal(1) |
836 | }) | 836 | }) |
837 | 837 | ||
838 | it('Should report correct abuses counts', async function () { | 838 | it('Should report correct abuses counts', async function () { |
839 | const reason = 'my super bad reason' | 839 | const reason = 'my super bad reason' |
840 | await server.abusesCommand.report({ token: user17AccessToken, videoId, reason }) | 840 | await server.abuses.report({ token: user17AccessToken, videoId, reason }) |
841 | 841 | ||
842 | const body1 = await server.abusesCommand.getAdminList() | 842 | const body1 = await server.abuses.getAdminList() |
843 | const abuseId = body1.data[0].id | 843 | const abuseId = body1.data[0].id |
844 | 844 | ||
845 | const user2 = await server.usersCommand.get({ userId: user17Id, withStats: true }) | 845 | const user2 = await server.users.get({ userId: user17Id, withStats: true }) |
846 | expect(user2.abusesCount).to.equal(1) // number of incriminations | 846 | expect(user2.abusesCount).to.equal(1) // number of incriminations |
847 | expect(user2.abusesCreatedCount).to.equal(1) // number of reports created | 847 | expect(user2.abusesCreatedCount).to.equal(1) // number of reports created |
848 | 848 | ||
849 | await server.abusesCommand.update({ abuseId, body: { state: AbuseState.ACCEPTED } }) | 849 | await server.abuses.update({ abuseId, body: { state: AbuseState.ACCEPTED } }) |
850 | 850 | ||
851 | const user3 = await server.usersCommand.get({ userId: user17Id, withStats: true }) | 851 | const user3 = await server.users.get({ userId: user17Id, withStats: true }) |
852 | expect(user3.abusesAcceptedCount).to.equal(1) // number of reports created accepted | 852 | expect(user3.abusesAcceptedCount).to.equal(1) // number of reports created accepted |
853 | }) | 853 | }) |
854 | }) | 854 | }) |