X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;ds=inline;f=server%2Ftests%2Fapi%2Fnotifications%2Fuser-notifications.ts;h=1d159c48f41b1e792736ddb3c69ee7665bedcb1c;hb=a54618880c394ad7571f3f3222dc96ec2dd10d9a;hp=6a65447fdefc513f5213934a84732987574459c3;hpb=9f39c5466ea643bc46bc4d4751ce09cb05b6c762;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/tests/api/notifications/user-notifications.ts b/server/tests/api/notifications/user-notifications.ts index 6a65447fd..1d159c48f 100644 --- a/server/tests/api/notifications/user-notifications.ts +++ b/server/tests/api/notifications/user-notifications.ts @@ -2,31 +2,26 @@ import 'mocha' import * as chai from 'chai' -import { v4 as uuidv4 } from 'uuid' -import { - cleanupTests, - updateMyUser, - updateVideo, - updateVideoChannel, - uploadRandomVideoOnServers, - wait -} from '../../../../shared/extra-utils' -import { ServerInfo } from '../../../../shared/extra-utils/index' -import { MockSmtpServer } from '../../../../shared/extra-utils/miscs/email' -import { waitJobs } from '../../../../shared/extra-utils/server/jobs' +import { buildUUID } from '@server/helpers/uuid' import { CheckerBaseParams, checkMyVideoImportIsFinished, checkNewActorFollow, checkNewVideoFromSubscription, checkVideoIsPublished, + cleanupTests, getLastNotification, - prepareNotificationsTest -} from '../../../../shared/extra-utils/users/user-notifications' -import { addUserSubscription, removeUserSubscription } from '../../../../shared/extra-utils/users/user-subscriptions' -import { getBadVideoUrl, getGoodVideoUrl, importVideo } from '../../../../shared/extra-utils/videos/video-imports' -import { UserNotification, UserNotificationType } from '../../../../shared/models/users' -import { VideoPrivacy } from '../../../../shared/models/videos' + ImportsCommand, + MockSmtpServer, + prepareNotificationsTest, + ServerInfo, + updateMyUser, + updateVideo, + uploadRandomVideoOnServers, + wait, + waitJobs +} from '@shared/extra-utils' +import { UserNotification, UserNotificationType, VideoPrivacy } from '@shared/models' const expect = chai.expect @@ -79,7 +74,7 @@ describe('Test user notifications', function () { it('Should send a new video notification if the user follows the local video publisher', async function () { this.timeout(15000) - await addUserSubscription(servers[0].url, userAccessToken, 'root_channel@localhost:' + servers[0].port) + await servers[0].subscriptionsCommand.add({ token: userAccessToken, targetUri: 'root_channel@localhost:' + servers[0].port }) await waitJobs(servers) const { name, uuid } = await uploadRandomVideoOnServers(servers, 1) @@ -89,7 +84,7 @@ describe('Test user notifications', function () { it('Should send a new video notification from a remote account', async function () { this.timeout(150000) // Server 2 has transcoding enabled - await addUserSubscription(servers[0].url, userAccessToken, 'root_channel@localhost:' + servers[1].port) + await servers[0].subscriptionsCommand.add({ token: userAccessToken, targetUri: 'root_channel@localhost:' + servers[1].port }) await waitJobs(servers) const { name, uuid } = await uploadRandomVideoOnServers(servers, 2) @@ -207,20 +202,19 @@ describe('Test user notifications', function () { it('Should send a new video notification after a video import', async function () { this.timeout(100000) - const name = 'video import ' + uuidv4() + const name = 'video import ' + buildUUID() const attributes = { name, channelId, privacy: VideoPrivacy.PUBLIC, - targetUrl: getGoodVideoUrl() + targetUrl: ImportsCommand.getGoodVideoUrl() } - const res = await importVideo(servers[0].url, servers[0].accessToken, attributes) - const uuid = res.body.video.uuid + const { video } = await servers[0].importsCommand.importVideo({ attributes }) await waitJobs(servers) - await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence') + await checkNewVideoFromSubscription(baseParams, name, video.uuid, 'presence') }) }) @@ -278,20 +272,19 @@ describe('Test user notifications', function () { it('Should send a notification when an imported video is transcoded', async function () { this.timeout(50000) - const name = 'video import ' + uuidv4() + const name = 'video import ' + buildUUID() const attributes = { name, channelId, privacy: VideoPrivacy.PUBLIC, - targetUrl: getGoodVideoUrl(), + targetUrl: ImportsCommand.getGoodVideoUrl(), waitTranscoding: true } - const res = await importVideo(servers[1].url, servers[1].accessToken, attributes) - const uuid = res.body.video.uuid + const { video } = await servers[1].importsCommand.importVideo({ attributes }) await waitJobs(servers) - await checkVideoIsPublished(baseParams, name, uuid, 'presence') + await checkVideoIsPublished(baseParams, name, video.uuid, 'presence') }) it('Should send a notification when the scheduled update has been proceeded', async function () { @@ -314,7 +307,7 @@ describe('Test user notifications', function () { }) it('Should not send a notification before the video is published', async function () { - this.timeout(40000) + this.timeout(50000) const updateAt = new Date(new Date().getTime() + 1000000) @@ -347,37 +340,35 @@ describe('Test user notifications', function () { it('Should send a notification when the video import failed', async function () { this.timeout(70000) - const name = 'video import ' + uuidv4() + const name = 'video import ' + buildUUID() const attributes = { name, channelId, privacy: VideoPrivacy.PRIVATE, - targetUrl: getBadVideoUrl() + targetUrl: ImportsCommand.getBadVideoUrl() } - const res = await importVideo(servers[0].url, servers[0].accessToken, attributes) - const uuid = res.body.video.uuid + const { video } = await servers[0].importsCommand.importVideo({ attributes }) await waitJobs(servers) - await checkMyVideoImportIsFinished(baseParams, name, uuid, getBadVideoUrl(), false, 'presence') + await checkMyVideoImportIsFinished(baseParams, name, video.uuid, ImportsCommand.getBadVideoUrl(), false, 'presence') }) it('Should send a notification when the video import succeeded', async function () { this.timeout(70000) - const name = 'video import ' + uuidv4() + const name = 'video import ' + buildUUID() const attributes = { name, channelId, privacy: VideoPrivacy.PRIVATE, - targetUrl: getGoodVideoUrl() + targetUrl: ImportsCommand.getGoodVideoUrl() } - const res = await importVideo(servers[0].url, servers[0].accessToken, attributes) - const uuid = res.body.video.uuid + const { video } = await servers[0].importsCommand.importVideo({ attributes }) await waitJobs(servers) - await checkMyVideoImportIsFinished(baseParams, name, uuid, getGoodVideoUrl(), true, 'presence') + await checkMyVideoImportIsFinished(baseParams, name, video.uuid, ImportsCommand.getGoodVideoUrl(), true, 'presence') }) }) @@ -412,29 +403,33 @@ describe('Test user notifications', function () { displayName: 'super root 2 name' }) - await updateVideoChannel(servers[0].url, userAccessToken, 'user_1_channel', { displayName: myChannelName }) + await servers[0].channelsCommand.update({ + token: userAccessToken, + channelName: 'user_1_channel', + attributes: { displayName: myChannelName } + }) }) it('Should notify when a local channel is following one of our channel', async function () { this.timeout(50000) - await addUserSubscription(servers[0].url, servers[0].accessToken, 'user_1_channel@localhost:' + servers[0].port) + await servers[0].subscriptionsCommand.add({ targetUri: 'user_1_channel@localhost:' + servers[0].port }) await waitJobs(servers) await checkNewActorFollow(baseParams, 'channel', 'root', 'super root name', myChannelName, 'presence') - await removeUserSubscription(servers[0].url, servers[0].accessToken, 'user_1_channel@localhost:' + servers[0].port) + await servers[0].subscriptionsCommand.remove({ uri: 'user_1_channel@localhost:' + servers[0].port }) }) it('Should notify when a remote channel is following one of our channel', async function () { this.timeout(50000) - await addUserSubscription(servers[1].url, servers[1].accessToken, 'user_1_channel@localhost:' + servers[0].port) + await servers[1].subscriptionsCommand.add({ targetUri: 'user_1_channel@localhost:' + servers[0].port }) await waitJobs(servers) await checkNewActorFollow(baseParams, 'channel', 'root', 'super root 2 name', myChannelName, 'presence') - await removeUserSubscription(servers[1].url, servers[1].accessToken, 'user_1_channel@localhost:' + servers[0].port) + await servers[1].subscriptionsCommand.remove({ uri: 'user_1_channel@localhost:' + servers[0].port }) }) // PeerTube does not support accout -> account follows