X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Ftests%2Fapi%2Fnotifications%2Fuser-notifications.ts;h=662b64e05467f4ea0a9900eacf40f15c5e60d020;hb=1600235a2f4e30c5d4e7d4342d1c299845decc60;hp=7bff527962aec864401e34f088804b1f5fa87c9d;hpb=883993c81ecc2388d4a4b37b29b81b6de73d264f;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/tests/api/notifications/user-notifications.ts b/server/tests/api/notifications/user-notifications.ts index 7bff52796..662b64e05 100644 --- a/server/tests/api/notifications/user-notifications.ts +++ b/server/tests/api/notifications/user-notifications.ts @@ -4,27 +4,30 @@ import * as chai from 'chai' import 'mocha' import { addVideoToBlacklist, + cleanupTests, createUser, doubleFollow, flushAndRunMultipleServers, - flushTests, + follow, + getCustomConfig, getMyUserInformation, + getVideoCommentThreads, + getVideoThreadComments, immutableAssign, registerUser, removeVideoFromBlacklist, reportVideoAbuse, + updateCustomConfig, updateMyUser, updateVideo, updateVideoChannel, userLogin, - wait, - getCustomConfig, - updateCustomConfig, getVideoThreadComments, getVideoCommentThreads, follow -} from '../../../../shared/utils' -import { killallServers, ServerInfo, uploadVideo } from '../../../../shared/utils/index' -import { setAccessTokensToServers } from '../../../../shared/utils/users/login' -import { waitJobs } from '../../../../shared/utils/server/jobs' -import { getUserNotificationSocket } from '../../../../shared/utils/socket/socket-io' + wait +} from '../../../../shared/extra-utils' +import { ServerInfo, uploadVideo } from '../../../../shared/extra-utils/index' +import { setAccessTokensToServers } from '../../../../shared/extra-utils/users/login' +import { waitJobs } from '../../../../shared/extra-utils/server/jobs' +import { getUserNotificationSocket } from '../../../../shared/extra-utils/socket/socket-io' import { checkCommentMention, CheckerBaseParams, @@ -32,17 +35,18 @@ import { checkNewActorFollow, checkNewBlacklistOnMyVideo, checkNewCommentOnMyVideo, + checkNewInstanceFollower, checkNewVideoAbuseForModerators, - checkVideoAutoBlacklistForModerators, checkNewVideoFromSubscription, checkUserRegistered, + checkVideoAutoBlacklistForModerators, checkVideoIsPublished, getLastNotification, getUserNotifications, + markAsReadAllNotifications, markAsReadNotifications, - updateMyNotificationSettings, - markAsReadAllNotifications, checkNewInstanceFollower -} from '../../../../shared/utils/users/user-notifications' + updateMyNotificationSettings +} from '../../../../shared/extra-utils/users/user-notifications' import { User, UserNotification, @@ -50,13 +54,13 @@ import { UserNotificationSettingValue, UserNotificationType } from '../../../../shared/models/users' -import { MockSmtpServer } from '../../../../shared/utils/miscs/email' -import { addUserSubscription, removeUserSubscription } from '../../../../shared/utils/users/user-subscriptions' +import { MockSmtpServer } from '../../../../shared/extra-utils/miscs/email' +import { addUserSubscription, removeUserSubscription } from '../../../../shared/extra-utils/users/user-subscriptions' import { VideoPrivacy } from '../../../../shared/models/videos' -import { getBadVideoUrl, getYoutubeVideoUrl, importVideo } from '../../../../shared/utils/videos/video-imports' -import { addVideoCommentReply, addVideoCommentThread } from '../../../../shared/utils/videos/video-comments' +import { getBadVideoUrl, getYoutubeVideoUrl, importVideo } from '../../../../shared/extra-utils/videos/video-imports' +import { addVideoCommentReply, addVideoCommentThread } from '../../../../shared/extra-utils/videos/video-comments' import * as uuidv4 from 'uuid/v4' -import { addAccountToAccountBlocklist, removeAccountFromAccountBlocklist } from '../../../../shared/utils/users/blocklist' +import { addAccountToAccountBlocklist, removeAccountFromAccountBlocklist } from '../../../../shared/extra-utils/users/blocklist' import { CustomConfig } from '../../../../shared/models/server' import { VideoCommentThreadTree } from '../../../../shared/models/videos/video-comment.model' @@ -110,13 +114,12 @@ describe('Test users notifications', function () { before(async function () { this.timeout(120000) - await MockSmtpServer.Instance.collectEmails(emails) - - await flushTests() + const port = await MockSmtpServer.Instance.collectEmails(emails) const overrideConfig = { smtp: { - hostname: 'localhost' + hostname: 'localhost', + port } } servers = await flushAndRunMultipleServers(3, overrideConfig) @@ -133,7 +136,13 @@ describe('Test users notifications', function () { username: 'user_1', password: 'super password' } - await createUser(servers[0].url, servers[0].accessToken, user.username, user.password, 10 * 1000 * 1000) + await createUser({ + url: servers[ 0 ].url, + accessToken: servers[ 0 ].accessToken, + username: user.username, + password: user.password, + videoQuota: 10 * 1000 * 1000 + }) userAccessToken = await userLogin(servers[0], user) await updateMyNotificationSettings(servers[0].url, userAccessToken, allNotificationSettings) @@ -186,7 +195,7 @@ describe('Test users notifications', function () { it('Should send a new video notification if the user follows the local video publisher', async function () { this.timeout(15000) - await addUserSubscription(servers[0].url, userAccessToken, 'root_channel@localhost:9001') + await addUserSubscription(servers[0].url, userAccessToken, 'root_channel@localhost:' + servers[0].port) await waitJobs(servers) const { name, uuid } = await uploadVideoByLocalAccount(servers) @@ -196,7 +205,7 @@ describe('Test users notifications', function () { it('Should send a new video notification from a remote account', async function () { this.timeout(50000) // Server 2 has transcoding enabled - await addUserSubscription(servers[0].url, userAccessToken, 'root_channel@localhost:9002') + await addUserSubscription(servers[0].url, userAccessToken, 'root_channel@localhost:' + servers[1].port) await waitJobs(servers) const { name, uuid } = await uploadVideoByRemoteAccount(servers) @@ -570,7 +579,9 @@ describe('Test users notifications', function () { const uuid = resVideo.body.video.uuid await waitJobs(servers) - const resThread = await addVideoCommentThread(servers[1].url, servers[1].accessToken, uuid, 'hello @user_1@localhost:9001 1') + + const text1 = `hello @user_1@localhost:${servers[ 0 ].port} 1` + const resThread = await addVideoCommentThread(servers[1].url, servers[1].accessToken, uuid, text1) const server2ThreadId = resThread.body.comment.id await waitJobs(servers) @@ -580,8 +591,8 @@ describe('Test users notifications', function () { const server1ThreadId = resThread2.body.data[0].id await checkCommentMention(baseParams, uuid, server1ThreadId, server1ThreadId, 'super root 2 name', 'presence') - const text = '@user_1@localhost:9001 hello 2 @root@localhost:9001' - await addVideoCommentReply(servers[1].url, servers[1].accessToken, uuid, server2ThreadId, text) + const text2 = `@user_1@localhost:${servers[ 0 ].port} hello 2 @root@localhost:${servers[ 0 ].port}` + await addVideoCommentReply(servers[1].url, servers[1].accessToken, uuid, server2ThreadId, text2) await waitJobs(servers) @@ -875,16 +886,16 @@ describe('Test users notifications', function () { }) it('Should send a notification only to admin when there is a new instance follower', async function () { - this.timeout(10000) + this.timeout(20000) await follow(servers[2].url, [ servers[0].url ], servers[2].accessToken) await waitJobs(servers) - await checkNewInstanceFollower(baseParams, 'localhost:9003', 'presence') + await checkNewInstanceFollower(baseParams, 'localhost:' + servers[2].port, 'presence') const userOverride = { socketNotifications: userNotifications, token: userAccessToken, check: { web: true, mail: false } } - await checkNewInstanceFollower(immutableAssign(baseParams, userOverride), 'localhost:9003', 'absence') + await checkNewInstanceFollower(immutableAssign(baseParams, userOverride), 'localhost:' + servers[2].port, 'absence') }) }) @@ -925,29 +936,29 @@ describe('Test users notifications', function () { it('Should notify when a local channel is following one of our channel', async function () { this.timeout(10000) - await addUserSubscription(servers[0].url, servers[0].accessToken, 'user_1_channel@localhost:9001') + await addUserSubscription(servers[0].url, servers[0].accessToken, 'user_1_channel@localhost:' + servers[0].port) await waitJobs(servers) await checkNewActorFollow(baseParams, 'channel', 'root', 'super root name', myChannelName, 'presence') - await removeUserSubscription(servers[0].url, servers[0].accessToken, 'user_1_channel@localhost:9001') + await removeUserSubscription(servers[0].url, servers[0].accessToken, 'user_1_channel@localhost:' + servers[0].port) }) it('Should notify when a remote channel is following one of our channel', async function () { this.timeout(10000) - await addUserSubscription(servers[1].url, servers[1].accessToken, 'user_1_channel@localhost:9001') + await addUserSubscription(servers[1].url, servers[1].accessToken, 'user_1_channel@localhost:' + servers[0].port) await waitJobs(servers) await checkNewActorFollow(baseParams, 'channel', 'root', 'super root 2 name', myChannelName, 'presence') - await removeUserSubscription(servers[1].url, servers[1].accessToken, 'user_1_channel@localhost:9001') + await removeUserSubscription(servers[1].url, servers[1].accessToken, 'user_1_channel@localhost:' + servers[0].port) }) it('Should notify when a local account is following one of our channel', async function () { this.timeout(10000) - await addUserSubscription(servers[0].url, servers[0].accessToken, 'user_1@localhost:9001') + await addUserSubscription(servers[0].url, servers[0].accessToken, 'user_1@localhost:' + servers[0].port) await waitJobs(servers) @@ -957,7 +968,7 @@ describe('Test users notifications', function () { it('Should notify when a remote account is following one of our channel', async function () { this.timeout(10000) - await addUserSubscription(servers[1].url, servers[1].accessToken, 'user_1@localhost:9001') + await addUserSubscription(servers[1].url, servers[1].accessToken, 'user_1@localhost:' + servers[0].port) await waitJobs(servers) @@ -1011,8 +1022,8 @@ describe('Test users notifications', function () { autoBlacklistTestsCustomConfig.transcoding.enabled = true await updateCustomConfig(servers[0].url, servers[0].accessToken, autoBlacklistTestsCustomConfig) - await addUserSubscription(servers[0].url, servers[0].accessToken, 'user_1_channel@localhost:9001') - await addUserSubscription(servers[1].url, servers[1].accessToken, 'user_1_channel@localhost:9001') + await addUserSubscription(servers[0].url, servers[0].accessToken, 'user_1_channel@localhost:' + servers[0].port) + await addUserSubscription(servers[1].url, servers[1].accessToken, 'user_1_channel@localhost:' + servers[0].port) }) @@ -1134,8 +1145,8 @@ describe('Test users notifications', function () { after(async () => { await updateCustomConfig(servers[0].url, servers[0].accessToken, currentCustomConfig) - await removeUserSubscription(servers[0].url, servers[0].accessToken, 'user_1_channel@localhost:9001') - await removeUserSubscription(servers[1].url, servers[1].accessToken, 'user_1_channel@localhost:9001') + await removeUserSubscription(servers[0].url, servers[0].accessToken, 'user_1_channel@localhost:' + servers[0].port) + await removeUserSubscription(servers[1].url, servers[1].accessToken, 'user_1_channel@localhost:' + servers[0].port) }) }) @@ -1294,6 +1305,6 @@ describe('Test users notifications', function () { after(async function () { MockSmtpServer.Instance.kill() - killallServers(servers) + await cleanupTests(servers) }) })