From 29837f8885eb37fa300e4b80c90a6d03ab337084 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 27 Jul 2021 09:07:38 +0200 Subject: Add ability to search by host in server --- server/middlewares/validators/search.ts | 5 ++ server/models/user/user-notification.ts | 3 + .../video/sql/videos-id-list-query-builder.ts | 19 +++++ server/models/video/video-playlist.ts | 2 +- server/models/video/video.ts | 6 +- .../tests/api/notifications/admin-notifications.ts | 10 +-- .../api/notifications/comments-notifications.ts | 64 ++++++++------- .../api/notifications/moderation-notifications.ts | 92 +++++++++++---------- .../tests/api/notifications/notifications-api.ts | 20 ++--- .../tests/api/notifications/user-notifications.ts | 94 +++++++++++++--------- server/tests/api/search/search-videos.ts | 42 ++++++++-- server/tests/api/server/email.ts | 9 ++- 12 files changed, 227 insertions(+), 139 deletions(-) (limited to 'server') diff --git a/server/middlewares/validators/search.ts b/server/middlewares/validators/search.ts index 7bbf81048..6bb335127 100644 --- a/server/middlewares/validators/search.ts +++ b/server/middlewares/validators/search.ts @@ -1,6 +1,7 @@ import * as express from 'express' import { query } from 'express-validator' import { isSearchTargetValid } from '@server/helpers/custom-validators/search' +import { isHostValid } from '@server/helpers/custom-validators/servers' import { isDateValid } from '../../helpers/custom-validators/misc' import { logger } from '../../helpers/logger' import { areValidationErrors } from './shared' @@ -8,6 +9,10 @@ import { areValidationErrors } from './shared' const videosSearchValidator = [ query('search').optional().not().isEmpty().withMessage('Should have a valid search'), + query('host') + .optional() + .custom(isHostValid).withMessage('Should have a valid host'), + query('startDate') .optional() .custom(isDateValid).withMessage('Should have a start date that conforms to ISO 8601'), diff --git a/server/models/user/user-notification.ts b/server/models/user/user-notification.ts index a7f84e9ca..04c5513a9 100644 --- a/server/models/user/user-notification.ts +++ b/server/models/user/user-notification.ts @@ -1,5 +1,6 @@ import { FindOptions, ModelIndexesOptions, Op, WhereOptions } from 'sequelize' import { AllowNull, BelongsTo, Column, CreatedAt, Default, ForeignKey, Is, Model, Scopes, Table, UpdatedAt } from 'sequelize-typescript' +import { uuidToShort } from '@server/helpers/uuid' import { UserNotificationIncludes, UserNotificationModelForApi } from '@server/types/models/user' import { AttributesOnly } from '@shared/core-utils' import { UserNotification, UserNotificationType } from '../../../shared' @@ -615,6 +616,7 @@ export class UserNotificationModel extends Model>> { static async searchAndPopulateAccountAndServer (options: { includeLocalVideos: boolean search?: string + host?: string start?: number count?: number sort?: string @@ -1151,6 +1152,7 @@ export class VideoModel extends Model>> { user: options.user, filter: options.filter, + host: options.host, start: options.start, count: options.count, @@ -1579,7 +1581,7 @@ export class VideoModel extends Model>> { } getWatchStaticPath () { - return buildVideoWatchPath({ shortUUID: shortToUUID(this.uuid) }) + return buildVideoWatchPath({ shortUUID: uuidToShort(this.uuid) }) } getEmbedStaticPath () { diff --git a/server/tests/api/notifications/admin-notifications.ts b/server/tests/api/notifications/admin-notifications.ts index b36ba11a9..c00d4e257 100644 --- a/server/tests/api/notifications/admin-notifications.ts +++ b/server/tests/api/notifications/admin-notifications.ts @@ -70,7 +70,7 @@ describe('Test admin notifications', function () { joinPeerTubeServer.setLatestVersion('1.4.2') await wait(3000) - await checkNewPeerTubeVersion(baseParams, '1.4.2', 'absence') + await checkNewPeerTubeVersion({ ...baseParams, latestVersion: '1.4.2', checkType: 'absence' }) }) it('Should send a notification to admins on new plugin version', async function () { @@ -79,7 +79,7 @@ describe('Test admin notifications', function () { joinPeerTubeServer.setLatestVersion('15.4.2') await wait(3000) - await checkNewPeerTubeVersion(baseParams, '15.4.2', 'presence') + await checkNewPeerTubeVersion({ ...baseParams, latestVersion: '15.4.2', checkType: 'presence' }) }) it('Should not send the same notification to admins', async function () { @@ -101,7 +101,7 @@ describe('Test admin notifications', function () { joinPeerTubeServer.setLatestVersion('15.4.3') await wait(3000) - await checkNewPeerTubeVersion(baseParams, '15.4.3', 'presence') + await checkNewPeerTubeVersion({ ...baseParams, latestVersion: '15.4.3', checkType: 'presence' }) expect(adminNotifications.filter(n => n.type === UserNotificationType.NEW_PEERTUBE_VERSION)).to.have.lengthOf(2) }) }) @@ -112,7 +112,7 @@ describe('Test admin notifications', function () { this.timeout(30000) await wait(6000) - await checkNewPluginVersion(baseParams, PluginType.PLUGIN, 'hello-world', 'absence') + await checkNewPluginVersion({ ...baseParams, pluginType: PluginType.PLUGIN, pluginName: 'hello-world', checkType: 'absence' }) }) it('Should send a notification to admins on new plugin version', async function () { @@ -122,7 +122,7 @@ describe('Test admin notifications', function () { await server.sql.setPluginLatestVersion('hello-world', '0.0.1') await wait(6000) - await checkNewPluginVersion(baseParams, PluginType.PLUGIN, 'hello-world', 'presence') + await checkNewPluginVersion({ ...baseParams, pluginType: PluginType.PLUGIN, pluginName: 'hello-world', checkType: 'presence' }) }) it('Should not send the same notification to admins', async function () { diff --git a/server/tests/api/notifications/comments-notifications.ts b/server/tests/api/notifications/comments-notifications.ts index cbb46e510..7cbb21397 100644 --- a/server/tests/api/notifications/comments-notifications.ts +++ b/server/tests/api/notifications/comments-notifications.ts @@ -52,25 +52,25 @@ describe('Test comments notifications', function () { it('Should not send a new comment notification after a comment on another video', async function () { this.timeout(20000) - const { uuid } = await servers[0].videos.upload({ attributes: { name: 'super video' } }) + const { uuid, shortUUID } = await servers[0].videos.upload({ attributes: { name: 'super video' } }) const created = await servers[0].comments.createThread({ videoId: uuid, text: 'comment' }) const commentId = created.id await waitJobs(servers) - await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'absence') + await checkNewCommentOnMyVideo({ ...baseParams, shortUUID, threadId: commentId, commentId, checkType: 'absence' }) }) it('Should not send a new comment notification if I comment my own video', async function () { this.timeout(20000) - const { uuid } = await servers[0].videos.upload({ token: userToken, attributes: { name: 'super video' } }) + const { uuid, shortUUID } = await servers[0].videos.upload({ token: userToken, attributes: { name: 'super video' } }) const created = await servers[0].comments.createThread({ token: userToken, videoId: uuid, text: 'comment' }) const commentId = created.id await waitJobs(servers) - await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'absence') + await checkNewCommentOnMyVideo({ ...baseParams, shortUUID, threadId: commentId, commentId, checkType: 'absence' }) }) it('Should not send a new comment notification if the account is muted', async function () { @@ -78,13 +78,13 @@ describe('Test comments notifications', function () { await servers[0].blocklist.addToMyBlocklist({ token: userToken, account: 'root' }) - const { uuid } = await servers[0].videos.upload({ token: userToken, attributes: { name: 'super video' } }) + const { uuid, shortUUID } = await servers[0].videos.upload({ token: userToken, attributes: { name: 'super video' } }) const created = await servers[0].comments.createThread({ videoId: uuid, text: 'comment' }) const commentId = created.id await waitJobs(servers) - await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'absence') + await checkNewCommentOnMyVideo({ ...baseParams, shortUUID, threadId: commentId, commentId, checkType: 'absence' }) await servers[0].blocklist.removeFromMyBlocklist({ token: userToken, account: 'root' }) }) @@ -92,19 +92,19 @@ describe('Test comments notifications', function () { it('Should send a new comment notification after a local comment on my video', async function () { this.timeout(20000) - const { uuid } = await servers[0].videos.upload({ token: userToken, attributes: { name: 'super video' } }) + const { uuid, shortUUID } = await servers[0].videos.upload({ token: userToken, attributes: { name: 'super video' } }) const created = await servers[0].comments.createThread({ videoId: uuid, text: 'comment' }) const commentId = created.id await waitJobs(servers) - await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'presence') + await checkNewCommentOnMyVideo({ ...baseParams, shortUUID, threadId: commentId, commentId, checkType: 'presence' }) }) it('Should send a new comment notification after a remote comment on my video', async function () { this.timeout(20000) - const { uuid } = await servers[0].videos.upload({ token: userToken, attributes: { name: 'super video' } }) + const { uuid, shortUUID } = await servers[0].videos.upload({ token: userToken, attributes: { name: 'super video' } }) await waitJobs(servers) @@ -116,26 +116,26 @@ describe('Test comments notifications', function () { expect(data).to.have.lengthOf(1) const commentId = data[0].id - await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'presence') + await checkNewCommentOnMyVideo({ ...baseParams, shortUUID, threadId: commentId, commentId, checkType: 'presence' }) }) it('Should send a new comment notification after a local reply on my video', async function () { this.timeout(20000) - const { uuid } = await servers[0].videos.upload({ token: userToken, attributes: { name: 'super video' } }) + const { uuid, shortUUID } = await servers[0].videos.upload({ token: userToken, attributes: { name: 'super video' } }) const { id: threadId } = await servers[0].comments.createThread({ videoId: uuid, text: 'comment' }) const { id: commentId } = await servers[0].comments.addReply({ videoId: uuid, toCommentId: threadId, text: 'reply' }) await waitJobs(servers) - await checkNewCommentOnMyVideo(baseParams, uuid, commentId, threadId, 'presence') + await checkNewCommentOnMyVideo({ ...baseParams, shortUUID, threadId, commentId, checkType: 'presence' }) }) it('Should send a new comment notification after a remote reply on my video', async function () { this.timeout(20000) - const { uuid } = await servers[0].videos.upload({ token: userToken, attributes: { name: 'super video' } }) + const { uuid, shortUUID } = await servers[0].videos.upload({ token: userToken, attributes: { name: 'super video' } }) await waitJobs(servers) { @@ -155,7 +155,7 @@ describe('Test comments notifications', function () { expect(tree.children).to.have.lengthOf(1) const commentId = tree.children[0].comment.id - await checkNewCommentOnMyVideo(baseParams, uuid, commentId, threadId, 'presence') + await checkNewCommentOnMyVideo({ ...baseParams, shortUUID, threadId, commentId, checkType: 'presence' }) }) it('Should convert markdown in comment to html', async function () { @@ -174,6 +174,7 @@ describe('Test comments notifications', function () { describe('Mention notifications', function () { let baseParams: CheckerBaseParams + const byAccountDisplayName = 'super root name' before(async () => { baseParams = { @@ -190,23 +191,23 @@ describe('Test comments notifications', function () { it('Should not send a new mention comment notification if I mention the video owner', async function () { this.timeout(10000) - const { uuid } = await servers[0].videos.upload({ token: userToken, attributes: { name: 'super video' } }) + const { uuid, shortUUID } = await servers[0].videos.upload({ token: userToken, attributes: { name: 'super video' } }) const { id: commentId } = await servers[0].comments.createThread({ videoId: uuid, text: '@user_1 hello' }) await waitJobs(servers) - await checkCommentMention(baseParams, uuid, commentId, commentId, 'super root name', 'absence') + await checkCommentMention({ ...baseParams, shortUUID, threadId: commentId, commentId, byAccountDisplayName, checkType: 'absence' }) }) it('Should not send a new mention comment notification if I mention myself', async function () { this.timeout(10000) - const { uuid } = await servers[0].videos.upload({ attributes: { name: 'super video' } }) + const { uuid, shortUUID } = await servers[0].videos.upload({ attributes: { name: 'super video' } }) const { id: commentId } = await servers[0].comments.createThread({ token: userToken, videoId: uuid, text: '@user_1 hello' }) await waitJobs(servers) - await checkCommentMention(baseParams, uuid, commentId, commentId, 'super root name', 'absence') + await checkCommentMention({ ...baseParams, shortUUID, threadId: commentId, commentId, byAccountDisplayName, checkType: 'absence' }) }) it('Should not send a new mention notification if the account is muted', async function () { @@ -214,12 +215,12 @@ describe('Test comments notifications', function () { await servers[0].blocklist.addToMyBlocklist({ token: userToken, account: 'root' }) - const { uuid } = await servers[0].videos.upload({ attributes: { name: 'super video' } }) + const { uuid, shortUUID } = await servers[0].videos.upload({ attributes: { name: 'super video' } }) const { id: commentId } = await servers[0].comments.createThread({ videoId: uuid, text: '@user_1 hello' }) await waitJobs(servers) - await checkCommentMention(baseParams, uuid, commentId, commentId, 'super root name', 'absence') + await checkCommentMention({ ...baseParams, shortUUID, threadId: commentId, commentId, byAccountDisplayName, checkType: 'absence' }) await servers[0].blocklist.removeFromMyBlocklist({ token: userToken, account: 'root' }) }) @@ -227,35 +228,37 @@ describe('Test comments notifications', function () { it('Should not send a new mention notification if the remote account mention a local account', async function () { this.timeout(20000) - const { uuid } = await servers[0].videos.upload({ attributes: { name: 'super video' } }) + const { uuid, shortUUID } = await servers[0].videos.upload({ attributes: { name: 'super video' } }) await waitJobs(servers) const { id: threadId } = await servers[1].comments.createThread({ videoId: uuid, text: '@user_1 hello' }) await waitJobs(servers) - await checkCommentMention(baseParams, uuid, threadId, threadId, 'super root 2 name', 'absence') + + const byAccountDisplayName = 'super root 2 name' + await checkCommentMention({ ...baseParams, shortUUID, threadId, commentId: threadId, byAccountDisplayName, checkType: 'absence' }) }) it('Should send a new mention notification after local comments', async function () { this.timeout(10000) - const { uuid } = await servers[0].videos.upload({ attributes: { name: 'super video' } }) + const { uuid, shortUUID } = await servers[0].videos.upload({ attributes: { name: 'super video' } }) const { id: threadId } = await servers[0].comments.createThread({ videoId: uuid, text: '@user_1 hellotext: 1' }) await waitJobs(servers) - await checkCommentMention(baseParams, uuid, threadId, threadId, 'super root name', 'presence') + await checkCommentMention({ ...baseParams, shortUUID, threadId, commentId: threadId, byAccountDisplayName, checkType: 'presence' }) const { id: commentId } = await servers[0].comments.addReply({ videoId: uuid, toCommentId: threadId, text: 'hello 2 @user_1' }) await waitJobs(servers) - await checkCommentMention(baseParams, uuid, commentId, threadId, 'super root name', 'presence') + await checkCommentMention({ ...baseParams, shortUUID, commentId, threadId, byAccountDisplayName, checkType: 'presence' }) }) it('Should send a new mention notification after remote comments', async function () { this.timeout(20000) - const { uuid } = await servers[0].videos.upload({ attributes: { name: 'super video' } }) + const { uuid, shortUUID } = await servers[0].videos.upload({ attributes: { name: 'super video' } }) await waitJobs(servers) @@ -267,20 +270,21 @@ describe('Test comments notifications', function () { const { data } = await servers[0].comments.listThreads({ videoId: uuid }) expect(data).to.have.lengthOf(1) - const server1ThreadId = data[0].id - await checkCommentMention(baseParams, uuid, server1ThreadId, server1ThreadId, 'super root 2 name', 'presence') + const byAccountDisplayName = 'super root 2 name' + const threadId = data[0].id + await checkCommentMention({ ...baseParams, shortUUID, commentId: threadId, threadId, byAccountDisplayName, checkType: 'presence' }) const text2 = `@user_1@localhost:${servers[0].port} hello 2 @root@localhost:${servers[0].port}` await servers[1].comments.addReply({ videoId: uuid, toCommentId: server2ThreadId, text: text2 }) await waitJobs(servers) - const tree = await servers[0].comments.getThread({ videoId: uuid, threadId: server1ThreadId }) + const tree = await servers[0].comments.getThread({ videoId: uuid, threadId }) expect(tree.children).to.have.lengthOf(1) const commentId = tree.children[0].comment.id - await checkCommentMention(baseParams, uuid, commentId, server1ThreadId, 'super root 2 name', 'presence') + await checkCommentMention({ ...baseParams, shortUUID, commentId, threadId, byAccountDisplayName, checkType: 'presence' }) }) it('Should convert markdown in comment to html', async function () { diff --git a/server/tests/api/notifications/moderation-notifications.ts b/server/tests/api/notifications/moderation-notifications.ts index 6f74709b3..eb3c29fe7 100644 --- a/server/tests/api/notifications/moderation-notifications.ts +++ b/server/tests/api/notifications/moderation-notifications.ts @@ -67,7 +67,7 @@ describe('Test moderation notifications', function () { await servers[0].abuses.report({ videoId: video.id, reason: 'super reason' }) await waitJobs(servers) - await checkNewVideoAbuseForModerators(baseParams, video.uuid, name, 'presence') + await checkNewVideoAbuseForModerators({ ...baseParams, shortUUID: video.shortUUID, videoName: name, checkType: 'presence' }) }) it('Should send a notification to moderators on remote video abuse', async function () { @@ -82,7 +82,7 @@ describe('Test moderation notifications', function () { await servers[1].abuses.report({ videoId, reason: 'super reason' }) await waitJobs(servers) - await checkNewVideoAbuseForModerators(baseParams, video.uuid, name, 'presence') + await checkNewVideoAbuseForModerators({ ...baseParams, shortUUID: video.shortUUID, videoName: name, checkType: 'presence' }) }) it('Should send a notification to moderators on local comment abuse', async function () { @@ -101,7 +101,7 @@ describe('Test moderation notifications', function () { await servers[0].abuses.report({ commentId: comment.id, reason: 'super reason' }) await waitJobs(servers) - await checkNewCommentAbuseForModerators(baseParams, video.uuid, name, 'presence') + await checkNewCommentAbuseForModerators({ ...baseParams, shortUUID: video.shortUUID, videoName: name, checkType: 'presence' }) }) it('Should send a notification to moderators on remote comment abuse', async function () { @@ -123,7 +123,7 @@ describe('Test moderation notifications', function () { await servers[1].abuses.report({ commentId, reason: 'super reason' }) await waitJobs(servers) - await checkNewCommentAbuseForModerators(baseParams, video.uuid, name, 'presence') + await checkNewCommentAbuseForModerators({ ...baseParams, shortUUID: video.shortUUID, videoName: name, checkType: 'presence' }) }) it('Should send a notification to moderators on local account abuse', async function () { @@ -136,7 +136,7 @@ describe('Test moderation notifications', function () { await servers[0].abuses.report({ accountId, reason: 'super reason' }) await waitJobs(servers) - await checkNewAccountAbuseForModerators(baseParams, username, 'presence') + await checkNewAccountAbuseForModerators({ ...baseParams, displayName: username, checkType: 'presence' }) }) it('Should send a notification to moderators on remote account abuse', async function () { @@ -152,7 +152,7 @@ describe('Test moderation notifications', function () { await servers[1].abuses.report({ accountId: account.id, reason: 'super reason' }) await waitJobs(servers) - await checkNewAccountAbuseForModerators(baseParams, username, 'presence') + await checkNewAccountAbuseForModerators({ ...baseParams, displayName: username, checkType: 'presence' }) }) }) @@ -181,7 +181,7 @@ describe('Test moderation notifications', function () { await servers[0].abuses.update({ abuseId, body: { state: AbuseState.ACCEPTED } }) await waitJobs(servers) - await checkAbuseStateChange(baseParams, abuseId, AbuseState.ACCEPTED, 'presence') + await checkAbuseStateChange({ ...baseParams, abuseId, state: AbuseState.ACCEPTED, checkType: 'presence' }) }) it('Should send a notification to reporter if the abuse has been rejected', async function () { @@ -190,7 +190,7 @@ describe('Test moderation notifications', function () { await servers[0].abuses.update({ abuseId, body: { state: AbuseState.REJECTED } }) await waitJobs(servers) - await checkAbuseStateChange(baseParams, abuseId, AbuseState.REJECTED, 'presence') + await checkAbuseStateChange({ ...baseParams, abuseId, state: AbuseState.REJECTED, checkType: 'presence' }) }) }) @@ -236,7 +236,7 @@ describe('Test moderation notifications', function () { await servers[0].abuses.addMessage({ abuseId, message }) await waitJobs(servers) - await checkNewAbuseMessage(baseParamsUser, abuseId, message, 'user_1@example.com', 'presence') + await checkNewAbuseMessage({ ...baseParamsUser, abuseId, message, toEmail: 'user_1@example.com', checkType: 'presence' }) }) it('Should not send a notification to the admin if sent by the admin', async function () { @@ -246,7 +246,8 @@ describe('Test moderation notifications', function () { await servers[0].abuses.addMessage({ abuseId, message }) await waitJobs(servers) - await checkNewAbuseMessage(baseParamsAdmin, abuseId, message, 'admin' + servers[0].internalServerNumber + '@example.com', 'absence') + const toEmail = 'admin' + servers[0].internalServerNumber + '@example.com' + await checkNewAbuseMessage({ ...baseParamsAdmin, abuseId, message, toEmail, checkType: 'absence' }) }) it('Should send a notification to moderators', async function () { @@ -256,7 +257,8 @@ describe('Test moderation notifications', function () { await servers[0].abuses.addMessage({ token: userAccessToken, abuseId: abuseId2, message }) await waitJobs(servers) - await checkNewAbuseMessage(baseParamsAdmin, abuseId2, message, 'admin' + servers[0].internalServerNumber + '@example.com', 'presence') + const toEmail = 'admin' + servers[0].internalServerNumber + '@example.com' + await checkNewAbuseMessage({ ...baseParamsAdmin, abuseId: abuseId2, message, toEmail, checkType: 'presence' }) }) it('Should not send a notification to reporter if sent by the reporter', async function () { @@ -266,7 +268,8 @@ describe('Test moderation notifications', function () { await servers[0].abuses.addMessage({ token: userAccessToken, abuseId: abuseId2, message }) await waitJobs(servers) - await checkNewAbuseMessage(baseParamsUser, abuseId2, message, 'user_1@example.com', 'absence') + const toEmail = 'user_1@example.com' + await checkNewAbuseMessage({ ...baseParamsUser, abuseId: abuseId2, message, toEmail, checkType: 'absence' }) }) }) @@ -286,19 +289,19 @@ describe('Test moderation notifications', function () { this.timeout(10000) const name = 'video for abuse ' + buildUUID() - const { uuid } = await servers[0].videos.upload({ token: userAccessToken, attributes: { name } }) + const { uuid, shortUUID } = await servers[0].videos.upload({ token: userAccessToken, attributes: { name } }) await servers[0].blacklist.add({ videoId: uuid }) await waitJobs(servers) - await checkNewBlacklistOnMyVideo(baseParams, uuid, name, 'blacklist') + await checkNewBlacklistOnMyVideo({ ...baseParams, shortUUID, videoName: name, blacklistType: 'blacklist' }) }) it('Should send a notification to video owner on unblacklist', async function () { this.timeout(10000) const name = 'video for abuse ' + buildUUID() - const { uuid } = await servers[0].videos.upload({ token: userAccessToken, attributes: { name } }) + const { uuid, shortUUID } = await servers[0].videos.upload({ token: userAccessToken, attributes: { name } }) await servers[0].blacklist.add({ videoId: uuid }) @@ -307,7 +310,7 @@ describe('Test moderation notifications', function () { await waitJobs(servers) await wait(500) - await checkNewBlacklistOnMyVideo(baseParams, uuid, name, 'unblacklist') + await checkNewBlacklistOnMyVideo({ ...baseParams, shortUUID, videoName: name, blacklistType: 'unblacklist' }) }) }) @@ -330,10 +333,10 @@ describe('Test moderation notifications', function () { await waitJobs(servers) - await checkUserRegistered(baseParams, 'user_45', 'presence') + await checkUserRegistered({ ...baseParams, username: 'user_45', checkType: 'presence' }) const userOverride = { socketNotifications: userNotifications, token: userAccessToken, check: { web: true, mail: false } } - await checkUserRegistered({ ...baseParams, ...userOverride }, 'user_45', 'absence') + await checkUserRegistered({ ...baseParams, ...userOverride, username: 'user_45', checkType: 'absence' }) }) }) @@ -372,10 +375,10 @@ describe('Test moderation notifications', function () { await waitJobs(servers) - await checkNewInstanceFollower(baseParams, 'localhost:' + servers[2].port, 'presence') + await checkNewInstanceFollower({ ...baseParams, followerHost: 'localhost:' + servers[2].port, checkType: 'presence' }) const userOverride = { socketNotifications: userNotifications, token: userAccessToken, check: { web: true, mail: false } } - await checkNewInstanceFollower({ ...baseParams, ...userOverride }, 'localhost:' + servers[2].port, 'absence') + await checkNewInstanceFollower({ ...baseParams, ...userOverride, followerHost: 'localhost:' + servers[2].port, checkType: 'absence' }) }) it('Should send a notification on auto follow back', async function () { @@ -399,10 +402,10 @@ describe('Test moderation notifications', function () { const followerHost = servers[0].host const followingHost = servers[2].host - await checkAutoInstanceFollowing(baseParams, followerHost, followingHost, 'presence') + await checkAutoInstanceFollowing({ ...baseParams, followerHost, followingHost, checkType: 'presence' }) const userOverride = { socketNotifications: userNotifications, token: userAccessToken, check: { web: true, mail: false } } - await checkAutoInstanceFollowing({ ...baseParams, ...userOverride }, followerHost, followingHost, 'absence') + await checkAutoInstanceFollowing({ ...baseParams, ...userOverride, followerHost, followingHost, checkType: 'absence' }) config.followings.instance.autoFollowBack.enabled = false await servers[0].config.updateCustomSubConfig({ newConfig: config }) @@ -421,7 +424,7 @@ describe('Test moderation notifications', function () { const followerHost = servers[0].host const followingHost = servers[1].host - await checkAutoInstanceFollowing(baseParams, followerHost, followingHost, 'presence') + await checkAutoInstanceFollowing({ ...baseParams, followerHost, followingHost, checkType: 'presence' }) config.followings.instance.autoFollowIndex.enabled = false await servers[0].config.updateCustomSubConfig({ newConfig: config }) @@ -433,7 +436,8 @@ describe('Test moderation notifications', function () { let userBaseParams: CheckerBaseParams let adminBaseParamsServer1: CheckerBaseParams let adminBaseParamsServer2: CheckerBaseParams - let videoUUID: string + let uuid: string + let shortUUID: string let videoName: string let currentCustomConfig: CustomConfig @@ -480,36 +484,36 @@ describe('Test moderation notifications', function () { await servers[0].subscriptions.add({ targetUri: 'user_1_channel@localhost:' + servers[0].port }) await servers[1].subscriptions.add({ targetUri: 'user_1_channel@localhost:' + servers[0].port }) - }) it('Should send notification to moderators on new video with auto-blacklist', async function () { this.timeout(40000) videoName = 'video with auto-blacklist ' + buildUUID() - const { uuid } = await servers[0].videos.upload({ token: userAccessToken, attributes: { name: videoName } }) - videoUUID = uuid + const video = await servers[0].videos.upload({ token: userAccessToken, attributes: { name: videoName } }) + shortUUID = video.shortUUID + uuid = video.uuid await waitJobs(servers) - await checkVideoAutoBlacklistForModerators(adminBaseParamsServer1, videoUUID, videoName, 'presence') + await checkVideoAutoBlacklistForModerators({ ...adminBaseParamsServer1, shortUUID, videoName, checkType: 'presence' }) }) it('Should not send video publish notification if auto-blacklisted', async function () { - await checkVideoIsPublished(userBaseParams, videoName, videoUUID, 'absence') + await checkVideoIsPublished({ ...userBaseParams, videoName, shortUUID, checkType: 'absence' }) }) it('Should not send a local user subscription notification if auto-blacklisted', async function () { - await checkNewVideoFromSubscription(adminBaseParamsServer1, videoName, videoUUID, 'absence') + await checkNewVideoFromSubscription({ ...adminBaseParamsServer1, videoName, shortUUID, checkType: 'absence' }) }) it('Should not send a remote user subscription notification if auto-blacklisted', async function () { - await checkNewVideoFromSubscription(adminBaseParamsServer2, videoName, videoUUID, 'absence') + await checkNewVideoFromSubscription({ ...adminBaseParamsServer2, videoName, shortUUID, checkType: 'absence' }) }) it('Should send video published and unblacklist after video unblacklisted', async function () { this.timeout(40000) - await servers[0].blacklist.remove({ videoId: videoUUID }) + await servers[0].blacklist.remove({ videoId: uuid }) await waitJobs(servers) @@ -520,11 +524,11 @@ describe('Test moderation notifications', function () { }) it('Should send a local user subscription notification after removed from blacklist', async function () { - await checkNewVideoFromSubscription(adminBaseParamsServer1, videoName, videoUUID, 'presence') + await checkNewVideoFromSubscription({ ...adminBaseParamsServer1, videoName, shortUUID, checkType: 'presence' }) }) it('Should send a remote user subscription notification after removed from blacklist', async function () { - await checkNewVideoFromSubscription(adminBaseParamsServer2, videoName, videoUUID, 'presence') + await checkNewVideoFromSubscription({ ...adminBaseParamsServer2, videoName, shortUUID, checkType: 'presence' }) }) it('Should send unblacklist but not published/subscription notes after unblacklisted if scheduled update pending', async function () { @@ -543,19 +547,19 @@ describe('Test moderation notifications', function () { } } - const { uuid } = await servers[0].videos.upload({ token: userAccessToken, attributes }) + const { shortUUID, uuid } = await servers[0].videos.upload({ token: userAccessToken, attributes }) await servers[0].blacklist.remove({ videoId: uuid }) await waitJobs(servers) - await checkNewBlacklistOnMyVideo(userBaseParams, uuid, name, 'unblacklist') + await checkNewBlacklistOnMyVideo({ ...userBaseParams, shortUUID, videoName: name, blacklistType: 'unblacklist' }) // FIXME: Can't test absence as two notifications sent to same user and util only checks last one // One notification might be better anyways // await checkVideoIsPublished(userBaseParams, name, uuid, 'absence') - await checkNewVideoFromSubscription(adminBaseParamsServer1, name, uuid, 'absence') - await checkNewVideoFromSubscription(adminBaseParamsServer2, name, uuid, 'absence') + await checkNewVideoFromSubscription({ ...adminBaseParamsServer1, videoName: name, shortUUID, checkType: 'absence' }) + await checkNewVideoFromSubscription({ ...adminBaseParamsServer2, videoName: name, shortUUID, checkType: 'absence' }) }) it('Should not send publish/subscription notifications after scheduled update if video still auto-blacklisted', async function () { @@ -575,12 +579,12 @@ describe('Test moderation notifications', function () { } } - const { uuid } = await servers[0].videos.upload({ token: userAccessToken, attributes }) + const { shortUUID } = await servers[0].videos.upload({ token: userAccessToken, attributes }) await wait(6000) - await checkVideoIsPublished(userBaseParams, name, uuid, 'absence') - await checkNewVideoFromSubscription(adminBaseParamsServer1, name, uuid, 'absence') - await checkNewVideoFromSubscription(adminBaseParamsServer2, name, uuid, 'absence') + await checkVideoIsPublished({ ...userBaseParams, videoName: name, shortUUID, checkType: 'absence' }) + await checkNewVideoFromSubscription({ ...adminBaseParamsServer1, videoName: name, shortUUID, checkType: 'absence' }) + await checkNewVideoFromSubscription({ ...adminBaseParamsServer2, videoName: name, shortUUID, checkType: 'absence' }) }) it('Should not send a notification to moderators on new video without auto-blacklist', async function () { @@ -589,10 +593,10 @@ describe('Test moderation notifications', function () { const name = 'video without auto-blacklist ' + buildUUID() // admin with blacklist right will not be auto-blacklisted - const { uuid } = await servers[0].videos.upload({ attributes: { name } }) + const { shortUUID } = await servers[0].videos.upload({ attributes: { name } }) await waitJobs(servers) - await checkVideoAutoBlacklistForModerators(adminBaseParamsServer1, uuid, name, 'absence') + await checkVideoAutoBlacklistForModerators({ ...adminBaseParamsServer1, shortUUID, videoName: name, checkType: 'absence' }) }) after(async () => { diff --git a/server/tests/api/notifications/notifications-api.ts b/server/tests/api/notifications/notifications-api.ts index fa4b53db6..a529a9bf7 100644 --- a/server/tests/api/notifications/notifications-api.ts +++ b/server/tests/api/notifications/notifications-api.ts @@ -111,10 +111,10 @@ describe('Test notifications API', function () { expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.NONE) } - const { name, uuid } = await server.videos.randomUpload() + const { name, shortUUID } = await server.videos.randomUpload() const check = { web: true, mail: true } - await checkNewVideoFromSubscription({ ...baseParams, check }, name, uuid, 'absence') + await checkNewVideoFromSubscription({ ...baseParams, check, videoName: name, shortUUID, checkType: 'absence' }) }) it('Should only have web notifications', async function () { @@ -130,16 +130,16 @@ describe('Test notifications API', function () { expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.WEB) } - const { name, uuid } = await server.videos.randomUpload() + const { name, shortUUID } = await server.videos.randomUpload() { const check = { mail: true, web: false } - await checkNewVideoFromSubscription({ ...baseParams, check }, name, uuid, 'absence') + await checkNewVideoFromSubscription({ ...baseParams, check, videoName: name, shortUUID, checkType: 'absence' }) } { const check = { mail: false, web: true } - await checkNewVideoFromSubscription({ ...baseParams, check }, name, uuid, 'presence') + await checkNewVideoFromSubscription({ ...baseParams, check, videoName: name, shortUUID, checkType: 'presence' }) } }) @@ -156,16 +156,16 @@ describe('Test notifications API', function () { expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.EMAIL) } - const { name, uuid } = await server.videos.randomUpload() + const { name, shortUUID } = await server.videos.randomUpload() { const check = { mail: false, web: true } - await checkNewVideoFromSubscription({ ...baseParams, check }, name, uuid, 'absence') + await checkNewVideoFromSubscription({ ...baseParams, check, videoName: name, shortUUID, checkType: 'absence' }) } { const check = { mail: true, web: false } - await checkNewVideoFromSubscription({ ...baseParams, check }, name, uuid, 'presence') + await checkNewVideoFromSubscription({ ...baseParams, check, videoName: name, shortUUID, checkType: 'presence' }) } }) @@ -187,9 +187,9 @@ describe('Test notifications API', function () { ) } - const { name, uuid } = await server.videos.randomUpload() + const { name, shortUUID } = await server.videos.randomUpload() - await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence') + await checkNewVideoFromSubscription({ ...baseParams, videoName: name, shortUUID, checkType: 'presence' }) }) }) diff --git a/server/tests/api/notifications/user-notifications.ts b/server/tests/api/notifications/user-notifications.ts index ca592d466..e53ab2aa5 100644 --- a/server/tests/api/notifications/user-notifications.ts +++ b/server/tests/api/notifications/user-notifications.ts @@ -74,8 +74,8 @@ describe('Test user notifications', function () { await servers[0].subscriptions.add({ token: userAccessToken, targetUri: 'root_channel@localhost:' + servers[0].port }) await waitJobs(servers) - const { name, uuid } = await uploadRandomVideoOnServers(servers, 1) - await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence') + const { name, shortUUID } = await uploadRandomVideoOnServers(servers, 1) + await checkNewVideoFromSubscription({ ...baseParams, videoName: name, shortUUID, checkType: 'presence' }) }) it('Should send a new video notification from a remote account', async function () { @@ -84,8 +84,8 @@ describe('Test user notifications', function () { await servers[0].subscriptions.add({ token: userAccessToken, targetUri: 'root_channel@localhost:' + servers[1].port }) await waitJobs(servers) - const { name, uuid } = await uploadRandomVideoOnServers(servers, 2) - await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence') + const { name, shortUUID } = await uploadRandomVideoOnServers(servers, 2) + await checkNewVideoFromSubscription({ ...baseParams, videoName: name, shortUUID, checkType: 'presence' }) }) it('Should send a new video notification on a scheduled publication', async function () { @@ -101,10 +101,10 @@ describe('Test user notifications', function () { privacy: VideoPrivacy.PUBLIC as VideoPrivacy.PUBLIC } } - const { name, uuid } = await uploadRandomVideoOnServers(servers, 1, data) + const { name, shortUUID } = await uploadRandomVideoOnServers(servers, 1, data) await wait(6000) - await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence') + await checkNewVideoFromSubscription({ ...baseParams, videoName: name, shortUUID, checkType: 'presence' }) }) it('Should send a new video notification on a remote scheduled publication', async function () { @@ -120,11 +120,11 @@ describe('Test user notifications', function () { privacy: VideoPrivacy.PUBLIC as VideoPrivacy.PUBLIC } } - const { name, uuid } = await uploadRandomVideoOnServers(servers, 2, data) + const { name, shortUUID } = await uploadRandomVideoOnServers(servers, 2, data) await waitJobs(servers) await wait(6000) - await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence') + await checkNewVideoFromSubscription({ ...baseParams, videoName: name, shortUUID, checkType: 'presence' }) }) it('Should not send a notification before the video is published', async function () { @@ -139,61 +139,61 @@ describe('Test user notifications', function () { privacy: VideoPrivacy.PUBLIC as VideoPrivacy.PUBLIC } } - const { name, uuid } = await uploadRandomVideoOnServers(servers, 1, data) + const { name, shortUUID } = await uploadRandomVideoOnServers(servers, 1, data) await wait(6000) - await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence') + await checkNewVideoFromSubscription({ ...baseParams, videoName: name, shortUUID, checkType: 'absence' }) }) it('Should send a new video notification when a video becomes public', async function () { this.timeout(50000) const data = { privacy: VideoPrivacy.PRIVATE } - const { name, uuid } = await uploadRandomVideoOnServers(servers, 1, data) + const { name, uuid, shortUUID } = await uploadRandomVideoOnServers(servers, 1, data) - await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence') + await checkNewVideoFromSubscription({ ...baseParams, videoName: name, shortUUID, checkType: 'absence' }) await servers[0].videos.update({ id: uuid, attributes: { privacy: VideoPrivacy.PUBLIC } }) await waitJobs(servers) - await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence') + await checkNewVideoFromSubscription({ ...baseParams, videoName: name, shortUUID, checkType: 'presence' }) }) it('Should send a new video notification when a remote video becomes public', async function () { this.timeout(50000) const data = { privacy: VideoPrivacy.PRIVATE } - const { name, uuid } = await uploadRandomVideoOnServers(servers, 2, data) + const { name, uuid, shortUUID } = await uploadRandomVideoOnServers(servers, 2, data) - await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence') + await checkNewVideoFromSubscription({ ...baseParams, videoName: name, shortUUID, checkType: 'absence' }) await servers[1].videos.update({ id: uuid, attributes: { privacy: VideoPrivacy.PUBLIC } }) await waitJobs(servers) - await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence') + await checkNewVideoFromSubscription({ ...baseParams, videoName: name, shortUUID, checkType: 'presence' }) }) it('Should not send a new video notification when a video becomes unlisted', async function () { this.timeout(50000) const data = { privacy: VideoPrivacy.PRIVATE } - const { name, uuid } = await uploadRandomVideoOnServers(servers, 1, data) + const { name, uuid, shortUUID } = await uploadRandomVideoOnServers(servers, 1, data) await servers[0].videos.update({ id: uuid, attributes: { privacy: VideoPrivacy.UNLISTED } }) - await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence') + await checkNewVideoFromSubscription({ ...baseParams, videoName: name, shortUUID, checkType: 'absence' }) }) it('Should not send a new video notification when a remote video becomes unlisted', async function () { this.timeout(50000) const data = { privacy: VideoPrivacy.PRIVATE } - const { name, uuid } = await uploadRandomVideoOnServers(servers, 2, data) + const { name, uuid, shortUUID } = await uploadRandomVideoOnServers(servers, 2, data) await servers[1].videos.update({ id: uuid, attributes: { privacy: VideoPrivacy.UNLISTED } }) await waitJobs(servers) - await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence') + await checkNewVideoFromSubscription({ ...baseParams, videoName: name, shortUUID, checkType: 'absence' }) }) it('Should send a new video notification after a video import', async function () { @@ -211,7 +211,7 @@ describe('Test user notifications', function () { await waitJobs(servers) - await checkNewVideoFromSubscription(baseParams, name, video.uuid, 'presence') + await checkNewVideoFromSubscription({ ...baseParams, videoName: name, shortUUID: video.shortUUID, checkType: 'presence' }) }) }) @@ -230,10 +230,10 @@ describe('Test user notifications', function () { it('Should not send a notification if transcoding is not enabled', async function () { this.timeout(50000) - const { name, uuid } = await uploadRandomVideoOnServers(servers, 1) + const { name, shortUUID } = await uploadRandomVideoOnServers(servers, 1) await waitJobs(servers) - await checkVideoIsPublished(baseParams, name, uuid, 'absence') + await checkVideoIsPublished({ ...baseParams, videoName: name, shortUUID, checkType: 'absence' }) }) it('Should not send a notification if the wait transcoding is false', async function () { @@ -251,19 +251,19 @@ describe('Test user notifications', function () { it('Should send a notification even if the video is not transcoded in other resolutions', async function () { this.timeout(50000) - const { name, uuid } = await uploadRandomVideoOnServers(servers, 2, { waitTranscoding: true, fixture: 'video_short_240p.mp4' }) + const { name, shortUUID } = await uploadRandomVideoOnServers(servers, 2, { waitTranscoding: true, fixture: 'video_short_240p.mp4' }) await waitJobs(servers) - await checkVideoIsPublished(baseParams, name, uuid, 'presence') + await checkVideoIsPublished({ ...baseParams, videoName: name, shortUUID, checkType: 'presence' }) }) it('Should send a notification with a transcoded video', async function () { this.timeout(50000) - const { name, uuid } = await uploadRandomVideoOnServers(servers, 2, { waitTranscoding: true }) + const { name, shortUUID } = await uploadRandomVideoOnServers(servers, 2, { waitTranscoding: true }) await waitJobs(servers) - await checkVideoIsPublished(baseParams, name, uuid, 'presence') + await checkVideoIsPublished({ ...baseParams, videoName: name, shortUUID, checkType: 'presence' }) }) it('Should send a notification when an imported video is transcoded', async function () { @@ -281,7 +281,7 @@ describe('Test user notifications', function () { const { video } = await servers[1].imports.importVideo({ attributes }) await waitJobs(servers) - await checkVideoIsPublished(baseParams, name, video.uuid, 'presence') + await checkVideoIsPublished({ ...baseParams, videoName: name, shortUUID: video.shortUUID, checkType: 'presence' }) }) it('Should send a notification when the scheduled update has been proceeded', async function () { @@ -297,10 +297,10 @@ describe('Test user notifications', function () { privacy: VideoPrivacy.PUBLIC as VideoPrivacy.PUBLIC } } - const { name, uuid } = await uploadRandomVideoOnServers(servers, 2, data) + const { name, shortUUID } = await uploadRandomVideoOnServers(servers, 2, data) await wait(6000) - await checkVideoIsPublished(baseParams, name, uuid, 'presence') + await checkVideoIsPublished({ ...baseParams, videoName: name, shortUUID, checkType: 'presence' }) }) it('Should not send a notification before the video is published', async function () { @@ -315,10 +315,10 @@ describe('Test user notifications', function () { privacy: VideoPrivacy.PUBLIC as VideoPrivacy.PUBLIC } } - const { name, uuid } = await uploadRandomVideoOnServers(servers, 2, data) + const { name, shortUUID } = await uploadRandomVideoOnServers(servers, 2, data) await wait(6000) - await checkVideoIsPublished(baseParams, name, uuid, 'absence') + await checkVideoIsPublished({ ...baseParams, videoName: name, shortUUID, checkType: 'absence' }) }) }) @@ -345,10 +345,12 @@ describe('Test user notifications', function () { privacy: VideoPrivacy.PRIVATE, targetUrl: FIXTURE_URLS.badVideo } - const { video } = await servers[0].imports.importVideo({ attributes }) + const { video: { shortUUID } } = await servers[0].imports.importVideo({ attributes }) await waitJobs(servers) - await checkMyVideoImportIsFinished(baseParams, name, video.uuid, FIXTURE_URLS.badVideo, false, 'presence') + + const url = FIXTURE_URLS.badVideo + await checkMyVideoImportIsFinished({ ...baseParams, videoName: name, shortUUID, url, success: false, checkType: 'presence' }) }) it('Should send a notification when the video import succeeded', async function () { @@ -362,10 +364,12 @@ describe('Test user notifications', function () { privacy: VideoPrivacy.PRIVATE, targetUrl: FIXTURE_URLS.goodVideo } - const { video } = await servers[0].imports.importVideo({ attributes }) + const { video: { shortUUID } } = await servers[0].imports.importVideo({ attributes }) await waitJobs(servers) - await checkMyVideoImportIsFinished(baseParams, name, video.uuid, FIXTURE_URLS.goodVideo, true, 'presence') + + const url = FIXTURE_URLS.goodVideo + await checkMyVideoImportIsFinished({ ...baseParams, videoName: name, shortUUID, url, success: true, checkType: 'presence' }) }) }) @@ -404,7 +408,14 @@ describe('Test user notifications', function () { await servers[0].subscriptions.add({ targetUri: 'user_1_channel@localhost:' + servers[0].port }) await waitJobs(servers) - await checkNewActorFollow(baseParams, 'channel', 'root', 'super root name', myChannelName, 'presence') + await checkNewActorFollow({ + ...baseParams, + followType: 'channel', + followerName: 'root', + followerDisplayName: 'super root name', + followingDisplayName: myChannelName, + checkType: 'presence' + }) await servers[0].subscriptions.remove({ uri: 'user_1_channel@localhost:' + servers[0].port }) }) @@ -415,7 +426,14 @@ describe('Test user notifications', function () { await servers[1].subscriptions.add({ targetUri: 'user_1_channel@localhost:' + servers[0].port }) await waitJobs(servers) - await checkNewActorFollow(baseParams, 'channel', 'root', 'super root 2 name', myChannelName, 'presence') + await checkNewActorFollow({ + ...baseParams, + followType: 'channel', + followerName: 'root', + followerDisplayName: 'super root 2 name', + followingDisplayName: myChannelName, + checkType: 'presence' + }) await servers[1].subscriptions.remove({ uri: 'user_1_channel@localhost:' + servers[0].port }) }) diff --git a/server/tests/api/search/search-videos.ts b/server/tests/api/search/search-videos.ts index 965766742..a56dc1d87 100644 --- a/server/tests/api/search/search-videos.ts +++ b/server/tests/api/search/search-videos.ts @@ -5,6 +5,7 @@ import * as chai from 'chai' import { cleanupTests, createSingleServer, + doubleFollow, PeerTubeServer, SearchCommand, setAccessTokensToServers, @@ -17,19 +18,21 @@ import { VideoPrivacy } from '@shared/models' const expect = chai.expect describe('Test videos search', function () { - let server: PeerTubeServer = null + let server: PeerTubeServer + let remoteServer: PeerTubeServer let startDate: string let videoUUID: string let command: SearchCommand before(async function () { - this.timeout(60000) + this.timeout(120000) server = await createSingleServer(1) + remoteServer = await createSingleServer(2) - await setAccessTokensToServers([ server ]) - await setDefaultVideoChannel([ server ]) + await setAccessTokensToServers([ server, remoteServer ]) + await setDefaultVideoChannel([ server, remoteServer ]) { const attributes1 = { @@ -131,6 +134,13 @@ describe('Test videos search', function () { await server.videos.upload({ attributes: { ...attributes1, category: 2 } }) } + { + await remoteServer.videos.upload({ attributes: { name: 'remote video 1' } }) + await remoteServer.videos.upload({ attributes: { name: 'remote video 2' } }) + } + + await doubleFollow(server, remoteServer) + command = server.search }) @@ -469,8 +479,30 @@ describe('Test videos search', function () { expect(body.data[0].name).to.equal('1111 2222 3333 - 3') }) + it('Should search by host', async function () { + { + const body = await command.advancedVideoSearch({ search: { search: '6666 7777 8888', host: server.host } }) + expect(body.total).to.equal(1) + expect(body.data[0].name).to.equal('6666 7777 8888') + } + + { + const body = await command.advancedVideoSearch({ search: { search: '1111', host: 'example.com' } }) + expect(body.total).to.equal(0) + expect(body.data).to.have.lengthOf(0) + } + + { + const body = await command.advancedVideoSearch({ search: { search: 'remote', host: remoteServer.host } }) + expect(body.total).to.equal(2) + expect(body.data).to.have.lengthOf(2) + expect(body.data[0].name).to.equal('remote video 1') + expect(body.data[1].name).to.equal('remote video 2') + } + }) + it('Should search by live', async function () { - this.timeout(30000) + this.timeout(60000) { const newConfig = { diff --git a/server/tests/api/server/email.ts b/server/tests/api/server/email.ts index ae86b380f..5f97edbc2 100644 --- a/server/tests/api/server/email.ts +++ b/server/tests/api/server/email.ts @@ -13,7 +13,7 @@ describe('Test emails', function () { let userId2: number let userAccessToken: string - let videoUUID: string + let videoShortUUID: string let videoId: number let videoUserUUID: string @@ -59,8 +59,8 @@ describe('Test emails', function () { const attributes = { name: 'my super name' } - const { uuid, id } = await server.videos.upload({ attributes }) - videoUUID = uuid + const { shortUUID, id } = await server.videos.upload({ attributes }) + videoShortUUID = shortUUID videoId = id } }) @@ -180,6 +180,7 @@ describe('Test emails', function () { }) describe('When creating an abuse', function () { + it('Should send the notification email', async function () { this.timeout(10000) @@ -195,7 +196,7 @@ describe('Test emails', function () { expect(email['from'][0]['address']).equal('test-admin@localhost') expect(email['to'][0]['address']).equal('admin' + server.internalServerNumber + '@example.com') expect(email['subject']).contains('abuse') - expect(email['text']).contains(videoUUID) + expect(email['text']).contains(videoShortUUID) }) }) -- cgit v1.2.3