From b379759f55a35837b803a3b988674972db2903d1 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 19 Jan 2023 09:28:29 +0100 Subject: Add signup approval API tests --- server/tests/api/notifications/index.ts | 1 + .../api/notifications/moderation-notifications.ts | 27 ------- .../notifications/registrations-notifications.ts | 88 ++++++++++++++++++++++ 3 files changed, 89 insertions(+), 27 deletions(-) create mode 100644 server/tests/api/notifications/registrations-notifications.ts (limited to 'server/tests/api/notifications') diff --git a/server/tests/api/notifications/index.ts b/server/tests/api/notifications/index.ts index 8caa30a3d..c0216b74f 100644 --- a/server/tests/api/notifications/index.ts +++ b/server/tests/api/notifications/index.ts @@ -2,4 +2,5 @@ import './admin-notifications' import './comments-notifications' import './moderation-notifications' import './notifications-api' +import './registrations-notifications' import './user-notifications' diff --git a/server/tests/api/notifications/moderation-notifications.ts b/server/tests/api/notifications/moderation-notifications.ts index c7b9b5fb0..bb11a08aa 100644 --- a/server/tests/api/notifications/moderation-notifications.ts +++ b/server/tests/api/notifications/moderation-notifications.ts @@ -11,7 +11,6 @@ import { checkNewInstanceFollower, checkNewVideoAbuseForModerators, checkNewVideoFromSubscription, - checkUserRegistered, checkVideoAutoBlacklistForModerators, checkVideoIsPublished, MockInstancesIndex, @@ -327,32 +326,6 @@ describe('Test moderation notifications', function () { }) }) - describe('New registration', function () { - let baseParams: CheckerBaseParams - - before(() => { - baseParams = { - server: servers[0], - emails, - socketNotifications: adminNotifications, - token: servers[0].accessToken - } - }) - - it('Should send a notification only to moderators when a user registers on the instance', async function () { - this.timeout(10000) - - await servers[0].users.register({ username: 'user_45' }) - - await waitJobs(servers) - - await checkUserRegistered({ ...baseParams, username: 'user_45', checkType: 'presence' }) - - const userOverride = { socketNotifications: userNotifications, token: userToken1, check: { web: true, mail: false } } - await checkUserRegistered({ ...baseParams, ...userOverride, username: 'user_45', checkType: 'absence' }) - }) - }) - describe('New instance follows', function () { const instanceIndexServer = new MockInstancesIndex() let config: any diff --git a/server/tests/api/notifications/registrations-notifications.ts b/server/tests/api/notifications/registrations-notifications.ts new file mode 100644 index 000000000..b5a7c2bb5 --- /dev/null +++ b/server/tests/api/notifications/registrations-notifications.ts @@ -0,0 +1,88 @@ +/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ + +import { + CheckerBaseParams, + checkRegistrationRequest, + checkUserRegistered, + MockSmtpServer, + prepareNotificationsTest +} from '@server/tests/shared' +import { UserNotification } from '@shared/models' +import { cleanupTests, PeerTubeServer, waitJobs } from '@shared/server-commands' + +describe('Test registrations notifications', function () { + let server: PeerTubeServer + let userToken1: string + + let userNotifications: UserNotification[] = [] + let adminNotifications: UserNotification[] = [] + let emails: object[] = [] + + let baseParams: CheckerBaseParams + + before(async function () { + this.timeout(50000) + + const res = await prepareNotificationsTest(1) + + server = res.servers[0] + emails = res.emails + userToken1 = res.userAccessToken + adminNotifications = res.adminNotifications + userNotifications = res.userNotifications + + baseParams = { + server, + emails, + socketNotifications: adminNotifications, + token: server.accessToken + } + }) + + describe('New direct registration for moderators', function () { + + before(async function () { + await server.config.enableSignup(false) + }) + + it('Should send a notification only to moderators when a user registers on the instance', async function () { + this.timeout(50000) + + await server.registrations.register({ username: 'user_10' }) + + await waitJobs([ server ]) + + await checkUserRegistered({ ...baseParams, username: 'user_10', checkType: 'presence' }) + + const userOverride = { socketNotifications: userNotifications, token: userToken1, check: { web: true, mail: false } } + await checkUserRegistered({ ...baseParams, ...userOverride, username: 'user_10', checkType: 'absence' }) + }) + }) + + describe('New registration request for moderators', function () { + + before(async function () { + await server.config.enableSignup(true) + }) + + it('Should send a notification on new registration request', async function () { + this.timeout(50000) + + const registrationReason = 'my reason' + await server.registrations.requestRegistration({ username: 'user_11', registrationReason }) + + await waitJobs([ server ]) + + await checkRegistrationRequest({ ...baseParams, username: 'user_11', registrationReason, checkType: 'presence' }) + + const userOverride = { socketNotifications: userNotifications, token: userToken1, check: { web: true, mail: false } } + await checkRegistrationRequest({ ...baseParams, ...userOverride, username: 'user_11', registrationReason, checkType: 'absence' }) + }) + }) + + after(async function () { + MockSmtpServer.Instance.kill() + + await cleanupTests([ server ]) + }) +}) -- cgit v1.2.3