X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;ds=sidebyside;f=server%2Ftests%2Fapi%2Fusers%2Fusers.ts;h=d15daeba5097de6b0332521c483ff7127e0e0997;hb=e722fb5923ddf11d72e48cec9788abc64327c22f;hp=310136a37ab674f0955d851c3bb096c5343a1bb0;hpb=89d241a79c262b9775c233b73cff080043ebb5e6;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/tests/api/users/users.ts b/server/tests/api/users/users.ts index 310136a37..d15daeba5 100644 --- a/server/tests/api/users/users.ts +++ b/server/tests/api/users/users.ts @@ -2,24 +2,22 @@ import 'mocha' import * as chai from 'chai' -import { HttpStatusCode } from '@shared/core-utils' +import { testImage } from '@server/tests/shared' +import { AbuseState, HttpStatusCode, OAuth2ErrorCode, UserAdminFlag, UserRole, Video, VideoPlaylistType } from '@shared/models' import { cleanupTests, - flushAndRunServer, + createSingleServer, killallServers, makePutBodyRequest, - reRunServer, - ServerInfo, + PeerTubeServer, setAccessTokensToServers, - testImage, waitJobs -} from '@shared/extra-utils' -import { AbuseState, OAuth2ErrorCode, UserAdminFlag, UserRole, Video, VideoPlaylistType } from '@shared/models' +} from '@shared/server-commands' const expect = chai.expect describe('Test users', function () { - let server: ServerInfo + let server: PeerTubeServer let token: string let userToken: string let videoId: number @@ -32,7 +30,7 @@ describe('Test users', function () { before(async function () { this.timeout(30000) - server = await flushAndRunServer(1, { + server = await createSingleServer(1, { rates_limit: { login: { max: 30 @@ -105,7 +103,7 @@ describe('Test users', function () { token = 'my_super_token' await server.follows.follow({ - targets: [ 'http://example.com' ], + hosts: [ 'http://example.com' ], token, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) @@ -216,7 +214,7 @@ describe('Test users', function () { path: path + videoId, token: 'wrong token', fields: data, - statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 + expectedStatus: HttpStatusCode.UNAUTHORIZED_401 } await makePutBodyRequest(options) }) @@ -232,13 +230,13 @@ describe('Test users', function () { }) it('Should have an expired access token', async function () { - this.timeout(15000) + this.timeout(60000) await server.sql.setTokenField(server.accessToken, 'accessTokenExpiresAt', new Date().toISOString()) await server.sql.setTokenField(server.accessToken, 'refreshTokenExpiresAt', new Date().toISOString()) await killallServers([ server ]) - await reRunServer(server) + await server.run() await server.users.getMyInfo({ expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) }) @@ -254,7 +252,7 @@ describe('Test users', function () { await server.sql.setTokenField(server.accessToken, 'refreshTokenExpiresAt', futureDate) await killallServers([ server ]) - await reRunServer(server) + await server.run() const res = await server.login.refreshToken({ refreshToken: server.refreshToken }) server.accessToken = res.body.access_token @@ -292,7 +290,7 @@ describe('Test users', function () { expect(user.account.description).to.be.null } - expect(userMe.adminFlags).to.be.undefined + expect(userMe.adminFlags).to.equal(UserAdminFlag.BYPASS_VIDEO_AUTO_BLACKLIST) expect(userGet.adminFlags).to.equal(UserAdminFlag.BYPASS_VIDEO_AUTO_BLACKLIST) expect(userMe.specialPlaylists).to.have.lengthOf(1) @@ -320,6 +318,8 @@ describe('Test users', function () { fixture: 'video_short.webm' } await server.videos.upload({ token: userToken, attributes }) + + await server.channels.create({ token: userToken, attributes: { name: 'other_channel' } }) }) it('Should have video quota updated', async function () { @@ -342,6 +342,29 @@ describe('Test users', function () { expect(video.previewPath).to.not.be.null }) + it('Should be able to filter by channel in my videos', async function () { + const myInfo = await server.users.getMyInfo({ token: userToken }) + const mainChannel = myInfo.videoChannels.find(c => c.name !== 'other_channel') + const otherChannel = myInfo.videoChannels.find(c => c.name === 'other_channel') + + { + const { total, data } = await server.videos.listMyVideos({ token: userToken, channelId: mainChannel.id }) + expect(total).to.equal(1) + expect(data).to.have.lengthOf(1) + + const video: Video = data[0] + expect(video.name).to.equal('super user video') + expect(video.thumbnailPath).to.not.be.null + expect(video.previewPath).to.not.be.null + } + + { + const { total, data } = await server.videos.listMyVideos({ token: userToken, channelId: otherChannel.id }) + expect(total).to.equal(0) + expect(data).to.have.lengthOf(0) + } + }) + it('Should be able to search in my videos', async function () { { const { total, data } = await server.videos.listMyVideos({ token: userToken, sort: '-createdAt', search: 'user video' }) @@ -357,7 +380,7 @@ describe('Test users', function () { }) it('Should disable webtorrent, enable HLS, and update my quota', async function () { - this.timeout(60000) + this.timeout(160000) { const config = await server.config.getCustomConfig() @@ -536,6 +559,28 @@ describe('Test users', function () { expect(user.autoPlayNextVideo).to.be.true }) + it('Should be able to change the p2p attribute', async function () { + { + await server.users.updateMe({ + token: userToken, + webTorrentEnabled: false + }) + + const user = await server.users.getMyInfo({ token: userToken }) + expect(user.p2pEnabled).to.be.false + } + + { + await server.users.updateMe({ + token: userToken, + p2pEnabled: true + }) + + const user = await server.users.getMyInfo({ token: userToken }) + expect(user.p2pEnabled).to.be.true + } + }) + it('Should be able to change the email attribute', async function () { await server.users.updateMe({ token: userToken, @@ -559,7 +604,9 @@ describe('Test users', function () { await server.users.updateMyAvatar({ token: userToken, fixture }) const user = await server.users.getMyInfo({ token: userToken }) - await testImage(server.url, 'avatar-resized', user.account.avatar.path, '.gif') + for (const avatar of user.account.avatars) { + await testImage(server.url, `avatar-resized-${avatar.width}x${avatar.width}`, avatar.path, '.gif') + } }) it('Should be able to update my avatar with a gif, and then a png', async function () { @@ -569,10 +616,19 @@ describe('Test users', function () { await server.users.updateMyAvatar({ token: userToken, fixture }) const user = await server.users.getMyInfo({ token: userToken }) - await testImage(server.url, 'avatar-resized', user.account.avatar.path, extension) + for (const avatar of user.account.avatars) { + await testImage(server.url, `avatar-resized-${avatar.width}x${avatar.width}`, avatar.path, extension) + } } }) + it('Should still have the same amount of videos in my account', async function () { + const { total, data } = await server.videos.listMyVideos({ token: userToken }) + + expect(total).to.equal(2) + expect(data).to.have.lengthOf(2) + }) + it('Should be able to update my display name', async function () { await server.users.updateMe({ token: userToken, displayName: 'new display name' }) @@ -599,6 +655,7 @@ describe('Test users', function () { expect(user.account.description).to.equal('my super description updated') expect(user.noWelcomeModal).to.be.false expect(user.noInstanceConfigWarningModal).to.be.false + expect(user.noAccountSetupWarningModal).to.be.false }) it('Should be able to update my theme', async function () { @@ -614,12 +671,14 @@ describe('Test users', function () { await server.users.updateMe({ token: userToken, noInstanceConfigWarningModal: true, - noWelcomeModal: true + noWelcomeModal: true, + noAccountSetupWarningModal: true }) const user = await server.users.getMyInfo({ token: userToken }) expect(user.noWelcomeModal).to.be.true expect(user.noInstanceConfigWarningModal).to.be.true + expect(user.noAccountSetupWarningModal).to.be.true }) })