diff options
Diffstat (limited to 'shared/extra-utils/users/user-notifications.ts')
-rw-r--r-- | shared/extra-utils/users/user-notifications.ts | 72 |
1 files changed, 64 insertions, 8 deletions
diff --git a/shared/extra-utils/users/user-notifications.ts b/shared/extra-utils/users/user-notifications.ts index 467a3d959..249e82925 100644 --- a/shared/extra-utils/users/user-notifications.ts +++ b/shared/extra-utils/users/user-notifications.ts | |||
@@ -2,7 +2,8 @@ | |||
2 | 2 | ||
3 | import { expect } from 'chai' | 3 | import { expect } from 'chai' |
4 | import { inspect } from 'util' | 4 | import { inspect } from 'util' |
5 | import { AbuseState } from '@shared/models' | 5 | import { AbuseState, PluginType } from '@shared/models' |
6 | import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' | ||
6 | import { UserNotification, UserNotificationSetting, UserNotificationSettingValue, UserNotificationType } from '../../models/users' | 7 | import { UserNotification, UserNotificationSetting, UserNotificationSettingValue, UserNotificationType } from '../../models/users' |
7 | import { MockSmtpServer } from '../miscs/email' | 8 | import { MockSmtpServer } from '../miscs/email' |
8 | import { makeGetRequest, makePostBodyRequest, makePutBodyRequest } from '../requests/requests' | 9 | import { makeGetRequest, makePostBodyRequest, makePutBodyRequest } from '../requests/requests' |
@@ -11,7 +12,6 @@ import { flushAndRunMultipleServers, ServerInfo } from '../server/servers' | |||
11 | import { getUserNotificationSocket } from '../socket/socket-io' | 12 | import { getUserNotificationSocket } from '../socket/socket-io' |
12 | import { setAccessTokensToServers, userLogin } from './login' | 13 | import { setAccessTokensToServers, userLogin } from './login' |
13 | import { createUser, getMyUserInformation } from './users' | 14 | import { createUser, getMyUserInformation } from './users' |
14 | import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' | ||
15 | 15 | ||
16 | function updateMyNotificationSettings ( | 16 | function updateMyNotificationSettings ( |
17 | url: string, | 17 | url: string, |
@@ -629,7 +629,59 @@ async function checkNewBlacklistOnMyVideo ( | |||
629 | await checkNotification(base, notificationChecker, emailNotificationFinder, 'presence') | 629 | await checkNotification(base, notificationChecker, emailNotificationFinder, 'presence') |
630 | } | 630 | } |
631 | 631 | ||
632 | function getAllNotificationsSettings () { | 632 | async function checkNewPeerTubeVersion (base: CheckerBaseParams, latestVersion: string, type: CheckerType) { |
633 | const notificationType = UserNotificationType.NEW_PEERTUBE_VERSION | ||
634 | |||
635 | function notificationChecker (notification: UserNotification, type: CheckerType) { | ||
636 | if (type === 'presence') { | ||
637 | expect(notification).to.not.be.undefined | ||
638 | expect(notification.type).to.equal(notificationType) | ||
639 | |||
640 | expect(notification.peertube).to.exist | ||
641 | expect(notification.peertube.latestVersion).to.equal(latestVersion) | ||
642 | } else { | ||
643 | expect(notification).to.satisfy((n: UserNotification) => { | ||
644 | return n === undefined || n.peertube === undefined || n.peertube.latestVersion !== latestVersion | ||
645 | }) | ||
646 | } | ||
647 | } | ||
648 | |||
649 | function emailNotificationFinder (email: object) { | ||
650 | const text = email['text'] | ||
651 | |||
652 | return text.includes(latestVersion) | ||
653 | } | ||
654 | |||
655 | await checkNotification(base, notificationChecker, emailNotificationFinder, type) | ||
656 | } | ||
657 | |||
658 | async function checkNewPluginVersion (base: CheckerBaseParams, pluginType: PluginType, pluginName: string, type: CheckerType) { | ||
659 | const notificationType = UserNotificationType.NEW_PLUGIN_VERSION | ||
660 | |||
661 | function notificationChecker (notification: UserNotification, type: CheckerType) { | ||
662 | if (type === 'presence') { | ||
663 | expect(notification).to.not.be.undefined | ||
664 | expect(notification.type).to.equal(notificationType) | ||
665 | |||
666 | expect(notification.plugin.name).to.equal(pluginName) | ||
667 | expect(notification.plugin.type).to.equal(pluginType) | ||
668 | } else { | ||
669 | expect(notification).to.satisfy((n: UserNotification) => { | ||
670 | return n === undefined || n.plugin === undefined || n.plugin.name !== pluginName | ||
671 | }) | ||
672 | } | ||
673 | } | ||
674 | |||
675 | function emailNotificationFinder (email: object) { | ||
676 | const text = email['text'] | ||
677 | |||
678 | return text.includes(pluginName) | ||
679 | } | ||
680 | |||
681 | await checkNotification(base, notificationChecker, emailNotificationFinder, type) | ||
682 | } | ||
683 | |||
684 | function getAllNotificationsSettings (): UserNotificationSetting { | ||
633 | return { | 685 | return { |
634 | newVideoFromSubscription: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, | 686 | newVideoFromSubscription: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, |
635 | newCommentOnMyVideo: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, | 687 | newCommentOnMyVideo: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, |
@@ -644,11 +696,13 @@ function getAllNotificationsSettings () { | |||
644 | newInstanceFollower: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, | 696 | newInstanceFollower: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, |
645 | abuseNewMessage: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, | 697 | abuseNewMessage: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, |
646 | abuseStateChange: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, | 698 | abuseStateChange: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, |
647 | autoInstanceFollowing: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL | 699 | autoInstanceFollowing: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, |
648 | } as UserNotificationSetting | 700 | newPeerTubeVersion: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, |
701 | newPluginVersion: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL | ||
702 | } | ||
649 | } | 703 | } |
650 | 704 | ||
651 | async function prepareNotificationsTest (serversCount = 3) { | 705 | async function prepareNotificationsTest (serversCount = 3, overrideConfigArg: any = {}) { |
652 | const userNotifications: UserNotification[] = [] | 706 | const userNotifications: UserNotification[] = [] |
653 | const adminNotifications: UserNotification[] = [] | 707 | const adminNotifications: UserNotification[] = [] |
654 | const adminNotificationsServer2: UserNotification[] = [] | 708 | const adminNotificationsServer2: UserNotification[] = [] |
@@ -665,7 +719,7 @@ async function prepareNotificationsTest (serversCount = 3) { | |||
665 | limit: 20 | 719 | limit: 20 |
666 | } | 720 | } |
667 | } | 721 | } |
668 | const servers = await flushAndRunMultipleServers(serversCount, overrideConfig) | 722 | const servers = await flushAndRunMultipleServers(serversCount, Object.assign(overrideConfig, overrideConfigArg)) |
669 | 723 | ||
670 | await setAccessTokensToServers(servers) | 724 | await setAccessTokensToServers(servers) |
671 | 725 | ||
@@ -749,5 +803,7 @@ export { | |||
749 | checkNewInstanceFollower, | 803 | checkNewInstanceFollower, |
750 | prepareNotificationsTest, | 804 | prepareNotificationsTest, |
751 | checkNewCommentAbuseForModerators, | 805 | checkNewCommentAbuseForModerators, |
752 | checkNewAccountAbuseForModerators | 806 | checkNewAccountAbuseForModerators, |
807 | checkNewPeerTubeVersion, | ||
808 | checkNewPluginVersion | ||
753 | } | 809 | } |