comment?: {
threadId: number
- video: {
- id: number
- uuid: string
- name: string
- }
+ video: VideoInfo
}
account?: ActorInfo
import { Subject } from 'rxjs'
import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core'
import { ComponentPagination, hasMoreItems, Notifier } from '@app/core'
-import { UserNotificationType, AbuseState } from '@shared/models'
+import { AbuseState } from '@shared/models'
import { UserNotification } from './user-notification.model'
import { UserNotificationService } from './user-notification.service'
videoCaptions,
inactivityTimeout: 2500,
videoViewUrl: this.getVideoUrl(videoInfo.uuid) + '/views',
+ videoShortUUID: videoInfo.shortUUID,
videoUUID: videoInfo.uuid,
isLive: videoInfo.isLive,
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'
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'),
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'
return {
id: video.id,
uuid: video.uuid,
+ shortUUID: uuidToShort(video.uuid),
name: video.name
}
}
? {
id: abuse.VideoCommentAbuse.VideoComment.Video.id,
name: abuse.VideoCommentAbuse.VideoComment.Video.name,
+ shortUUID: uuidToShort(abuse.VideoCommentAbuse.VideoComment.Video.uuid),
uuid: abuse.VideoCommentAbuse.VideoComment.Video.uuid
}
: undefined
import { Sequelize } from 'sequelize'
import validator from 'validator'
import { exists } from '@server/helpers/custom-validators/misc'
+import { WEBSERVER } from '@server/initializers/constants'
import { buildDirectionAndField, createSafeIn } from '@server/models/utils'
import { MUserAccountId, MUserId } from '@server/types/models'
import { VideoFilter, VideoPrivacy, VideoState } from '@shared/models'
nsfw?: boolean
filter?: VideoFilter
+ host?: string
isLive?: boolean
categoryOneOf?: number[]
this.whereOnlyLocal()
}
+ if (options.host) {
+ this.whereHost(options.host)
+ }
+
if (options.accountId) {
this.whereAccountId(options.accountId)
}
this.and.push('"video"."remote" IS FALSE')
}
+ private whereHost (host: string) {
+ // Local instance
+ if (host === WEBSERVER.HOST) {
+ this.and.push('"accountActor"."serverId" IS NULL')
+ return
+ }
+
+ this.joins.push('INNER JOIN "server" ON "server"."id" = "accountActor"."serverId"')
+
+ this.and.push('"server"."host" = :host')
+ this.replacements.host = host
+ }
+
private whereAccountId (accountId: number) {
this.and.push('"account"."id" = :accountId')
this.replacements.accountId = accountId
import { setAsUpdated } from '@server/helpers/database-utils'
import { buildUUID, uuidToShort } from '@server/helpers/uuid'
import { MAccountId, MChannelId } from '@server/types/models'
-import { AttributesOnly, buildPlaylistEmbedPath, buildPlaylistLink, buildPlaylistWatchPath } from '@shared/core-utils'
+import { AttributesOnly, buildPlaylistEmbedPath, buildPlaylistWatchPath } from '@shared/core-utils'
import { ActivityIconObject } from '../../../shared/models/activitypub/objects'
import { PlaylistObject } from '../../../shared/models/activitypub/objects/playlist-object'
import { VideoPlaylistPrivacy } from '../../../shared/models/videos/playlist/video-playlist-privacy.model'
} from 'sequelize-typescript'
import { setAsUpdated } from '@server/helpers/database-utils'
import { buildNSFWFilter } from '@server/helpers/express-utils'
-import { shortToUUID } from '@server/helpers/uuid'
+import { uuidToShort } from '@server/helpers/uuid'
import { getPrivaciesForFederation, isPrivacyForFederation, isStateForFederation } from '@server/helpers/video'
import { LiveManager } from '@server/lib/live/live-manager'
import { getHLSDirectory, getVideoFilePath } from '@server/lib/video-paths'
static async searchAndPopulateAccountAndServer (options: {
includeLocalVideos: boolean
search?: string
+ host?: string
start?: number
count?: number
sort?: string
user: options.user,
filter: options.filter,
+ host: options.host,
start: options.start,
count: options.count,
}
getWatchStaticPath () {
- return buildVideoWatchPath({ shortUUID: shortToUUID(this.uuid) })
+ return buildVideoWatchPath({ shortUUID: uuidToShort(this.uuid) })
}
getEmbedStaticPath () {
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 () {
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 () {
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)
})
})
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 () {
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 () {
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 () {
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' })
})
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)
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)
{
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 () {
describe('Mention notifications', function () {
let baseParams: CheckerBaseParams
+ const byAccountDisplayName = 'super root name'
before(async () => {
baseParams = {
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 () {
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' })
})
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)
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 () {
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 () {
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 () {
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 () {
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 () {
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 () {
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' })
})
})
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 () {
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' })
})
})
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 () {
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 () {
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 () {
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' })
})
})
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 })
await waitJobs(servers)
await wait(500)
- await checkNewBlacklistOnMyVideo(baseParams, uuid, name, 'unblacklist')
+ await checkNewBlacklistOnMyVideo({ ...baseParams, shortUUID, videoName: name, blacklistType: 'unblacklist' })
})
})
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' })
})
})
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 () {
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 })
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 })
let userBaseParams: CheckerBaseParams
let adminBaseParamsServer1: CheckerBaseParams
let adminBaseParamsServer2: CheckerBaseParams
- let videoUUID: string
+ let uuid: string
+ let shortUUID: string
let videoName: string
let currentCustomConfig: CustomConfig
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)
})
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 () {
}
}
- 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 () {
}
}
- 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 () {
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 () => {
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 () {
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' })
}
})
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' })
}
})
)
}
- 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' })
})
})
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 () {
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 () {
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 () {
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 () {
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 () {
await waitJobs(servers)
- await checkNewVideoFromSubscription(baseParams, name, video.uuid, 'presence')
+ await checkNewVideoFromSubscription({ ...baseParams, videoName: name, shortUUID: video.shortUUID, checkType: 'presence' })
})
})
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 () {
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 () {
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 () {
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 () {
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' })
})
})
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 () {
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' })
})
})
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 })
})
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 })
})
import {
cleanupTests,
createSingleServer,
+ doubleFollow,
PeerTubeServer,
SearchCommand,
setAccessTokensToServers,
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 = {
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
})
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 = {
let userId2: number
let userAccessToken: string
- let videoUUID: string
+ let videoShortUUID: string
let videoId: number
let videoUserUUID: string
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
}
})
})
describe('When creating an abuse', function () {
+
it('Should send the notification email', async function () {
this.timeout(10000)
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)
})
})
import { createMultipleServers } from '../server/servers'
import { setAccessTokensToServers } from './login'
+type CheckerBaseParams = {
+ server: PeerTubeServer
+ emails: any[]
+ socketNotifications: UserNotification[]
+ token: string
+ check?: { web: boolean, mail: boolean }
+}
+
+type CheckerType = 'presence' | 'absence'
+
function getAllNotificationsSettings (): UserNotificationSetting {
return {
newVideoFromSubscription: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
}
}
-type CheckerBaseParams = {
- server: PeerTubeServer
- emails: any[]
- socketNotifications: UserNotification[]
- token: string
- check?: { web: boolean, mail: boolean }
-}
-
-type CheckerType = 'presence' | 'absence'
-
-async function checkNotification (
- base: CheckerBaseParams,
- notificationChecker: (notification: UserNotification, type: CheckerType) => void,
- emailNotificationFinder: (email: object) => boolean,
+async function checkNewVideoFromSubscription (options: CheckerBaseParams & {
+ videoName: string
+ shortUUID: string
checkType: CheckerType
-) {
- const check = base.check || { web: true, mail: true }
-
- if (check.web) {
- const notification = await base.server.notifications.getLastest({ token: base.token })
-
- if (notification || checkType !== 'absence') {
- notificationChecker(notification, checkType)
- }
-
- const socketNotification = base.socketNotifications.find(n => {
- try {
- notificationChecker(n, 'presence')
- return true
- } catch {
- return false
- }
- })
-
- if (checkType === 'presence') {
- const obj = inspect(base.socketNotifications, { depth: 5 })
- expect(socketNotification, 'The socket notification is absent when it should be present. ' + obj).to.not.be.undefined
- } else {
- const obj = inspect(socketNotification, { depth: 5 })
- expect(socketNotification, 'The socket notification is present when it should not be present. ' + obj).to.be.undefined
- }
- }
-
- if (check.mail) {
- // Last email
- const email = base.emails
- .slice()
- .reverse()
- .find(e => emailNotificationFinder(e))
-
- if (checkType === 'presence') {
- const emails = base.emails.map(e => e.text)
- expect(email, 'The email is absent when is should be present. ' + inspect(emails)).to.not.be.undefined
- } else {
- expect(email, 'The email is present when is should not be present. ' + inspect(email)).to.be.undefined
- }
- }
-}
-
-function checkVideo (video: any, videoName?: string, videoUUID?: string) {
- if (videoName) {
- expect(video.name).to.be.a('string')
- expect(video.name).to.not.be.empty
- expect(video.name).to.equal(videoName)
- }
-
- if (videoUUID) {
- expect(video.uuid).to.be.a('string')
- expect(video.uuid).to.not.be.empty
- expect(video.uuid).to.equal(videoUUID)
- }
-
- expect(video.id).to.be.a('number')
-}
-
-function checkActor (actor: any) {
- expect(actor.displayName).to.be.a('string')
- expect(actor.displayName).to.not.be.empty
- expect(actor.host).to.not.be.undefined
-}
-
-function checkComment (comment: any, commentId: number, threadId: number) {
- expect(comment.id).to.equal(commentId)
- expect(comment.threadId).to.equal(threadId)
-}
-
-async function checkNewVideoFromSubscription (base: CheckerBaseParams, videoName: string, videoUUID: string, type: CheckerType) {
+}) {
+ const { videoName, shortUUID } = options
const notificationType = UserNotificationType.NEW_VIDEO_FROM_SUBSCRIPTION
- function notificationChecker (notification: UserNotification, type: CheckerType) {
- if (type === 'presence') {
+ function notificationChecker (notification: UserNotification, checkType: CheckerType) {
+ if (checkType === 'presence') {
expect(notification).to.not.be.undefined
expect(notification.type).to.equal(notificationType)
- checkVideo(notification.video, videoName, videoUUID)
+ checkVideo(notification.video, videoName, shortUUID)
checkActor(notification.video.channel)
} else {
expect(notification).to.satisfy((n: UserNotification) => {
function emailNotificationFinder (email: object) {
const text = email['text']
- return text.indexOf(videoUUID) !== -1 && text.indexOf('Your subscription') !== -1
+ return text.indexOf(shortUUID) !== -1 && text.indexOf('Your subscription') !== -1
}
- await checkNotification(base, notificationChecker, emailNotificationFinder, type)
+ await checkNotification({ ...options, notificationChecker, emailNotificationFinder })
}
-async function checkVideoIsPublished (base: CheckerBaseParams, videoName: string, videoUUID: string, type: CheckerType) {
+async function checkVideoIsPublished (options: CheckerBaseParams & {
+ videoName: string
+ shortUUID: string
+ checkType: CheckerType
+}) {
+ const { videoName, shortUUID } = options
const notificationType = UserNotificationType.MY_VIDEO_PUBLISHED
- function notificationChecker (notification: UserNotification, type: CheckerType) {
- if (type === 'presence') {
+ function notificationChecker (notification: UserNotification, checkType: CheckerType) {
+ if (checkType === 'presence') {
expect(notification).to.not.be.undefined
expect(notification.type).to.equal(notificationType)
- checkVideo(notification.video, videoName, videoUUID)
+ checkVideo(notification.video, videoName, shortUUID)
checkActor(notification.video.channel)
} else {
expect(notification.video).to.satisfy(v => v === undefined || v.name !== videoName)
function emailNotificationFinder (email: object) {
const text: string = email['text']
- return text.includes(videoUUID) && text.includes('Your video')
+ return text.includes(shortUUID) && text.includes('Your video')
}
- await checkNotification(base, notificationChecker, emailNotificationFinder, type)
+ await checkNotification({ ...options, notificationChecker, emailNotificationFinder })
}
-async function checkMyVideoImportIsFinished (
- base: CheckerBaseParams,
- videoName: string,
- videoUUID: string,
- url: string,
- success: boolean,
- type: CheckerType
-) {
+async function checkMyVideoImportIsFinished (options: CheckerBaseParams & {
+ videoName: string
+ shortUUID: string
+ url: string
+ success: boolean
+ checkType: CheckerType
+}) {
+ const { videoName, shortUUID, url, success } = options
+
const notificationType = success ? UserNotificationType.MY_VIDEO_IMPORT_SUCCESS : UserNotificationType.MY_VIDEO_IMPORT_ERROR
- function notificationChecker (notification: UserNotification, type: CheckerType) {
- if (type === 'presence') {
+ function notificationChecker (notification: UserNotification, checkType: CheckerType) {
+ if (checkType === 'presence') {
expect(notification).to.not.be.undefined
expect(notification.type).to.equal(notificationType)
expect(notification.videoImport.targetUrl).to.equal(url)
- if (success) checkVideo(notification.videoImport.video, videoName, videoUUID)
+ if (success) checkVideo(notification.videoImport.video, videoName, shortUUID)
} else {
expect(notification.videoImport).to.satisfy(i => i === undefined || i.targetUrl !== url)
}
return text.includes(url) && text.includes(toFind)
}
- await checkNotification(base, notificationChecker, emailNotificationFinder, type)
+ await checkNotification({ ...options, notificationChecker, emailNotificationFinder })
}
-async function checkUserRegistered (base: CheckerBaseParams, username: string, type: CheckerType) {
+async function checkUserRegistered (options: CheckerBaseParams & {
+ username: string
+ checkType: CheckerType
+}) {
+ const { username } = options
const notificationType = UserNotificationType.NEW_USER_REGISTRATION
- function notificationChecker (notification: UserNotification, type: CheckerType) {
- if (type === 'presence') {
+ function notificationChecker (notification: UserNotification, checkType: CheckerType) {
+ if (checkType === 'presence') {
expect(notification).to.not.be.undefined
expect(notification.type).to.equal(notificationType)
return text.includes(' registered.') && text.includes(username)
}
- await checkNotification(base, notificationChecker, emailNotificationFinder, type)
+ await checkNotification({ ...options, notificationChecker, emailNotificationFinder })
}
-async function checkNewActorFollow (
- base: CheckerBaseParams,
- followType: 'channel' | 'account',
- followerName: string,
- followerDisplayName: string,
- followingDisplayName: string,
- type: CheckerType
-) {
+async function checkNewActorFollow (options: CheckerBaseParams & {
+ followType: 'channel' | 'account'
+ followerName: string
+ followerDisplayName: string
+ followingDisplayName: string
+ checkType: CheckerType
+}) {
+ const { followType, followerName, followerDisplayName, followingDisplayName } = options
const notificationType = UserNotificationType.NEW_FOLLOW
- function notificationChecker (notification: UserNotification, type: CheckerType) {
- if (type === 'presence') {
+ function notificationChecker (notification: UserNotification, checkType: CheckerType) {
+ if (checkType === 'presence') {
expect(notification).to.not.be.undefined
expect(notification.type).to.equal(notificationType)
return text.includes(followType) && text.includes(followingDisplayName) && text.includes(followerDisplayName)
}
- await checkNotification(base, notificationChecker, emailNotificationFinder, type)
+ await checkNotification({ ...options, notificationChecker, emailNotificationFinder })
}
-async function checkNewInstanceFollower (base: CheckerBaseParams, followerHost: string, type: CheckerType) {
+async function checkNewInstanceFollower (options: CheckerBaseParams & {
+ followerHost: string
+ checkType: CheckerType
+}) {
+ const { followerHost } = options
const notificationType = UserNotificationType.NEW_INSTANCE_FOLLOWER
- function notificationChecker (notification: UserNotification, type: CheckerType) {
- if (type === 'presence') {
+ function notificationChecker (notification: UserNotification, checkType: CheckerType) {
+ if (checkType === 'presence') {
expect(notification).to.not.be.undefined
expect(notification.type).to.equal(notificationType)
return text.includes('instance has a new follower') && text.includes(followerHost)
}
- await checkNotification(base, notificationChecker, emailNotificationFinder, type)
+ await checkNotification({ ...options, notificationChecker, emailNotificationFinder })
}
-async function checkAutoInstanceFollowing (base: CheckerBaseParams, followerHost: string, followingHost: string, type: CheckerType) {
+async function checkAutoInstanceFollowing (options: CheckerBaseParams & {
+ followerHost: string
+ followingHost: string
+ checkType: CheckerType
+}) {
+ const { followerHost, followingHost } = options
const notificationType = UserNotificationType.AUTO_INSTANCE_FOLLOWING
- function notificationChecker (notification: UserNotification, type: CheckerType) {
- if (type === 'presence') {
+ function notificationChecker (notification: UserNotification, checkType: CheckerType) {
+ if (checkType === 'presence') {
expect(notification).to.not.be.undefined
expect(notification.type).to.equal(notificationType)
return text.includes(' automatically followed a new instance') && text.includes(followingHost)
}
- await checkNotification(base, notificationChecker, emailNotificationFinder, type)
+ await checkNotification({ ...options, notificationChecker, emailNotificationFinder })
}
-async function checkCommentMention (
- base: CheckerBaseParams,
- uuid: string,
- commentId: number,
- threadId: number,
- byAccountDisplayName: string,
- type: CheckerType
-) {
+async function checkCommentMention (options: CheckerBaseParams & {
+ shortUUID: string
+ commentId: number
+ threadId: number
+ byAccountDisplayName: string
+ checkType: CheckerType
+}) {
+ const { shortUUID, commentId, threadId, byAccountDisplayName } = options
const notificationType = UserNotificationType.COMMENT_MENTION
- function notificationChecker (notification: UserNotification, type: CheckerType) {
- if (type === 'presence') {
+ function notificationChecker (notification: UserNotification, checkType: CheckerType) {
+ if (checkType === 'presence') {
expect(notification).to.not.be.undefined
expect(notification.type).to.equal(notificationType)
checkActor(notification.comment.account)
expect(notification.comment.account.displayName).to.equal(byAccountDisplayName)
- checkVideo(notification.comment.video, undefined, uuid)
+ checkVideo(notification.comment.video, undefined, shortUUID)
} else {
expect(notification).to.satisfy(n => n.type !== notificationType || n.comment.id !== commentId)
}
function emailNotificationFinder (email: object) {
const text: string = email['text']
- return text.includes(' mentioned ') && text.includes(uuid) && text.includes(byAccountDisplayName)
+ return text.includes(' mentioned ') && text.includes(shortUUID) && text.includes(byAccountDisplayName)
}
- await checkNotification(base, notificationChecker, emailNotificationFinder, type)
+ await checkNotification({ ...options, notificationChecker, emailNotificationFinder })
}
let lastEmailCount = 0
-async function checkNewCommentOnMyVideo (base: CheckerBaseParams, uuid: string, commentId: number, threadId: number, type: CheckerType) {
+async function checkNewCommentOnMyVideo (options: CheckerBaseParams & {
+ shortUUID: string
+ commentId: number
+ threadId: number
+ checkType: CheckerType
+}) {
+ const { server, shortUUID, commentId, threadId, checkType, emails } = options
const notificationType = UserNotificationType.NEW_COMMENT_ON_MY_VIDEO
- function notificationChecker (notification: UserNotification, type: CheckerType) {
- if (type === 'presence') {
+ function notificationChecker (notification: UserNotification, checkType: CheckerType) {
+ if (checkType === 'presence') {
expect(notification).to.not.be.undefined
expect(notification.type).to.equal(notificationType)
checkComment(notification.comment, commentId, threadId)
checkActor(notification.comment.account)
- checkVideo(notification.comment.video, undefined, uuid)
+ checkVideo(notification.comment.video, undefined, shortUUID)
} else {
expect(notification).to.satisfy((n: UserNotification) => {
return n === undefined || n.comment === undefined || n.comment.id !== commentId
}
}
- const commentUrl = `http://localhost:${base.server.port}/w/${uuid};threadId=${threadId}`
+ const commentUrl = `http://localhost:${server.port}/w/${shortUUID};threadId=${threadId}`
function emailNotificationFinder (email: object) {
return email['text'].indexOf(commentUrl) !== -1
}
- await checkNotification(base, notificationChecker, emailNotificationFinder, type)
+ await checkNotification({ ...options, notificationChecker, emailNotificationFinder })
- if (type === 'presence') {
+ if (checkType === 'presence') {
// We cannot detect email duplicates, so check we received another email
- expect(base.emails).to.have.length.above(lastEmailCount)
- lastEmailCount = base.emails.length
+ expect(emails).to.have.length.above(lastEmailCount)
+ lastEmailCount = emails.length
}
}
-async function checkNewVideoAbuseForModerators (base: CheckerBaseParams, videoUUID: string, videoName: string, type: CheckerType) {
+async function checkNewVideoAbuseForModerators (options: CheckerBaseParams & {
+ shortUUID: string
+ videoName: string
+ checkType: CheckerType
+}) {
+ const { shortUUID, videoName } = options
const notificationType = UserNotificationType.NEW_ABUSE_FOR_MODERATORS
- function notificationChecker (notification: UserNotification, type: CheckerType) {
- if (type === 'presence') {
+ function notificationChecker (notification: UserNotification, checkType: CheckerType) {
+ if (checkType === 'presence') {
expect(notification).to.not.be.undefined
expect(notification.type).to.equal(notificationType)
expect(notification.abuse.id).to.be.a('number')
- checkVideo(notification.abuse.video, videoName, videoUUID)
+ checkVideo(notification.abuse.video, videoName, shortUUID)
} else {
expect(notification).to.satisfy((n: UserNotification) => {
- return n === undefined || n.abuse === undefined || n.abuse.video.uuid !== videoUUID
+ return n === undefined || n.abuse === undefined || n.abuse.video.shortUUID !== shortUUID
})
}
}
function emailNotificationFinder (email: object) {
const text = email['text']
- return text.indexOf(videoUUID) !== -1 && text.indexOf('abuse') !== -1
+ return text.indexOf(shortUUID) !== -1 && text.indexOf('abuse') !== -1
}
- await checkNotification(base, notificationChecker, emailNotificationFinder, type)
+ await checkNotification({ ...options, notificationChecker, emailNotificationFinder })
}
-async function checkNewAbuseMessage (base: CheckerBaseParams, abuseId: number, message: string, toEmail: string, type: CheckerType) {
+async function checkNewAbuseMessage (options: CheckerBaseParams & {
+ abuseId: number
+ message: string
+ toEmail: string
+ checkType: CheckerType
+}) {
+ const { abuseId, message, toEmail } = options
const notificationType = UserNotificationType.ABUSE_NEW_MESSAGE
- function notificationChecker (notification: UserNotification, type: CheckerType) {
- if (type === 'presence') {
+ function notificationChecker (notification: UserNotification, checkType: CheckerType) {
+ if (checkType === 'presence') {
expect(notification).to.not.be.undefined
expect(notification.type).to.equal(notificationType)
return text.indexOf(message) !== -1 && to.length !== 0
}
- await checkNotification(base, notificationChecker, emailNotificationFinder, type)
+ await checkNotification({ ...options, notificationChecker, emailNotificationFinder })
}
-async function checkAbuseStateChange (base: CheckerBaseParams, abuseId: number, state: AbuseState, type: CheckerType) {
+async function checkAbuseStateChange (options: CheckerBaseParams & {
+ abuseId: number
+ state: AbuseState
+ checkType: CheckerType
+}) {
+ const { abuseId, state } = options
const notificationType = UserNotificationType.ABUSE_STATE_CHANGE
- function notificationChecker (notification: UserNotification, type: CheckerType) {
- if (type === 'presence') {
+ function notificationChecker (notification: UserNotification, checkType: CheckerType) {
+ if (checkType === 'presence') {
expect(notification).to.not.be.undefined
expect(notification.type).to.equal(notificationType)
return text.indexOf(contains) !== -1
}
- await checkNotification(base, notificationChecker, emailNotificationFinder, type)
+ await checkNotification({ ...options, notificationChecker, emailNotificationFinder })
}
-async function checkNewCommentAbuseForModerators (base: CheckerBaseParams, videoUUID: string, videoName: string, type: CheckerType) {
+async function checkNewCommentAbuseForModerators (options: CheckerBaseParams & {
+ shortUUID: string
+ videoName: string
+ checkType: CheckerType
+}) {
+ const { shortUUID, videoName } = options
const notificationType = UserNotificationType.NEW_ABUSE_FOR_MODERATORS
- function notificationChecker (notification: UserNotification, type: CheckerType) {
- if (type === 'presence') {
+ function notificationChecker (notification: UserNotification, checkType: CheckerType) {
+ if (checkType === 'presence') {
expect(notification).to.not.be.undefined
expect(notification.type).to.equal(notificationType)
expect(notification.abuse.id).to.be.a('number')
- checkVideo(notification.abuse.comment.video, videoName, videoUUID)
+ checkVideo(notification.abuse.comment.video, videoName, shortUUID)
} else {
expect(notification).to.satisfy((n: UserNotification) => {
- return n === undefined || n.abuse === undefined || n.abuse.comment.video.uuid !== videoUUID
+ return n === undefined || n.abuse === undefined || n.abuse.comment.video.shortUUID !== shortUUID
})
}
}
function emailNotificationFinder (email: object) {
const text = email['text']
- return text.indexOf(videoUUID) !== -1 && text.indexOf('abuse') !== -1
+ return text.indexOf(shortUUID) !== -1 && text.indexOf('abuse') !== -1
}
- await checkNotification(base, notificationChecker, emailNotificationFinder, type)
+ await checkNotification({ ...options, notificationChecker, emailNotificationFinder })
}
-async function checkNewAccountAbuseForModerators (base: CheckerBaseParams, displayName: string, type: CheckerType) {
+async function checkNewAccountAbuseForModerators (options: CheckerBaseParams & {
+ displayName: string
+ checkType: CheckerType
+}) {
+ const { displayName } = options
const notificationType = UserNotificationType.NEW_ABUSE_FOR_MODERATORS
- function notificationChecker (notification: UserNotification, type: CheckerType) {
- if (type === 'presence') {
+ function notificationChecker (notification: UserNotification, checkType: CheckerType) {
+ if (checkType === 'presence') {
expect(notification).to.not.be.undefined
expect(notification.type).to.equal(notificationType)
return text.indexOf(displayName) !== -1 && text.indexOf('abuse') !== -1
}
- await checkNotification(base, notificationChecker, emailNotificationFinder, type)
+ await checkNotification({ ...options, notificationChecker, emailNotificationFinder })
}
-async function checkVideoAutoBlacklistForModerators (base: CheckerBaseParams, videoUUID: string, videoName: string, type: CheckerType) {
+async function checkVideoAutoBlacklistForModerators (options: CheckerBaseParams & {
+ shortUUID: string
+ videoName: string
+ checkType: CheckerType
+}) {
+ const { shortUUID, videoName } = options
const notificationType = UserNotificationType.VIDEO_AUTO_BLACKLIST_FOR_MODERATORS
- function notificationChecker (notification: UserNotification, type: CheckerType) {
- if (type === 'presence') {
+ function notificationChecker (notification: UserNotification, checkType: CheckerType) {
+ if (checkType === 'presence') {
expect(notification).to.not.be.undefined
expect(notification.type).to.equal(notificationType)
expect(notification.videoBlacklist.video.id).to.be.a('number')
- checkVideo(notification.videoBlacklist.video, videoName, videoUUID)
+ checkVideo(notification.videoBlacklist.video, videoName, shortUUID)
} else {
expect(notification).to.satisfy((n: UserNotification) => {
- return n === undefined || n.video === undefined || n.video.uuid !== videoUUID
+ return n === undefined || n.video === undefined || n.video.shortUUID !== shortUUID
})
}
}
function emailNotificationFinder (email: object) {
const text = email['text']
- return text.indexOf(videoUUID) !== -1 && email['text'].indexOf('video-auto-blacklist/list') !== -1
+ return text.indexOf(shortUUID) !== -1 && email['text'].indexOf('video-auto-blacklist/list') !== -1
}
- await checkNotification(base, notificationChecker, emailNotificationFinder, type)
+ await checkNotification({ ...options, notificationChecker, emailNotificationFinder })
}
-async function checkNewBlacklistOnMyVideo (
- base: CheckerBaseParams,
- videoUUID: string,
- videoName: string,
+async function checkNewBlacklistOnMyVideo (options: CheckerBaseParams & {
+ shortUUID: string
+ videoName: string
blacklistType: 'blacklist' | 'unblacklist'
-) {
+}) {
+ const { videoName, shortUUID, blacklistType } = options
const notificationType = blacklistType === 'blacklist'
? UserNotificationType.BLACKLIST_ON_MY_VIDEO
: UserNotificationType.UNBLACKLIST_ON_MY_VIDEO
const video = blacklistType === 'blacklist' ? notification.videoBlacklist.video : notification.video
- checkVideo(video, videoName, videoUUID)
+ checkVideo(video, videoName, shortUUID)
}
function emailNotificationFinder (email: object) {
const text = email['text']
- return text.indexOf(videoUUID) !== -1 && text.indexOf(' ' + blacklistType) !== -1
+ const blacklistText = blacklistType === 'blacklist'
+ ? 'blacklisted'
+ : 'unblacklisted'
+
+ return text.includes(shortUUID) && text.includes(blacklistText)
}
- await checkNotification(base, notificationChecker, emailNotificationFinder, 'presence')
+ await checkNotification({ ...options, notificationChecker, emailNotificationFinder, checkType: 'presence' })
}
-async function checkNewPeerTubeVersion (base: CheckerBaseParams, latestVersion: string, type: CheckerType) {
+async function checkNewPeerTubeVersion (options: CheckerBaseParams & {
+ latestVersion: string
+ checkType: CheckerType
+}) {
+ const { latestVersion } = options
const notificationType = UserNotificationType.NEW_PEERTUBE_VERSION
- function notificationChecker (notification: UserNotification, type: CheckerType) {
- if (type === 'presence') {
+ function notificationChecker (notification: UserNotification, checkType: CheckerType) {
+ if (checkType === 'presence') {
expect(notification).to.not.be.undefined
expect(notification.type).to.equal(notificationType)
return text.includes(latestVersion)
}
- await checkNotification(base, notificationChecker, emailNotificationFinder, type)
+ await checkNotification({ ...options, notificationChecker, emailNotificationFinder })
}
-async function checkNewPluginVersion (base: CheckerBaseParams, pluginType: PluginType, pluginName: string, type: CheckerType) {
+async function checkNewPluginVersion (options: CheckerBaseParams & {
+ pluginType: PluginType
+ pluginName: string
+ checkType: CheckerType
+}) {
+ const { pluginName, pluginType } = options
const notificationType = UserNotificationType.NEW_PLUGIN_VERSION
- function notificationChecker (notification: UserNotification, type: CheckerType) {
- if (type === 'presence') {
+ function notificationChecker (notification: UserNotification, checkType: CheckerType) {
+ if (checkType === 'presence') {
expect(notification).to.not.be.undefined
expect(notification.type).to.equal(notificationType)
return text.includes(pluginName)
}
- await checkNotification(base, notificationChecker, emailNotificationFinder, type)
+ await checkNotification({ ...options, notificationChecker, emailNotificationFinder })
}
async function prepareNotificationsTest (serversCount = 3, overrideConfigArg: any = {}) {
CheckerBaseParams,
CheckerType,
- checkNotification,
checkMyVideoImportIsFinished,
checkUserRegistered,
checkAutoInstanceFollowing,
checkNewPeerTubeVersion,
checkNewPluginVersion
}
+
+// ---------------------------------------------------------------------------
+
+async function checkNotification (options: CheckerBaseParams & {
+ notificationChecker: (notification: UserNotification, checkType: CheckerType) => void
+ emailNotificationFinder: (email: object) => boolean
+ checkType: CheckerType
+}) {
+ const { server, token, checkType, notificationChecker, emailNotificationFinder, socketNotifications, emails } = options
+
+ const check = options.check || { web: true, mail: true }
+
+ if (check.web) {
+ const notification = await server.notifications.getLastest({ token: token })
+
+ if (notification || checkType !== 'absence') {
+ notificationChecker(notification, checkType)
+ }
+
+ const socketNotification = socketNotifications.find(n => {
+ try {
+ notificationChecker(n, 'presence')
+ return true
+ } catch {
+ return false
+ }
+ })
+
+ if (checkType === 'presence') {
+ const obj = inspect(socketNotifications, { depth: 5 })
+ expect(socketNotification, 'The socket notification is absent when it should be present. ' + obj).to.not.be.undefined
+ } else {
+ const obj = inspect(socketNotification, { depth: 5 })
+ expect(socketNotification, 'The socket notification is present when it should not be present. ' + obj).to.be.undefined
+ }
+ }
+
+ if (check.mail) {
+ // Last email
+ const email = emails
+ .slice()
+ .reverse()
+ .find(e => emailNotificationFinder(e))
+
+ if (checkType === 'presence') {
+ const texts = emails.map(e => e.text)
+ expect(email, 'The email is absent when is should be present. ' + inspect(texts)).to.not.be.undefined
+ } else {
+ expect(email, 'The email is present when is should not be present. ' + inspect(email)).to.be.undefined
+ }
+ }
+}
+
+function checkVideo (video: any, videoName?: string, shortUUID?: string) {
+ if (videoName) {
+ expect(video.name).to.be.a('string')
+ expect(video.name).to.not.be.empty
+ expect(video.name).to.equal(videoName)
+ }
+
+ if (shortUUID) {
+ expect(video.shortUUID).to.be.a('string')
+ expect(video.shortUUID).to.not.be.empty
+ expect(video.shortUUID).to.equal(shortUUID)
+ }
+
+ expect(video.id).to.be.a('number')
+}
+
+function checkActor (actor: any) {
+ expect(actor.displayName).to.be.a('string')
+ expect(actor.displayName).to.not.be.empty
+ expect(actor.host).to.not.be.undefined
+}
+
+function checkComment (comment: any, commentId: number, threadId: number) {
+ expect(comment.id).to.equal(commentId)
+ expect(comment.threadId).to.equal(threadId)
+}
export interface VideosSearchQuery extends SearchTargetQuery, VideosCommonQuery {
search?: string
+ host?: string
+
startDate?: string // ISO 8601
endDate?: string // ISO 8601
export interface VideoInfo {
id: number
uuid: string
+ shortUUID: string
name: string
}
comment?: {
threadId: number
- video: {
- id: number
- uuid: string
- name: string
- }
+ video: VideoInfo
}
account?: ActorInfo