From 2c27e70471120c92e0bc8c8114141fbb31ff98ac Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 7 Jul 2021 16:40:49 +0200 Subject: Introduce subscriptions command --- .../api/notifications/moderation-notifications.ts | 10 +++--- .../tests/api/notifications/notifications-api.ts | 19 +++++----- .../tests/api/notifications/user-notifications.ts | 42 ++++++++++------------ 3 files changed, 34 insertions(+), 37 deletions(-) (limited to 'server/tests/api/notifications') diff --git a/server/tests/api/notifications/moderation-notifications.ts b/server/tests/api/notifications/moderation-notifications.ts index e90640ad6..605b41947 100644 --- a/server/tests/api/notifications/moderation-notifications.ts +++ b/server/tests/api/notifications/moderation-notifications.ts @@ -3,7 +3,6 @@ import 'mocha' import { buildUUID } from '@server/helpers/uuid' import { - addUserSubscription, addVideoCommentThread, addVideoToBlacklist, checkAbuseStateChange, @@ -29,7 +28,6 @@ import { MockSmtpServer, prepareNotificationsTest, registerUser, - removeUserSubscription, removeVideoFromBlacklist, ServerInfo, uploadVideo, @@ -488,8 +486,8 @@ describe('Test moderation notifications', function () { autoBlacklistTestsCustomConfig.transcoding.enabled = true await servers[0].configCommand.updateCustomConfig({ newCustomConfig: autoBlacklistTestsCustomConfig }) - 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) + await servers[0].subscriptionsCommand.add({ targetUri: 'user_1_channel@localhost:' + servers[0].port }) + await servers[1].subscriptionsCommand.add({ targetUri: 'user_1_channel@localhost:' + servers[0].port }) }) @@ -611,8 +609,8 @@ describe('Test moderation notifications', function () { after(async () => { await servers[0].configCommand.updateCustomConfig({ newCustomConfig: currentCustomConfig }) - 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) + await servers[0].subscriptionsCommand.remove({ uri: 'user_1_channel@localhost:' + servers[0].port }) + await servers[1].subscriptionsCommand.remove({ uri: 'user_1_channel@localhost:' + servers[0].port }) }) }) diff --git a/server/tests/api/notifications/notifications-api.ts b/server/tests/api/notifications/notifications-api.ts index 19f9dbbab..1ed98ae7a 100644 --- a/server/tests/api/notifications/notifications-api.ts +++ b/server/tests/api/notifications/notifications-api.ts @@ -2,21 +2,24 @@ import 'mocha' import * as chai from 'chai' -import { addUserSubscription } from '@shared/extra-utils/users/user-subscriptions' -import { cleanupTests, getMyUserInformation, immutableAssign, uploadRandomVideo, waitJobs } from '../../../../shared/extra-utils' -import { ServerInfo } from '../../../../shared/extra-utils/index' -import { MockSmtpServer } from '../../../../shared/extra-utils/mock-servers/mock-email' import { CheckerBaseParams, checkNewVideoFromSubscription, + cleanupTests, getAllNotificationsSettings, + getMyUserInformation, getUserNotifications, + immutableAssign, markAsReadAllNotifications, markAsReadNotifications, + MockSmtpServer, prepareNotificationsTest, - updateMyNotificationSettings -} from '../../../../shared/extra-utils/users/user-notifications' -import { User, UserNotification, UserNotificationSettingValue } from '../../../../shared/models/users' + ServerInfo, + updateMyNotificationSettings, + uploadRandomVideo, + waitJobs +} from '@shared/extra-utils' +import { User, UserNotification, UserNotificationSettingValue } from '@shared/models' const expect = chai.expect @@ -35,7 +38,7 @@ describe('Test notifications API', function () { userNotifications = res.userNotifications server = res.servers[0] - await addUserSubscription(server.url, userAccessToken, 'root_channel@localhost:' + server.port) + await server.subscriptionsCommand.add({ token: userAccessToken, targetUri: 'root_channel@localhost:' + server.port }) for (let i = 0; i < 10; i++) { await uploadRandomVideo(server, false) diff --git a/server/tests/api/notifications/user-notifications.ts b/server/tests/api/notifications/user-notifications.ts index ace7e48c7..15be983f2 100644 --- a/server/tests/api/notifications/user-notifications.ts +++ b/server/tests/api/notifications/user-notifications.ts @@ -3,30 +3,26 @@ import 'mocha' import * as chai from 'chai' import { buildUUID } from '@server/helpers/uuid' -import { - cleanupTests, - updateMyUser, - updateVideo, - updateVideoChannel, - uploadRandomVideoOnServers, - wait -} from '../../../../shared/extra-utils' -import { ServerInfo } from '../../../../shared/extra-utils/index' -import { MockSmtpServer } from '../../../../shared/extra-utils/mock-servers/mock-email' -import { waitJobs } from '../../../../shared/extra-utils/server/jobs' import { CheckerBaseParams, checkMyVideoImportIsFinished, checkNewActorFollow, checkNewVideoFromSubscription, checkVideoIsPublished, + cleanupTests, getLastNotification, - prepareNotificationsTest -} from '../../../../shared/extra-utils/users/user-notifications' -import { addUserSubscription, removeUserSubscription } from '../../../../shared/extra-utils/users/user-subscriptions' -import { getBadVideoUrl, getGoodVideoUrl, importVideo } from '../../../../shared/extra-utils/videos/video-imports' -import { UserNotification, UserNotificationType } from '../../../../shared/models/users' -import { VideoPrivacy } from '../../../../shared/models/videos' + MockSmtpServer, + prepareNotificationsTest, + ServerInfo, + updateMyUser, + updateVideo, + updateVideoChannel, + uploadRandomVideoOnServers, + wait, + waitJobs +} from '@shared/extra-utils' +import { getBadVideoUrl, getGoodVideoUrl, importVideo } from '@shared/extra-utils/videos/video-imports' +import { UserNotification, UserNotificationType, VideoPrivacy } from '@shared/models' const expect = chai.expect @@ -79,7 +75,7 @@ describe('Test user 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:' + servers[0].port) + await servers[0].subscriptionsCommand.add({ token: userAccessToken, targetUri: 'root_channel@localhost:' + servers[0].port }) await waitJobs(servers) const { name, uuid } = await uploadRandomVideoOnServers(servers, 1) @@ -89,7 +85,7 @@ describe('Test user notifications', function () { it('Should send a new video notification from a remote account', async function () { this.timeout(150000) // Server 2 has transcoding enabled - await addUserSubscription(servers[0].url, userAccessToken, 'root_channel@localhost:' + servers[1].port) + await servers[0].subscriptionsCommand.add({ token: userAccessToken, targetUri: 'root_channel@localhost:' + servers[1].port }) await waitJobs(servers) const { name, uuid } = await uploadRandomVideoOnServers(servers, 2) @@ -418,23 +414,23 @@ describe('Test user notifications', function () { it('Should notify when a local channel is following one of our channel', async function () { this.timeout(50000) - await addUserSubscription(servers[0].url, servers[0].accessToken, 'user_1_channel@localhost:' + servers[0].port) + await servers[0].subscriptionsCommand.add({ targetUri: '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:' + servers[0].port) + await servers[0].subscriptionsCommand.remove({ uri: 'user_1_channel@localhost:' + servers[0].port }) }) it('Should notify when a remote channel is following one of our channel', async function () { this.timeout(50000) - await addUserSubscription(servers[1].url, servers[1].accessToken, 'user_1_channel@localhost:' + servers[0].port) + await servers[1].subscriptionsCommand.add({ targetUri: '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:' + servers[0].port) + await servers[1].subscriptionsCommand.remove({ uri: 'user_1_channel@localhost:' + servers[0].port }) }) // PeerTube does not support accout -> account follows -- cgit v1.2.3