aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-04-15 13:52:27 +0200
committerChocobozzz <me@florianbigard.com>2021-04-15 13:52:27 +0200
commitf6500729850549e632399155d0f3b69822e28b16 (patch)
tree7ca40188e38b0281f538c4cddf79ea633745cc4a
parentf1ac63488c0050fec1c4d713d74db4f4ea944395 (diff)
downloadPeerTube-f6500729850549e632399155d0f3b69822e28b16.tar.gz
PeerTube-f6500729850549e632399155d0f3b69822e28b16.tar.zst
PeerTube-f6500729850549e632399155d0f3b69822e28b16.zip
More robust tests
-rw-r--r--server/tests/api/notifications/admin-notifications.ts10
-rw-r--r--server/tests/api/notifications/moderation-notifications.ts39
-rw-r--r--server/tests/api/server/auto-follows.ts7
-rw-r--r--shared/extra-utils/mock-servers/joinpeertube-versions.ts6
-rw-r--r--shared/extra-utils/mock-servers/mock-instances-index.ts6
5 files changed, 37 insertions, 31 deletions
diff --git a/server/tests/api/notifications/admin-notifications.ts b/server/tests/api/notifications/admin-notifications.ts
index e07327d74..cfe0bd2bb 100644
--- a/server/tests/api/notifications/admin-notifications.ts
+++ b/server/tests/api/notifications/admin-notifications.ts
@@ -3,6 +3,7 @@
3import 'mocha' 3import 'mocha'
4import { expect } from 'chai' 4import { expect } from 'chai'
5import { MockJoinPeerTubeVersions } from '@shared/extra-utils/mock-servers/joinpeertube-versions' 5import { MockJoinPeerTubeVersions } from '@shared/extra-utils/mock-servers/joinpeertube-versions'
6import { PluginType } from '@shared/models'
6import { cleanupTests, installPlugin, setPluginLatestVersion, setPluginVersion, wait } from '../../../../shared/extra-utils' 7import { cleanupTests, installPlugin, setPluginLatestVersion, setPluginVersion, wait } from '../../../../shared/extra-utils'
7import { ServerInfo } from '../../../../shared/extra-utils/index' 8import { ServerInfo } from '../../../../shared/extra-utils/index'
8import { MockSmtpServer } from '../../../../shared/extra-utils/miscs/email' 9import { MockSmtpServer } from '../../../../shared/extra-utils/miscs/email'
@@ -13,7 +14,6 @@ import {
13 prepareNotificationsTest 14 prepareNotificationsTest
14} from '../../../../shared/extra-utils/users/user-notifications' 15} from '../../../../shared/extra-utils/users/user-notifications'
15import { UserNotification, UserNotificationType } from '../../../../shared/models/users' 16import { UserNotification, UserNotificationType } from '../../../../shared/models/users'
16import { PluginType } from '@shared/models'
17 17
18describe('Test admin notifications', function () { 18describe('Test admin notifications', function () {
19 let server: ServerInfo 19 let server: ServerInfo
@@ -26,11 +26,14 @@ describe('Test admin notifications', function () {
26 before(async function () { 26 before(async function () {
27 this.timeout(120000) 27 this.timeout(120000)
28 28
29 joinPeerTubeServer = new MockJoinPeerTubeVersions()
30 const port = await joinPeerTubeServer.initialize()
31
29 const config = { 32 const config = {
30 peertube: { 33 peertube: {
31 check_latest_version: { 34 check_latest_version: {
32 enabled: true, 35 enabled: true,
33 url: 'http://localhost:42102/versions.json' 36 url: `http://localhost:${port}/versions.json`
34 } 37 }
35 }, 38 },
36 plugins: { 39 plugins: {
@@ -66,9 +69,6 @@ describe('Test admin notifications', function () {
66 accessToken: server.accessToken, 69 accessToken: server.accessToken,
67 npmName: 'peertube-theme-background-red' 70 npmName: 'peertube-theme-background-red'
68 }) 71 })
69
70 joinPeerTubeServer = new MockJoinPeerTubeVersions()
71 await joinPeerTubeServer.initialize()
72 }) 72 })
73 73
74 describe('Latest PeerTube version notification', function () { 74 describe('Latest PeerTube version notification', function () {
diff --git a/server/tests/api/notifications/moderation-notifications.ts b/server/tests/api/notifications/moderation-notifications.ts
index 4c00d97f8..4ce6675b6 100644
--- a/server/tests/api/notifications/moderation-notifications.ts
+++ b/server/tests/api/notifications/moderation-notifications.ts
@@ -2,8 +2,9 @@
2 2
3import 'mocha' 3import 'mocha'
4import { v4 as uuidv4 } from 'uuid' 4import { v4 as uuidv4 } from 'uuid'
5 5import { AbuseState } from '@shared/models'
6import { 6import {
7 addAbuseMessage,
7 addVideoCommentThread, 8 addVideoCommentThread,
8 addVideoToBlacklist, 9 addVideoToBlacklist,
9 cleanupTests, 10 cleanupTests,
@@ -20,18 +21,19 @@ import {
20 removeVideoFromBlacklist, 21 removeVideoFromBlacklist,
21 reportAbuse, 22 reportAbuse,
22 unfollow, 23 unfollow,
24 updateAbuse,
23 updateCustomConfig, 25 updateCustomConfig,
24 updateCustomSubConfig, 26 updateCustomSubConfig,
25 wait, 27 wait
26 updateAbuse,
27 addAbuseMessage
28} from '../../../../shared/extra-utils' 28} from '../../../../shared/extra-utils'
29import { ServerInfo, uploadVideo } from '../../../../shared/extra-utils/index' 29import { ServerInfo, uploadVideo } from '../../../../shared/extra-utils/index'
30import { MockSmtpServer } from '../../../../shared/extra-utils/miscs/email' 30import { MockSmtpServer } from '../../../../shared/extra-utils/miscs/email'
31import { waitJobs } from '../../../../shared/extra-utils/server/jobs' 31import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
32import { 32import {
33 checkAbuseStateChange,
33 checkAutoInstanceFollowing, 34 checkAutoInstanceFollowing,
34 CheckerBaseParams, 35 CheckerBaseParams,
36 checkNewAbuseMessage,
35 checkNewAccountAbuseForModerators, 37 checkNewAccountAbuseForModerators,
36 checkNewBlacklistOnMyVideo, 38 checkNewBlacklistOnMyVideo,
37 checkNewCommentAbuseForModerators, 39 checkNewCommentAbuseForModerators,
@@ -41,15 +43,12 @@ import {
41 checkUserRegistered, 43 checkUserRegistered,
42 checkVideoAutoBlacklistForModerators, 44 checkVideoAutoBlacklistForModerators,
43 checkVideoIsPublished, 45 checkVideoIsPublished,
44 prepareNotificationsTest, 46 prepareNotificationsTest
45 checkAbuseStateChange,
46 checkNewAbuseMessage
47} from '../../../../shared/extra-utils/users/user-notifications' 47} from '../../../../shared/extra-utils/users/user-notifications'
48import { addUserSubscription, removeUserSubscription } from '../../../../shared/extra-utils/users/user-subscriptions' 48import { addUserSubscription, removeUserSubscription } from '../../../../shared/extra-utils/users/user-subscriptions'
49import { CustomConfig } from '../../../../shared/models/server' 49import { CustomConfig } from '../../../../shared/models/server'
50import { UserNotification } from '../../../../shared/models/users' 50import { UserNotification } from '../../../../shared/models/users'
51import { VideoPrivacy } from '../../../../shared/models/videos' 51import { VideoPrivacy } from '../../../../shared/models/videos'
52import { AbuseState } from '@shared/models'
53 52
54describe('Test moderation notifications', function () { 53describe('Test moderation notifications', function () {
55 let servers: ServerInfo[] = [] 54 let servers: ServerInfo[] = []
@@ -364,16 +363,7 @@ describe('Test moderation notifications', function () {
364 363
365 describe('New instance follows', function () { 364 describe('New instance follows', function () {
366 const instanceIndexServer = new MockInstancesIndex() 365 const instanceIndexServer = new MockInstancesIndex()
367 const config = { 366 let config: any
368 followings: {
369 instance: {
370 autoFollowIndex: {
371 indexUrl: 'http://localhost:42101/api/v1/instances/hosts',
372 enabled: true
373 }
374 }
375 }
376 }
377 let baseParams: CheckerBaseParams 367 let baseParams: CheckerBaseParams
378 368
379 before(async () => { 369 before(async () => {
@@ -384,8 +374,19 @@ describe('Test moderation notifications', function () {
384 token: servers[0].accessToken 374 token: servers[0].accessToken
385 } 375 }
386 376
387 await instanceIndexServer.initialize() 377 const port = await instanceIndexServer.initialize()
388 instanceIndexServer.addInstance(servers[1].host) 378 instanceIndexServer.addInstance(servers[1].host)
379
380 config = {
381 followings: {
382 instance: {
383 autoFollowIndex: {
384 indexUrl: `http://localhost:${port}/api/v1/instances/hosts`,
385 enabled: true
386 }
387 }
388 }
389 }
389 }) 390 })
390 391
391 it('Should send a notification only to admin when there is a new instance follower', async function () { 392 it('Should send a notification only to admin when there is a new instance follower', async function () {
diff --git a/server/tests/api/server/auto-follows.ts b/server/tests/api/server/auto-follows.ts
index e04d70af4..1519b263f 100644
--- a/server/tests/api/server/auto-follows.ts
+++ b/server/tests/api/server/auto-follows.ts
@@ -1,7 +1,7 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2 2
3import * as chai from 'chai'
4import 'mocha' 3import 'mocha'
4import * as chai from 'chai'
5import { 5import {
6 acceptFollower, 6 acceptFollower,
7 cleanupTests, 7 cleanupTests,
@@ -153,9 +153,10 @@ describe('Test auto follows', function () {
153 153
154 describe('Auto follow index', function () { 154 describe('Auto follow index', function () {
155 const instanceIndexServer = new MockInstancesIndex() 155 const instanceIndexServer = new MockInstancesIndex()
156 let port: number
156 157
157 before(async () => { 158 before(async () => {
158 await instanceIndexServer.initialize() 159 port = await instanceIndexServer.initialize()
159 }) 160 })
160 161
161 it('Should not auto follow index if the option is not enabled', async function () { 162 it('Should not auto follow index if the option is not enabled', async function () {
@@ -177,7 +178,7 @@ describe('Test auto follows', function () {
177 followings: { 178 followings: {
178 instance: { 179 instance: {
179 autoFollowIndex: { 180 autoFollowIndex: {
180 indexUrl: 'http://localhost:42101/api/v1/instances/hosts', 181 indexUrl: `http://localhost:${port}/api/v1/instances/hosts`,
181 enabled: true 182 enabled: true
182 } 183 }
183 } 184 }
diff --git a/shared/extra-utils/mock-servers/joinpeertube-versions.ts b/shared/extra-utils/mock-servers/joinpeertube-versions.ts
index d7d5b2c49..5ea432ecf 100644
--- a/shared/extra-utils/mock-servers/joinpeertube-versions.ts
+++ b/shared/extra-utils/mock-servers/joinpeertube-versions.ts
@@ -1,10 +1,11 @@
1import * as express from 'express' 1import * as express from 'express'
2import { randomInt } from '@shared/core-utils'
2 3
3export class MockJoinPeerTubeVersions { 4export class MockJoinPeerTubeVersions {
4 private latestVersion: string 5 private latestVersion: string
5 6
6 initialize () { 7 initialize () {
7 return new Promise<void>(res => { 8 return new Promise<number>(res => {
8 const app = express() 9 const app = express()
9 10
10 app.use('/', (req: express.Request, res: express.Response, next: express.NextFunction) => { 11 app.use('/', (req: express.Request, res: express.Response, next: express.NextFunction) => {
@@ -21,7 +22,8 @@ export class MockJoinPeerTubeVersions {
21 }) 22 })
22 }) 23 })
23 24
24 app.listen(42102, () => res()) 25 const port = 42201 + randomInt(1, 100)
26 app.listen(port, () => res(port))
25 }) 27 })
26 } 28 }
27 29
diff --git a/shared/extra-utils/mock-servers/mock-instances-index.ts b/shared/extra-utils/mock-servers/mock-instances-index.ts
index 2604eda03..c9e33087d 100644
--- a/shared/extra-utils/mock-servers/mock-instances-index.ts
+++ b/shared/extra-utils/mock-servers/mock-instances-index.ts
@@ -1,10 +1,11 @@
1import * as express from 'express' 1import * as express from 'express'
2import { randomInt } from '@shared/core-utils'
2 3
3export class MockInstancesIndex { 4export class MockInstancesIndex {
4 private readonly indexInstances: { host: string, createdAt: string }[] = [] 5 private readonly indexInstances: { host: string, createdAt: string }[] = []
5 6
6 initialize () { 7 initialize () {
7 return new Promise<void>(res => { 8 return new Promise<number>(res => {
8 const app = express() 9 const app = express()
9 10
10 app.use('/', (req: express.Request, res: express.Response, next: express.NextFunction) => { 11 app.use('/', (req: express.Request, res: express.Response, next: express.NextFunction) => {
@@ -28,7 +29,8 @@ export class MockInstancesIndex {
28 }) 29 })
29 }) 30 })
30 31
31 app.listen(42101, () => res()) 32 const port = 42101 + randomInt(1, 100)
33 app.listen(port, () => res(port))
32 }) 34 })
33 } 35 }
34 36