diff options
author | Chocobozzz <me@florianbigard.com> | 2020-06-16 15:52:05 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2020-06-16 15:55:42 +0200 |
commit | 8eb07b01306429abe5c538ff7aa0a16e44fff26f (patch) | |
tree | aa6461099e0652a54c9f49ecd5652f3ddfcc0fc1 /shared | |
parent | 1ba471c55fdbf05ef2c10152b3e4b0c5d8da3213 (diff) | |
download | PeerTube-8eb07b01306429abe5c538ff7aa0a16e44fff26f.tar.gz PeerTube-8eb07b01306429abe5c538ff7aa0a16e44fff26f.tar.zst PeerTube-8eb07b01306429abe5c538ff7aa0a16e44fff26f.zip |
Split notification tests
Diffstat (limited to 'shared')
-rw-r--r-- | shared/extra-utils/users/user-notifications.ts | 108 | ||||
-rw-r--r-- | shared/extra-utils/videos/videos.ts | 48 |
2 files changed, 137 insertions, 19 deletions
diff --git a/shared/extra-utils/users/user-notifications.ts b/shared/extra-utils/users/user-notifications.ts index bd00894c4..30c36a388 100644 --- a/shared/extra-utils/users/user-notifications.ts +++ b/shared/extra-utils/users/user-notifications.ts | |||
@@ -1,10 +1,15 @@ | |||
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | 1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
2 | 2 | ||
3 | import { makeGetRequest, makePostBodyRequest, makePutBodyRequest } from '../requests/requests' | ||
4 | import { UserNotification, UserNotificationSetting, UserNotificationType } from '../../models/users' | ||
5 | import { ServerInfo } from '..' | ||
6 | import { expect } from 'chai' | 3 | import { expect } from 'chai' |
7 | import { inspect } from 'util' | 4 | import { inspect } from 'util' |
5 | import { UserNotification, UserNotificationSetting, UserNotificationSettingValue, UserNotificationType } from '../../models/users' | ||
6 | import { MockSmtpServer } from '../miscs/email' | ||
7 | import { makeGetRequest, makePostBodyRequest, makePutBodyRequest } from '../requests/requests' | ||
8 | import { doubleFollow } from '../server/follows' | ||
9 | import { flushAndRunMultipleServers, ServerInfo } from '../server/servers' | ||
10 | import { getUserNotificationSocket } from '../socket/socket-io' | ||
11 | import { setAccessTokensToServers, userLogin } from './login' | ||
12 | import { createUser, getMyUserInformation } from './users' | ||
8 | 13 | ||
9 | function updateMyNotificationSettings (url: string, token: string, settings: UserNotificationSetting, statusCodeExpected = 204) { | 14 | function updateMyNotificationSettings (url: string, token: string, settings: UserNotificationSetting, statusCodeExpected = 204) { |
10 | const path = '/api/v1/users/me/notification-settings' | 15 | const path = '/api/v1/users/me/notification-settings' |
@@ -76,7 +81,7 @@ async function getLastNotification (serverUrl: string, accessToken: string) { | |||
76 | 81 | ||
77 | type CheckerBaseParams = { | 82 | type CheckerBaseParams = { |
78 | server: ServerInfo | 83 | server: ServerInfo |
79 | emails: object[] | 84 | emails: any[] |
80 | socketNotifications: UserNotification[] | 85 | socketNotifications: UserNotification[] |
81 | token: string | 86 | token: string |
82 | check?: { web: boolean, mail: boolean } | 87 | check?: { web: boolean, mail: boolean } |
@@ -110,10 +115,10 @@ async function checkNotification ( | |||
110 | 115 | ||
111 | if (checkType === 'presence') { | 116 | if (checkType === 'presence') { |
112 | const obj = inspect(base.socketNotifications, { depth: 5 }) | 117 | const obj = inspect(base.socketNotifications, { depth: 5 }) |
113 | expect(socketNotification, 'The socket notification is absent when is should be present. ' + obj).to.not.be.undefined | 118 | expect(socketNotification, 'The socket notification is absent when it should be present. ' + obj).to.not.be.undefined |
114 | } else { | 119 | } else { |
115 | const obj = inspect(socketNotification, { depth: 5 }) | 120 | const obj = inspect(socketNotification, { depth: 5 }) |
116 | expect(socketNotification, 'The socket notification is present when is should not be present. ' + obj).to.be.undefined | 121 | expect(socketNotification, 'The socket notification is present when it should not be present. ' + obj).to.be.undefined |
117 | } | 122 | } |
118 | } | 123 | } |
119 | 124 | ||
@@ -125,7 +130,8 @@ async function checkNotification ( | |||
125 | .find(e => emailNotificationFinder(e)) | 130 | .find(e => emailNotificationFinder(e)) |
126 | 131 | ||
127 | if (checkType === 'presence') { | 132 | if (checkType === 'presence') { |
128 | expect(email, 'The email is absent when is should be present. ' + inspect(base.emails)).to.not.be.undefined | 133 | const emails = base.emails.map(e => e.text) |
134 | expect(email, 'The email is absent when is should be present. ' + inspect(emails)).to.not.be.undefined | ||
129 | } else { | 135 | } else { |
130 | expect(email, 'The email is present when is should not be present. ' + inspect(email)).to.be.undefined | 136 | expect(email, 'The email is present when is should not be present. ' + inspect(email)).to.be.undefined |
131 | } | 137 | } |
@@ -506,11 +512,96 @@ async function checkNewBlacklistOnMyVideo ( | |||
506 | await checkNotification(base, notificationChecker, emailNotificationFinder, 'presence') | 512 | await checkNotification(base, notificationChecker, emailNotificationFinder, 'presence') |
507 | } | 513 | } |
508 | 514 | ||
515 | function getAllNotificationsSettings () { | ||
516 | return { | ||
517 | newVideoFromSubscription: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, | ||
518 | newCommentOnMyVideo: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, | ||
519 | videoAbuseAsModerator: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, | ||
520 | videoAutoBlacklistAsModerator: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, | ||
521 | blacklistOnMyVideo: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, | ||
522 | myVideoImportFinished: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, | ||
523 | myVideoPublished: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, | ||
524 | commentMention: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, | ||
525 | newFollow: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, | ||
526 | newUserRegistration: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, | ||
527 | newInstanceFollower: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, | ||
528 | autoInstanceFollowing: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL | ||
529 | } as UserNotificationSetting | ||
530 | } | ||
531 | |||
532 | async function prepareNotificationsTest (serversCount = 3) { | ||
533 | const userNotifications: UserNotification[] = [] | ||
534 | const adminNotifications: UserNotification[] = [] | ||
535 | const adminNotificationsServer2: UserNotification[] = [] | ||
536 | const emails: object[] = [] | ||
537 | |||
538 | const port = await MockSmtpServer.Instance.collectEmails(emails) | ||
539 | |||
540 | const overrideConfig = { | ||
541 | smtp: { | ||
542 | hostname: 'localhost', | ||
543 | port | ||
544 | } | ||
545 | } | ||
546 | const servers = await flushAndRunMultipleServers(serversCount, overrideConfig) | ||
547 | |||
548 | await setAccessTokensToServers(servers) | ||
549 | await doubleFollow(servers[0], servers[1]) | ||
550 | |||
551 | const user = { | ||
552 | username: 'user_1', | ||
553 | password: 'super password' | ||
554 | } | ||
555 | await createUser({ | ||
556 | url: servers[0].url, | ||
557 | accessToken: servers[0].accessToken, | ||
558 | username: user.username, | ||
559 | password: user.password, | ||
560 | videoQuota: 10 * 1000 * 1000 | ||
561 | }) | ||
562 | const userAccessToken = await userLogin(servers[0], user) | ||
563 | |||
564 | await updateMyNotificationSettings(servers[0].url, userAccessToken, getAllNotificationsSettings()) | ||
565 | await updateMyNotificationSettings(servers[0].url, servers[0].accessToken, getAllNotificationsSettings()) | ||
566 | |||
567 | if (serversCount > 1) { | ||
568 | await updateMyNotificationSettings(servers[1].url, servers[1].accessToken, getAllNotificationsSettings()) | ||
569 | } | ||
570 | |||
571 | { | ||
572 | const socket = getUserNotificationSocket(servers[0].url, userAccessToken) | ||
573 | socket.on('new-notification', n => userNotifications.push(n)) | ||
574 | } | ||
575 | { | ||
576 | const socket = getUserNotificationSocket(servers[0].url, servers[0].accessToken) | ||
577 | socket.on('new-notification', n => adminNotifications.push(n)) | ||
578 | } | ||
579 | |||
580 | if (serversCount > 1) { | ||
581 | const socket = getUserNotificationSocket(servers[1].url, servers[1].accessToken) | ||
582 | socket.on('new-notification', n => adminNotificationsServer2.push(n)) | ||
583 | } | ||
584 | |||
585 | const resChannel = await getMyUserInformation(servers[0].url, servers[0].accessToken) | ||
586 | const channelId = resChannel.body.videoChannels[0].id | ||
587 | |||
588 | return { | ||
589 | userNotifications, | ||
590 | adminNotifications, | ||
591 | adminNotificationsServer2, | ||
592 | userAccessToken, | ||
593 | emails, | ||
594 | servers, | ||
595 | channelId | ||
596 | } | ||
597 | } | ||
598 | |||
509 | // --------------------------------------------------------------------------- | 599 | // --------------------------------------------------------------------------- |
510 | 600 | ||
511 | export { | 601 | export { |
512 | CheckerBaseParams, | 602 | CheckerBaseParams, |
513 | CheckerType, | 603 | CheckerType, |
604 | getAllNotificationsSettings, | ||
514 | checkNotification, | 605 | checkNotification, |
515 | markAsReadAllNotifications, | 606 | markAsReadAllNotifications, |
516 | checkMyVideoImportIsFinished, | 607 | checkMyVideoImportIsFinished, |
@@ -528,5 +619,6 @@ export { | |||
528 | getUserNotifications, | 619 | getUserNotifications, |
529 | markAsReadNotifications, | 620 | markAsReadNotifications, |
530 | getLastNotification, | 621 | getLastNotification, |
531 | checkNewInstanceFollower | 622 | checkNewInstanceFollower, |
623 | prepareNotificationsTest | ||
532 | } | 624 | } |
diff --git a/shared/extra-utils/videos/videos.ts b/shared/extra-utils/videos/videos.ts index 99e591cb2..2f7f2182c 100644 --- a/shared/extra-utils/videos/videos.ts +++ b/shared/extra-utils/videos/videos.ts | |||
@@ -5,21 +5,23 @@ import { pathExists, readdir, readFile } from 'fs-extra' | |||
5 | import * as parseTorrent from 'parse-torrent' | 5 | import * as parseTorrent from 'parse-torrent' |
6 | import { extname, join } from 'path' | 6 | import { extname, join } from 'path' |
7 | import * as request from 'supertest' | 7 | import * as request from 'supertest' |
8 | import { v4 as uuidv4 } from 'uuid' | ||
9 | import validator from 'validator' | ||
10 | import { loadLanguages, VIDEO_CATEGORIES, VIDEO_LANGUAGES, VIDEO_LICENCES, VIDEO_PRIVACIES } from '../../../server/initializers/constants' | ||
11 | import { VideoDetails, VideoPrivacy } from '../../models/videos' | ||
8 | import { | 12 | import { |
9 | buildAbsoluteFixturePath, | 13 | buildAbsoluteFixturePath, |
10 | getMyUserInformation, | 14 | buildServerDirectory, |
15 | dateIsValid, | ||
11 | immutableAssign, | 16 | immutableAssign, |
12 | makeGetRequest, | ||
13 | makePutBodyRequest, | ||
14 | makeUploadRequest, | ||
15 | root, | 17 | root, |
16 | ServerInfo, | 18 | testImage, |
17 | testImage | 19 | webtorrentAdd |
18 | } from '../' | 20 | } from '../miscs/miscs' |
19 | import validator from 'validator' | 21 | import { makeGetRequest, makePutBodyRequest, makeUploadRequest } from '../requests/requests' |
20 | import { VideoDetails, VideoPrivacy } from '../../models/videos' | 22 | import { waitJobs } from '../server/jobs' |
21 | import { VIDEO_CATEGORIES, VIDEO_LANGUAGES, loadLanguages, VIDEO_LICENCES, VIDEO_PRIVACIES } from '../../../server/initializers/constants' | 23 | import { ServerInfo } from '../server/servers' |
22 | import { dateIsValid, webtorrentAdd, buildServerDirectory } from '../miscs/miscs' | 24 | import { getMyUserInformation } from '../users/users' |
23 | 25 | ||
24 | loadLanguages() | 26 | loadLanguages() |
25 | 27 | ||
@@ -644,11 +646,34 @@ async function getLocalIdByUUID (url: string, uuid: string) { | |||
644 | return res.body.id | 646 | return res.body.id |
645 | } | 647 | } |
646 | 648 | ||
649 | // serverNumber starts from 1 | ||
650 | async function uploadRandomVideoOnServers (servers: ServerInfo[], serverNumber: number, additionalParams: any = {}) { | ||
651 | const server = servers.find(s => s.serverNumber === serverNumber) | ||
652 | const res = await uploadRandomVideo(server, false, additionalParams) | ||
653 | |||
654 | await waitJobs(servers) | ||
655 | |||
656 | return res | ||
657 | } | ||
658 | |||
659 | async function uploadRandomVideo (server: ServerInfo, wait = true, additionalParams: any = {}) { | ||
660 | const prefixName = additionalParams.prefixName || '' | ||
661 | const name = prefixName + uuidv4() | ||
662 | |||
663 | const data = Object.assign({ name }, additionalParams) | ||
664 | const res = await uploadVideo(server.url, server.accessToken, data) | ||
665 | |||
666 | if (wait) await waitJobs([ server ]) | ||
667 | |||
668 | return { uuid: res.body.video.uuid, name } | ||
669 | } | ||
670 | |||
647 | // --------------------------------------------------------------------------- | 671 | // --------------------------------------------------------------------------- |
648 | 672 | ||
649 | export { | 673 | export { |
650 | getVideoDescription, | 674 | getVideoDescription, |
651 | getVideoCategories, | 675 | getVideoCategories, |
676 | uploadRandomVideo, | ||
652 | getVideoLicences, | 677 | getVideoLicences, |
653 | videoUUIDToId, | 678 | videoUUIDToId, |
654 | getVideoPrivacies, | 679 | getVideoPrivacies, |
@@ -666,6 +691,7 @@ export { | |||
666 | getVideosListWithToken, | 691 | getVideosListWithToken, |
667 | uploadVideo, | 692 | uploadVideo, |
668 | getVideosWithFilters, | 693 | getVideosWithFilters, |
694 | uploadRandomVideoOnServers, | ||
669 | updateVideo, | 695 | updateVideo, |
670 | rateVideo, | 696 | rateVideo, |
671 | viewVideo, | 697 | viewVideo, |