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
before(async function () {
this.timeout(30000)
- server = await flushAndRunServer(1, {
+ server = await createSingleServer(1, {
rates_limit: {
login: {
max: 30
token = 'my_super_token'
await server.follows.follow({
- targets: [ 'http://example.com' ],
+ hosts: [ 'http://example.com' ],
token,
expectedStatus: HttpStatusCode.UNAUTHORIZED_401
})
path: path + videoId,
token: 'wrong token',
fields: data,
- statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
+ expectedStatus: HttpStatusCode.UNAUTHORIZED_401
}
await makePutBodyRequest(options)
})
})
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 })
})
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
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)
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 () {
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' })
})
it('Should disable webtorrent, enable HLS, and update my quota', async function () {
- this.timeout(60000)
+ this.timeout(160000)
{
const config = await server.config.getCustomConfig()
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,
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 () {
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' })
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 () {
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
})
})