More robust tests

pull/3988/head
Chocobozzz 2021-04-15 13:52:27 +02:00
parent f1ac63488c
commit f650072985
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
5 changed files with 37 additions and 31 deletions

View File

@ -3,6 +3,7 @@
import 'mocha' import 'mocha'
import { expect } from 'chai' import { expect } from 'chai'
import { MockJoinPeerTubeVersions } from '@shared/extra-utils/mock-servers/joinpeertube-versions' import { MockJoinPeerTubeVersions } from '@shared/extra-utils/mock-servers/joinpeertube-versions'
import { PluginType } from '@shared/models'
import { cleanupTests, installPlugin, setPluginLatestVersion, setPluginVersion, wait } from '../../../../shared/extra-utils' import { cleanupTests, installPlugin, setPluginLatestVersion, setPluginVersion, wait } from '../../../../shared/extra-utils'
import { ServerInfo } from '../../../../shared/extra-utils/index' import { ServerInfo } from '../../../../shared/extra-utils/index'
import { MockSmtpServer } from '../../../../shared/extra-utils/miscs/email' import { MockSmtpServer } from '../../../../shared/extra-utils/miscs/email'
@ -13,7 +14,6 @@ import {
prepareNotificationsTest prepareNotificationsTest
} from '../../../../shared/extra-utils/users/user-notifications' } from '../../../../shared/extra-utils/users/user-notifications'
import { UserNotification, UserNotificationType } from '../../../../shared/models/users' import { UserNotification, UserNotificationType } from '../../../../shared/models/users'
import { PluginType } from '@shared/models'
describe('Test admin notifications', function () { describe('Test admin notifications', function () {
let server: ServerInfo let server: ServerInfo
@ -26,11 +26,14 @@ describe('Test admin notifications', function () {
before(async function () { before(async function () {
this.timeout(120000) this.timeout(120000)
joinPeerTubeServer = new MockJoinPeerTubeVersions()
const port = await joinPeerTubeServer.initialize()
const config = { const config = {
peertube: { peertube: {
check_latest_version: { check_latest_version: {
enabled: true, enabled: true,
url: 'http://localhost:42102/versions.json' url: `http://localhost:${port}/versions.json`
} }
}, },
plugins: { plugins: {
@ -66,9 +69,6 @@ describe('Test admin notifications', function () {
accessToken: server.accessToken, accessToken: server.accessToken,
npmName: 'peertube-theme-background-red' npmName: 'peertube-theme-background-red'
}) })
joinPeerTubeServer = new MockJoinPeerTubeVersions()
await joinPeerTubeServer.initialize()
}) })
describe('Latest PeerTube version notification', function () { describe('Latest PeerTube version notification', function () {

View File

@ -2,8 +2,9 @@
import 'mocha' import 'mocha'
import { v4 as uuidv4 } from 'uuid' import { v4 as uuidv4 } from 'uuid'
import { AbuseState } from '@shared/models'
import { import {
addAbuseMessage,
addVideoCommentThread, addVideoCommentThread,
addVideoToBlacklist, addVideoToBlacklist,
cleanupTests, cleanupTests,
@ -20,18 +21,19 @@ import {
removeVideoFromBlacklist, removeVideoFromBlacklist,
reportAbuse, reportAbuse,
unfollow, unfollow,
updateAbuse,
updateCustomConfig, updateCustomConfig,
updateCustomSubConfig, updateCustomSubConfig,
wait, wait
updateAbuse,
addAbuseMessage
} from '../../../../shared/extra-utils' } from '../../../../shared/extra-utils'
import { ServerInfo, uploadVideo } from '../../../../shared/extra-utils/index' import { ServerInfo, uploadVideo } from '../../../../shared/extra-utils/index'
import { MockSmtpServer } from '../../../../shared/extra-utils/miscs/email' import { MockSmtpServer } from '../../../../shared/extra-utils/miscs/email'
import { waitJobs } from '../../../../shared/extra-utils/server/jobs' import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
import { import {
checkAbuseStateChange,
checkAutoInstanceFollowing, checkAutoInstanceFollowing,
CheckerBaseParams, CheckerBaseParams,
checkNewAbuseMessage,
checkNewAccountAbuseForModerators, checkNewAccountAbuseForModerators,
checkNewBlacklistOnMyVideo, checkNewBlacklistOnMyVideo,
checkNewCommentAbuseForModerators, checkNewCommentAbuseForModerators,
@ -41,15 +43,12 @@ import {
checkUserRegistered, checkUserRegistered,
checkVideoAutoBlacklistForModerators, checkVideoAutoBlacklistForModerators,
checkVideoIsPublished, checkVideoIsPublished,
prepareNotificationsTest, prepareNotificationsTest
checkAbuseStateChange,
checkNewAbuseMessage
} from '../../../../shared/extra-utils/users/user-notifications' } from '../../../../shared/extra-utils/users/user-notifications'
import { addUserSubscription, removeUserSubscription } from '../../../../shared/extra-utils/users/user-subscriptions' import { addUserSubscription, removeUserSubscription } from '../../../../shared/extra-utils/users/user-subscriptions'
import { CustomConfig } from '../../../../shared/models/server' import { CustomConfig } from '../../../../shared/models/server'
import { UserNotification } from '../../../../shared/models/users' import { UserNotification } from '../../../../shared/models/users'
import { VideoPrivacy } from '../../../../shared/models/videos' import { VideoPrivacy } from '../../../../shared/models/videos'
import { AbuseState } from '@shared/models'
describe('Test moderation notifications', function () { describe('Test moderation notifications', function () {
let servers: ServerInfo[] = [] let servers: ServerInfo[] = []
@ -364,16 +363,7 @@ describe('Test moderation notifications', function () {
describe('New instance follows', function () { describe('New instance follows', function () {
const instanceIndexServer = new MockInstancesIndex() const instanceIndexServer = new MockInstancesIndex()
const config = { let config: any
followings: {
instance: {
autoFollowIndex: {
indexUrl: 'http://localhost:42101/api/v1/instances/hosts',
enabled: true
}
}
}
}
let baseParams: CheckerBaseParams let baseParams: CheckerBaseParams
before(async () => { before(async () => {
@ -384,8 +374,19 @@ describe('Test moderation notifications', function () {
token: servers[0].accessToken token: servers[0].accessToken
} }
await instanceIndexServer.initialize() const port = await instanceIndexServer.initialize()
instanceIndexServer.addInstance(servers[1].host) instanceIndexServer.addInstance(servers[1].host)
config = {
followings: {
instance: {
autoFollowIndex: {
indexUrl: `http://localhost:${port}/api/v1/instances/hosts`,
enabled: true
}
}
}
}
}) })
it('Should send a notification only to admin when there is a new instance follower', async function () { it('Should send a notification only to admin when there is a new instance follower', async function () {

View File

@ -1,7 +1,7 @@
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
import * as chai from 'chai'
import 'mocha' import 'mocha'
import * as chai from 'chai'
import { import {
acceptFollower, acceptFollower,
cleanupTests, cleanupTests,
@ -153,9 +153,10 @@ describe('Test auto follows', function () {
describe('Auto follow index', function () { describe('Auto follow index', function () {
const instanceIndexServer = new MockInstancesIndex() const instanceIndexServer = new MockInstancesIndex()
let port: number
before(async () => { before(async () => {
await instanceIndexServer.initialize() port = await instanceIndexServer.initialize()
}) })
it('Should not auto follow index if the option is not enabled', async function () { it('Should not auto follow index if the option is not enabled', async function () {
@ -177,7 +178,7 @@ describe('Test auto follows', function () {
followings: { followings: {
instance: { instance: {
autoFollowIndex: { autoFollowIndex: {
indexUrl: 'http://localhost:42101/api/v1/instances/hosts', indexUrl: `http://localhost:${port}/api/v1/instances/hosts`,
enabled: true enabled: true
} }
} }

View File

@ -1,10 +1,11 @@
import * as express from 'express' import * as express from 'express'
import { randomInt } from '@shared/core-utils'
export class MockJoinPeerTubeVersions { export class MockJoinPeerTubeVersions {
private latestVersion: string private latestVersion: string
initialize () { initialize () {
return new Promise<void>(res => { return new Promise<number>(res => {
const app = express() const app = express()
app.use('/', (req: express.Request, res: express.Response, next: express.NextFunction) => { app.use('/', (req: express.Request, res: express.Response, next: express.NextFunction) => {
@ -21,7 +22,8 @@ export class MockJoinPeerTubeVersions {
}) })
}) })
app.listen(42102, () => res()) const port = 42201 + randomInt(1, 100)
app.listen(port, () => res(port))
}) })
} }

View File

@ -1,10 +1,11 @@
import * as express from 'express' import * as express from 'express'
import { randomInt } from '@shared/core-utils'
export class MockInstancesIndex { export class MockInstancesIndex {
private readonly indexInstances: { host: string, createdAt: string }[] = [] private readonly indexInstances: { host: string, createdAt: string }[] = []
initialize () { initialize () {
return new Promise<void>(res => { return new Promise<number>(res => {
const app = express() const app = express()
app.use('/', (req: express.Request, res: express.Response, next: express.NextFunction) => { app.use('/', (req: express.Request, res: express.Response, next: express.NextFunction) => {
@ -28,7 +29,8 @@ export class MockInstancesIndex {
}) })
}) })
app.listen(42101, () => res()) const port = 42101 + randomInt(1, 100)
app.listen(port, () => res(port))
}) })
} }