diff options
18 files changed, 513 insertions, 354 deletions
diff --git a/client/src/app/shared/shared-main/users/user-notification.model.ts b/client/src/app/shared/shared-main/users/user-notification.model.ts index 4c15eb981..439547102 100644 --- a/client/src/app/shared/shared-main/users/user-notification.model.ts +++ b/client/src/app/shared/shared-main/users/user-notification.model.ts | |||
@@ -47,11 +47,7 @@ export class UserNotification implements UserNotificationServer { | |||
47 | comment?: { | 47 | comment?: { |
48 | threadId: number | 48 | threadId: number |
49 | 49 | ||
50 | video: { | 50 | video: VideoInfo |
51 | id: number | ||
52 | uuid: string | ||
53 | name: string | ||
54 | } | ||
55 | } | 51 | } |
56 | 52 | ||
57 | account?: ActorInfo | 53 | account?: ActorInfo |
diff --git a/client/src/app/shared/shared-main/users/user-notifications.component.ts b/client/src/app/shared/shared-main/users/user-notifications.component.ts index d7c722355..96b141543 100644 --- a/client/src/app/shared/shared-main/users/user-notifications.component.ts +++ b/client/src/app/shared/shared-main/users/user-notifications.component.ts | |||
@@ -1,7 +1,7 @@ | |||
1 | import { Subject } from 'rxjs' | 1 | import { Subject } from 'rxjs' |
2 | import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core' | 2 | import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core' |
3 | import { ComponentPagination, hasMoreItems, Notifier } from '@app/core' | 3 | import { ComponentPagination, hasMoreItems, Notifier } from '@app/core' |
4 | import { UserNotificationType, AbuseState } from '@shared/models' | 4 | import { AbuseState } from '@shared/models' |
5 | import { UserNotification } from './user-notification.model' | 5 | import { UserNotification } from './user-notification.model' |
6 | import { UserNotificationService } from './user-notification.service' | 6 | import { UserNotificationService } from './user-notification.service' |
7 | 7 | ||
diff --git a/client/src/standalone/videos/embed.ts b/client/src/standalone/videos/embed.ts index 97437ce45..334f386b6 100644 --- a/client/src/standalone/videos/embed.ts +++ b/client/src/standalone/videos/embed.ts | |||
@@ -536,6 +536,7 @@ export class PeerTubeEmbed { | |||
536 | videoCaptions, | 536 | videoCaptions, |
537 | inactivityTimeout: 2500, | 537 | inactivityTimeout: 2500, |
538 | videoViewUrl: this.getVideoUrl(videoInfo.uuid) + '/views', | 538 | videoViewUrl: this.getVideoUrl(videoInfo.uuid) + '/views', |
539 | videoShortUUID: videoInfo.shortUUID, | ||
539 | videoUUID: videoInfo.uuid, | 540 | videoUUID: videoInfo.uuid, |
540 | 541 | ||
541 | isLive: videoInfo.isLive, | 542 | isLive: videoInfo.isLive, |
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 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { query } from 'express-validator' | 2 | import { query } from 'express-validator' |
3 | import { isSearchTargetValid } from '@server/helpers/custom-validators/search' | 3 | import { isSearchTargetValid } from '@server/helpers/custom-validators/search' |
4 | import { isHostValid } from '@server/helpers/custom-validators/servers' | ||
4 | import { isDateValid } from '../../helpers/custom-validators/misc' | 5 | import { isDateValid } from '../../helpers/custom-validators/misc' |
5 | import { logger } from '../../helpers/logger' | 6 | import { logger } from '../../helpers/logger' |
6 | import { areValidationErrors } from './shared' | 7 | import { areValidationErrors } from './shared' |
@@ -8,6 +9,10 @@ import { areValidationErrors } from './shared' | |||
8 | const videosSearchValidator = [ | 9 | const videosSearchValidator = [ |
9 | query('search').optional().not().isEmpty().withMessage('Should have a valid search'), | 10 | query('search').optional().not().isEmpty().withMessage('Should have a valid search'), |
10 | 11 | ||
12 | query('host') | ||
13 | .optional() | ||
14 | .custom(isHostValid).withMessage('Should have a valid host'), | ||
15 | |||
11 | query('startDate') | 16 | query('startDate') |
12 | .optional() | 17 | .optional() |
13 | .custom(isDateValid).withMessage('Should have a start date that conforms to ISO 8601'), | 18 | .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 @@ | |||
1 | import { FindOptions, ModelIndexesOptions, Op, WhereOptions } from 'sequelize' | 1 | import { FindOptions, ModelIndexesOptions, Op, WhereOptions } from 'sequelize' |
2 | import { AllowNull, BelongsTo, Column, CreatedAt, Default, ForeignKey, Is, Model, Scopes, Table, UpdatedAt } from 'sequelize-typescript' | 2 | import { AllowNull, BelongsTo, Column, CreatedAt, Default, ForeignKey, Is, Model, Scopes, Table, UpdatedAt } from 'sequelize-typescript' |
3 | import { uuidToShort } from '@server/helpers/uuid' | ||
3 | import { UserNotificationIncludes, UserNotificationModelForApi } from '@server/types/models/user' | 4 | import { UserNotificationIncludes, UserNotificationModelForApi } from '@server/types/models/user' |
4 | import { AttributesOnly } from '@shared/core-utils' | 5 | import { AttributesOnly } from '@shared/core-utils' |
5 | import { UserNotification, UserNotificationType } from '../../../shared' | 6 | import { UserNotification, UserNotificationType } from '../../../shared' |
@@ -615,6 +616,7 @@ export class UserNotificationModel extends Model<Partial<AttributesOnly<UserNoti | |||
615 | return { | 616 | return { |
616 | id: video.id, | 617 | id: video.id, |
617 | uuid: video.uuid, | 618 | uuid: video.uuid, |
619 | shortUUID: uuidToShort(video.uuid), | ||
618 | name: video.name | 620 | name: video.name |
619 | } | 621 | } |
620 | } | 622 | } |
@@ -628,6 +630,7 @@ export class UserNotificationModel extends Model<Partial<AttributesOnly<UserNoti | |||
628 | ? { | 630 | ? { |
629 | id: abuse.VideoCommentAbuse.VideoComment.Video.id, | 631 | id: abuse.VideoCommentAbuse.VideoComment.Video.id, |
630 | name: abuse.VideoCommentAbuse.VideoComment.Video.name, | 632 | name: abuse.VideoCommentAbuse.VideoComment.Video.name, |
633 | shortUUID: uuidToShort(abuse.VideoCommentAbuse.VideoComment.Video.uuid), | ||
631 | uuid: abuse.VideoCommentAbuse.VideoComment.Video.uuid | 634 | uuid: abuse.VideoCommentAbuse.VideoComment.Video.uuid |
632 | } | 635 | } |
633 | : undefined | 636 | : undefined |
diff --git a/server/models/video/sql/videos-id-list-query-builder.ts b/server/models/video/sql/videos-id-list-query-builder.ts index 054f71c8c..d4260c69c 100644 --- a/server/models/video/sql/videos-id-list-query-builder.ts +++ b/server/models/video/sql/videos-id-list-query-builder.ts | |||
@@ -1,6 +1,7 @@ | |||
1 | import { Sequelize } from 'sequelize' | 1 | import { Sequelize } from 'sequelize' |
2 | import validator from 'validator' | 2 | import validator from 'validator' |
3 | import { exists } from '@server/helpers/custom-validators/misc' | 3 | import { exists } from '@server/helpers/custom-validators/misc' |
4 | import { WEBSERVER } from '@server/initializers/constants' | ||
4 | import { buildDirectionAndField, createSafeIn } from '@server/models/utils' | 5 | import { buildDirectionAndField, createSafeIn } from '@server/models/utils' |
5 | import { MUserAccountId, MUserId } from '@server/types/models' | 6 | import { MUserAccountId, MUserId } from '@server/types/models' |
6 | import { VideoFilter, VideoPrivacy, VideoState } from '@shared/models' | 7 | import { VideoFilter, VideoPrivacy, VideoState } from '@shared/models' |
@@ -25,6 +26,7 @@ export type BuildVideosListQueryOptions = { | |||
25 | 26 | ||
26 | nsfw?: boolean | 27 | nsfw?: boolean |
27 | filter?: VideoFilter | 28 | filter?: VideoFilter |
29 | host?: string | ||
28 | isLive?: boolean | 30 | isLive?: boolean |
29 | 31 | ||
30 | categoryOneOf?: number[] | 32 | categoryOneOf?: number[] |
@@ -131,6 +133,10 @@ export class VideosIdListQueryBuilder extends AbstractVideosQueryBuilder { | |||
131 | this.whereOnlyLocal() | 133 | this.whereOnlyLocal() |
132 | } | 134 | } |
133 | 135 | ||
136 | if (options.host) { | ||
137 | this.whereHost(options.host) | ||
138 | } | ||
139 | |||
134 | if (options.accountId) { | 140 | if (options.accountId) { |
135 | this.whereAccountId(options.accountId) | 141 | this.whereAccountId(options.accountId) |
136 | } | 142 | } |
@@ -291,6 +297,19 @@ export class VideosIdListQueryBuilder extends AbstractVideosQueryBuilder { | |||
291 | this.and.push('"video"."remote" IS FALSE') | 297 | this.and.push('"video"."remote" IS FALSE') |
292 | } | 298 | } |
293 | 299 | ||
300 | private whereHost (host: string) { | ||
301 | // Local instance | ||
302 | if (host === WEBSERVER.HOST) { | ||
303 | this.and.push('"accountActor"."serverId" IS NULL') | ||
304 | return | ||
305 | } | ||
306 | |||
307 | this.joins.push('INNER JOIN "server" ON "server"."id" = "accountActor"."serverId"') | ||
308 | |||
309 | this.and.push('"server"."host" = :host') | ||
310 | this.replacements.host = host | ||
311 | } | ||
312 | |||
294 | private whereAccountId (accountId: number) { | 313 | private whereAccountId (accountId: number) { |
295 | this.and.push('"account"."id" = :accountId') | 314 | this.and.push('"account"."id" = :accountId') |
296 | this.replacements.accountId = accountId | 315 | this.replacements.accountId = accountId |
diff --git a/server/models/video/video-playlist.ts b/server/models/video/video-playlist.ts index 245475f94..72ba474b4 100644 --- a/server/models/video/video-playlist.ts +++ b/server/models/video/video-playlist.ts | |||
@@ -20,7 +20,7 @@ import { | |||
20 | import { setAsUpdated } from '@server/helpers/database-utils' | 20 | import { setAsUpdated } from '@server/helpers/database-utils' |
21 | import { buildUUID, uuidToShort } from '@server/helpers/uuid' | 21 | import { buildUUID, uuidToShort } from '@server/helpers/uuid' |
22 | import { MAccountId, MChannelId } from '@server/types/models' | 22 | import { MAccountId, MChannelId } from '@server/types/models' |
23 | import { AttributesOnly, buildPlaylistEmbedPath, buildPlaylistLink, buildPlaylistWatchPath } from '@shared/core-utils' | 23 | import { AttributesOnly, buildPlaylistEmbedPath, buildPlaylistWatchPath } from '@shared/core-utils' |
24 | import { ActivityIconObject } from '../../../shared/models/activitypub/objects' | 24 | import { ActivityIconObject } from '../../../shared/models/activitypub/objects' |
25 | import { PlaylistObject } from '../../../shared/models/activitypub/objects/playlist-object' | 25 | import { PlaylistObject } from '../../../shared/models/activitypub/objects/playlist-object' |
26 | import { VideoPlaylistPrivacy } from '../../../shared/models/videos/playlist/video-playlist-privacy.model' | 26 | import { VideoPlaylistPrivacy } from '../../../shared/models/videos/playlist/video-playlist-privacy.model' |
diff --git a/server/models/video/video.ts b/server/models/video/video.ts index 543e604bb..c006a91af 100644 --- a/server/models/video/video.ts +++ b/server/models/video/video.ts | |||
@@ -26,7 +26,7 @@ import { | |||
26 | } from 'sequelize-typescript' | 26 | } from 'sequelize-typescript' |
27 | import { setAsUpdated } from '@server/helpers/database-utils' | 27 | import { setAsUpdated } from '@server/helpers/database-utils' |
28 | import { buildNSFWFilter } from '@server/helpers/express-utils' | 28 | import { buildNSFWFilter } from '@server/helpers/express-utils' |
29 | import { shortToUUID } from '@server/helpers/uuid' | 29 | import { uuidToShort } from '@server/helpers/uuid' |
30 | import { getPrivaciesForFederation, isPrivacyForFederation, isStateForFederation } from '@server/helpers/video' | 30 | import { getPrivaciesForFederation, isPrivacyForFederation, isStateForFederation } from '@server/helpers/video' |
31 | import { LiveManager } from '@server/lib/live/live-manager' | 31 | import { LiveManager } from '@server/lib/live/live-manager' |
32 | import { getHLSDirectory, getVideoFilePath } from '@server/lib/video-paths' | 32 | import { getHLSDirectory, getVideoFilePath } from '@server/lib/video-paths' |
@@ -1113,6 +1113,7 @@ export class VideoModel extends Model<Partial<AttributesOnly<VideoModel>>> { | |||
1113 | static async searchAndPopulateAccountAndServer (options: { | 1113 | static async searchAndPopulateAccountAndServer (options: { |
1114 | includeLocalVideos: boolean | 1114 | includeLocalVideos: boolean |
1115 | search?: string | 1115 | search?: string |
1116 | host?: string | ||
1116 | start?: number | 1117 | start?: number |
1117 | count?: number | 1118 | count?: number |
1118 | sort?: string | 1119 | sort?: string |
@@ -1151,6 +1152,7 @@ export class VideoModel extends Model<Partial<AttributesOnly<VideoModel>>> { | |||
1151 | 1152 | ||
1152 | user: options.user, | 1153 | user: options.user, |
1153 | filter: options.filter, | 1154 | filter: options.filter, |
1155 | host: options.host, | ||
1154 | 1156 | ||
1155 | start: options.start, | 1157 | start: options.start, |
1156 | count: options.count, | 1158 | count: options.count, |
@@ -1579,7 +1581,7 @@ export class VideoModel extends Model<Partial<AttributesOnly<VideoModel>>> { | |||
1579 | } | 1581 | } |
1580 | 1582 | ||
1581 | getWatchStaticPath () { | 1583 | getWatchStaticPath () { |
1582 | return buildVideoWatchPath({ shortUUID: shortToUUID(this.uuid) }) | 1584 | return buildVideoWatchPath({ shortUUID: uuidToShort(this.uuid) }) |
1583 | } | 1585 | } |
1584 | 1586 | ||
1585 | getEmbedStaticPath () { | 1587 | 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 () { | |||
70 | joinPeerTubeServer.setLatestVersion('1.4.2') | 70 | joinPeerTubeServer.setLatestVersion('1.4.2') |
71 | 71 | ||
72 | await wait(3000) | 72 | await wait(3000) |
73 | await checkNewPeerTubeVersion(baseParams, '1.4.2', 'absence') | 73 | await checkNewPeerTubeVersion({ ...baseParams, latestVersion: '1.4.2', checkType: 'absence' }) |
74 | }) | 74 | }) |
75 | 75 | ||
76 | it('Should send a notification to admins on new plugin version', async function () { | 76 | it('Should send a notification to admins on new plugin version', async function () { |
@@ -79,7 +79,7 @@ describe('Test admin notifications', function () { | |||
79 | joinPeerTubeServer.setLatestVersion('15.4.2') | 79 | joinPeerTubeServer.setLatestVersion('15.4.2') |
80 | 80 | ||
81 | await wait(3000) | 81 | await wait(3000) |
82 | await checkNewPeerTubeVersion(baseParams, '15.4.2', 'presence') | 82 | await checkNewPeerTubeVersion({ ...baseParams, latestVersion: '15.4.2', checkType: 'presence' }) |
83 | }) | 83 | }) |
84 | 84 | ||
85 | it('Should not send the same notification to admins', async function () { | 85 | it('Should not send the same notification to admins', async function () { |
@@ -101,7 +101,7 @@ describe('Test admin notifications', function () { | |||
101 | joinPeerTubeServer.setLatestVersion('15.4.3') | 101 | joinPeerTubeServer.setLatestVersion('15.4.3') |
102 | 102 | ||
103 | await wait(3000) | 103 | await wait(3000) |
104 | await checkNewPeerTubeVersion(baseParams, '15.4.3', 'presence') | 104 | await checkNewPeerTubeVersion({ ...baseParams, latestVersion: '15.4.3', checkType: 'presence' }) |
105 | expect(adminNotifications.filter(n => n.type === UserNotificationType.NEW_PEERTUBE_VERSION)).to.have.lengthOf(2) | 105 | expect(adminNotifications.filter(n => n.type === UserNotificationType.NEW_PEERTUBE_VERSION)).to.have.lengthOf(2) |
106 | }) | 106 | }) |
107 | }) | 107 | }) |
@@ -112,7 +112,7 @@ describe('Test admin notifications', function () { | |||
112 | this.timeout(30000) | 112 | this.timeout(30000) |
113 | 113 | ||
114 | await wait(6000) | 114 | await wait(6000) |
115 | await checkNewPluginVersion(baseParams, PluginType.PLUGIN, 'hello-world', 'absence') | 115 | await checkNewPluginVersion({ ...baseParams, pluginType: PluginType.PLUGIN, pluginName: 'hello-world', checkType: 'absence' }) |
116 | }) | 116 | }) |
117 | 117 | ||
118 | it('Should send a notification to admins on new plugin version', async function () { | 118 | it('Should send a notification to admins on new plugin version', async function () { |
@@ -122,7 +122,7 @@ describe('Test admin notifications', function () { | |||
122 | await server.sql.setPluginLatestVersion('hello-world', '0.0.1') | 122 | await server.sql.setPluginLatestVersion('hello-world', '0.0.1') |
123 | await wait(6000) | 123 | await wait(6000) |
124 | 124 | ||
125 | await checkNewPluginVersion(baseParams, PluginType.PLUGIN, 'hello-world', 'presence') | 125 | await checkNewPluginVersion({ ...baseParams, pluginType: PluginType.PLUGIN, pluginName: 'hello-world', checkType: 'presence' }) |
126 | }) | 126 | }) |
127 | 127 | ||
128 | it('Should not send the same notification to admins', async function () { | 128 | 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 () { | |||
52 | it('Should not send a new comment notification after a comment on another video', async function () { | 52 | it('Should not send a new comment notification after a comment on another video', async function () { |
53 | this.timeout(20000) | 53 | this.timeout(20000) |
54 | 54 | ||
55 | const { uuid } = await servers[0].videos.upload({ attributes: { name: 'super video' } }) | 55 | const { uuid, shortUUID } = await servers[0].videos.upload({ attributes: { name: 'super video' } }) |
56 | 56 | ||
57 | const created = await servers[0].comments.createThread({ videoId: uuid, text: 'comment' }) | 57 | const created = await servers[0].comments.createThread({ videoId: uuid, text: 'comment' }) |
58 | const commentId = created.id | 58 | const commentId = created.id |
59 | 59 | ||
60 | await waitJobs(servers) | 60 | await waitJobs(servers) |
61 | await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'absence') | 61 | await checkNewCommentOnMyVideo({ ...baseParams, shortUUID, threadId: commentId, commentId, checkType: 'absence' }) |
62 | }) | 62 | }) |
63 | 63 | ||
64 | it('Should not send a new comment notification if I comment my own video', async function () { | 64 | it('Should not send a new comment notification if I comment my own video', async function () { |
65 | this.timeout(20000) | 65 | this.timeout(20000) |
66 | 66 | ||
67 | const { uuid } = await servers[0].videos.upload({ token: userToken, attributes: { name: 'super video' } }) | 67 | const { uuid, shortUUID } = await servers[0].videos.upload({ token: userToken, attributes: { name: 'super video' } }) |
68 | 68 | ||
69 | const created = await servers[0].comments.createThread({ token: userToken, videoId: uuid, text: 'comment' }) | 69 | const created = await servers[0].comments.createThread({ token: userToken, videoId: uuid, text: 'comment' }) |
70 | const commentId = created.id | 70 | const commentId = created.id |
71 | 71 | ||
72 | await waitJobs(servers) | 72 | await waitJobs(servers) |
73 | await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'absence') | 73 | await checkNewCommentOnMyVideo({ ...baseParams, shortUUID, threadId: commentId, commentId, checkType: 'absence' }) |
74 | }) | 74 | }) |
75 | 75 | ||
76 | it('Should not send a new comment notification if the account is muted', async function () { | 76 | it('Should not send a new comment notification if the account is muted', async function () { |
@@ -78,13 +78,13 @@ describe('Test comments notifications', function () { | |||
78 | 78 | ||
79 | await servers[0].blocklist.addToMyBlocklist({ token: userToken, account: 'root' }) | 79 | await servers[0].blocklist.addToMyBlocklist({ token: userToken, account: 'root' }) |
80 | 80 | ||
81 | const { uuid } = await servers[0].videos.upload({ token: userToken, attributes: { name: 'super video' } }) | 81 | const { uuid, shortUUID } = await servers[0].videos.upload({ token: userToken, attributes: { name: 'super video' } }) |
82 | 82 | ||
83 | const created = await servers[0].comments.createThread({ videoId: uuid, text: 'comment' }) | 83 | const created = await servers[0].comments.createThread({ videoId: uuid, text: 'comment' }) |
84 | const commentId = created.id | 84 | const commentId = created.id |
85 | 85 | ||
86 | await waitJobs(servers) | 86 | await waitJobs(servers) |
87 | await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'absence') | 87 | await checkNewCommentOnMyVideo({ ...baseParams, shortUUID, threadId: commentId, commentId, checkType: 'absence' }) |
88 | 88 | ||
89 | await servers[0].blocklist.removeFromMyBlocklist({ token: userToken, account: 'root' }) | 89 | await servers[0].blocklist.removeFromMyBlocklist({ token: userToken, account: 'root' }) |
90 | }) | 90 | }) |
@@ -92,19 +92,19 @@ describe('Test comments notifications', function () { | |||
92 | it('Should send a new comment notification after a local comment on my video', async function () { | 92 | it('Should send a new comment notification after a local comment on my video', async function () { |
93 | this.timeout(20000) | 93 | this.timeout(20000) |
94 | 94 | ||
95 | const { uuid } = await servers[0].videos.upload({ token: userToken, attributes: { name: 'super video' } }) | 95 | const { uuid, shortUUID } = await servers[0].videos.upload({ token: userToken, attributes: { name: 'super video' } }) |
96 | 96 | ||
97 | const created = await servers[0].comments.createThread({ videoId: uuid, text: 'comment' }) | 97 | const created = await servers[0].comments.createThread({ videoId: uuid, text: 'comment' }) |
98 | const commentId = created.id | 98 | const commentId = created.id |
99 | 99 | ||
100 | await waitJobs(servers) | 100 | await waitJobs(servers) |
101 | await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'presence') | 101 | await checkNewCommentOnMyVideo({ ...baseParams, shortUUID, threadId: commentId, commentId, checkType: 'presence' }) |
102 | }) | 102 | }) |
103 | 103 | ||
104 | it('Should send a new comment notification after a remote comment on my video', async function () { | 104 | it('Should send a new comment notification after a remote comment on my video', async function () { |
105 | this.timeout(20000) | 105 | this.timeout(20000) |
106 | 106 | ||
107 | const { uuid } = await servers[0].videos.upload({ token: userToken, attributes: { name: 'super video' } }) | 107 | const { uuid, shortUUID } = await servers[0].videos.upload({ token: userToken, attributes: { name: 'super video' } }) |
108 | 108 | ||
109 | await waitJobs(servers) | 109 | await waitJobs(servers) |
110 | 110 | ||
@@ -116,26 +116,26 @@ describe('Test comments notifications', function () { | |||
116 | expect(data).to.have.lengthOf(1) | 116 | expect(data).to.have.lengthOf(1) |
117 | 117 | ||
118 | const commentId = data[0].id | 118 | const commentId = data[0].id |
119 | await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'presence') | 119 | await checkNewCommentOnMyVideo({ ...baseParams, shortUUID, threadId: commentId, commentId, checkType: 'presence' }) |
120 | }) | 120 | }) |
121 | 121 | ||
122 | it('Should send a new comment notification after a local reply on my video', async function () { | 122 | it('Should send a new comment notification after a local reply on my video', async function () { |
123 | this.timeout(20000) | 123 | this.timeout(20000) |
124 | 124 | ||
125 | const { uuid } = await servers[0].videos.upload({ token: userToken, attributes: { name: 'super video' } }) | 125 | const { uuid, shortUUID } = await servers[0].videos.upload({ token: userToken, attributes: { name: 'super video' } }) |
126 | 126 | ||
127 | const { id: threadId } = await servers[0].comments.createThread({ videoId: uuid, text: 'comment' }) | 127 | const { id: threadId } = await servers[0].comments.createThread({ videoId: uuid, text: 'comment' }) |
128 | 128 | ||
129 | const { id: commentId } = await servers[0].comments.addReply({ videoId: uuid, toCommentId: threadId, text: 'reply' }) | 129 | const { id: commentId } = await servers[0].comments.addReply({ videoId: uuid, toCommentId: threadId, text: 'reply' }) |
130 | 130 | ||
131 | await waitJobs(servers) | 131 | await waitJobs(servers) |
132 | await checkNewCommentOnMyVideo(baseParams, uuid, commentId, threadId, 'presence') | 132 | await checkNewCommentOnMyVideo({ ...baseParams, shortUUID, threadId, commentId, checkType: 'presence' }) |
133 | }) | 133 | }) |
134 | 134 | ||
135 | it('Should send a new comment notification after a remote reply on my video', async function () { | 135 | it('Should send a new comment notification after a remote reply on my video', async function () { |
136 | this.timeout(20000) | 136 | this.timeout(20000) |
137 | 137 | ||
138 | const { uuid } = await servers[0].videos.upload({ token: userToken, attributes: { name: 'super video' } }) | 138 | const { uuid, shortUUID } = await servers[0].videos.upload({ token: userToken, attributes: { name: 'super video' } }) |
139 | await waitJobs(servers) | 139 | await waitJobs(servers) |
140 | 140 | ||
141 | { | 141 | { |
@@ -155,7 +155,7 @@ describe('Test comments notifications', function () { | |||
155 | expect(tree.children).to.have.lengthOf(1) | 155 | expect(tree.children).to.have.lengthOf(1) |
156 | const commentId = tree.children[0].comment.id | 156 | const commentId = tree.children[0].comment.id |
157 | 157 | ||
158 | await checkNewCommentOnMyVideo(baseParams, uuid, commentId, threadId, 'presence') | 158 | await checkNewCommentOnMyVideo({ ...baseParams, shortUUID, threadId, commentId, checkType: 'presence' }) |
159 | }) | 159 | }) |
160 | 160 | ||
161 | it('Should convert markdown in comment to html', async function () { | 161 | it('Should convert markdown in comment to html', async function () { |
@@ -174,6 +174,7 @@ describe('Test comments notifications', function () { | |||
174 | 174 | ||
175 | describe('Mention notifications', function () { | 175 | describe('Mention notifications', function () { |
176 | let baseParams: CheckerBaseParams | 176 | let baseParams: CheckerBaseParams |
177 | const byAccountDisplayName = 'super root name' | ||
177 | 178 | ||
178 | before(async () => { | 179 | before(async () => { |
179 | baseParams = { | 180 | baseParams = { |
@@ -190,23 +191,23 @@ describe('Test comments notifications', function () { | |||
190 | it('Should not send a new mention comment notification if I mention the video owner', async function () { | 191 | it('Should not send a new mention comment notification if I mention the video owner', async function () { |
191 | this.timeout(10000) | 192 | this.timeout(10000) |
192 | 193 | ||
193 | const { uuid } = await servers[0].videos.upload({ token: userToken, attributes: { name: 'super video' } }) | 194 | const { uuid, shortUUID } = await servers[0].videos.upload({ token: userToken, attributes: { name: 'super video' } }) |
194 | 195 | ||
195 | const { id: commentId } = await servers[0].comments.createThread({ videoId: uuid, text: '@user_1 hello' }) | 196 | const { id: commentId } = await servers[0].comments.createThread({ videoId: uuid, text: '@user_1 hello' }) |
196 | 197 | ||
197 | await waitJobs(servers) | 198 | await waitJobs(servers) |
198 | await checkCommentMention(baseParams, uuid, commentId, commentId, 'super root name', 'absence') | 199 | await checkCommentMention({ ...baseParams, shortUUID, threadId: commentId, commentId, byAccountDisplayName, checkType: 'absence' }) |
199 | }) | 200 | }) |
200 | 201 | ||
201 | it('Should not send a new mention comment notification if I mention myself', async function () { | 202 | it('Should not send a new mention comment notification if I mention myself', async function () { |
202 | this.timeout(10000) | 203 | this.timeout(10000) |
203 | 204 | ||
204 | const { uuid } = await servers[0].videos.upload({ attributes: { name: 'super video' } }) | 205 | const { uuid, shortUUID } = await servers[0].videos.upload({ attributes: { name: 'super video' } }) |
205 | 206 | ||
206 | const { id: commentId } = await servers[0].comments.createThread({ token: userToken, videoId: uuid, text: '@user_1 hello' }) | 207 | const { id: commentId } = await servers[0].comments.createThread({ token: userToken, videoId: uuid, text: '@user_1 hello' }) |
207 | 208 | ||
208 | await waitJobs(servers) | 209 | await waitJobs(servers) |
209 | await checkCommentMention(baseParams, uuid, commentId, commentId, 'super root name', 'absence') | 210 | await checkCommentMention({ ...baseParams, shortUUID, threadId: commentId, commentId, byAccountDisplayName, checkType: 'absence' }) |
210 | }) | 211 | }) |
211 | 212 | ||
212 | it('Should not send a new mention notification if the account is muted', async function () { | 213 | it('Should not send a new mention notification if the account is muted', async function () { |
@@ -214,12 +215,12 @@ describe('Test comments notifications', function () { | |||
214 | 215 | ||
215 | await servers[0].blocklist.addToMyBlocklist({ token: userToken, account: 'root' }) | 216 | await servers[0].blocklist.addToMyBlocklist({ token: userToken, account: 'root' }) |
216 | 217 | ||
217 | const { uuid } = await servers[0].videos.upload({ attributes: { name: 'super video' } }) | 218 | const { uuid, shortUUID } = await servers[0].videos.upload({ attributes: { name: 'super video' } }) |
218 | 219 | ||
219 | const { id: commentId } = await servers[0].comments.createThread({ videoId: uuid, text: '@user_1 hello' }) | 220 | const { id: commentId } = await servers[0].comments.createThread({ videoId: uuid, text: '@user_1 hello' }) |
220 | 221 | ||
221 | await waitJobs(servers) | 222 | await waitJobs(servers) |
222 | await checkCommentMention(baseParams, uuid, commentId, commentId, 'super root name', 'absence') | 223 | await checkCommentMention({ ...baseParams, shortUUID, threadId: commentId, commentId, byAccountDisplayName, checkType: 'absence' }) |
223 | 224 | ||
224 | await servers[0].blocklist.removeFromMyBlocklist({ token: userToken, account: 'root' }) | 225 | await servers[0].blocklist.removeFromMyBlocklist({ token: userToken, account: 'root' }) |
225 | }) | 226 | }) |
@@ -227,35 +228,37 @@ describe('Test comments notifications', function () { | |||
227 | it('Should not send a new mention notification if the remote account mention a local account', async function () { | 228 | it('Should not send a new mention notification if the remote account mention a local account', async function () { |
228 | this.timeout(20000) | 229 | this.timeout(20000) |
229 | 230 | ||
230 | const { uuid } = await servers[0].videos.upload({ attributes: { name: 'super video' } }) | 231 | const { uuid, shortUUID } = await servers[0].videos.upload({ attributes: { name: 'super video' } }) |
231 | 232 | ||
232 | await waitJobs(servers) | 233 | await waitJobs(servers) |
233 | const { id: threadId } = await servers[1].comments.createThread({ videoId: uuid, text: '@user_1 hello' }) | 234 | const { id: threadId } = await servers[1].comments.createThread({ videoId: uuid, text: '@user_1 hello' }) |
234 | 235 | ||
235 | await waitJobs(servers) | 236 | await waitJobs(servers) |
236 | await checkCommentMention(baseParams, uuid, threadId, threadId, 'super root 2 name', 'absence') | 237 | |
238 | const byAccountDisplayName = 'super root 2 name' | ||
239 | await checkCommentMention({ ...baseParams, shortUUID, threadId, commentId: threadId, byAccountDisplayName, checkType: 'absence' }) | ||
237 | }) | 240 | }) |
238 | 241 | ||
239 | it('Should send a new mention notification after local comments', async function () { | 242 | it('Should send a new mention notification after local comments', async function () { |
240 | this.timeout(10000) | 243 | this.timeout(10000) |
241 | 244 | ||
242 | const { uuid } = await servers[0].videos.upload({ attributes: { name: 'super video' } }) | 245 | const { uuid, shortUUID } = await servers[0].videos.upload({ attributes: { name: 'super video' } }) |
243 | 246 | ||
244 | const { id: threadId } = await servers[0].comments.createThread({ videoId: uuid, text: '@user_1 hellotext: 1' }) | 247 | const { id: threadId } = await servers[0].comments.createThread({ videoId: uuid, text: '@user_1 hellotext: 1' }) |
245 | 248 | ||
246 | await waitJobs(servers) | 249 | await waitJobs(servers) |
247 | await checkCommentMention(baseParams, uuid, threadId, threadId, 'super root name', 'presence') | 250 | await checkCommentMention({ ...baseParams, shortUUID, threadId, commentId: threadId, byAccountDisplayName, checkType: 'presence' }) |
248 | 251 | ||
249 | const { id: commentId } = await servers[0].comments.addReply({ videoId: uuid, toCommentId: threadId, text: 'hello 2 @user_1' }) | 252 | const { id: commentId } = await servers[0].comments.addReply({ videoId: uuid, toCommentId: threadId, text: 'hello 2 @user_1' }) |
250 | 253 | ||
251 | await waitJobs(servers) | 254 | await waitJobs(servers) |
252 | await checkCommentMention(baseParams, uuid, commentId, threadId, 'super root name', 'presence') | 255 | await checkCommentMention({ ...baseParams, shortUUID, commentId, threadId, byAccountDisplayName, checkType: 'presence' }) |
253 | }) | 256 | }) |
254 | 257 | ||
255 | it('Should send a new mention notification after remote comments', async function () { | 258 | it('Should send a new mention notification after remote comments', async function () { |
256 | this.timeout(20000) | 259 | this.timeout(20000) |
257 | 260 | ||
258 | const { uuid } = await servers[0].videos.upload({ attributes: { name: 'super video' } }) | 261 | const { uuid, shortUUID } = await servers[0].videos.upload({ attributes: { name: 'super video' } }) |
259 | 262 | ||
260 | await waitJobs(servers) | 263 | await waitJobs(servers) |
261 | 264 | ||
@@ -267,20 +270,21 @@ describe('Test comments notifications', function () { | |||
267 | const { data } = await servers[0].comments.listThreads({ videoId: uuid }) | 270 | const { data } = await servers[0].comments.listThreads({ videoId: uuid }) |
268 | expect(data).to.have.lengthOf(1) | 271 | expect(data).to.have.lengthOf(1) |
269 | 272 | ||
270 | const server1ThreadId = data[0].id | 273 | const byAccountDisplayName = 'super root 2 name' |
271 | await checkCommentMention(baseParams, uuid, server1ThreadId, server1ThreadId, 'super root 2 name', 'presence') | 274 | const threadId = data[0].id |
275 | await checkCommentMention({ ...baseParams, shortUUID, commentId: threadId, threadId, byAccountDisplayName, checkType: 'presence' }) | ||
272 | 276 | ||
273 | const text2 = `@user_1@localhost:${servers[0].port} hello 2 @root@localhost:${servers[0].port}` | 277 | const text2 = `@user_1@localhost:${servers[0].port} hello 2 @root@localhost:${servers[0].port}` |
274 | await servers[1].comments.addReply({ videoId: uuid, toCommentId: server2ThreadId, text: text2 }) | 278 | await servers[1].comments.addReply({ videoId: uuid, toCommentId: server2ThreadId, text: text2 }) |
275 | 279 | ||
276 | await waitJobs(servers) | 280 | await waitJobs(servers) |
277 | 281 | ||
278 | const tree = await servers[0].comments.getThread({ videoId: uuid, threadId: server1ThreadId }) | 282 | const tree = await servers[0].comments.getThread({ videoId: uuid, threadId }) |
279 | 283 | ||
280 | expect(tree.children).to.have.lengthOf(1) | 284 | expect(tree.children).to.have.lengthOf(1) |
281 | const commentId = tree.children[0].comment.id | 285 | const commentId = tree.children[0].comment.id |
282 | 286 | ||
283 | await checkCommentMention(baseParams, uuid, commentId, server1ThreadId, 'super root 2 name', 'presence') | 287 | await checkCommentMention({ ...baseParams, shortUUID, commentId, threadId, byAccountDisplayName, checkType: 'presence' }) |
284 | }) | 288 | }) |
285 | 289 | ||
286 | it('Should convert markdown in comment to html', async function () { | 290 | 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 () { | |||
67 | await servers[0].abuses.report({ videoId: video.id, reason: 'super reason' }) | 67 | await servers[0].abuses.report({ videoId: video.id, reason: 'super reason' }) |
68 | 68 | ||
69 | await waitJobs(servers) | 69 | await waitJobs(servers) |
70 | await checkNewVideoAbuseForModerators(baseParams, video.uuid, name, 'presence') | 70 | await checkNewVideoAbuseForModerators({ ...baseParams, shortUUID: video.shortUUID, videoName: name, checkType: 'presence' }) |
71 | }) | 71 | }) |
72 | 72 | ||
73 | it('Should send a notification to moderators on remote video abuse', async function () { | 73 | it('Should send a notification to moderators on remote video abuse', async function () { |
@@ -82,7 +82,7 @@ describe('Test moderation notifications', function () { | |||
82 | await servers[1].abuses.report({ videoId, reason: 'super reason' }) | 82 | await servers[1].abuses.report({ videoId, reason: 'super reason' }) |
83 | 83 | ||
84 | await waitJobs(servers) | 84 | await waitJobs(servers) |
85 | await checkNewVideoAbuseForModerators(baseParams, video.uuid, name, 'presence') | 85 | await checkNewVideoAbuseForModerators({ ...baseParams, shortUUID: video.shortUUID, videoName: name, checkType: 'presence' }) |
86 | }) | 86 | }) |
87 | 87 | ||
88 | it('Should send a notification to moderators on local comment abuse', async function () { | 88 | it('Should send a notification to moderators on local comment abuse', async function () { |
@@ -101,7 +101,7 @@ describe('Test moderation notifications', function () { | |||
101 | await servers[0].abuses.report({ commentId: comment.id, reason: 'super reason' }) | 101 | await servers[0].abuses.report({ commentId: comment.id, reason: 'super reason' }) |
102 | 102 | ||
103 | await waitJobs(servers) | 103 | await waitJobs(servers) |
104 | await checkNewCommentAbuseForModerators(baseParams, video.uuid, name, 'presence') | 104 | await checkNewCommentAbuseForModerators({ ...baseParams, shortUUID: video.shortUUID, videoName: name, checkType: 'presence' }) |
105 | }) | 105 | }) |
106 | 106 | ||
107 | it('Should send a notification to moderators on remote comment abuse', async function () { | 107 | it('Should send a notification to moderators on remote comment abuse', async function () { |
@@ -123,7 +123,7 @@ describe('Test moderation notifications', function () { | |||
123 | await servers[1].abuses.report({ commentId, reason: 'super reason' }) | 123 | await servers[1].abuses.report({ commentId, reason: 'super reason' }) |
124 | 124 | ||
125 | await waitJobs(servers) | 125 | await waitJobs(servers) |
126 | await checkNewCommentAbuseForModerators(baseParams, video.uuid, name, 'presence') | 126 | await checkNewCommentAbuseForModerators({ ...baseParams, shortUUID: video.shortUUID, videoName: name, checkType: 'presence' }) |
127 | }) | 127 | }) |
128 | 128 | ||
129 | it('Should send a notification to moderators on local account abuse', async function () { | 129 | it('Should send a notification to moderators on local account abuse', async function () { |
@@ -136,7 +136,7 @@ describe('Test moderation notifications', function () { | |||
136 | await servers[0].abuses.report({ accountId, reason: 'super reason' }) | 136 | await servers[0].abuses.report({ accountId, reason: 'super reason' }) |
137 | 137 | ||
138 | await waitJobs(servers) | 138 | await waitJobs(servers) |
139 | await checkNewAccountAbuseForModerators(baseParams, username, 'presence') | 139 | await checkNewAccountAbuseForModerators({ ...baseParams, displayName: username, checkType: 'presence' }) |
140 | }) | 140 | }) |
141 | 141 | ||
142 | it('Should send a notification to moderators on remote account abuse', async function () { | 142 | it('Should send a notification to moderators on remote account abuse', async function () { |
@@ -152,7 +152,7 @@ describe('Test moderation notifications', function () { | |||
152 | await servers[1].abuses.report({ accountId: account.id, reason: 'super reason' }) | 152 | await servers[1].abuses.report({ accountId: account.id, reason: 'super reason' }) |
153 | 153 | ||
154 | await waitJobs(servers) | 154 | await waitJobs(servers) |
155 | await checkNewAccountAbuseForModerators(baseParams, username, 'presence') | 155 | await checkNewAccountAbuseForModerators({ ...baseParams, displayName: username, checkType: 'presence' }) |
156 | }) | 156 | }) |
157 | }) | 157 | }) |
158 | 158 | ||
@@ -181,7 +181,7 @@ describe('Test moderation notifications', function () { | |||
181 | await servers[0].abuses.update({ abuseId, body: { state: AbuseState.ACCEPTED } }) | 181 | await servers[0].abuses.update({ abuseId, body: { state: AbuseState.ACCEPTED } }) |
182 | await waitJobs(servers) | 182 | await waitJobs(servers) |
183 | 183 | ||
184 | await checkAbuseStateChange(baseParams, abuseId, AbuseState.ACCEPTED, 'presence') | 184 | await checkAbuseStateChange({ ...baseParams, abuseId, state: AbuseState.ACCEPTED, checkType: 'presence' }) |
185 | }) | 185 | }) |
186 | 186 | ||
187 | it('Should send a notification to reporter if the abuse has been rejected', async function () { | 187 | it('Should send a notification to reporter if the abuse has been rejected', async function () { |
@@ -190,7 +190,7 @@ describe('Test moderation notifications', function () { | |||
190 | await servers[0].abuses.update({ abuseId, body: { state: AbuseState.REJECTED } }) | 190 | await servers[0].abuses.update({ abuseId, body: { state: AbuseState.REJECTED } }) |
191 | await waitJobs(servers) | 191 | await waitJobs(servers) |
192 | 192 | ||
193 | await checkAbuseStateChange(baseParams, abuseId, AbuseState.REJECTED, 'presence') | 193 | await checkAbuseStateChange({ ...baseParams, abuseId, state: AbuseState.REJECTED, checkType: 'presence' }) |
194 | }) | 194 | }) |
195 | }) | 195 | }) |
196 | 196 | ||
@@ -236,7 +236,7 @@ describe('Test moderation notifications', function () { | |||
236 | await servers[0].abuses.addMessage({ abuseId, message }) | 236 | await servers[0].abuses.addMessage({ abuseId, message }) |
237 | await waitJobs(servers) | 237 | await waitJobs(servers) |
238 | 238 | ||
239 | await checkNewAbuseMessage(baseParamsUser, abuseId, message, 'user_1@example.com', 'presence') | 239 | await checkNewAbuseMessage({ ...baseParamsUser, abuseId, message, toEmail: 'user_1@example.com', checkType: 'presence' }) |
240 | }) | 240 | }) |
241 | 241 | ||
242 | it('Should not send a notification to the admin if sent by the admin', async function () { | 242 | 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 () { | |||
246 | await servers[0].abuses.addMessage({ abuseId, message }) | 246 | await servers[0].abuses.addMessage({ abuseId, message }) |
247 | await waitJobs(servers) | 247 | await waitJobs(servers) |
248 | 248 | ||
249 | await checkNewAbuseMessage(baseParamsAdmin, abuseId, message, 'admin' + servers[0].internalServerNumber + '@example.com', 'absence') | 249 | const toEmail = 'admin' + servers[0].internalServerNumber + '@example.com' |
250 | await checkNewAbuseMessage({ ...baseParamsAdmin, abuseId, message, toEmail, checkType: 'absence' }) | ||
250 | }) | 251 | }) |
251 | 252 | ||
252 | it('Should send a notification to moderators', async function () { | 253 | it('Should send a notification to moderators', async function () { |
@@ -256,7 +257,8 @@ describe('Test moderation notifications', function () { | |||
256 | await servers[0].abuses.addMessage({ token: userAccessToken, abuseId: abuseId2, message }) | 257 | await servers[0].abuses.addMessage({ token: userAccessToken, abuseId: abuseId2, message }) |
257 | await waitJobs(servers) | 258 | await waitJobs(servers) |
258 | 259 | ||
259 | await checkNewAbuseMessage(baseParamsAdmin, abuseId2, message, 'admin' + servers[0].internalServerNumber + '@example.com', 'presence') | 260 | const toEmail = 'admin' + servers[0].internalServerNumber + '@example.com' |
261 | await checkNewAbuseMessage({ ...baseParamsAdmin, abuseId: abuseId2, message, toEmail, checkType: 'presence' }) | ||
260 | }) | 262 | }) |
261 | 263 | ||
262 | it('Should not send a notification to reporter if sent by the reporter', async function () { | 264 | it('Should not send a notification to reporter if sent by the reporter', async function () { |
@@ -266,7 +268,8 @@ describe('Test moderation notifications', function () { | |||
266 | await servers[0].abuses.addMessage({ token: userAccessToken, abuseId: abuseId2, message }) | 268 | await servers[0].abuses.addMessage({ token: userAccessToken, abuseId: abuseId2, message }) |
267 | await waitJobs(servers) | 269 | await waitJobs(servers) |
268 | 270 | ||
269 | await checkNewAbuseMessage(baseParamsUser, abuseId2, message, 'user_1@example.com', 'absence') | 271 | const toEmail = 'user_1@example.com' |
272 | await checkNewAbuseMessage({ ...baseParamsUser, abuseId: abuseId2, message, toEmail, checkType: 'absence' }) | ||
270 | }) | 273 | }) |
271 | }) | 274 | }) |
272 | 275 | ||
@@ -286,19 +289,19 @@ describe('Test moderation notifications', function () { | |||
286 | this.timeout(10000) | 289 | this.timeout(10000) |
287 | 290 | ||
288 | const name = 'video for abuse ' + buildUUID() | 291 | const name = 'video for abuse ' + buildUUID() |
289 | const { uuid } = await servers[0].videos.upload({ token: userAccessToken, attributes: { name } }) | 292 | const { uuid, shortUUID } = await servers[0].videos.upload({ token: userAccessToken, attributes: { name } }) |
290 | 293 | ||
291 | await servers[0].blacklist.add({ videoId: uuid }) | 294 | await servers[0].blacklist.add({ videoId: uuid }) |
292 | 295 | ||
293 | await waitJobs(servers) | 296 | await waitJobs(servers) |
294 | await checkNewBlacklistOnMyVideo(baseParams, uuid, name, 'blacklist') | 297 | await checkNewBlacklistOnMyVideo({ ...baseParams, shortUUID, videoName: name, blacklistType: 'blacklist' }) |
295 | }) | 298 | }) |
296 | 299 | ||
297 | it('Should send a notification to video owner on unblacklist', async function () { | 300 | it('Should send a notification to video owner on unblacklist', async function () { |
298 | this.timeout(10000) | 301 | this.timeout(10000) |
299 | 302 | ||
300 | const name = 'video for abuse ' + buildUUID() | 303 | const name = 'video for abuse ' + buildUUID() |
301 | const { uuid } = await servers[0].videos.upload({ token: userAccessToken, attributes: { name } }) | 304 | const { uuid, shortUUID } = await servers[0].videos.upload({ token: userAccessToken, attributes: { name } }) |
302 | 305 | ||
303 | await servers[0].blacklist.add({ videoId: uuid }) | 306 | await servers[0].blacklist.add({ videoId: uuid }) |
304 | 307 | ||
@@ -307,7 +310,7 @@ describe('Test moderation notifications', function () { | |||
307 | await waitJobs(servers) | 310 | await waitJobs(servers) |
308 | 311 | ||
309 | await wait(500) | 312 | await wait(500) |
310 | await checkNewBlacklistOnMyVideo(baseParams, uuid, name, 'unblacklist') | 313 | await checkNewBlacklistOnMyVideo({ ...baseParams, shortUUID, videoName: name, blacklistType: 'unblacklist' }) |
311 | }) | 314 | }) |
312 | }) | 315 | }) |
313 | 316 | ||
@@ -330,10 +333,10 @@ describe('Test moderation notifications', function () { | |||
330 | 333 | ||
331 | await waitJobs(servers) | 334 | await waitJobs(servers) |
332 | 335 | ||
333 | await checkUserRegistered(baseParams, 'user_45', 'presence') | 336 | await checkUserRegistered({ ...baseParams, username: 'user_45', checkType: 'presence' }) |
334 | 337 | ||
335 | const userOverride = { socketNotifications: userNotifications, token: userAccessToken, check: { web: true, mail: false } } | 338 | const userOverride = { socketNotifications: userNotifications, token: userAccessToken, check: { web: true, mail: false } } |
336 | await checkUserRegistered({ ...baseParams, ...userOverride }, 'user_45', 'absence') | 339 | await checkUserRegistered({ ...baseParams, ...userOverride, username: 'user_45', checkType: 'absence' }) |
337 | }) | 340 | }) |
338 | }) | 341 | }) |
339 | 342 | ||
@@ -372,10 +375,10 @@ describe('Test moderation notifications', function () { | |||
372 | 375 | ||
373 | await waitJobs(servers) | 376 | await waitJobs(servers) |
374 | 377 | ||
375 | await checkNewInstanceFollower(baseParams, 'localhost:' + servers[2].port, 'presence') | 378 | await checkNewInstanceFollower({ ...baseParams, followerHost: 'localhost:' + servers[2].port, checkType: 'presence' }) |
376 | 379 | ||
377 | const userOverride = { socketNotifications: userNotifications, token: userAccessToken, check: { web: true, mail: false } } | 380 | const userOverride = { socketNotifications: userNotifications, token: userAccessToken, check: { web: true, mail: false } } |
378 | await checkNewInstanceFollower({ ...baseParams, ...userOverride }, 'localhost:' + servers[2].port, 'absence') | 381 | await checkNewInstanceFollower({ ...baseParams, ...userOverride, followerHost: 'localhost:' + servers[2].port, checkType: 'absence' }) |
379 | }) | 382 | }) |
380 | 383 | ||
381 | it('Should send a notification on auto follow back', async function () { | 384 | it('Should send a notification on auto follow back', async function () { |
@@ -399,10 +402,10 @@ describe('Test moderation notifications', function () { | |||
399 | 402 | ||
400 | const followerHost = servers[0].host | 403 | const followerHost = servers[0].host |
401 | const followingHost = servers[2].host | 404 | const followingHost = servers[2].host |
402 | await checkAutoInstanceFollowing(baseParams, followerHost, followingHost, 'presence') | 405 | await checkAutoInstanceFollowing({ ...baseParams, followerHost, followingHost, checkType: 'presence' }) |
403 | 406 | ||
404 | const userOverride = { socketNotifications: userNotifications, token: userAccessToken, check: { web: true, mail: false } } | 407 | const userOverride = { socketNotifications: userNotifications, token: userAccessToken, check: { web: true, mail: false } } |
405 | await checkAutoInstanceFollowing({ ...baseParams, ...userOverride }, followerHost, followingHost, 'absence') | 408 | await checkAutoInstanceFollowing({ ...baseParams, ...userOverride, followerHost, followingHost, checkType: 'absence' }) |
406 | 409 | ||
407 | config.followings.instance.autoFollowBack.enabled = false | 410 | config.followings.instance.autoFollowBack.enabled = false |
408 | await servers[0].config.updateCustomSubConfig({ newConfig: config }) | 411 | await servers[0].config.updateCustomSubConfig({ newConfig: config }) |
@@ -421,7 +424,7 @@ describe('Test moderation notifications', function () { | |||
421 | 424 | ||
422 | const followerHost = servers[0].host | 425 | const followerHost = servers[0].host |
423 | const followingHost = servers[1].host | 426 | const followingHost = servers[1].host |
424 | await checkAutoInstanceFollowing(baseParams, followerHost, followingHost, 'presence') | 427 | await checkAutoInstanceFollowing({ ...baseParams, followerHost, followingHost, checkType: 'presence' }) |
425 | 428 | ||
426 | config.followings.instance.autoFollowIndex.enabled = false | 429 | config.followings.instance.autoFollowIndex.enabled = false |
427 | await servers[0].config.updateCustomSubConfig({ newConfig: config }) | 430 | await servers[0].config.updateCustomSubConfig({ newConfig: config }) |
@@ -433,7 +436,8 @@ describe('Test moderation notifications', function () { | |||
433 | let userBaseParams: CheckerBaseParams | 436 | let userBaseParams: CheckerBaseParams |
434 | let adminBaseParamsServer1: CheckerBaseParams | 437 | let adminBaseParamsServer1: CheckerBaseParams |
435 | let adminBaseParamsServer2: CheckerBaseParams | 438 | let adminBaseParamsServer2: CheckerBaseParams |
436 | let videoUUID: string | 439 | let uuid: string |
440 | let shortUUID: string | ||
437 | let videoName: string | 441 | let videoName: string |
438 | let currentCustomConfig: CustomConfig | 442 | let currentCustomConfig: CustomConfig |
439 | 443 | ||
@@ -480,36 +484,36 @@ describe('Test moderation notifications', function () { | |||
480 | 484 | ||
481 | await servers[0].subscriptions.add({ targetUri: 'user_1_channel@localhost:' + servers[0].port }) | 485 | await servers[0].subscriptions.add({ targetUri: 'user_1_channel@localhost:' + servers[0].port }) |
482 | await servers[1].subscriptions.add({ targetUri: 'user_1_channel@localhost:' + servers[0].port }) | 486 | await servers[1].subscriptions.add({ targetUri: 'user_1_channel@localhost:' + servers[0].port }) |
483 | |||
484 | }) | 487 | }) |
485 | 488 | ||
486 | it('Should send notification to moderators on new video with auto-blacklist', async function () { | 489 | it('Should send notification to moderators on new video with auto-blacklist', async function () { |
487 | this.timeout(40000) | 490 | this.timeout(40000) |
488 | 491 | ||
489 | videoName = 'video with auto-blacklist ' + buildUUID() | 492 | videoName = 'video with auto-blacklist ' + buildUUID() |
490 | const { uuid } = await servers[0].videos.upload({ token: userAccessToken, attributes: { name: videoName } }) | 493 | const video = await servers[0].videos.upload({ token: userAccessToken, attributes: { name: videoName } }) |
491 | videoUUID = uuid | 494 | shortUUID = video.shortUUID |
495 | uuid = video.uuid | ||
492 | 496 | ||
493 | await waitJobs(servers) | 497 | await waitJobs(servers) |
494 | await checkVideoAutoBlacklistForModerators(adminBaseParamsServer1, videoUUID, videoName, 'presence') | 498 | await checkVideoAutoBlacklistForModerators({ ...adminBaseParamsServer1, shortUUID, videoName, checkType: 'presence' }) |
495 | }) | 499 | }) |
496 | 500 | ||
497 | it('Should not send video publish notification if auto-blacklisted', async function () { | 501 | it('Should not send video publish notification if auto-blacklisted', async function () { |
498 | await checkVideoIsPublished(userBaseParams, videoName, videoUUID, 'absence') | 502 | await checkVideoIsPublished({ ...userBaseParams, videoName, shortUUID, checkType: 'absence' }) |
499 | }) | 503 | }) |
500 | 504 | ||
501 | it('Should not send a local user subscription notification if auto-blacklisted', async function () { | 505 | it('Should not send a local user subscription notification if auto-blacklisted', async function () { |
502 | await checkNewVideoFromSubscription(adminBaseParamsServer1, videoName, videoUUID, 'absence') | 506 | await checkNewVideoFromSubscription({ ...adminBaseParamsServer1, videoName, shortUUID, checkType: 'absence' }) |
503 | }) | 507 | }) |
504 | 508 | ||
505 | it('Should not send a remote user subscription notification if auto-blacklisted', async function () { | 509 | it('Should not send a remote user subscription notification if auto-blacklisted', async function () { |
506 | await checkNewVideoFromSubscription(adminBaseParamsServer2, videoName, videoUUID, 'absence') | 510 | await checkNewVideoFromSubscription({ ...adminBaseParamsServer2, videoName, shortUUID, checkType: 'absence' }) |
507 | }) | 511 | }) |
508 | 512 | ||
509 | it('Should send video published and unblacklist after video unblacklisted', async function () { | 513 | it('Should send video published and unblacklist after video unblacklisted', async function () { |
510 | this.timeout(40000) | 514 | this.timeout(40000) |
511 | 515 | ||
512 | await servers[0].blacklist.remove({ videoId: videoUUID }) | 516 | await servers[0].blacklist.remove({ videoId: uuid }) |
513 | 517 | ||
514 | await waitJobs(servers) | 518 | await waitJobs(servers) |
515 | 519 | ||
@@ -520,11 +524,11 @@ describe('Test moderation notifications', function () { | |||
520 | }) | 524 | }) |
521 | 525 | ||
522 | it('Should send a local user subscription notification after removed from blacklist', async function () { | 526 | it('Should send a local user subscription notification after removed from blacklist', async function () { |
523 | await checkNewVideoFromSubscription(adminBaseParamsServer1, videoName, videoUUID, 'presence') | 527 | await checkNewVideoFromSubscription({ ...adminBaseParamsServer1, videoName, shortUUID, checkType: 'presence' }) |
524 | }) | 528 | }) |
525 | 529 | ||
526 | it('Should send a remote user subscription notification after removed from blacklist', async function () { | 530 | it('Should send a remote user subscription notification after removed from blacklist', async function () { |
527 | await checkNewVideoFromSubscription(adminBaseParamsServer2, videoName, videoUUID, 'presence') | 531 | await checkNewVideoFromSubscription({ ...adminBaseParamsServer2, videoName, shortUUID, checkType: 'presence' }) |
528 | }) | 532 | }) |
529 | 533 | ||
530 | it('Should send unblacklist but not published/subscription notes after unblacklisted if scheduled update pending', async function () { | 534 | 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 () { | |||
543 | } | 547 | } |
544 | } | 548 | } |
545 | 549 | ||
546 | const { uuid } = await servers[0].videos.upload({ token: userAccessToken, attributes }) | 550 | const { shortUUID, uuid } = await servers[0].videos.upload({ token: userAccessToken, attributes }) |
547 | 551 | ||
548 | await servers[0].blacklist.remove({ videoId: uuid }) | 552 | await servers[0].blacklist.remove({ videoId: uuid }) |
549 | 553 | ||
550 | await waitJobs(servers) | 554 | await waitJobs(servers) |
551 | await checkNewBlacklistOnMyVideo(userBaseParams, uuid, name, 'unblacklist') | 555 | await checkNewBlacklistOnMyVideo({ ...userBaseParams, shortUUID, videoName: name, blacklistType: 'unblacklist' }) |
552 | 556 | ||
553 | // FIXME: Can't test absence as two notifications sent to same user and util only checks last one | 557 | // FIXME: Can't test absence as two notifications sent to same user and util only checks last one |
554 | // One notification might be better anyways | 558 | // One notification might be better anyways |
555 | // await checkVideoIsPublished(userBaseParams, name, uuid, 'absence') | 559 | // await checkVideoIsPublished(userBaseParams, name, uuid, 'absence') |
556 | 560 | ||
557 | await checkNewVideoFromSubscription(adminBaseParamsServer1, name, uuid, 'absence') | 561 | await checkNewVideoFromSubscription({ ...adminBaseParamsServer1, videoName: name, shortUUID, checkType: 'absence' }) |
558 | await checkNewVideoFromSubscription(adminBaseParamsServer2, name, uuid, 'absence') | 562 | await checkNewVideoFromSubscription({ ...adminBaseParamsServer2, videoName: name, shortUUID, checkType: 'absence' }) |
559 | }) | 563 | }) |
560 | 564 | ||
561 | it('Should not send publish/subscription notifications after scheduled update if video still auto-blacklisted', async function () { | 565 | 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 () { | |||
575 | } | 579 | } |
576 | } | 580 | } |
577 | 581 | ||
578 | const { uuid } = await servers[0].videos.upload({ token: userAccessToken, attributes }) | 582 | const { shortUUID } = await servers[0].videos.upload({ token: userAccessToken, attributes }) |
579 | 583 | ||
580 | await wait(6000) | 584 | await wait(6000) |
581 | await checkVideoIsPublished(userBaseParams, name, uuid, 'absence') | 585 | await checkVideoIsPublished({ ...userBaseParams, videoName: name, shortUUID, checkType: 'absence' }) |
582 | await checkNewVideoFromSubscription(adminBaseParamsServer1, name, uuid, 'absence') | 586 | await checkNewVideoFromSubscription({ ...adminBaseParamsServer1, videoName: name, shortUUID, checkType: 'absence' }) |
583 | await checkNewVideoFromSubscription(adminBaseParamsServer2, name, uuid, 'absence') | 587 | await checkNewVideoFromSubscription({ ...adminBaseParamsServer2, videoName: name, shortUUID, checkType: 'absence' }) |
584 | }) | 588 | }) |
585 | 589 | ||
586 | it('Should not send a notification to moderators on new video without auto-blacklist', async function () { | 590 | 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 () { | |||
589 | const name = 'video without auto-blacklist ' + buildUUID() | 593 | const name = 'video without auto-blacklist ' + buildUUID() |
590 | 594 | ||
591 | // admin with blacklist right will not be auto-blacklisted | 595 | // admin with blacklist right will not be auto-blacklisted |
592 | const { uuid } = await servers[0].videos.upload({ attributes: { name } }) | 596 | const { shortUUID } = await servers[0].videos.upload({ attributes: { name } }) |
593 | 597 | ||
594 | await waitJobs(servers) | 598 | await waitJobs(servers) |
595 | await checkVideoAutoBlacklistForModerators(adminBaseParamsServer1, uuid, name, 'absence') | 599 | await checkVideoAutoBlacklistForModerators({ ...adminBaseParamsServer1, shortUUID, videoName: name, checkType: 'absence' }) |
596 | }) | 600 | }) |
597 | 601 | ||
598 | after(async () => { | 602 | 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 () { | |||
111 | expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.NONE) | 111 | expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.NONE) |
112 | } | 112 | } |
113 | 113 | ||
114 | const { name, uuid } = await server.videos.randomUpload() | 114 | const { name, shortUUID } = await server.videos.randomUpload() |
115 | 115 | ||
116 | const check = { web: true, mail: true } | 116 | const check = { web: true, mail: true } |
117 | await checkNewVideoFromSubscription({ ...baseParams, check }, name, uuid, 'absence') | 117 | await checkNewVideoFromSubscription({ ...baseParams, check, videoName: name, shortUUID, checkType: 'absence' }) |
118 | }) | 118 | }) |
119 | 119 | ||
120 | it('Should only have web notifications', async function () { | 120 | it('Should only have web notifications', async function () { |
@@ -130,16 +130,16 @@ describe('Test notifications API', function () { | |||
130 | expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.WEB) | 130 | expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.WEB) |
131 | } | 131 | } |
132 | 132 | ||
133 | const { name, uuid } = await server.videos.randomUpload() | 133 | const { name, shortUUID } = await server.videos.randomUpload() |
134 | 134 | ||
135 | { | 135 | { |
136 | const check = { mail: true, web: false } | 136 | const check = { mail: true, web: false } |
137 | await checkNewVideoFromSubscription({ ...baseParams, check }, name, uuid, 'absence') | 137 | await checkNewVideoFromSubscription({ ...baseParams, check, videoName: name, shortUUID, checkType: 'absence' }) |
138 | } | 138 | } |
139 | 139 | ||
140 | { | 140 | { |
141 | const check = { mail: false, web: true } | 141 | const check = { mail: false, web: true } |
142 | await checkNewVideoFromSubscription({ ...baseParams, check }, name, uuid, 'presence') | 142 | await checkNewVideoFromSubscription({ ...baseParams, check, videoName: name, shortUUID, checkType: 'presence' }) |
143 | } | 143 | } |
144 | }) | 144 | }) |
145 | 145 | ||
@@ -156,16 +156,16 @@ describe('Test notifications API', function () { | |||
156 | expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.EMAIL) | 156 | expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.EMAIL) |
157 | } | 157 | } |
158 | 158 | ||
159 | const { name, uuid } = await server.videos.randomUpload() | 159 | const { name, shortUUID } = await server.videos.randomUpload() |
160 | 160 | ||
161 | { | 161 | { |
162 | const check = { mail: false, web: true } | 162 | const check = { mail: false, web: true } |
163 | await checkNewVideoFromSubscription({ ...baseParams, check }, name, uuid, 'absence') | 163 | await checkNewVideoFromSubscription({ ...baseParams, check, videoName: name, shortUUID, checkType: 'absence' }) |
164 | } | 164 | } |
165 | 165 | ||
166 | { | 166 | { |
167 | const check = { mail: true, web: false } | 167 | const check = { mail: true, web: false } |
168 | await checkNewVideoFromSubscription({ ...baseParams, check }, name, uuid, 'presence') | 168 | await checkNewVideoFromSubscription({ ...baseParams, check, videoName: name, shortUUID, checkType: 'presence' }) |
169 | } | 169 | } |
170 | }) | 170 | }) |
171 | 171 | ||
@@ -187,9 +187,9 @@ describe('Test notifications API', function () { | |||
187 | ) | 187 | ) |
188 | } | 188 | } |
189 | 189 | ||
190 | const { name, uuid } = await server.videos.randomUpload() | 190 | const { name, shortUUID } = await server.videos.randomUpload() |
191 | 191 | ||
192 | await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence') | 192 | await checkNewVideoFromSubscription({ ...baseParams, videoName: name, shortUUID, checkType: 'presence' }) |
193 | }) | 193 | }) |
194 | }) | 194 | }) |
195 | 195 | ||
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 () { | |||
74 | await servers[0].subscriptions.add({ token: userAccessToken, targetUri: 'root_channel@localhost:' + servers[0].port }) | 74 | await servers[0].subscriptions.add({ token: userAccessToken, targetUri: 'root_channel@localhost:' + servers[0].port }) |
75 | await waitJobs(servers) | 75 | await waitJobs(servers) |
76 | 76 | ||
77 | const { name, uuid } = await uploadRandomVideoOnServers(servers, 1) | 77 | const { name, shortUUID } = await uploadRandomVideoOnServers(servers, 1) |
78 | await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence') | 78 | await checkNewVideoFromSubscription({ ...baseParams, videoName: name, shortUUID, checkType: 'presence' }) |
79 | }) | 79 | }) |
80 | 80 | ||
81 | it('Should send a new video notification from a remote account', async function () { | 81 | it('Should send a new video notification from a remote account', async function () { |
@@ -84,8 +84,8 @@ describe('Test user notifications', function () { | |||
84 | await servers[0].subscriptions.add({ token: userAccessToken, targetUri: 'root_channel@localhost:' + servers[1].port }) | 84 | await servers[0].subscriptions.add({ token: userAccessToken, targetUri: 'root_channel@localhost:' + servers[1].port }) |
85 | await waitJobs(servers) | 85 | await waitJobs(servers) |
86 | 86 | ||
87 | const { name, uuid } = await uploadRandomVideoOnServers(servers, 2) | 87 | const { name, shortUUID } = await uploadRandomVideoOnServers(servers, 2) |
88 | await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence') | 88 | await checkNewVideoFromSubscription({ ...baseParams, videoName: name, shortUUID, checkType: 'presence' }) |
89 | }) | 89 | }) |
90 | 90 | ||
91 | it('Should send a new video notification on a scheduled publication', async function () { | 91 | it('Should send a new video notification on a scheduled publication', async function () { |
@@ -101,10 +101,10 @@ describe('Test user notifications', function () { | |||
101 | privacy: VideoPrivacy.PUBLIC as VideoPrivacy.PUBLIC | 101 | privacy: VideoPrivacy.PUBLIC as VideoPrivacy.PUBLIC |
102 | } | 102 | } |
103 | } | 103 | } |
104 | const { name, uuid } = await uploadRandomVideoOnServers(servers, 1, data) | 104 | const { name, shortUUID } = await uploadRandomVideoOnServers(servers, 1, data) |
105 | 105 | ||
106 | await wait(6000) | 106 | await wait(6000) |
107 | await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence') | 107 | await checkNewVideoFromSubscription({ ...baseParams, videoName: name, shortUUID, checkType: 'presence' }) |
108 | }) | 108 | }) |
109 | 109 | ||
110 | it('Should send a new video notification on a remote scheduled publication', async function () { | 110 | it('Should send a new video notification on a remote scheduled publication', async function () { |
@@ -120,11 +120,11 @@ describe('Test user notifications', function () { | |||
120 | privacy: VideoPrivacy.PUBLIC as VideoPrivacy.PUBLIC | 120 | privacy: VideoPrivacy.PUBLIC as VideoPrivacy.PUBLIC |
121 | } | 121 | } |
122 | } | 122 | } |
123 | const { name, uuid } = await uploadRandomVideoOnServers(servers, 2, data) | 123 | const { name, shortUUID } = await uploadRandomVideoOnServers(servers, 2, data) |
124 | await waitJobs(servers) | 124 | await waitJobs(servers) |
125 | 125 | ||
126 | await wait(6000) | 126 | await wait(6000) |
127 | await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence') | 127 | await checkNewVideoFromSubscription({ ...baseParams, videoName: name, shortUUID, checkType: 'presence' }) |
128 | }) | 128 | }) |
129 | 129 | ||
130 | it('Should not send a notification before the video is published', async function () { | 130 | it('Should not send a notification before the video is published', async function () { |
@@ -139,61 +139,61 @@ describe('Test user notifications', function () { | |||
139 | privacy: VideoPrivacy.PUBLIC as VideoPrivacy.PUBLIC | 139 | privacy: VideoPrivacy.PUBLIC as VideoPrivacy.PUBLIC |
140 | } | 140 | } |
141 | } | 141 | } |
142 | const { name, uuid } = await uploadRandomVideoOnServers(servers, 1, data) | 142 | const { name, shortUUID } = await uploadRandomVideoOnServers(servers, 1, data) |
143 | 143 | ||
144 | await wait(6000) | 144 | await wait(6000) |
145 | await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence') | 145 | await checkNewVideoFromSubscription({ ...baseParams, videoName: name, shortUUID, checkType: 'absence' }) |
146 | }) | 146 | }) |
147 | 147 | ||
148 | it('Should send a new video notification when a video becomes public', async function () { | 148 | it('Should send a new video notification when a video becomes public', async function () { |
149 | this.timeout(50000) | 149 | this.timeout(50000) |
150 | 150 | ||
151 | const data = { privacy: VideoPrivacy.PRIVATE } | 151 | const data = { privacy: VideoPrivacy.PRIVATE } |
152 | const { name, uuid } = await uploadRandomVideoOnServers(servers, 1, data) | 152 | const { name, uuid, shortUUID } = await uploadRandomVideoOnServers(servers, 1, data) |
153 | 153 | ||
154 | await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence') | 154 | await checkNewVideoFromSubscription({ ...baseParams, videoName: name, shortUUID, checkType: 'absence' }) |
155 | 155 | ||
156 | await servers[0].videos.update({ id: uuid, attributes: { privacy: VideoPrivacy.PUBLIC } }) | 156 | await servers[0].videos.update({ id: uuid, attributes: { privacy: VideoPrivacy.PUBLIC } }) |
157 | 157 | ||
158 | await waitJobs(servers) | 158 | await waitJobs(servers) |
159 | await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence') | 159 | await checkNewVideoFromSubscription({ ...baseParams, videoName: name, shortUUID, checkType: 'presence' }) |
160 | }) | 160 | }) |
161 | 161 | ||
162 | it('Should send a new video notification when a remote video becomes public', async function () { | 162 | it('Should send a new video notification when a remote video becomes public', async function () { |
163 | this.timeout(50000) | 163 | this.timeout(50000) |
164 | 164 | ||
165 | const data = { privacy: VideoPrivacy.PRIVATE } | 165 | const data = { privacy: VideoPrivacy.PRIVATE } |
166 | const { name, uuid } = await uploadRandomVideoOnServers(servers, 2, data) | 166 | const { name, uuid, shortUUID } = await uploadRandomVideoOnServers(servers, 2, data) |
167 | 167 | ||
168 | await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence') | 168 | await checkNewVideoFromSubscription({ ...baseParams, videoName: name, shortUUID, checkType: 'absence' }) |
169 | 169 | ||
170 | await servers[1].videos.update({ id: uuid, attributes: { privacy: VideoPrivacy.PUBLIC } }) | 170 | await servers[1].videos.update({ id: uuid, attributes: { privacy: VideoPrivacy.PUBLIC } }) |
171 | 171 | ||
172 | await waitJobs(servers) | 172 | await waitJobs(servers) |
173 | await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence') | 173 | await checkNewVideoFromSubscription({ ...baseParams, videoName: name, shortUUID, checkType: 'presence' }) |
174 | }) | 174 | }) |
175 | 175 | ||
176 | it('Should not send a new video notification when a video becomes unlisted', async function () { | 176 | it('Should not send a new video notification when a video becomes unlisted', async function () { |
177 | this.timeout(50000) | 177 | this.timeout(50000) |
178 | 178 | ||
179 | const data = { privacy: VideoPrivacy.PRIVATE } | 179 | const data = { privacy: VideoPrivacy.PRIVATE } |
180 | const { name, uuid } = await uploadRandomVideoOnServers(servers, 1, data) | 180 | const { name, uuid, shortUUID } = await uploadRandomVideoOnServers(servers, 1, data) |
181 | 181 | ||
182 | await servers[0].videos.update({ id: uuid, attributes: { privacy: VideoPrivacy.UNLISTED } }) | 182 | await servers[0].videos.update({ id: uuid, attributes: { privacy: VideoPrivacy.UNLISTED } }) |
183 | 183 | ||
184 | await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence') | 184 | await checkNewVideoFromSubscription({ ...baseParams, videoName: name, shortUUID, checkType: 'absence' }) |
185 | }) | 185 | }) |
186 | 186 | ||
187 | it('Should not send a new video notification when a remote video becomes unlisted', async function () { | 187 | it('Should not send a new video notification when a remote video becomes unlisted', async function () { |
188 | this.timeout(50000) | 188 | this.timeout(50000) |
189 | 189 | ||
190 | const data = { privacy: VideoPrivacy.PRIVATE } | 190 | const data = { privacy: VideoPrivacy.PRIVATE } |
191 | const { name, uuid } = await uploadRandomVideoOnServers(servers, 2, data) | 191 | const { name, uuid, shortUUID } = await uploadRandomVideoOnServers(servers, 2, data) |
192 | 192 | ||
193 | await servers[1].videos.update({ id: uuid, attributes: { privacy: VideoPrivacy.UNLISTED } }) | 193 | await servers[1].videos.update({ id: uuid, attributes: { privacy: VideoPrivacy.UNLISTED } }) |
194 | 194 | ||
195 | await waitJobs(servers) | 195 | await waitJobs(servers) |
196 | await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence') | 196 | await checkNewVideoFromSubscription({ ...baseParams, videoName: name, shortUUID, checkType: 'absence' }) |
197 | }) | 197 | }) |
198 | 198 | ||
199 | it('Should send a new video notification after a video import', async function () { | 199 | it('Should send a new video notification after a video import', async function () { |
@@ -211,7 +211,7 @@ describe('Test user notifications', function () { | |||
211 | 211 | ||
212 | await waitJobs(servers) | 212 | await waitJobs(servers) |
213 | 213 | ||
214 | await checkNewVideoFromSubscription(baseParams, name, video.uuid, 'presence') | 214 | await checkNewVideoFromSubscription({ ...baseParams, videoName: name, shortUUID: video.shortUUID, checkType: 'presence' }) |
215 | }) | 215 | }) |
216 | }) | 216 | }) |
217 | 217 | ||
@@ -230,10 +230,10 @@ describe('Test user notifications', function () { | |||
230 | it('Should not send a notification if transcoding is not enabled', async function () { | 230 | it('Should not send a notification if transcoding is not enabled', async function () { |
231 | this.timeout(50000) | 231 | this.timeout(50000) |
232 | 232 | ||
233 | const { name, uuid } = await uploadRandomVideoOnServers(servers, 1) | 233 | const { name, shortUUID } = await uploadRandomVideoOnServers(servers, 1) |
234 | await waitJobs(servers) | 234 | await waitJobs(servers) |
235 | 235 | ||
236 | await checkVideoIsPublished(baseParams, name, uuid, 'absence') | 236 | await checkVideoIsPublished({ ...baseParams, videoName: name, shortUUID, checkType: 'absence' }) |
237 | }) | 237 | }) |
238 | 238 | ||
239 | it('Should not send a notification if the wait transcoding is false', async function () { | 239 | it('Should not send a notification if the wait transcoding is false', async function () { |
@@ -251,19 +251,19 @@ describe('Test user notifications', function () { | |||
251 | it('Should send a notification even if the video is not transcoded in other resolutions', async function () { | 251 | it('Should send a notification even if the video is not transcoded in other resolutions', async function () { |
252 | this.timeout(50000) | 252 | this.timeout(50000) |
253 | 253 | ||
254 | const { name, uuid } = await uploadRandomVideoOnServers(servers, 2, { waitTranscoding: true, fixture: 'video_short_240p.mp4' }) | 254 | const { name, shortUUID } = await uploadRandomVideoOnServers(servers, 2, { waitTranscoding: true, fixture: 'video_short_240p.mp4' }) |
255 | await waitJobs(servers) | 255 | await waitJobs(servers) |
256 | 256 | ||
257 | await checkVideoIsPublished(baseParams, name, uuid, 'presence') | 257 | await checkVideoIsPublished({ ...baseParams, videoName: name, shortUUID, checkType: 'presence' }) |
258 | }) | 258 | }) |
259 | 259 | ||
260 | it('Should send a notification with a transcoded video', async function () { | 260 | it('Should send a notification with a transcoded video', async function () { |
261 | this.timeout(50000) | 261 | this.timeout(50000) |
262 | 262 | ||
263 | const { name, uuid } = await uploadRandomVideoOnServers(servers, 2, { waitTranscoding: true }) | 263 | const { name, shortUUID } = await uploadRandomVideoOnServers(servers, 2, { waitTranscoding: true }) |
264 | await waitJobs(servers) | 264 | await waitJobs(servers) |
265 | 265 | ||
266 | await checkVideoIsPublished(baseParams, name, uuid, 'presence') | 266 | await checkVideoIsPublished({ ...baseParams, videoName: name, shortUUID, checkType: 'presence' }) |
267 | }) | 267 | }) |
268 | 268 | ||
269 | it('Should send a notification when an imported video is transcoded', async function () { | 269 | it('Should send a notification when an imported video is transcoded', async function () { |
@@ -281,7 +281,7 @@ describe('Test user notifications', function () { | |||
281 | const { video } = await servers[1].imports.importVideo({ attributes }) | 281 | const { video } = await servers[1].imports.importVideo({ attributes }) |
282 | 282 | ||
283 | await waitJobs(servers) | 283 | await waitJobs(servers) |
284 | await checkVideoIsPublished(baseParams, name, video.uuid, 'presence') | 284 | await checkVideoIsPublished({ ...baseParams, videoName: name, shortUUID: video.shortUUID, checkType: 'presence' }) |
285 | }) | 285 | }) |
286 | 286 | ||
287 | it('Should send a notification when the scheduled update has been proceeded', async function () { | 287 | it('Should send a notification when the scheduled update has been proceeded', async function () { |
@@ -297,10 +297,10 @@ describe('Test user notifications', function () { | |||
297 | privacy: VideoPrivacy.PUBLIC as VideoPrivacy.PUBLIC | 297 | privacy: VideoPrivacy.PUBLIC as VideoPrivacy.PUBLIC |
298 | } | 298 | } |
299 | } | 299 | } |
300 | const { name, uuid } = await uploadRandomVideoOnServers(servers, 2, data) | 300 | const { name, shortUUID } = await uploadRandomVideoOnServers(servers, 2, data) |
301 | 301 | ||
302 | await wait(6000) | 302 | await wait(6000) |
303 | await checkVideoIsPublished(baseParams, name, uuid, 'presence') | 303 | await checkVideoIsPublished({ ...baseParams, videoName: name, shortUUID, checkType: 'presence' }) |
304 | }) | 304 | }) |
305 | 305 | ||
306 | it('Should not send a notification before the video is published', async function () { | 306 | it('Should not send a notification before the video is published', async function () { |
@@ -315,10 +315,10 @@ describe('Test user notifications', function () { | |||
315 | privacy: VideoPrivacy.PUBLIC as VideoPrivacy.PUBLIC | 315 | privacy: VideoPrivacy.PUBLIC as VideoPrivacy.PUBLIC |
316 | } | 316 | } |
317 | } | 317 | } |
318 | const { name, uuid } = await uploadRandomVideoOnServers(servers, 2, data) | 318 | const { name, shortUUID } = await uploadRandomVideoOnServers(servers, 2, data) |
319 | 319 | ||
320 | await wait(6000) | 320 | await wait(6000) |
321 | await checkVideoIsPublished(baseParams, name, uuid, 'absence') | 321 | await checkVideoIsPublished({ ...baseParams, videoName: name, shortUUID, checkType: 'absence' }) |
322 | }) | 322 | }) |
323 | }) | 323 | }) |
324 | 324 | ||
@@ -345,10 +345,12 @@ describe('Test user notifications', function () { | |||
345 | privacy: VideoPrivacy.PRIVATE, | 345 | privacy: VideoPrivacy.PRIVATE, |
346 | targetUrl: FIXTURE_URLS.badVideo | 346 | targetUrl: FIXTURE_URLS.badVideo |
347 | } | 347 | } |
348 | const { video } = await servers[0].imports.importVideo({ attributes }) | 348 | const { video: { shortUUID } } = await servers[0].imports.importVideo({ attributes }) |
349 | 349 | ||
350 | await waitJobs(servers) | 350 | await waitJobs(servers) |
351 | await checkMyVideoImportIsFinished(baseParams, name, video.uuid, FIXTURE_URLS.badVideo, false, 'presence') | 351 | |
352 | const url = FIXTURE_URLS.badVideo | ||
353 | await checkMyVideoImportIsFinished({ ...baseParams, videoName: name, shortUUID, url, success: false, checkType: 'presence' }) | ||
352 | }) | 354 | }) |
353 | 355 | ||
354 | it('Should send a notification when the video import succeeded', async function () { | 356 | it('Should send a notification when the video import succeeded', async function () { |
@@ -362,10 +364,12 @@ describe('Test user notifications', function () { | |||
362 | privacy: VideoPrivacy.PRIVATE, | 364 | privacy: VideoPrivacy.PRIVATE, |
363 | targetUrl: FIXTURE_URLS.goodVideo | 365 | targetUrl: FIXTURE_URLS.goodVideo |
364 | } | 366 | } |
365 | const { video } = await servers[0].imports.importVideo({ attributes }) | 367 | const { video: { shortUUID } } = await servers[0].imports.importVideo({ attributes }) |
366 | 368 | ||
367 | await waitJobs(servers) | 369 | await waitJobs(servers) |
368 | await checkMyVideoImportIsFinished(baseParams, name, video.uuid, FIXTURE_URLS.goodVideo, true, 'presence') | 370 | |
371 | const url = FIXTURE_URLS.goodVideo | ||
372 | await checkMyVideoImportIsFinished({ ...baseParams, videoName: name, shortUUID, url, success: true, checkType: 'presence' }) | ||
369 | }) | 373 | }) |
370 | }) | 374 | }) |
371 | 375 | ||
@@ -404,7 +408,14 @@ describe('Test user notifications', function () { | |||
404 | await servers[0].subscriptions.add({ targetUri: 'user_1_channel@localhost:' + servers[0].port }) | 408 | await servers[0].subscriptions.add({ targetUri: 'user_1_channel@localhost:' + servers[0].port }) |
405 | await waitJobs(servers) | 409 | await waitJobs(servers) |
406 | 410 | ||
407 | await checkNewActorFollow(baseParams, 'channel', 'root', 'super root name', myChannelName, 'presence') | 411 | await checkNewActorFollow({ |
412 | ...baseParams, | ||
413 | followType: 'channel', | ||
414 | followerName: 'root', | ||
415 | followerDisplayName: 'super root name', | ||
416 | followingDisplayName: myChannelName, | ||
417 | checkType: 'presence' | ||
418 | }) | ||
408 | 419 | ||
409 | await servers[0].subscriptions.remove({ uri: 'user_1_channel@localhost:' + servers[0].port }) | 420 | await servers[0].subscriptions.remove({ uri: 'user_1_channel@localhost:' + servers[0].port }) |
410 | }) | 421 | }) |
@@ -415,7 +426,14 @@ describe('Test user notifications', function () { | |||
415 | await servers[1].subscriptions.add({ targetUri: 'user_1_channel@localhost:' + servers[0].port }) | 426 | await servers[1].subscriptions.add({ targetUri: 'user_1_channel@localhost:' + servers[0].port }) |
416 | await waitJobs(servers) | 427 | await waitJobs(servers) |
417 | 428 | ||
418 | await checkNewActorFollow(baseParams, 'channel', 'root', 'super root 2 name', myChannelName, 'presence') | 429 | await checkNewActorFollow({ |
430 | ...baseParams, | ||
431 | followType: 'channel', | ||
432 | followerName: 'root', | ||
433 | followerDisplayName: 'super root 2 name', | ||
434 | followingDisplayName: myChannelName, | ||
435 | checkType: 'presence' | ||
436 | }) | ||
419 | 437 | ||
420 | await servers[1].subscriptions.remove({ uri: 'user_1_channel@localhost:' + servers[0].port }) | 438 | await servers[1].subscriptions.remove({ uri: 'user_1_channel@localhost:' + servers[0].port }) |
421 | }) | 439 | }) |
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' | |||
5 | import { | 5 | import { |
6 | cleanupTests, | 6 | cleanupTests, |
7 | createSingleServer, | 7 | createSingleServer, |
8 | doubleFollow, | ||
8 | PeerTubeServer, | 9 | PeerTubeServer, |
9 | SearchCommand, | 10 | SearchCommand, |
10 | setAccessTokensToServers, | 11 | setAccessTokensToServers, |
@@ -17,19 +18,21 @@ import { VideoPrivacy } from '@shared/models' | |||
17 | const expect = chai.expect | 18 | const expect = chai.expect |
18 | 19 | ||
19 | describe('Test videos search', function () { | 20 | describe('Test videos search', function () { |
20 | let server: PeerTubeServer = null | 21 | let server: PeerTubeServer |
22 | let remoteServer: PeerTubeServer | ||
21 | let startDate: string | 23 | let startDate: string |
22 | let videoUUID: string | 24 | let videoUUID: string |
23 | 25 | ||
24 | let command: SearchCommand | 26 | let command: SearchCommand |
25 | 27 | ||
26 | before(async function () { | 28 | before(async function () { |
27 | this.timeout(60000) | 29 | this.timeout(120000) |
28 | 30 | ||
29 | server = await createSingleServer(1) | 31 | server = await createSingleServer(1) |
32 | remoteServer = await createSingleServer(2) | ||
30 | 33 | ||
31 | await setAccessTokensToServers([ server ]) | 34 | await setAccessTokensToServers([ server, remoteServer ]) |
32 | await setDefaultVideoChannel([ server ]) | 35 | await setDefaultVideoChannel([ server, remoteServer ]) |
33 | 36 | ||
34 | { | 37 | { |
35 | const attributes1 = { | 38 | const attributes1 = { |
@@ -131,6 +134,13 @@ describe('Test videos search', function () { | |||
131 | await server.videos.upload({ attributes: { ...attributes1, category: 2 } }) | 134 | await server.videos.upload({ attributes: { ...attributes1, category: 2 } }) |
132 | } | 135 | } |
133 | 136 | ||
137 | { | ||
138 | await remoteServer.videos.upload({ attributes: { name: 'remote video 1' } }) | ||
139 | await remoteServer.videos.upload({ attributes: { name: 'remote video 2' } }) | ||
140 | } | ||
141 | |||
142 | await doubleFollow(server, remoteServer) | ||
143 | |||
134 | command = server.search | 144 | command = server.search |
135 | }) | 145 | }) |
136 | 146 | ||
@@ -469,8 +479,30 @@ describe('Test videos search', function () { | |||
469 | expect(body.data[0].name).to.equal('1111 2222 3333 - 3') | 479 | expect(body.data[0].name).to.equal('1111 2222 3333 - 3') |
470 | }) | 480 | }) |
471 | 481 | ||
482 | it('Should search by host', async function () { | ||
483 | { | ||
484 | const body = await command.advancedVideoSearch({ search: { search: '6666 7777 8888', host: server.host } }) | ||
485 | expect(body.total).to.equal(1) | ||
486 | expect(body.data[0].name).to.equal('6666 7777 8888') | ||
487 | } | ||
488 | |||
489 | { | ||
490 | const body = await command.advancedVideoSearch({ search: { search: '1111', host: 'example.com' } }) | ||
491 | expect(body.total).to.equal(0) | ||
492 | expect(body.data).to.have.lengthOf(0) | ||
493 | } | ||
494 | |||
495 | { | ||
496 | const body = await command.advancedVideoSearch({ search: { search: 'remote', host: remoteServer.host } }) | ||
497 | expect(body.total).to.equal(2) | ||
498 | expect(body.data).to.have.lengthOf(2) | ||
499 | expect(body.data[0].name).to.equal('remote video 1') | ||
500 | expect(body.data[1].name).to.equal('remote video 2') | ||
501 | } | ||
502 | }) | ||
503 | |||
472 | it('Should search by live', async function () { | 504 | it('Should search by live', async function () { |
473 | this.timeout(30000) | 505 | this.timeout(60000) |
474 | 506 | ||
475 | { | 507 | { |
476 | const newConfig = { | 508 | 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 () { | |||
13 | let userId2: number | 13 | let userId2: number |
14 | let userAccessToken: string | 14 | let userAccessToken: string |
15 | 15 | ||
16 | let videoUUID: string | 16 | let videoShortUUID: string |
17 | let videoId: number | 17 | let videoId: number |
18 | 18 | ||
19 | let videoUserUUID: string | 19 | let videoUserUUID: string |
@@ -59,8 +59,8 @@ describe('Test emails', function () { | |||
59 | const attributes = { | 59 | const attributes = { |
60 | name: 'my super name' | 60 | name: 'my super name' |
61 | } | 61 | } |
62 | const { uuid, id } = await server.videos.upload({ attributes }) | 62 | const { shortUUID, id } = await server.videos.upload({ attributes }) |
63 | videoUUID = uuid | 63 | videoShortUUID = shortUUID |
64 | videoId = id | 64 | videoId = id |
65 | } | 65 | } |
66 | }) | 66 | }) |
@@ -180,6 +180,7 @@ describe('Test emails', function () { | |||
180 | }) | 180 | }) |
181 | 181 | ||
182 | describe('When creating an abuse', function () { | 182 | describe('When creating an abuse', function () { |
183 | |||
183 | it('Should send the notification email', async function () { | 184 | it('Should send the notification email', async function () { |
184 | this.timeout(10000) | 185 | this.timeout(10000) |
185 | 186 | ||
@@ -195,7 +196,7 @@ describe('Test emails', function () { | |||
195 | expect(email['from'][0]['address']).equal('test-admin@localhost') | 196 | expect(email['from'][0]['address']).equal('test-admin@localhost') |
196 | expect(email['to'][0]['address']).equal('admin' + server.internalServerNumber + '@example.com') | 197 | expect(email['to'][0]['address']).equal('admin' + server.internalServerNumber + '@example.com') |
197 | expect(email['subject']).contains('abuse') | 198 | expect(email['subject']).contains('abuse') |
198 | expect(email['text']).contains(videoUUID) | 199 | expect(email['text']).contains(videoShortUUID) |
199 | }) | 200 | }) |
200 | }) | 201 | }) |
201 | 202 | ||
diff --git a/shared/extra-utils/users/notifications.ts b/shared/extra-utils/users/notifications.ts index 4c42fad3e..7db4bfd3f 100644 --- a/shared/extra-utils/users/notifications.ts +++ b/shared/extra-utils/users/notifications.ts | |||
@@ -10,6 +10,16 @@ import { doubleFollow } from '../server/follows' | |||
10 | import { createMultipleServers } from '../server/servers' | 10 | import { createMultipleServers } from '../server/servers' |
11 | import { setAccessTokensToServers } from './login' | 11 | import { setAccessTokensToServers } from './login' |
12 | 12 | ||
13 | type CheckerBaseParams = { | ||
14 | server: PeerTubeServer | ||
15 | emails: any[] | ||
16 | socketNotifications: UserNotification[] | ||
17 | token: string | ||
18 | check?: { web: boolean, mail: boolean } | ||
19 | } | ||
20 | |||
21 | type CheckerType = 'presence' | 'absence' | ||
22 | |||
13 | function getAllNotificationsSettings (): UserNotificationSetting { | 23 | function getAllNotificationsSettings (): UserNotificationSetting { |
14 | return { | 24 | return { |
15 | newVideoFromSubscription: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, | 25 | newVideoFromSubscription: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, |
@@ -31,101 +41,20 @@ function getAllNotificationsSettings (): UserNotificationSetting { | |||
31 | } | 41 | } |
32 | } | 42 | } |
33 | 43 | ||
34 | type CheckerBaseParams = { | 44 | async function checkNewVideoFromSubscription (options: CheckerBaseParams & { |
35 | server: PeerTubeServer | 45 | videoName: string |
36 | emails: any[] | 46 | shortUUID: string |
37 | socketNotifications: UserNotification[] | ||
38 | token: string | ||
39 | check?: { web: boolean, mail: boolean } | ||
40 | } | ||
41 | |||
42 | type CheckerType = 'presence' | 'absence' | ||
43 | |||
44 | async function checkNotification ( | ||
45 | base: CheckerBaseParams, | ||
46 | notificationChecker: (notification: UserNotification, type: CheckerType) => void, | ||
47 | emailNotificationFinder: (email: object) => boolean, | ||
48 | checkType: CheckerType | 47 | checkType: CheckerType |
49 | ) { | 48 | }) { |
50 | const check = base.check || { web: true, mail: true } | 49 | const { videoName, shortUUID } = options |
51 | |||
52 | if (check.web) { | ||
53 | const notification = await base.server.notifications.getLastest({ token: base.token }) | ||
54 | |||
55 | if (notification || checkType !== 'absence') { | ||
56 | notificationChecker(notification, checkType) | ||
57 | } | ||
58 | |||
59 | const socketNotification = base.socketNotifications.find(n => { | ||
60 | try { | ||
61 | notificationChecker(n, 'presence') | ||
62 | return true | ||
63 | } catch { | ||
64 | return false | ||
65 | } | ||
66 | }) | ||
67 | |||
68 | if (checkType === 'presence') { | ||
69 | const obj = inspect(base.socketNotifications, { depth: 5 }) | ||
70 | expect(socketNotification, 'The socket notification is absent when it should be present. ' + obj).to.not.be.undefined | ||
71 | } else { | ||
72 | const obj = inspect(socketNotification, { depth: 5 }) | ||
73 | expect(socketNotification, 'The socket notification is present when it should not be present. ' + obj).to.be.undefined | ||
74 | } | ||
75 | } | ||
76 | |||
77 | if (check.mail) { | ||
78 | // Last email | ||
79 | const email = base.emails | ||
80 | .slice() | ||
81 | .reverse() | ||
82 | .find(e => emailNotificationFinder(e)) | ||
83 | |||
84 | if (checkType === 'presence') { | ||
85 | const emails = base.emails.map(e => e.text) | ||
86 | expect(email, 'The email is absent when is should be present. ' + inspect(emails)).to.not.be.undefined | ||
87 | } else { | ||
88 | expect(email, 'The email is present when is should not be present. ' + inspect(email)).to.be.undefined | ||
89 | } | ||
90 | } | ||
91 | } | ||
92 | |||
93 | function checkVideo (video: any, videoName?: string, videoUUID?: string) { | ||
94 | if (videoName) { | ||
95 | expect(video.name).to.be.a('string') | ||
96 | expect(video.name).to.not.be.empty | ||
97 | expect(video.name).to.equal(videoName) | ||
98 | } | ||
99 | |||
100 | if (videoUUID) { | ||
101 | expect(video.uuid).to.be.a('string') | ||
102 | expect(video.uuid).to.not.be.empty | ||
103 | expect(video.uuid).to.equal(videoUUID) | ||
104 | } | ||
105 | |||
106 | expect(video.id).to.be.a('number') | ||
107 | } | ||
108 | |||
109 | function checkActor (actor: any) { | ||
110 | expect(actor.displayName).to.be.a('string') | ||
111 | expect(actor.displayName).to.not.be.empty | ||
112 | expect(actor.host).to.not.be.undefined | ||
113 | } | ||
114 | |||
115 | function checkComment (comment: any, commentId: number, threadId: number) { | ||
116 | expect(comment.id).to.equal(commentId) | ||
117 | expect(comment.threadId).to.equal(threadId) | ||
118 | } | ||
119 | |||
120 | async function checkNewVideoFromSubscription (base: CheckerBaseParams, videoName: string, videoUUID: string, type: CheckerType) { | ||
121 | const notificationType = UserNotificationType.NEW_VIDEO_FROM_SUBSCRIPTION | 50 | const notificationType = UserNotificationType.NEW_VIDEO_FROM_SUBSCRIPTION |
122 | 51 | ||
123 | function notificationChecker (notification: UserNotification, type: CheckerType) { | 52 | function notificationChecker (notification: UserNotification, checkType: CheckerType) { |
124 | if (type === 'presence') { | 53 | if (checkType === 'presence') { |
125 | expect(notification).to.not.be.undefined | 54 | expect(notification).to.not.be.undefined |
126 | expect(notification.type).to.equal(notificationType) | 55 | expect(notification.type).to.equal(notificationType) |
127 | 56 | ||
128 | checkVideo(notification.video, videoName, videoUUID) | 57 | checkVideo(notification.video, videoName, shortUUID) |
129 | checkActor(notification.video.channel) | 58 | checkActor(notification.video.channel) |
130 | } else { | 59 | } else { |
131 | expect(notification).to.satisfy((n: UserNotification) => { | 60 | expect(notification).to.satisfy((n: UserNotification) => { |
@@ -136,21 +65,26 @@ async function checkNewVideoFromSubscription (base: CheckerBaseParams, videoName | |||
136 | 65 | ||
137 | function emailNotificationFinder (email: object) { | 66 | function emailNotificationFinder (email: object) { |
138 | const text = email['text'] | 67 | const text = email['text'] |
139 | return text.indexOf(videoUUID) !== -1 && text.indexOf('Your subscription') !== -1 | 68 | return text.indexOf(shortUUID) !== -1 && text.indexOf('Your subscription') !== -1 |
140 | } | 69 | } |
141 | 70 | ||
142 | await checkNotification(base, notificationChecker, emailNotificationFinder, type) | 71 | await checkNotification({ ...options, notificationChecker, emailNotificationFinder }) |
143 | } | 72 | } |
144 | 73 | ||
145 | async function checkVideoIsPublished (base: CheckerBaseParams, videoName: string, videoUUID: string, type: CheckerType) { | 74 | async function checkVideoIsPublished (options: CheckerBaseParams & { |
75 | videoName: string | ||
76 | shortUUID: string | ||
77 | checkType: CheckerType | ||
78 | }) { | ||
79 | const { videoName, shortUUID } = options | ||
146 | const notificationType = UserNotificationType.MY_VIDEO_PUBLISHED | 80 | const notificationType = UserNotificationType.MY_VIDEO_PUBLISHED |
147 | 81 | ||
148 | function notificationChecker (notification: UserNotification, type: CheckerType) { | 82 | function notificationChecker (notification: UserNotification, checkType: CheckerType) { |
149 | if (type === 'presence') { | 83 | if (checkType === 'presence') { |
150 | expect(notification).to.not.be.undefined | 84 | expect(notification).to.not.be.undefined |
151 | expect(notification.type).to.equal(notificationType) | 85 | expect(notification.type).to.equal(notificationType) |
152 | 86 | ||
153 | checkVideo(notification.video, videoName, videoUUID) | 87 | checkVideo(notification.video, videoName, shortUUID) |
154 | checkActor(notification.video.channel) | 88 | checkActor(notification.video.channel) |
155 | } else { | 89 | } else { |
156 | expect(notification.video).to.satisfy(v => v === undefined || v.name !== videoName) | 90 | expect(notification.video).to.satisfy(v => v === undefined || v.name !== videoName) |
@@ -159,30 +93,31 @@ async function checkVideoIsPublished (base: CheckerBaseParams, videoName: string | |||
159 | 93 | ||
160 | function emailNotificationFinder (email: object) { | 94 | function emailNotificationFinder (email: object) { |
161 | const text: string = email['text'] | 95 | const text: string = email['text'] |
162 | return text.includes(videoUUID) && text.includes('Your video') | 96 | return text.includes(shortUUID) && text.includes('Your video') |
163 | } | 97 | } |
164 | 98 | ||
165 | await checkNotification(base, notificationChecker, emailNotificationFinder, type) | 99 | await checkNotification({ ...options, notificationChecker, emailNotificationFinder }) |
166 | } | 100 | } |
167 | 101 | ||
168 | async function checkMyVideoImportIsFinished ( | 102 | async function checkMyVideoImportIsFinished (options: CheckerBaseParams & { |
169 | base: CheckerBaseParams, | 103 | videoName: string |
170 | videoName: string, | 104 | shortUUID: string |
171 | videoUUID: string, | 105 | url: string |
172 | url: string, | 106 | success: boolean |
173 | success: boolean, | 107 | checkType: CheckerType |
174 | type: CheckerType | 108 | }) { |
175 | ) { | 109 | const { videoName, shortUUID, url, success } = options |
110 | |||
176 | const notificationType = success ? UserNotificationType.MY_VIDEO_IMPORT_SUCCESS : UserNotificationType.MY_VIDEO_IMPORT_ERROR | 111 | const notificationType = success ? UserNotificationType.MY_VIDEO_IMPORT_SUCCESS : UserNotificationType.MY_VIDEO_IMPORT_ERROR |
177 | 112 | ||
178 | function notificationChecker (notification: UserNotification, type: CheckerType) { | 113 | function notificationChecker (notification: UserNotification, checkType: CheckerType) { |
179 | if (type === 'presence') { | 114 | if (checkType === 'presence') { |
180 | expect(notification).to.not.be.undefined | 115 | expect(notification).to.not.be.undefined |
181 | expect(notification.type).to.equal(notificationType) | 116 | expect(notification.type).to.equal(notificationType) |
182 | 117 | ||
183 | expect(notification.videoImport.targetUrl).to.equal(url) | 118 | expect(notification.videoImport.targetUrl).to.equal(url) |
184 | 119 | ||
185 | if (success) checkVideo(notification.videoImport.video, videoName, videoUUID) | 120 | if (success) checkVideo(notification.videoImport.video, videoName, shortUUID) |
186 | } else { | 121 | } else { |
187 | expect(notification.videoImport).to.satisfy(i => i === undefined || i.targetUrl !== url) | 122 | expect(notification.videoImport).to.satisfy(i => i === undefined || i.targetUrl !== url) |
188 | } | 123 | } |
@@ -195,14 +130,18 @@ async function checkMyVideoImportIsFinished ( | |||
195 | return text.includes(url) && text.includes(toFind) | 130 | return text.includes(url) && text.includes(toFind) |
196 | } | 131 | } |
197 | 132 | ||
198 | await checkNotification(base, notificationChecker, emailNotificationFinder, type) | 133 | await checkNotification({ ...options, notificationChecker, emailNotificationFinder }) |
199 | } | 134 | } |
200 | 135 | ||
201 | async function checkUserRegistered (base: CheckerBaseParams, username: string, type: CheckerType) { | 136 | async function checkUserRegistered (options: CheckerBaseParams & { |
137 | username: string | ||
138 | checkType: CheckerType | ||
139 | }) { | ||
140 | const { username } = options | ||
202 | const notificationType = UserNotificationType.NEW_USER_REGISTRATION | 141 | const notificationType = UserNotificationType.NEW_USER_REGISTRATION |
203 | 142 | ||
204 | function notificationChecker (notification: UserNotification, type: CheckerType) { | 143 | function notificationChecker (notification: UserNotification, checkType: CheckerType) { |
205 | if (type === 'presence') { | 144 | if (checkType === 'presence') { |
206 | expect(notification).to.not.be.undefined | 145 | expect(notification).to.not.be.undefined |
207 | expect(notification.type).to.equal(notificationType) | 146 | expect(notification.type).to.equal(notificationType) |
208 | 147 | ||
@@ -219,21 +158,21 @@ async function checkUserRegistered (base: CheckerBaseParams, username: string, t | |||
219 | return text.includes(' registered.') && text.includes(username) | 158 | return text.includes(' registered.') && text.includes(username) |
220 | } | 159 | } |
221 | 160 | ||
222 | await checkNotification(base, notificationChecker, emailNotificationFinder, type) | 161 | await checkNotification({ ...options, notificationChecker, emailNotificationFinder }) |
223 | } | 162 | } |
224 | 163 | ||
225 | async function checkNewActorFollow ( | 164 | async function checkNewActorFollow (options: CheckerBaseParams & { |
226 | base: CheckerBaseParams, | 165 | followType: 'channel' | 'account' |
227 | followType: 'channel' | 'account', | 166 | followerName: string |
228 | followerName: string, | 167 | followerDisplayName: string |
229 | followerDisplayName: string, | 168 | followingDisplayName: string |
230 | followingDisplayName: string, | 169 | checkType: CheckerType |
231 | type: CheckerType | 170 | }) { |
232 | ) { | 171 | const { followType, followerName, followerDisplayName, followingDisplayName } = options |
233 | const notificationType = UserNotificationType.NEW_FOLLOW | 172 | const notificationType = UserNotificationType.NEW_FOLLOW |
234 | 173 | ||
235 | function notificationChecker (notification: UserNotification, type: CheckerType) { | 174 | function notificationChecker (notification: UserNotification, checkType: CheckerType) { |
236 | if (type === 'presence') { | 175 | if (checkType === 'presence') { |
237 | expect(notification).to.not.be.undefined | 176 | expect(notification).to.not.be.undefined |
238 | expect(notification.type).to.equal(notificationType) | 177 | expect(notification.type).to.equal(notificationType) |
239 | 178 | ||
@@ -259,14 +198,18 @@ async function checkNewActorFollow ( | |||
259 | return text.includes(followType) && text.includes(followingDisplayName) && text.includes(followerDisplayName) | 198 | return text.includes(followType) && text.includes(followingDisplayName) && text.includes(followerDisplayName) |
260 | } | 199 | } |
261 | 200 | ||
262 | await checkNotification(base, notificationChecker, emailNotificationFinder, type) | 201 | await checkNotification({ ...options, notificationChecker, emailNotificationFinder }) |
263 | } | 202 | } |
264 | 203 | ||
265 | async function checkNewInstanceFollower (base: CheckerBaseParams, followerHost: string, type: CheckerType) { | 204 | async function checkNewInstanceFollower (options: CheckerBaseParams & { |
205 | followerHost: string | ||
206 | checkType: CheckerType | ||
207 | }) { | ||
208 | const { followerHost } = options | ||
266 | const notificationType = UserNotificationType.NEW_INSTANCE_FOLLOWER | 209 | const notificationType = UserNotificationType.NEW_INSTANCE_FOLLOWER |
267 | 210 | ||
268 | function notificationChecker (notification: UserNotification, type: CheckerType) { | 211 | function notificationChecker (notification: UserNotification, checkType: CheckerType) { |
269 | if (type === 'presence') { | 212 | if (checkType === 'presence') { |
270 | expect(notification).to.not.be.undefined | 213 | expect(notification).to.not.be.undefined |
271 | expect(notification.type).to.equal(notificationType) | 214 | expect(notification.type).to.equal(notificationType) |
272 | 215 | ||
@@ -288,14 +231,19 @@ async function checkNewInstanceFollower (base: CheckerBaseParams, followerHost: | |||
288 | return text.includes('instance has a new follower') && text.includes(followerHost) | 231 | return text.includes('instance has a new follower') && text.includes(followerHost) |
289 | } | 232 | } |
290 | 233 | ||
291 | await checkNotification(base, notificationChecker, emailNotificationFinder, type) | 234 | await checkNotification({ ...options, notificationChecker, emailNotificationFinder }) |
292 | } | 235 | } |
293 | 236 | ||
294 | async function checkAutoInstanceFollowing (base: CheckerBaseParams, followerHost: string, followingHost: string, type: CheckerType) { | 237 | async function checkAutoInstanceFollowing (options: CheckerBaseParams & { |
238 | followerHost: string | ||
239 | followingHost: string | ||
240 | checkType: CheckerType | ||
241 | }) { | ||
242 | const { followerHost, followingHost } = options | ||
295 | const notificationType = UserNotificationType.AUTO_INSTANCE_FOLLOWING | 243 | const notificationType = UserNotificationType.AUTO_INSTANCE_FOLLOWING |
296 | 244 | ||
297 | function notificationChecker (notification: UserNotification, type: CheckerType) { | 245 | function notificationChecker (notification: UserNotification, checkType: CheckerType) { |
298 | if (type === 'presence') { | 246 | if (checkType === 'presence') { |
299 | expect(notification).to.not.be.undefined | 247 | expect(notification).to.not.be.undefined |
300 | expect(notification.type).to.equal(notificationType) | 248 | expect(notification.type).to.equal(notificationType) |
301 | 249 | ||
@@ -319,21 +267,21 @@ async function checkAutoInstanceFollowing (base: CheckerBaseParams, followerHost | |||
319 | return text.includes(' automatically followed a new instance') && text.includes(followingHost) | 267 | return text.includes(' automatically followed a new instance') && text.includes(followingHost) |
320 | } | 268 | } |
321 | 269 | ||
322 | await checkNotification(base, notificationChecker, emailNotificationFinder, type) | 270 | await checkNotification({ ...options, notificationChecker, emailNotificationFinder }) |
323 | } | 271 | } |
324 | 272 | ||
325 | async function checkCommentMention ( | 273 | async function checkCommentMention (options: CheckerBaseParams & { |
326 | base: CheckerBaseParams, | 274 | shortUUID: string |
327 | uuid: string, | 275 | commentId: number |
328 | commentId: number, | 276 | threadId: number |
329 | threadId: number, | 277 | byAccountDisplayName: string |
330 | byAccountDisplayName: string, | 278 | checkType: CheckerType |
331 | type: CheckerType | 279 | }) { |
332 | ) { | 280 | const { shortUUID, commentId, threadId, byAccountDisplayName } = options |
333 | const notificationType = UserNotificationType.COMMENT_MENTION | 281 | const notificationType = UserNotificationType.COMMENT_MENTION |
334 | 282 | ||
335 | function notificationChecker (notification: UserNotification, type: CheckerType) { | 283 | function notificationChecker (notification: UserNotification, checkType: CheckerType) { |
336 | if (type === 'presence') { | 284 | if (checkType === 'presence') { |
337 | expect(notification).to.not.be.undefined | 285 | expect(notification).to.not.be.undefined |
338 | expect(notification.type).to.equal(notificationType) | 286 | expect(notification.type).to.equal(notificationType) |
339 | 287 | ||
@@ -341,7 +289,7 @@ async function checkCommentMention ( | |||
341 | checkActor(notification.comment.account) | 289 | checkActor(notification.comment.account) |
342 | expect(notification.comment.account.displayName).to.equal(byAccountDisplayName) | 290 | expect(notification.comment.account.displayName).to.equal(byAccountDisplayName) |
343 | 291 | ||
344 | checkVideo(notification.comment.video, undefined, uuid) | 292 | checkVideo(notification.comment.video, undefined, shortUUID) |
345 | } else { | 293 | } else { |
346 | expect(notification).to.satisfy(n => n.type !== notificationType || n.comment.id !== commentId) | 294 | expect(notification).to.satisfy(n => n.type !== notificationType || n.comment.id !== commentId) |
347 | } | 295 | } |
@@ -350,25 +298,31 @@ async function checkCommentMention ( | |||
350 | function emailNotificationFinder (email: object) { | 298 | function emailNotificationFinder (email: object) { |
351 | const text: string = email['text'] | 299 | const text: string = email['text'] |
352 | 300 | ||
353 | return text.includes(' mentioned ') && text.includes(uuid) && text.includes(byAccountDisplayName) | 301 | return text.includes(' mentioned ') && text.includes(shortUUID) && text.includes(byAccountDisplayName) |
354 | } | 302 | } |
355 | 303 | ||
356 | await checkNotification(base, notificationChecker, emailNotificationFinder, type) | 304 | await checkNotification({ ...options, notificationChecker, emailNotificationFinder }) |
357 | } | 305 | } |
358 | 306 | ||
359 | let lastEmailCount = 0 | 307 | let lastEmailCount = 0 |
360 | 308 | ||
361 | async function checkNewCommentOnMyVideo (base: CheckerBaseParams, uuid: string, commentId: number, threadId: number, type: CheckerType) { | 309 | async function checkNewCommentOnMyVideo (options: CheckerBaseParams & { |
310 | shortUUID: string | ||
311 | commentId: number | ||
312 | threadId: number | ||
313 | checkType: CheckerType | ||
314 | }) { | ||
315 | const { server, shortUUID, commentId, threadId, checkType, emails } = options | ||
362 | const notificationType = UserNotificationType.NEW_COMMENT_ON_MY_VIDEO | 316 | const notificationType = UserNotificationType.NEW_COMMENT_ON_MY_VIDEO |
363 | 317 | ||
364 | function notificationChecker (notification: UserNotification, type: CheckerType) { | 318 | function notificationChecker (notification: UserNotification, checkType: CheckerType) { |
365 | if (type === 'presence') { | 319 | if (checkType === 'presence') { |
366 | expect(notification).to.not.be.undefined | 320 | expect(notification).to.not.be.undefined |
367 | expect(notification.type).to.equal(notificationType) | 321 | expect(notification.type).to.equal(notificationType) |
368 | 322 | ||
369 | checkComment(notification.comment, commentId, threadId) | 323 | checkComment(notification.comment, commentId, threadId) |
370 | checkActor(notification.comment.account) | 324 | checkActor(notification.comment.account) |
371 | checkVideo(notification.comment.video, undefined, uuid) | 325 | checkVideo(notification.comment.video, undefined, shortUUID) |
372 | } else { | 326 | } else { |
373 | expect(notification).to.satisfy((n: UserNotification) => { | 327 | expect(notification).to.satisfy((n: UserNotification) => { |
374 | return n === undefined || n.comment === undefined || n.comment.id !== commentId | 328 | return n === undefined || n.comment === undefined || n.comment.id !== commentId |
@@ -376,51 +330,62 @@ async function checkNewCommentOnMyVideo (base: CheckerBaseParams, uuid: string, | |||
376 | } | 330 | } |
377 | } | 331 | } |
378 | 332 | ||
379 | const commentUrl = `http://localhost:${base.server.port}/w/${uuid};threadId=${threadId}` | 333 | const commentUrl = `http://localhost:${server.port}/w/${shortUUID};threadId=${threadId}` |
380 | 334 | ||
381 | function emailNotificationFinder (email: object) { | 335 | function emailNotificationFinder (email: object) { |
382 | return email['text'].indexOf(commentUrl) !== -1 | 336 | return email['text'].indexOf(commentUrl) !== -1 |
383 | } | 337 | } |
384 | 338 | ||
385 | await checkNotification(base, notificationChecker, emailNotificationFinder, type) | 339 | await checkNotification({ ...options, notificationChecker, emailNotificationFinder }) |
386 | 340 | ||
387 | if (type === 'presence') { | 341 | if (checkType === 'presence') { |
388 | // We cannot detect email duplicates, so check we received another email | 342 | // We cannot detect email duplicates, so check we received another email |
389 | expect(base.emails).to.have.length.above(lastEmailCount) | 343 | expect(emails).to.have.length.above(lastEmailCount) |
390 | lastEmailCount = base.emails.length | 344 | lastEmailCount = emails.length |
391 | } | 345 | } |
392 | } | 346 | } |
393 | 347 | ||
394 | async function checkNewVideoAbuseForModerators (base: CheckerBaseParams, videoUUID: string, videoName: string, type: CheckerType) { | 348 | async function checkNewVideoAbuseForModerators (options: CheckerBaseParams & { |
349 | shortUUID: string | ||
350 | videoName: string | ||
351 | checkType: CheckerType | ||
352 | }) { | ||
353 | const { shortUUID, videoName } = options | ||
395 | const notificationType = UserNotificationType.NEW_ABUSE_FOR_MODERATORS | 354 | const notificationType = UserNotificationType.NEW_ABUSE_FOR_MODERATORS |
396 | 355 | ||
397 | function notificationChecker (notification: UserNotification, type: CheckerType) { | 356 | function notificationChecker (notification: UserNotification, checkType: CheckerType) { |
398 | if (type === 'presence') { | 357 | if (checkType === 'presence') { |
399 | expect(notification).to.not.be.undefined | 358 | expect(notification).to.not.be.undefined |
400 | expect(notification.type).to.equal(notificationType) | 359 | expect(notification.type).to.equal(notificationType) |
401 | 360 | ||
402 | expect(notification.abuse.id).to.be.a('number') | 361 | expect(notification.abuse.id).to.be.a('number') |
403 | checkVideo(notification.abuse.video, videoName, videoUUID) | 362 | checkVideo(notification.abuse.video, videoName, shortUUID) |
404 | } else { | 363 | } else { |
405 | expect(notification).to.satisfy((n: UserNotification) => { | 364 | expect(notification).to.satisfy((n: UserNotification) => { |
406 | return n === undefined || n.abuse === undefined || n.abuse.video.uuid !== videoUUID | 365 | return n === undefined || n.abuse === undefined || n.abuse.video.shortUUID !== shortUUID |
407 | }) | 366 | }) |
408 | } | 367 | } |
409 | } | 368 | } |
410 | 369 | ||
411 | function emailNotificationFinder (email: object) { | 370 | function emailNotificationFinder (email: object) { |
412 | const text = email['text'] | 371 | const text = email['text'] |
413 | return text.indexOf(videoUUID) !== -1 && text.indexOf('abuse') !== -1 | 372 | return text.indexOf(shortUUID) !== -1 && text.indexOf('abuse') !== -1 |
414 | } | 373 | } |
415 | 374 | ||
416 | await checkNotification(base, notificationChecker, emailNotificationFinder, type) | 375 | await checkNotification({ ...options, notificationChecker, emailNotificationFinder }) |
417 | } | 376 | } |
418 | 377 | ||
419 | async function checkNewAbuseMessage (base: CheckerBaseParams, abuseId: number, message: string, toEmail: string, type: CheckerType) { | 378 | async function checkNewAbuseMessage (options: CheckerBaseParams & { |
379 | abuseId: number | ||
380 | message: string | ||
381 | toEmail: string | ||
382 | checkType: CheckerType | ||
383 | }) { | ||
384 | const { abuseId, message, toEmail } = options | ||
420 | const notificationType = UserNotificationType.ABUSE_NEW_MESSAGE | 385 | const notificationType = UserNotificationType.ABUSE_NEW_MESSAGE |
421 | 386 | ||
422 | function notificationChecker (notification: UserNotification, type: CheckerType) { | 387 | function notificationChecker (notification: UserNotification, checkType: CheckerType) { |
423 | if (type === 'presence') { | 388 | if (checkType === 'presence') { |
424 | expect(notification).to.not.be.undefined | 389 | expect(notification).to.not.be.undefined |
425 | expect(notification.type).to.equal(notificationType) | 390 | expect(notification.type).to.equal(notificationType) |
426 | 391 | ||
@@ -439,14 +404,19 @@ async function checkNewAbuseMessage (base: CheckerBaseParams, abuseId: number, m | |||
439 | return text.indexOf(message) !== -1 && to.length !== 0 | 404 | return text.indexOf(message) !== -1 && to.length !== 0 |
440 | } | 405 | } |
441 | 406 | ||
442 | await checkNotification(base, notificationChecker, emailNotificationFinder, type) | 407 | await checkNotification({ ...options, notificationChecker, emailNotificationFinder }) |
443 | } | 408 | } |
444 | 409 | ||
445 | async function checkAbuseStateChange (base: CheckerBaseParams, abuseId: number, state: AbuseState, type: CheckerType) { | 410 | async function checkAbuseStateChange (options: CheckerBaseParams & { |
411 | abuseId: number | ||
412 | state: AbuseState | ||
413 | checkType: CheckerType | ||
414 | }) { | ||
415 | const { abuseId, state } = options | ||
446 | const notificationType = UserNotificationType.ABUSE_STATE_CHANGE | 416 | const notificationType = UserNotificationType.ABUSE_STATE_CHANGE |
447 | 417 | ||
448 | function notificationChecker (notification: UserNotification, type: CheckerType) { | 418 | function notificationChecker (notification: UserNotification, checkType: CheckerType) { |
449 | if (type === 'presence') { | 419 | if (checkType === 'presence') { |
450 | expect(notification).to.not.be.undefined | 420 | expect(notification).to.not.be.undefined |
451 | expect(notification.type).to.equal(notificationType) | 421 | expect(notification.type).to.equal(notificationType) |
452 | 422 | ||
@@ -469,39 +439,48 @@ async function checkAbuseStateChange (base: CheckerBaseParams, abuseId: number, | |||
469 | return text.indexOf(contains) !== -1 | 439 | return text.indexOf(contains) !== -1 |
470 | } | 440 | } |
471 | 441 | ||
472 | await checkNotification(base, notificationChecker, emailNotificationFinder, type) | 442 | await checkNotification({ ...options, notificationChecker, emailNotificationFinder }) |
473 | } | 443 | } |
474 | 444 | ||
475 | async function checkNewCommentAbuseForModerators (base: CheckerBaseParams, videoUUID: string, videoName: string, type: CheckerType) { | 445 | async function checkNewCommentAbuseForModerators (options: CheckerBaseParams & { |
446 | shortUUID: string | ||
447 | videoName: string | ||
448 | checkType: CheckerType | ||
449 | }) { | ||
450 | const { shortUUID, videoName } = options | ||
476 | const notificationType = UserNotificationType.NEW_ABUSE_FOR_MODERATORS | 451 | const notificationType = UserNotificationType.NEW_ABUSE_FOR_MODERATORS |
477 | 452 | ||
478 | function notificationChecker (notification: UserNotification, type: CheckerType) { | 453 | function notificationChecker (notification: UserNotification, checkType: CheckerType) { |
479 | if (type === 'presence') { | 454 | if (checkType === 'presence') { |
480 | expect(notification).to.not.be.undefined | 455 | expect(notification).to.not.be.undefined |
481 | expect(notification.type).to.equal(notificationType) | 456 | expect(notification.type).to.equal(notificationType) |
482 | 457 | ||
483 | expect(notification.abuse.id).to.be.a('number') | 458 | expect(notification.abuse.id).to.be.a('number') |
484 | checkVideo(notification.abuse.comment.video, videoName, videoUUID) | 459 | checkVideo(notification.abuse.comment.video, videoName, shortUUID) |
485 | } else { | 460 | } else { |
486 | expect(notification).to.satisfy((n: UserNotification) => { | 461 | expect(notification).to.satisfy((n: UserNotification) => { |
487 | return n === undefined || n.abuse === undefined || n.abuse.comment.video.uuid !== videoUUID | 462 | return n === undefined || n.abuse === undefined || n.abuse.comment.video.shortUUID !== shortUUID |
488 | }) | 463 | }) |
489 | } | 464 | } |
490 | } | 465 | } |
491 | 466 | ||
492 | function emailNotificationFinder (email: object) { | 467 | function emailNotificationFinder (email: object) { |
493 | const text = email['text'] | 468 | const text = email['text'] |
494 | return text.indexOf(videoUUID) !== -1 && text.indexOf('abuse') !== -1 | 469 | return text.indexOf(shortUUID) !== -1 && text.indexOf('abuse') !== -1 |
495 | } | 470 | } |
496 | 471 | ||
497 | await checkNotification(base, notificationChecker, emailNotificationFinder, type) | 472 | await checkNotification({ ...options, notificationChecker, emailNotificationFinder }) |
498 | } | 473 | } |
499 | 474 | ||
500 | async function checkNewAccountAbuseForModerators (base: CheckerBaseParams, displayName: string, type: CheckerType) { | 475 | async function checkNewAccountAbuseForModerators (options: CheckerBaseParams & { |
476 | displayName: string | ||
477 | checkType: CheckerType | ||
478 | }) { | ||
479 | const { displayName } = options | ||
501 | const notificationType = UserNotificationType.NEW_ABUSE_FOR_MODERATORS | 480 | const notificationType = UserNotificationType.NEW_ABUSE_FOR_MODERATORS |
502 | 481 | ||
503 | function notificationChecker (notification: UserNotification, type: CheckerType) { | 482 | function notificationChecker (notification: UserNotification, checkType: CheckerType) { |
504 | if (type === 'presence') { | 483 | if (checkType === 'presence') { |
505 | expect(notification).to.not.be.undefined | 484 | expect(notification).to.not.be.undefined |
506 | expect(notification.type).to.equal(notificationType) | 485 | expect(notification.type).to.equal(notificationType) |
507 | 486 | ||
@@ -519,40 +498,45 @@ async function checkNewAccountAbuseForModerators (base: CheckerBaseParams, displ | |||
519 | return text.indexOf(displayName) !== -1 && text.indexOf('abuse') !== -1 | 498 | return text.indexOf(displayName) !== -1 && text.indexOf('abuse') !== -1 |
520 | } | 499 | } |
521 | 500 | ||
522 | await checkNotification(base, notificationChecker, emailNotificationFinder, type) | 501 | await checkNotification({ ...options, notificationChecker, emailNotificationFinder }) |
523 | } | 502 | } |
524 | 503 | ||
525 | async function checkVideoAutoBlacklistForModerators (base: CheckerBaseParams, videoUUID: string, videoName: string, type: CheckerType) { | 504 | async function checkVideoAutoBlacklistForModerators (options: CheckerBaseParams & { |
505 | shortUUID: string | ||
506 | videoName: string | ||
507 | checkType: CheckerType | ||
508 | }) { | ||
509 | const { shortUUID, videoName } = options | ||
526 | const notificationType = UserNotificationType.VIDEO_AUTO_BLACKLIST_FOR_MODERATORS | 510 | const notificationType = UserNotificationType.VIDEO_AUTO_BLACKLIST_FOR_MODERATORS |
527 | 511 | ||
528 | function notificationChecker (notification: UserNotification, type: CheckerType) { | 512 | function notificationChecker (notification: UserNotification, checkType: CheckerType) { |
529 | if (type === 'presence') { | 513 | if (checkType === 'presence') { |
530 | expect(notification).to.not.be.undefined | 514 | expect(notification).to.not.be.undefined |
531 | expect(notification.type).to.equal(notificationType) | 515 | expect(notification.type).to.equal(notificationType) |
532 | 516 | ||
533 | expect(notification.videoBlacklist.video.id).to.be.a('number') | 517 | expect(notification.videoBlacklist.video.id).to.be.a('number') |
534 | checkVideo(notification.videoBlacklist.video, videoName, videoUUID) | 518 | checkVideo(notification.videoBlacklist.video, videoName, shortUUID) |
535 | } else { | 519 | } else { |
536 | expect(notification).to.satisfy((n: UserNotification) => { | 520 | expect(notification).to.satisfy((n: UserNotification) => { |
537 | return n === undefined || n.video === undefined || n.video.uuid !== videoUUID | 521 | return n === undefined || n.video === undefined || n.video.shortUUID !== shortUUID |
538 | }) | 522 | }) |
539 | } | 523 | } |
540 | } | 524 | } |
541 | 525 | ||
542 | function emailNotificationFinder (email: object) { | 526 | function emailNotificationFinder (email: object) { |
543 | const text = email['text'] | 527 | const text = email['text'] |
544 | return text.indexOf(videoUUID) !== -1 && email['text'].indexOf('video-auto-blacklist/list') !== -1 | 528 | return text.indexOf(shortUUID) !== -1 && email['text'].indexOf('video-auto-blacklist/list') !== -1 |
545 | } | 529 | } |
546 | 530 | ||
547 | await checkNotification(base, notificationChecker, emailNotificationFinder, type) | 531 | await checkNotification({ ...options, notificationChecker, emailNotificationFinder }) |
548 | } | 532 | } |
549 | 533 | ||
550 | async function checkNewBlacklistOnMyVideo ( | 534 | async function checkNewBlacklistOnMyVideo (options: CheckerBaseParams & { |
551 | base: CheckerBaseParams, | 535 | shortUUID: string |
552 | videoUUID: string, | 536 | videoName: string |
553 | videoName: string, | ||
554 | blacklistType: 'blacklist' | 'unblacklist' | 537 | blacklistType: 'blacklist' | 'unblacklist' |
555 | ) { | 538 | }) { |
539 | const { videoName, shortUUID, blacklistType } = options | ||
556 | const notificationType = blacklistType === 'blacklist' | 540 | const notificationType = blacklistType === 'blacklist' |
557 | ? UserNotificationType.BLACKLIST_ON_MY_VIDEO | 541 | ? UserNotificationType.BLACKLIST_ON_MY_VIDEO |
558 | : UserNotificationType.UNBLACKLIST_ON_MY_VIDEO | 542 | : UserNotificationType.UNBLACKLIST_ON_MY_VIDEO |
@@ -563,22 +547,30 @@ async function checkNewBlacklistOnMyVideo ( | |||
563 | 547 | ||
564 | const video = blacklistType === 'blacklist' ? notification.videoBlacklist.video : notification.video | 548 | const video = blacklistType === 'blacklist' ? notification.videoBlacklist.video : notification.video |
565 | 549 | ||
566 | checkVideo(video, videoName, videoUUID) | 550 | checkVideo(video, videoName, shortUUID) |
567 | } | 551 | } |
568 | 552 | ||
569 | function emailNotificationFinder (email: object) { | 553 | function emailNotificationFinder (email: object) { |
570 | const text = email['text'] | 554 | const text = email['text'] |
571 | return text.indexOf(videoUUID) !== -1 && text.indexOf(' ' + blacklistType) !== -1 | 555 | const blacklistText = blacklistType === 'blacklist' |
556 | ? 'blacklisted' | ||
557 | : 'unblacklisted' | ||
558 | |||
559 | return text.includes(shortUUID) && text.includes(blacklistText) | ||
572 | } | 560 | } |
573 | 561 | ||
574 | await checkNotification(base, notificationChecker, emailNotificationFinder, 'presence') | 562 | await checkNotification({ ...options, notificationChecker, emailNotificationFinder, checkType: 'presence' }) |
575 | } | 563 | } |
576 | 564 | ||
577 | async function checkNewPeerTubeVersion (base: CheckerBaseParams, latestVersion: string, type: CheckerType) { | 565 | async function checkNewPeerTubeVersion (options: CheckerBaseParams & { |
566 | latestVersion: string | ||
567 | checkType: CheckerType | ||
568 | }) { | ||
569 | const { latestVersion } = options | ||
578 | const notificationType = UserNotificationType.NEW_PEERTUBE_VERSION | 570 | const notificationType = UserNotificationType.NEW_PEERTUBE_VERSION |
579 | 571 | ||
580 | function notificationChecker (notification: UserNotification, type: CheckerType) { | 572 | function notificationChecker (notification: UserNotification, checkType: CheckerType) { |
581 | if (type === 'presence') { | 573 | if (checkType === 'presence') { |
582 | expect(notification).to.not.be.undefined | 574 | expect(notification).to.not.be.undefined |
583 | expect(notification.type).to.equal(notificationType) | 575 | expect(notification.type).to.equal(notificationType) |
584 | 576 | ||
@@ -597,14 +589,19 @@ async function checkNewPeerTubeVersion (base: CheckerBaseParams, latestVersion: | |||
597 | return text.includes(latestVersion) | 589 | return text.includes(latestVersion) |
598 | } | 590 | } |
599 | 591 | ||
600 | await checkNotification(base, notificationChecker, emailNotificationFinder, type) | 592 | await checkNotification({ ...options, notificationChecker, emailNotificationFinder }) |
601 | } | 593 | } |
602 | 594 | ||
603 | async function checkNewPluginVersion (base: CheckerBaseParams, pluginType: PluginType, pluginName: string, type: CheckerType) { | 595 | async function checkNewPluginVersion (options: CheckerBaseParams & { |
596 | pluginType: PluginType | ||
597 | pluginName: string | ||
598 | checkType: CheckerType | ||
599 | }) { | ||
600 | const { pluginName, pluginType } = options | ||
604 | const notificationType = UserNotificationType.NEW_PLUGIN_VERSION | 601 | const notificationType = UserNotificationType.NEW_PLUGIN_VERSION |
605 | 602 | ||
606 | function notificationChecker (notification: UserNotification, type: CheckerType) { | 603 | function notificationChecker (notification: UserNotification, checkType: CheckerType) { |
607 | if (type === 'presence') { | 604 | if (checkType === 'presence') { |
608 | expect(notification).to.not.be.undefined | 605 | expect(notification).to.not.be.undefined |
609 | expect(notification.type).to.equal(notificationType) | 606 | expect(notification.type).to.equal(notificationType) |
610 | 607 | ||
@@ -623,7 +620,7 @@ async function checkNewPluginVersion (base: CheckerBaseParams, pluginType: Plugi | |||
623 | return text.includes(pluginName) | 620 | return text.includes(pluginName) |
624 | } | 621 | } |
625 | 622 | ||
626 | await checkNotification(base, notificationChecker, emailNotificationFinder, type) | 623 | await checkNotification({ ...options, notificationChecker, emailNotificationFinder }) |
627 | } | 624 | } |
628 | 625 | ||
629 | async function prepareNotificationsTest (serversCount = 3, overrideConfigArg: any = {}) { | 626 | async function prepareNotificationsTest (serversCount = 3, overrideConfigArg: any = {}) { |
@@ -697,7 +694,6 @@ export { | |||
697 | 694 | ||
698 | CheckerBaseParams, | 695 | CheckerBaseParams, |
699 | CheckerType, | 696 | CheckerType, |
700 | checkNotification, | ||
701 | checkMyVideoImportIsFinished, | 697 | checkMyVideoImportIsFinished, |
702 | checkUserRegistered, | 698 | checkUserRegistered, |
703 | checkAutoInstanceFollowing, | 699 | checkAutoInstanceFollowing, |
@@ -718,3 +714,82 @@ export { | |||
718 | checkNewPeerTubeVersion, | 714 | checkNewPeerTubeVersion, |
719 | checkNewPluginVersion | 715 | checkNewPluginVersion |
720 | } | 716 | } |
717 | |||
718 | // --------------------------------------------------------------------------- | ||
719 | |||
720 | async function checkNotification (options: CheckerBaseParams & { | ||
721 | notificationChecker: (notification: UserNotification, checkType: CheckerType) => void | ||
722 | emailNotificationFinder: (email: object) => boolean | ||
723 | checkType: CheckerType | ||
724 | }) { | ||
725 | const { server, token, checkType, notificationChecker, emailNotificationFinder, socketNotifications, emails } = options | ||
726 | |||
727 | const check = options.check || { web: true, mail: true } | ||
728 | |||
729 | if (check.web) { | ||
730 | const notification = await server.notifications.getLastest({ token: token }) | ||
731 | |||
732 | if (notification || checkType !== 'absence') { | ||
733 | notificationChecker(notification, checkType) | ||
734 | } | ||
735 | |||
736 | const socketNotification = socketNotifications.find(n => { | ||
737 | try { | ||
738 | notificationChecker(n, 'presence') | ||
739 | return true | ||
740 | } catch { | ||
741 | return false | ||
742 | } | ||
743 | }) | ||
744 | |||
745 | if (checkType === 'presence') { | ||
746 | const obj = inspect(socketNotifications, { depth: 5 }) | ||
747 | expect(socketNotification, 'The socket notification is absent when it should be present. ' + obj).to.not.be.undefined | ||
748 | } else { | ||
749 | const obj = inspect(socketNotification, { depth: 5 }) | ||
750 | expect(socketNotification, 'The socket notification is present when it should not be present. ' + obj).to.be.undefined | ||
751 | } | ||
752 | } | ||
753 | |||
754 | if (check.mail) { | ||
755 | // Last email | ||
756 | const email = emails | ||
757 | .slice() | ||
758 | .reverse() | ||
759 | .find(e => emailNotificationFinder(e)) | ||
760 | |||
761 | if (checkType === 'presence') { | ||
762 | const texts = emails.map(e => e.text) | ||
763 | expect(email, 'The email is absent when is should be present. ' + inspect(texts)).to.not.be.undefined | ||
764 | } else { | ||
765 | expect(email, 'The email is present when is should not be present. ' + inspect(email)).to.be.undefined | ||
766 | } | ||
767 | } | ||
768 | } | ||
769 | |||
770 | function checkVideo (video: any, videoName?: string, shortUUID?: string) { | ||
771 | if (videoName) { | ||
772 | expect(video.name).to.be.a('string') | ||
773 | expect(video.name).to.not.be.empty | ||
774 | expect(video.name).to.equal(videoName) | ||
775 | } | ||
776 | |||
777 | if (shortUUID) { | ||
778 | expect(video.shortUUID).to.be.a('string') | ||
779 | expect(video.shortUUID).to.not.be.empty | ||
780 | expect(video.shortUUID).to.equal(shortUUID) | ||
781 | } | ||
782 | |||
783 | expect(video.id).to.be.a('number') | ||
784 | } | ||
785 | |||
786 | function checkActor (actor: any) { | ||
787 | expect(actor.displayName).to.be.a('string') | ||
788 | expect(actor.displayName).to.not.be.empty | ||
789 | expect(actor.host).to.not.be.undefined | ||
790 | } | ||
791 | |||
792 | function checkComment (comment: any, commentId: number, threadId: number) { | ||
793 | expect(comment.id).to.equal(commentId) | ||
794 | expect(comment.threadId).to.equal(threadId) | ||
795 | } | ||
diff --git a/shared/models/search/videos-search-query.model.ts b/shared/models/search/videos-search-query.model.ts index 406f6cab2..a568c960e 100644 --- a/shared/models/search/videos-search-query.model.ts +++ b/shared/models/search/videos-search-query.model.ts | |||
@@ -4,6 +4,8 @@ import { VideosCommonQuery } from './videos-common-query.model' | |||
4 | export interface VideosSearchQuery extends SearchTargetQuery, VideosCommonQuery { | 4 | export interface VideosSearchQuery extends SearchTargetQuery, VideosCommonQuery { |
5 | search?: string | 5 | search?: string |
6 | 6 | ||
7 | host?: string | ||
8 | |||
7 | startDate?: string // ISO 8601 | 9 | startDate?: string // ISO 8601 |
8 | endDate?: string // ISO 8601 | 10 | endDate?: string // ISO 8601 |
9 | 11 | ||
diff --git a/shared/models/users/user-notification.model.ts b/shared/models/users/user-notification.model.ts index 8b33e3fbd..5820589fe 100644 --- a/shared/models/users/user-notification.model.ts +++ b/shared/models/users/user-notification.model.ts | |||
@@ -36,6 +36,7 @@ export const enum UserNotificationType { | |||
36 | export interface VideoInfo { | 36 | export interface VideoInfo { |
37 | id: number | 37 | id: number |
38 | uuid: string | 38 | uuid: string |
39 | shortUUID: string | ||
39 | name: string | 40 | name: string |
40 | } | 41 | } |
41 | 42 | ||
@@ -82,11 +83,7 @@ export interface UserNotification { | |||
82 | comment?: { | 83 | comment?: { |
83 | threadId: number | 84 | threadId: number |
84 | 85 | ||
85 | video: { | 86 | video: VideoInfo |
86 | id: number | ||
87 | uuid: string | ||
88 | name: string | ||
89 | } | ||
90 | } | 87 | } |
91 | 88 | ||
92 | account?: ActorInfo | 89 | account?: ActorInfo |