aboutsummaryrefslogtreecommitdiffhomepage
path: root/shared
diff options
context:
space:
mode:
Diffstat (limited to 'shared')
-rw-r--r--shared/extra-utils/search/search-command.ts2
-rw-r--r--shared/extra-utils/server/servers.ts6
-rw-r--r--shared/extra-utils/shared/abstract-command.ts7
-rw-r--r--shared/extra-utils/users/index.ts3
-rw-r--r--shared/extra-utils/users/notifications-command.ts87
-rw-r--r--shared/extra-utils/users/notifications.ts (renamed from shared/extra-utils/users/user-notifications.ts)129
-rw-r--r--shared/extra-utils/videos/streaming-playlists-command.ts2
7 files changed, 124 insertions, 112 deletions
diff --git a/shared/extra-utils/search/search-command.ts b/shared/extra-utils/search/search-command.ts
index 7539a21ec..b6054f093 100644
--- a/shared/extra-utils/search/search-command.ts
+++ b/shared/extra-utils/search/search-command.ts
@@ -90,7 +90,7 @@ export class SearchCommand extends AbstractCommand {
90 ...options, 90 ...options,
91 91
92 path, 92 path,
93 query: search, 93 query: { sort: '-publishedAt', ...search },
94 implicitToken: false, 94 implicitToken: false,
95 defaultExpectedStatus: HttpStatusCode.OK_200 95 defaultExpectedStatus: HttpStatusCode.OK_200
96 }) 96 })
diff --git a/shared/extra-utils/server/servers.ts b/shared/extra-utils/server/servers.ts
index bd3be8373..e0e49d2c4 100644
--- a/shared/extra-utils/server/servers.ts
+++ b/shared/extra-utils/server/servers.ts
@@ -11,13 +11,14 @@ import { CLICommand } from '../cli'
11import { CustomPagesCommand } from '../custom-pages' 11import { CustomPagesCommand } from '../custom-pages'
12import { FeedCommand } from '../feeds' 12import { FeedCommand } from '../feeds'
13import { LogsCommand } from '../logs' 13import { LogsCommand } from '../logs'
14import { SQLCommand } from '../miscs'
14import { buildServerDirectory, getFileSize, isGithubCI, root, wait } from '../miscs/miscs' 15import { buildServerDirectory, getFileSize, isGithubCI, root, wait } from '../miscs/miscs'
15import { AbusesCommand } from '../moderation' 16import { AbusesCommand } from '../moderation'
16import { OverviewsCommand } from '../overviews' 17import { OverviewsCommand } from '../overviews'
17import { makeGetRequest } from '../requests/requests' 18import { makeGetRequest } from '../requests/requests'
18import { SearchCommand } from '../search' 19import { SearchCommand } from '../search'
19import { SocketIOCommand } from '../socket' 20import { SocketIOCommand } from '../socket'
20import { AccountsCommand, BlocklistCommand, SubscriptionsCommand } from '../users' 21import { AccountsCommand, BlocklistCommand, NotificationsCommand, SubscriptionsCommand } from '../users'
21import { 22import {
22 BlacklistCommand, 23 BlacklistCommand,
23 CaptionsCommand, 24 CaptionsCommand,
@@ -30,7 +31,6 @@ import {
30 ServicesCommand, 31 ServicesCommand,
31 StreamingPlaylistsCommand 32 StreamingPlaylistsCommand
32} from '../videos' 33} from '../videos'
33import { SQLCommand } from '../miscs'
34import { CommentsCommand } from '../videos/comments-command' 34import { CommentsCommand } from '../videos/comments-command'
35import { ConfigCommand } from './config-command' 35import { ConfigCommand } from './config-command'
36import { ContactFormCommand } from './contact-form-command' 36import { ContactFormCommand } from './contact-form-command'
@@ -125,6 +125,7 @@ interface ServerInfo {
125 channelsCommand?: ChannelsCommand 125 channelsCommand?: ChannelsCommand
126 commentsCommand?: CommentsCommand 126 commentsCommand?: CommentsCommand
127 sqlCommand?: SQLCommand 127 sqlCommand?: SQLCommand
128 notificationsCommand?: NotificationsCommand
128} 129}
129 130
130function parallelTests () { 131function parallelTests () {
@@ -370,6 +371,7 @@ function assignCommands (server: ServerInfo) {
370 server.channelsCommand = new ChannelsCommand(server) 371 server.channelsCommand = new ChannelsCommand(server)
371 server.commentsCommand = new CommentsCommand(server) 372 server.commentsCommand = new CommentsCommand(server)
372 server.sqlCommand = new SQLCommand(server) 373 server.sqlCommand = new SQLCommand(server)
374 server.notificationsCommand = new NotificationsCommand(server)
373} 375}
374 376
375async function reRunServer (server: ServerInfo, configOverride?: any) { 377async function reRunServer (server: ServerInfo, configOverride?: any) {
diff --git a/shared/extra-utils/shared/abstract-command.ts b/shared/extra-utils/shared/abstract-command.ts
index 200db90d4..fd2deb57e 100644
--- a/shared/extra-utils/shared/abstract-command.ts
+++ b/shared/extra-utils/shared/abstract-command.ts
@@ -78,7 +78,7 @@ abstract class AbstractCommand {
78 } 78 }
79 79
80 protected getRequest (options: InternalGetCommandOptions) { 80 protected getRequest (options: InternalGetCommandOptions) {
81 const { redirects, query, contentType, accept } = options 81 const { redirects, query, contentType, accept, range } = options
82 82
83 return makeGetRequest({ 83 return makeGetRequest({
84 ...this.buildCommonRequestOptions(options), 84 ...this.buildCommonRequestOptions(options),
@@ -86,6 +86,7 @@ abstract class AbstractCommand {
86 redirects, 86 redirects,
87 query, 87 query,
88 contentType, 88 contentType,
89 range,
89 accept 90 accept
90 }) 91 })
91 } 92 }
@@ -168,10 +169,10 @@ abstract class AbstractCommand {
168 } 169 }
169 170
170 private buildCommonRequestOptions (options: InternalCommonCommandOptions) { 171 private buildCommonRequestOptions (options: InternalCommonCommandOptions) {
171 const { path } = options 172 const { url, path } = options
172 173
173 return { 174 return {
174 url: this.server.url, 175 url: url ?? this.server.url,
175 path, 176 path,
176 177
177 token: this.buildCommonRequestToken(options), 178 token: this.buildCommonRequestToken(options),
diff --git a/shared/extra-utils/users/index.ts b/shared/extra-utils/users/index.ts
index 9f760d7fd..ed166c756 100644
--- a/shared/extra-utils/users/index.ts
+++ b/shared/extra-utils/users/index.ts
@@ -2,6 +2,7 @@ export * from './accounts-command'
2export * from './accounts' 2export * from './accounts'
3export * from './blocklist-command' 3export * from './blocklist-command'
4export * from './login' 4export * from './login'
5export * from './user-notifications' 5export * from './notifications'
6export * from './notifications-command'
6export * from './subscriptions-command' 7export * from './subscriptions-command'
7export * from './users' 8export * from './users'
diff --git a/shared/extra-utils/users/notifications-command.ts b/shared/extra-utils/users/notifications-command.ts
new file mode 100644
index 000000000..dfe574ca1
--- /dev/null
+++ b/shared/extra-utils/users/notifications-command.ts
@@ -0,0 +1,87 @@
1import { ResultList } from '@shared/models'
2import { HttpStatusCode } from '../../core-utils/miscs/http-error-codes'
3import { UserNotification, UserNotificationSetting } from '../../models/users'
4import { AbstractCommand, OverrideCommandOptions } from '../shared'
5
6export class NotificationsCommand extends AbstractCommand {
7
8 updateMySettings (options: OverrideCommandOptions & {
9 settings: UserNotificationSetting
10 }) {
11 const path = '/api/v1/users/me/notification-settings'
12
13 return this.putBodyRequest({
14 ...options,
15
16 path,
17 fields: options.settings,
18 implicitToken: true,
19 defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
20 })
21 }
22
23 list (options: OverrideCommandOptions & {
24 start?: number
25 count?: number
26 unread?: boolean
27 sort?: string
28 }) {
29 const { start, count, unread, sort = '-createdAt' } = options
30 const path = '/api/v1/users/me/notifications'
31
32 return this.getRequestBody<ResultList<UserNotification>>({
33 ...options,
34
35 path,
36 query: {
37 start,
38 count,
39 sort,
40 unread
41 },
42 implicitToken: true,
43 defaultExpectedStatus: HttpStatusCode.OK_200
44 })
45 }
46
47 markAsRead (options: OverrideCommandOptions & {
48 ids: number[]
49 }) {
50 const { ids } = options
51 const path = '/api/v1/users/me/notifications/read'
52
53 return this.postBodyRequest({
54 ...options,
55
56 path,
57 fields: { ids },
58 implicitToken: true,
59 defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
60 })
61 }
62
63 markAsReadAll (options: OverrideCommandOptions) {
64 const path = '/api/v1/users/me/notifications/read-all'
65
66 return this.postBodyRequest({
67 ...options,
68
69 path,
70 implicitToken: true,
71 defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
72 })
73 }
74
75 async getLastest (options: OverrideCommandOptions = {}) {
76 const { total, data } = await this.list({
77 ...options,
78 start: 0,
79 count: 1,
80 sort: '-createdAt'
81 })
82
83 if (total === 0) return undefined
84
85 return data[0]
86 }
87}
diff --git a/shared/extra-utils/users/user-notifications.ts b/shared/extra-utils/users/notifications.ts
index 961cfcc0f..81f0729fa 100644
--- a/shared/extra-utils/users/user-notifications.ts
+++ b/shared/extra-utils/users/notifications.ts
@@ -3,86 +3,32 @@
3import { expect } from 'chai' 3import { expect } from 'chai'
4import { inspect } from 'util' 4import { inspect } from 'util'
5import { AbuseState, PluginType } from '@shared/models' 5import { AbuseState, PluginType } from '@shared/models'
6import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
7import { UserNotification, UserNotificationSetting, UserNotificationSettingValue, UserNotificationType } from '../../models/users' 6import { UserNotification, UserNotificationSetting, UserNotificationSettingValue, UserNotificationType } from '../../models/users'
8import { MockSmtpServer } from '../mock-servers/mock-email' 7import { MockSmtpServer } from '../mock-servers/mock-email'
9import { makeGetRequest, makePostBodyRequest, makePutBodyRequest } from '../requests/requests'
10import { doubleFollow } from '../server/follows' 8import { doubleFollow } from '../server/follows'
11import { flushAndRunMultipleServers, ServerInfo } from '../server/servers' 9import { flushAndRunMultipleServers, ServerInfo } from '../server/servers'
12import { setAccessTokensToServers, userLogin } from './login' 10import { setAccessTokensToServers, userLogin } from './login'
13import { createUser, getMyUserInformation } from './users' 11import { createUser, getMyUserInformation } from './users'
14 12
15function updateMyNotificationSettings ( 13function getAllNotificationsSettings (): UserNotificationSetting {
16 url: string, 14 return {
17 token: string, 15 newVideoFromSubscription: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
18 settings: UserNotificationSetting, 16 newCommentOnMyVideo: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
19 statusCodeExpected = HttpStatusCode.NO_CONTENT_204 17 abuseAsModerator: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
20) { 18 videoAutoBlacklistAsModerator: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
21 const path = '/api/v1/users/me/notification-settings' 19 blacklistOnMyVideo: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
22 20 myVideoImportFinished: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
23 return makePutBodyRequest({ 21 myVideoPublished: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
24 url, 22 commentMention: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
25 path, 23 newFollow: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
26 token, 24 newUserRegistration: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
27 fields: settings, 25 newInstanceFollower: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
28 statusCodeExpected 26 abuseNewMessage: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
29 }) 27 abuseStateChange: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
30} 28 autoInstanceFollowing: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
31 29 newPeerTubeVersion: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
32async function getUserNotifications ( 30 newPluginVersion: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL
33 url: string, 31 }
34 token: string,
35 start: number,
36 count: number,
37 unread?: boolean,
38 sort = '-createdAt',
39 statusCodeExpected = HttpStatusCode.OK_200
40) {
41 const path = '/api/v1/users/me/notifications'
42
43 return makeGetRequest({
44 url,
45 path,
46 token,
47 query: {
48 start,
49 count,
50 sort,
51 unread
52 },
53 statusCodeExpected
54 })
55}
56
57function markAsReadNotifications (url: string, token: string, ids: number[], statusCodeExpected = HttpStatusCode.NO_CONTENT_204) {
58 const path = '/api/v1/users/me/notifications/read'
59
60 return makePostBodyRequest({
61 url,
62 path,
63 token,
64 fields: { ids },
65 statusCodeExpected
66 })
67}
68
69function markAsReadAllNotifications (url: string, token: string, statusCodeExpected = HttpStatusCode.NO_CONTENT_204) {
70 const path = '/api/v1/users/me/notifications/read-all'
71
72 return makePostBodyRequest({
73 url,
74 path,
75 token,
76 statusCodeExpected
77 })
78}
79
80async function getLastNotification (serverUrl: string, accessToken: string) {
81 const res = await getUserNotifications(serverUrl, accessToken, 0, 1, undefined, '-createdAt')
82
83 if (res.body.total === 0) return undefined
84
85 return res.body.data[0] as UserNotification
86} 32}
87 33
88type CheckerBaseParams = { 34type CheckerBaseParams = {
@@ -104,7 +50,7 @@ async function checkNotification (
104 const check = base.check || { web: true, mail: true } 50 const check = base.check || { web: true, mail: true }
105 51
106 if (check.web) { 52 if (check.web) {
107 const notification = await getLastNotification(base.server.url, base.token) 53 const notification = await base.server.notificationsCommand.getLastest({ token: base.token })
108 54
109 if (notification || checkType !== 'absence') { 55 if (notification || checkType !== 'absence') {
110 notificationChecker(notification, checkType) 56 notificationChecker(notification, checkType)
@@ -680,27 +626,6 @@ async function checkNewPluginVersion (base: CheckerBaseParams, pluginType: Plugi
680 await checkNotification(base, notificationChecker, emailNotificationFinder, type) 626 await checkNotification(base, notificationChecker, emailNotificationFinder, type)
681} 627}
682 628
683function getAllNotificationsSettings (): UserNotificationSetting {
684 return {
685 newVideoFromSubscription: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
686 newCommentOnMyVideo: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
687 abuseAsModerator: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
688 videoAutoBlacklistAsModerator: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
689 blacklistOnMyVideo: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
690 myVideoImportFinished: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
691 myVideoPublished: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
692 commentMention: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
693 newFollow: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
694 newUserRegistration: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
695 newInstanceFollower: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
696 abuseNewMessage: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
697 abuseStateChange: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
698 autoInstanceFollowing: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
699 newPeerTubeVersion: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
700 newPluginVersion: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL
701 }
702}
703
704async function prepareNotificationsTest (serversCount = 3, overrideConfigArg: any = {}) { 629async function prepareNotificationsTest (serversCount = 3, overrideConfigArg: any = {}) {
705 const userNotifications: UserNotification[] = [] 630 const userNotifications: UserNotification[] = []
706 const adminNotifications: UserNotification[] = [] 631 const adminNotifications: UserNotification[] = []
@@ -739,11 +664,11 @@ async function prepareNotificationsTest (serversCount = 3, overrideConfigArg: an
739 }) 664 })
740 const userAccessToken = await userLogin(servers[0], user) 665 const userAccessToken = await userLogin(servers[0], user)
741 666
742 await updateMyNotificationSettings(servers[0].url, userAccessToken, getAllNotificationsSettings()) 667 await servers[0].notificationsCommand.updateMySettings({ token: userAccessToken, settings: getAllNotificationsSettings() })
743 await updateMyNotificationSettings(servers[0].url, servers[0].accessToken, getAllNotificationsSettings()) 668 await servers[0].notificationsCommand.updateMySettings({ settings: getAllNotificationsSettings() })
744 669
745 if (serversCount > 1) { 670 if (serversCount > 1) {
746 await updateMyNotificationSettings(servers[1].url, servers[1].accessToken, getAllNotificationsSettings()) 671 await servers[1].notificationsCommand.updateMySettings({ settings: getAllNotificationsSettings() })
747 } 672 }
748 673
749 { 674 {
@@ -777,11 +702,11 @@ async function prepareNotificationsTest (serversCount = 3, overrideConfigArg: an
777// --------------------------------------------------------------------------- 702// ---------------------------------------------------------------------------
778 703
779export { 704export {
705 getAllNotificationsSettings,
706
780 CheckerBaseParams, 707 CheckerBaseParams,
781 CheckerType, 708 CheckerType,
782 getAllNotificationsSettings,
783 checkNotification, 709 checkNotification,
784 markAsReadAllNotifications,
785 checkMyVideoImportIsFinished, 710 checkMyVideoImportIsFinished,
786 checkUserRegistered, 711 checkUserRegistered,
787 checkAutoInstanceFollowing, 712 checkAutoInstanceFollowing,
@@ -791,14 +716,10 @@ export {
791 checkNewCommentOnMyVideo, 716 checkNewCommentOnMyVideo,
792 checkNewBlacklistOnMyVideo, 717 checkNewBlacklistOnMyVideo,
793 checkCommentMention, 718 checkCommentMention,
794 updateMyNotificationSettings,
795 checkNewVideoAbuseForModerators, 719 checkNewVideoAbuseForModerators,
796 checkVideoAutoBlacklistForModerators, 720 checkVideoAutoBlacklistForModerators,
797 checkNewAbuseMessage, 721 checkNewAbuseMessage,
798 checkAbuseStateChange, 722 checkAbuseStateChange,
799 getUserNotifications,
800 markAsReadNotifications,
801 getLastNotification,
802 checkNewInstanceFollower, 723 checkNewInstanceFollower,
803 prepareNotificationsTest, 724 prepareNotificationsTest,
804 checkNewCommentAbuseForModerators, 725 checkNewCommentAbuseForModerators,
diff --git a/shared/extra-utils/videos/streaming-playlists-command.ts b/shared/extra-utils/videos/streaming-playlists-command.ts
index b109597c9..fab3eb556 100644
--- a/shared/extra-utils/videos/streaming-playlists-command.ts
+++ b/shared/extra-utils/videos/streaming-playlists-command.ts
@@ -21,7 +21,7 @@ export class StreamingPlaylistsCommand extends AbstractCommand {
21 url: string 21 url: string
22 range?: string 22 range?: string
23 }) { 23 }) {
24 return unwrapText(this.getRawRequest({ 24 return unwrapBody<Buffer>(this.getRawRequest({
25 ...options, 25 ...options,
26 26
27 url: options.url, 27 url: options.url,