aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-07-07 16:40:49 +0200
committerChocobozzz <me@florianbigard.com>2021-07-20 15:27:17 +0200
commit2c27e70471120c92e0bc8c8114141fbb31ff98ac (patch)
treef52d89adc0351168fd1d89cbc07652e1408caaf2
parent5f8bd4cbb178290da7d8f81e996f19f0eccc8e4c (diff)
downloadPeerTube-2c27e70471120c92e0bc8c8114141fbb31ff98ac.tar.gz
PeerTube-2c27e70471120c92e0bc8c8114141fbb31ff98ac.tar.zst
PeerTube-2c27e70471120c92e0bc8c8114141fbb31ff98ac.zip
Introduce subscriptions command
-rw-r--r--server/tests/api/moderation/blocklist-notification.ts10
-rw-r--r--server/tests/api/notifications/moderation-notifications.ts10
-rw-r--r--server/tests/api/notifications/notifications-api.ts19
-rw-r--r--server/tests/api/notifications/user-notifications.ts42
-rw-r--r--server/tests/api/users/user-subscriptions.ts144
-rw-r--r--server/tests/feeds/feeds.ts24
-rw-r--r--shared/extra-utils/server/servers.ts4
-rw-r--r--shared/extra-utils/users/index.ts2
-rw-r--r--shared/extra-utils/users/subscriptions-command.ts94
-rw-r--r--shared/extra-utils/users/user-subscriptions.ts93
10 files changed, 208 insertions, 234 deletions
diff --git a/server/tests/api/moderation/blocklist-notification.ts b/server/tests/api/moderation/blocklist-notification.ts
index 99da64a2d..5b9699816 100644
--- a/server/tests/api/moderation/blocklist-notification.ts
+++ b/server/tests/api/moderation/blocklist-notification.ts
@@ -3,7 +3,6 @@
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { 5import {
6 addUserSubscription,
7 addVideoCommentThread, 6 addVideoCommentThread,
8 cleanupTests, 7 cleanupTests,
9 createUser, 8 createUser,
@@ -11,7 +10,6 @@ import {
11 flushAndRunMultipleServers, 10 flushAndRunMultipleServers,
12 getUserNotifications, 11 getUserNotifications,
13 markAsReadAllNotifications, 12 markAsReadAllNotifications,
14 removeUserSubscription,
15 ServerInfo, 13 ServerInfo,
16 setAccessTokensToServers, 14 setAccessTokensToServers,
17 uploadVideo, 15 uploadVideo,
@@ -44,8 +42,8 @@ describe('Test blocklist', function () {
44 42
45 async function resetState () { 43 async function resetState () {
46 try { 44 try {
47 await removeUserSubscription(servers[1].url, remoteUserToken, 'user1_channel@' + servers[0].host) 45 await servers[1].subscriptionsCommand.remove({ token: remoteUserToken, uri: 'user1_channel@' + servers[0].host })
48 await removeUserSubscription(servers[1].url, remoteUserToken, 'user2_channel@' + servers[0].host) 46 await servers[1].subscriptionsCommand.remove({ token: remoteUserToken, uri: 'user2_channel@' + servers[0].host })
49 } catch {} 47 } catch {}
50 48
51 await waitJobs(servers) 49 await waitJobs(servers)
@@ -66,8 +64,8 @@ describe('Test blocklist', function () {
66 64
67 { 65 {
68 66
69 await addUserSubscription(servers[1].url, remoteUserToken, 'user1_channel@' + servers[0].host) 67 await servers[1].subscriptionsCommand.add({ token: remoteUserToken, targetUri: 'user1_channel@' + servers[0].host })
70 await addUserSubscription(servers[1].url, remoteUserToken, 'user2_channel@' + servers[0].host) 68 await servers[1].subscriptionsCommand.add({ token: remoteUserToken, targetUri: 'user2_channel@' + servers[0].host })
71 } 69 }
72 70
73 await waitJobs(servers) 71 await waitJobs(servers)
diff --git a/server/tests/api/notifications/moderation-notifications.ts b/server/tests/api/notifications/moderation-notifications.ts
index e90640ad6..605b41947 100644
--- a/server/tests/api/notifications/moderation-notifications.ts
+++ b/server/tests/api/notifications/moderation-notifications.ts
@@ -3,7 +3,6 @@
3import 'mocha' 3import 'mocha'
4import { buildUUID } from '@server/helpers/uuid' 4import { buildUUID } from '@server/helpers/uuid'
5import { 5import {
6 addUserSubscription,
7 addVideoCommentThread, 6 addVideoCommentThread,
8 addVideoToBlacklist, 7 addVideoToBlacklist,
9 checkAbuseStateChange, 8 checkAbuseStateChange,
@@ -29,7 +28,6 @@ import {
29 MockSmtpServer, 28 MockSmtpServer,
30 prepareNotificationsTest, 29 prepareNotificationsTest,
31 registerUser, 30 registerUser,
32 removeUserSubscription,
33 removeVideoFromBlacklist, 31 removeVideoFromBlacklist,
34 ServerInfo, 32 ServerInfo,
35 uploadVideo, 33 uploadVideo,
@@ -488,8 +486,8 @@ describe('Test moderation notifications', function () {
488 autoBlacklistTestsCustomConfig.transcoding.enabled = true 486 autoBlacklistTestsCustomConfig.transcoding.enabled = true
489 await servers[0].configCommand.updateCustomConfig({ newCustomConfig: autoBlacklistTestsCustomConfig }) 487 await servers[0].configCommand.updateCustomConfig({ newCustomConfig: autoBlacklistTestsCustomConfig })
490 488
491 await addUserSubscription(servers[0].url, servers[0].accessToken, 'user_1_channel@localhost:' + servers[0].port) 489 await servers[0].subscriptionsCommand.add({ targetUri: 'user_1_channel@localhost:' + servers[0].port })
492 await addUserSubscription(servers[1].url, servers[1].accessToken, 'user_1_channel@localhost:' + servers[0].port) 490 await servers[1].subscriptionsCommand.add({ targetUri: 'user_1_channel@localhost:' + servers[0].port })
493 491
494 }) 492 })
495 493
@@ -611,8 +609,8 @@ describe('Test moderation notifications', function () {
611 after(async () => { 609 after(async () => {
612 await servers[0].configCommand.updateCustomConfig({ newCustomConfig: currentCustomConfig }) 610 await servers[0].configCommand.updateCustomConfig({ newCustomConfig: currentCustomConfig })
613 611
614 await removeUserSubscription(servers[0].url, servers[0].accessToken, 'user_1_channel@localhost:' + servers[0].port) 612 await servers[0].subscriptionsCommand.remove({ uri: 'user_1_channel@localhost:' + servers[0].port })
615 await removeUserSubscription(servers[1].url, servers[1].accessToken, 'user_1_channel@localhost:' + servers[0].port) 613 await servers[1].subscriptionsCommand.remove({ uri: 'user_1_channel@localhost:' + servers[0].port })
616 }) 614 })
617 }) 615 })
618 616
diff --git a/server/tests/api/notifications/notifications-api.ts b/server/tests/api/notifications/notifications-api.ts
index 19f9dbbab..1ed98ae7a 100644
--- a/server/tests/api/notifications/notifications-api.ts
+++ b/server/tests/api/notifications/notifications-api.ts
@@ -2,21 +2,24 @@
2 2
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { addUserSubscription } from '@shared/extra-utils/users/user-subscriptions'
6import { cleanupTests, getMyUserInformation, immutableAssign, uploadRandomVideo, waitJobs } from '../../../../shared/extra-utils'
7import { ServerInfo } from '../../../../shared/extra-utils/index'
8import { MockSmtpServer } from '../../../../shared/extra-utils/mock-servers/mock-email'
9import { 5import {
10 CheckerBaseParams, 6 CheckerBaseParams,
11 checkNewVideoFromSubscription, 7 checkNewVideoFromSubscription,
8 cleanupTests,
12 getAllNotificationsSettings, 9 getAllNotificationsSettings,
10 getMyUserInformation,
13 getUserNotifications, 11 getUserNotifications,
12 immutableAssign,
14 markAsReadAllNotifications, 13 markAsReadAllNotifications,
15 markAsReadNotifications, 14 markAsReadNotifications,
15 MockSmtpServer,
16 prepareNotificationsTest, 16 prepareNotificationsTest,
17 updateMyNotificationSettings 17 ServerInfo,
18} from '../../../../shared/extra-utils/users/user-notifications' 18 updateMyNotificationSettings,
19import { User, UserNotification, UserNotificationSettingValue } from '../../../../shared/models/users' 19 uploadRandomVideo,
20 waitJobs
21} from '@shared/extra-utils'
22import { User, UserNotification, UserNotificationSettingValue } from '@shared/models'
20 23
21const expect = chai.expect 24const expect = chai.expect
22 25
@@ -35,7 +38,7 @@ describe('Test notifications API', function () {
35 userNotifications = res.userNotifications 38 userNotifications = res.userNotifications
36 server = res.servers[0] 39 server = res.servers[0]
37 40
38 await addUserSubscription(server.url, userAccessToken, 'root_channel@localhost:' + server.port) 41 await server.subscriptionsCommand.add({ token: userAccessToken, targetUri: 'root_channel@localhost:' + server.port })
39 42
40 for (let i = 0; i < 10; i++) { 43 for (let i = 0; i < 10; i++) {
41 await uploadRandomVideo(server, false) 44 await uploadRandomVideo(server, false)
diff --git a/server/tests/api/notifications/user-notifications.ts b/server/tests/api/notifications/user-notifications.ts
index ace7e48c7..15be983f2 100644
--- a/server/tests/api/notifications/user-notifications.ts
+++ b/server/tests/api/notifications/user-notifications.ts
@@ -4,29 +4,25 @@ import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { buildUUID } from '@server/helpers/uuid' 5import { buildUUID } from '@server/helpers/uuid'
6import { 6import {
7 cleanupTests,
8 updateMyUser,
9 updateVideo,
10 updateVideoChannel,
11 uploadRandomVideoOnServers,
12 wait
13} from '../../../../shared/extra-utils'
14import { ServerInfo } from '../../../../shared/extra-utils/index'
15import { MockSmtpServer } from '../../../../shared/extra-utils/mock-servers/mock-email'
16import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
17import {
18 CheckerBaseParams, 7 CheckerBaseParams,
19 checkMyVideoImportIsFinished, 8 checkMyVideoImportIsFinished,
20 checkNewActorFollow, 9 checkNewActorFollow,
21 checkNewVideoFromSubscription, 10 checkNewVideoFromSubscription,
22 checkVideoIsPublished, 11 checkVideoIsPublished,
12 cleanupTests,
23 getLastNotification, 13 getLastNotification,
24 prepareNotificationsTest 14 MockSmtpServer,
25} from '../../../../shared/extra-utils/users/user-notifications' 15 prepareNotificationsTest,
26import { addUserSubscription, removeUserSubscription } from '../../../../shared/extra-utils/users/user-subscriptions' 16 ServerInfo,
27import { getBadVideoUrl, getGoodVideoUrl, importVideo } from '../../../../shared/extra-utils/videos/video-imports' 17 updateMyUser,
28import { UserNotification, UserNotificationType } from '../../../../shared/models/users' 18 updateVideo,
29import { VideoPrivacy } from '../../../../shared/models/videos' 19 updateVideoChannel,
20 uploadRandomVideoOnServers,
21 wait,
22 waitJobs
23} from '@shared/extra-utils'
24import { getBadVideoUrl, getGoodVideoUrl, importVideo } from '@shared/extra-utils/videos/video-imports'
25import { UserNotification, UserNotificationType, VideoPrivacy } from '@shared/models'
30 26
31const expect = chai.expect 27const expect = chai.expect
32 28
@@ -79,7 +75,7 @@ describe('Test user notifications', function () {
79 it('Should send a new video notification if the user follows the local video publisher', async function () { 75 it('Should send a new video notification if the user follows the local video publisher', async function () {
80 this.timeout(15000) 76 this.timeout(15000)
81 77
82 await addUserSubscription(servers[0].url, userAccessToken, 'root_channel@localhost:' + servers[0].port) 78 await servers[0].subscriptionsCommand.add({ token: userAccessToken, targetUri: 'root_channel@localhost:' + servers[0].port })
83 await waitJobs(servers) 79 await waitJobs(servers)
84 80
85 const { name, uuid } = await uploadRandomVideoOnServers(servers, 1) 81 const { name, uuid } = await uploadRandomVideoOnServers(servers, 1)
@@ -89,7 +85,7 @@ describe('Test user notifications', function () {
89 it('Should send a new video notification from a remote account', async function () { 85 it('Should send a new video notification from a remote account', async function () {
90 this.timeout(150000) // Server 2 has transcoding enabled 86 this.timeout(150000) // Server 2 has transcoding enabled
91 87
92 await addUserSubscription(servers[0].url, userAccessToken, 'root_channel@localhost:' + servers[1].port) 88 await servers[0].subscriptionsCommand.add({ token: userAccessToken, targetUri: 'root_channel@localhost:' + servers[1].port })
93 await waitJobs(servers) 89 await waitJobs(servers)
94 90
95 const { name, uuid } = await uploadRandomVideoOnServers(servers, 2) 91 const { name, uuid } = await uploadRandomVideoOnServers(servers, 2)
@@ -418,23 +414,23 @@ describe('Test user notifications', function () {
418 it('Should notify when a local channel is following one of our channel', async function () { 414 it('Should notify when a local channel is following one of our channel', async function () {
419 this.timeout(50000) 415 this.timeout(50000)
420 416
421 await addUserSubscription(servers[0].url, servers[0].accessToken, 'user_1_channel@localhost:' + servers[0].port) 417 await servers[0].subscriptionsCommand.add({ targetUri: 'user_1_channel@localhost:' + servers[0].port })
422 await waitJobs(servers) 418 await waitJobs(servers)
423 419
424 await checkNewActorFollow(baseParams, 'channel', 'root', 'super root name', myChannelName, 'presence') 420 await checkNewActorFollow(baseParams, 'channel', 'root', 'super root name', myChannelName, 'presence')
425 421
426 await removeUserSubscription(servers[0].url, servers[0].accessToken, 'user_1_channel@localhost:' + servers[0].port) 422 await servers[0].subscriptionsCommand.remove({ uri: 'user_1_channel@localhost:' + servers[0].port })
427 }) 423 })
428 424
429 it('Should notify when a remote channel is following one of our channel', async function () { 425 it('Should notify when a remote channel is following one of our channel', async function () {
430 this.timeout(50000) 426 this.timeout(50000)
431 427
432 await addUserSubscription(servers[1].url, servers[1].accessToken, 'user_1_channel@localhost:' + servers[0].port) 428 await servers[1].subscriptionsCommand.add({ targetUri: 'user_1_channel@localhost:' + servers[0].port })
433 await waitJobs(servers) 429 await waitJobs(servers)
434 430
435 await checkNewActorFollow(baseParams, 'channel', 'root', 'super root 2 name', myChannelName, 'presence') 431 await checkNewActorFollow(baseParams, 'channel', 'root', 'super root 2 name', myChannelName, 'presence')
436 432
437 await removeUserSubscription(servers[1].url, servers[1].accessToken, 'user_1_channel@localhost:' + servers[0].port) 433 await servers[1].subscriptionsCommand.remove({ uri: 'user_1_channel@localhost:' + servers[0].port })
438 }) 434 })
439 435
440 // PeerTube does not support accout -> account follows 436 // PeerTube does not support accout -> account follows
diff --git a/server/tests/api/users/user-subscriptions.ts b/server/tests/api/users/user-subscriptions.ts
index 7e365d797..c119622ad 100644
--- a/server/tests/api/users/user-subscriptions.ts
+++ b/server/tests/api/users/user-subscriptions.ts
@@ -3,25 +3,19 @@
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { 5import {
6 addUserSubscription,
7 areSubscriptionsExist,
8 cleanupTests, 6 cleanupTests,
9 createUser, 7 createUser,
10 doubleFollow, 8 doubleFollow,
11 flushAndRunMultipleServers, 9 flushAndRunMultipleServers,
12 getUserSubscription,
13 getVideosList, 10 getVideosList,
14 listUserSubscriptions,
15 listUserSubscriptionVideos,
16 removeUserSubscription,
17 ServerInfo, 11 ServerInfo,
18 setAccessTokensToServers, 12 setAccessTokensToServers,
13 SubscriptionsCommand,
19 updateVideo, 14 updateVideo,
20 uploadVideo, 15 uploadVideo,
21 userLogin, 16 userLogin,
22 waitJobs 17 waitJobs
23} from '@shared/extra-utils' 18} from '@shared/extra-utils'
24import { Video, VideoChannel } from '@shared/models'
25 19
26const expect = chai.expect 20const expect = chai.expect
27 21
@@ -30,6 +24,8 @@ describe('Test users subscriptions', function () {
30 const users: { accessToken: string }[] = [] 24 const users: { accessToken: string }[] = []
31 let video3UUID: string 25 let video3UUID: string
32 26
27 let command: SubscriptionsCommand
28
33 before(async function () { 29 before(async function () {
34 this.timeout(120000) 30 this.timeout(120000)
35 31
@@ -58,6 +54,8 @@ describe('Test users subscriptions', function () {
58 } 54 }
59 55
60 await waitJobs(servers) 56 await waitJobs(servers)
57
58 command = servers[0].subscriptionsCommand
61 }) 59 })
62 60
63 it('Should display videos of server 2 on server 1', async function () { 61 it('Should display videos of server 2 on server 1', async function () {
@@ -69,8 +67,8 @@ describe('Test users subscriptions', function () {
69 it('User of server 1 should follow user of server 3 and root of server 1', async function () { 67 it('User of server 1 should follow user of server 3 and root of server 1', async function () {
70 this.timeout(60000) 68 this.timeout(60000)
71 69
72 await addUserSubscription(servers[0].url, users[0].accessToken, 'user3_channel@localhost:' + servers[2].port) 70 await command.add({ token: users[0].accessToken, targetUri: 'user3_channel@localhost:' + servers[2].port })
73 await addUserSubscription(servers[0].url, users[0].accessToken, 'root_channel@localhost:' + servers[0].port) 71 await command.add({ token: users[0].accessToken, targetUri: 'root_channel@localhost:' + servers[0].port })
74 72
75 await waitJobs(servers) 73 await waitJobs(servers)
76 74
@@ -93,17 +91,17 @@ describe('Test users subscriptions', function () {
93 91
94 it('Should list subscriptions', async function () { 92 it('Should list subscriptions', async function () {
95 { 93 {
96 const res = await listUserSubscriptions({ url: servers[0].url, token: servers[0].accessToken }) 94 const body = await command.list()
97 expect(res.body.total).to.equal(0) 95 expect(body.total).to.equal(0)
98 expect(res.body.data).to.be.an('array') 96 expect(body.data).to.be.an('array')
99 expect(res.body.data).to.have.lengthOf(0) 97 expect(body.data).to.have.lengthOf(0)
100 } 98 }
101 99
102 { 100 {
103 const res = await listUserSubscriptions({ url: servers[0].url, token: users[0].accessToken, sort: 'createdAt' }) 101 const body = await command.list({ token: users[0].accessToken, sort: 'createdAt' })
104 expect(res.body.total).to.equal(2) 102 expect(body.total).to.equal(2)
105 103
106 const subscriptions: VideoChannel[] = res.body.data 104 const subscriptions = body.data
107 expect(subscriptions).to.be.an('array') 105 expect(subscriptions).to.be.an('array')
108 expect(subscriptions).to.have.lengthOf(2) 106 expect(subscriptions).to.have.lengthOf(2)
109 107
@@ -114,8 +112,7 @@ describe('Test users subscriptions', function () {
114 112
115 it('Should get subscription', async function () { 113 it('Should get subscription', async function () {
116 { 114 {
117 const res = await getUserSubscription(servers[0].url, users[0].accessToken, 'user3_channel@localhost:' + servers[2].port) 115 const videoChannel = await command.get({ token: users[0].accessToken, uri: 'user3_channel@localhost:' + servers[2].port })
118 const videoChannel: VideoChannel = res.body
119 116
120 expect(videoChannel.name).to.equal('user3_channel') 117 expect(videoChannel.name).to.equal('user3_channel')
121 expect(videoChannel.host).to.equal('localhost:' + servers[2].port) 118 expect(videoChannel.host).to.equal('localhost:' + servers[2].port)
@@ -125,8 +122,7 @@ describe('Test users subscriptions', function () {
125 } 122 }
126 123
127 { 124 {
128 const res = await getUserSubscription(servers[0].url, users[0].accessToken, 'root_channel@localhost:' + servers[0].port) 125 const videoChannel = await command.get({ token: users[0].accessToken, uri: 'root_channel@localhost:' + servers[0].port })
129 const videoChannel: VideoChannel = res.body
130 126
131 expect(videoChannel.name).to.equal('root_channel') 127 expect(videoChannel.name).to.equal('root_channel')
132 expect(videoChannel.host).to.equal('localhost:' + servers[0].port) 128 expect(videoChannel.host).to.equal('localhost:' + servers[0].port)
@@ -144,8 +140,7 @@ describe('Test users subscriptions', function () {
144 'user3_channel@localhost:' + servers[0].port 140 'user3_channel@localhost:' + servers[0].port
145 ] 141 ]
146 142
147 const res = await areSubscriptionsExist(servers[0].url, users[0].accessToken, uris) 143 const body = await command.exist({ token: users[0].accessToken, uris })
148 const body = res.body
149 144
150 expect(body['user3_channel@localhost:' + servers[2].port]).to.be.true 145 expect(body['user3_channel@localhost:' + servers[2].port]).to.be.true
151 expect(body['root2_channel@localhost:' + servers[0].port]).to.be.false 146 expect(body['root2_channel@localhost:' + servers[0].port]).to.be.false
@@ -155,45 +150,31 @@ describe('Test users subscriptions', function () {
155 150
156 it('Should search among subscriptions', async function () { 151 it('Should search among subscriptions', async function () {
157 { 152 {
158 const res = await listUserSubscriptions({ 153 const body = await command.list({ token: users[0].accessToken, sort: '-createdAt', search: 'user3_channel' })
159 url: servers[0].url, 154 expect(body.total).to.equal(1)
160 token: users[0].accessToken, 155 expect(body.data).to.have.lengthOf(1)
161 sort: '-createdAt',
162 search: 'user3_channel'
163 })
164 expect(res.body.total).to.equal(1)
165
166 const subscriptions = res.body.data
167 expect(subscriptions).to.have.lengthOf(1)
168 } 156 }
169 157
170 { 158 {
171 const res = await listUserSubscriptions({ 159 const body = await command.list({ token: users[0].accessToken, sort: '-createdAt', search: 'toto' })
172 url: servers[0].url, 160 expect(body.total).to.equal(0)
173 token: users[0].accessToken, 161 expect(body.data).to.have.lengthOf(0)
174 sort: '-createdAt',
175 search: 'toto'
176 })
177 expect(res.body.total).to.equal(0)
178
179 const subscriptions = res.body.data
180 expect(subscriptions).to.have.lengthOf(0)
181 } 162 }
182 }) 163 })
183 164
184 it('Should list subscription videos', async function () { 165 it('Should list subscription videos', async function () {
185 { 166 {
186 const res = await listUserSubscriptionVideos(servers[0].url, servers[0].accessToken) 167 const body = await command.listVideos()
187 expect(res.body.total).to.equal(0) 168 expect(body.total).to.equal(0)
188 expect(res.body.data).to.be.an('array') 169 expect(body.data).to.be.an('array')
189 expect(res.body.data).to.have.lengthOf(0) 170 expect(body.data).to.have.lengthOf(0)
190 } 171 }
191 172
192 { 173 {
193 const res = await listUserSubscriptionVideos(servers[0].url, users[0].accessToken, 'createdAt') 174 const body = await command.listVideos({ token: users[0].accessToken, sort: 'createdAt' })
194 expect(res.body.total).to.equal(3) 175 expect(body.total).to.equal(3)
195 176
196 const videos: Video[] = res.body.data 177 const videos = body.data
197 expect(videos).to.be.an('array') 178 expect(videos).to.be.an('array')
198 expect(videos).to.have.lengthOf(3) 179 expect(videos).to.have.lengthOf(3)
199 180
@@ -212,17 +193,17 @@ describe('Test users subscriptions', function () {
212 await waitJobs(servers) 193 await waitJobs(servers)
213 194
214 { 195 {
215 const res = await listUserSubscriptionVideos(servers[0].url, servers[0].accessToken) 196 const body = await command.listVideos()
216 expect(res.body.total).to.equal(0) 197 expect(body.total).to.equal(0)
217 expect(res.body.data).to.be.an('array') 198 expect(body.data).to.be.an('array')
218 expect(res.body.data).to.have.lengthOf(0) 199 expect(body.data).to.have.lengthOf(0)
219 } 200 }
220 201
221 { 202 {
222 const res = await listUserSubscriptionVideos(servers[0].url, users[0].accessToken, 'createdAt') 203 const body = await command.listVideos({ token: users[0].accessToken, sort: 'createdAt' })
223 expect(res.body.total).to.equal(4) 204 expect(body.total).to.equal(4)
224 205
225 const videos: Video[] = res.body.data 206 const videos = body.data
226 expect(videos).to.be.an('array') 207 expect(videos).to.be.an('array')
227 expect(videos).to.have.lengthOf(4) 208 expect(videos).to.have.lengthOf(4)
228 209
@@ -281,17 +262,17 @@ describe('Test users subscriptions', function () {
281 262
282 it('Should still list subscription videos', async function () { 263 it('Should still list subscription videos', async function () {
283 { 264 {
284 const res = await listUserSubscriptionVideos(servers[0].url, servers[0].accessToken) 265 const body = await command.listVideos()
285 expect(res.body.total).to.equal(0) 266 expect(body.total).to.equal(0)
286 expect(res.body.data).to.be.an('array') 267 expect(body.data).to.be.an('array')
287 expect(res.body.data).to.have.lengthOf(0) 268 expect(body.data).to.have.lengthOf(0)
288 } 269 }
289 270
290 { 271 {
291 const res = await listUserSubscriptionVideos(servers[0].url, users[0].accessToken, 'createdAt') 272 const body = await command.listVideos({ token: users[0].accessToken, sort: 'createdAt' })
292 expect(res.body.total).to.equal(4) 273 expect(body.total).to.equal(4)
293 274
294 const videos: Video[] = res.body.data 275 const videos = body.data
295 expect(videos).to.be.an('array') 276 expect(videos).to.be.an('array')
296 expect(videos).to.have.lengthOf(4) 277 expect(videos).to.have.lengthOf(4)
297 278
@@ -309,44 +290,41 @@ describe('Test users subscriptions', function () {
309 290
310 await waitJobs(servers) 291 await waitJobs(servers)
311 292
312 const res = await listUserSubscriptionVideos(servers[0].url, users[0].accessToken, 'createdAt') 293 const body = await command.listVideos({ token: users[0].accessToken, sort: 'createdAt' })
313 const videos: Video[] = res.body.data 294 expect(body.data[2].name).to.equal('video server 3 added after follow updated')
314 expect(videos[2].name).to.equal('video server 3 added after follow updated')
315 }) 295 })
316 296
317 it('Should remove user of server 3 subscription', async function () { 297 it('Should remove user of server 3 subscription', async function () {
318 this.timeout(30000) 298 this.timeout(30000)
319 299
320 await removeUserSubscription(servers[0].url, users[0].accessToken, 'user3_channel@localhost:' + servers[2].port) 300 await command.remove({ token: users[0].accessToken, uri: 'user3_channel@localhost:' + servers[2].port })
321 301
322 await waitJobs(servers) 302 await waitJobs(servers)
323 }) 303 })
324 304
325 it('Should not display its videos anymore', async function () { 305 it('Should not display its videos anymore', async function () {
326 { 306 const body = await command.listVideos({ token: users[0].accessToken, sort: 'createdAt' })
327 const res = await listUserSubscriptionVideos(servers[0].url, users[0].accessToken, 'createdAt') 307 expect(body.total).to.equal(1)
328 expect(res.body.total).to.equal(1)
329 308
330 const videos: Video[] = res.body.data 309 const videos = body.data
331 expect(videos).to.be.an('array') 310 expect(videos).to.be.an('array')
332 expect(videos).to.have.lengthOf(1) 311 expect(videos).to.have.lengthOf(1)
333 312
334 expect(videos[0].name).to.equal('video server 1 added after follow') 313 expect(videos[0].name).to.equal('video server 1 added after follow')
335 }
336 }) 314 })
337 315
338 it('Should remove the root subscription and not display the videos anymore', async function () { 316 it('Should remove the root subscription and not display the videos anymore', async function () {
339 this.timeout(30000) 317 this.timeout(30000)
340 318
341 await removeUserSubscription(servers[0].url, users[0].accessToken, 'root_channel@localhost:' + servers[0].port) 319 await command.remove({ token: users[0].accessToken, uri: 'root_channel@localhost:' + servers[0].port })
342 320
343 await waitJobs(servers) 321 await waitJobs(servers)
344 322
345 { 323 {
346 const res = await listUserSubscriptionVideos(servers[0].url, users[0].accessToken, 'createdAt') 324 const body = await command.list({ token: users[0].accessToken, sort: 'createdAt' })
347 expect(res.body.total).to.equal(0) 325 expect(body.total).to.equal(0)
348 326
349 const videos: Video[] = res.body.data 327 const videos = body.data
350 expect(videos).to.be.an('array') 328 expect(videos).to.be.an('array')
351 expect(videos).to.have.lengthOf(0) 329 expect(videos).to.have.lengthOf(0)
352 } 330 }
@@ -366,15 +344,15 @@ describe('Test users subscriptions', function () {
366 it('Should follow user of server 3 again', async function () { 344 it('Should follow user of server 3 again', async function () {
367 this.timeout(60000) 345 this.timeout(60000)
368 346
369 await addUserSubscription(servers[0].url, users[0].accessToken, 'user3_channel@localhost:' + servers[2].port) 347 await command.add({ token: users[0].accessToken, targetUri: 'user3_channel@localhost:' + servers[2].port })
370 348
371 await waitJobs(servers) 349 await waitJobs(servers)
372 350
373 { 351 {
374 const res = await listUserSubscriptionVideos(servers[0].url, users[0].accessToken, 'createdAt') 352 const body = await command.listVideos({ token: users[0].accessToken, sort: 'createdAt' })
375 expect(res.body.total).to.equal(3) 353 expect(body.total).to.equal(3)
376 354
377 const videos: Video[] = res.body.data 355 const videos = body.data
378 expect(videos).to.be.an('array') 356 expect(videos).to.be.an('array')
379 expect(videos).to.have.lengthOf(3) 357 expect(videos).to.have.lengthOf(3)
380 358
diff --git a/server/tests/feeds/feeds.ts b/server/tests/feeds/feeds.ts
index 17efc666d..6ee22340b 100644
--- a/server/tests/feeds/feeds.ts
+++ b/server/tests/feeds/feeds.ts
@@ -5,7 +5,6 @@ import * as chai from 'chai'
5import * as xmlParser from 'fast-xml-parser' 5import * as xmlParser from 'fast-xml-parser'
6import { HttpStatusCode } from '@shared/core-utils' 6import { HttpStatusCode } from '@shared/core-utils'
7import { 7import {
8 addUserSubscription,
9 addVideoCommentThread, 8 addVideoCommentThread,
10 cleanupTests, 9 cleanupTests,
11 createUser, 10 createUser,
@@ -14,7 +13,6 @@ import {
14 flushAndRunServer, 13 flushAndRunServer,
15 getMyUserInformation, 14 getMyUserInformation,
16 getUserScopedTokens, 15 getUserScopedTokens,
17 listUserSubscriptionVideos,
18 renewUserScopedTokens, 16 renewUserScopedTokens,
19 ServerInfo, 17 ServerInfo,
20 setAccessTokensToServers, 18 setAccessTokensToServers,
@@ -319,8 +317,8 @@ describe('Test syndication feeds', () => {
319 } 317 }
320 318
321 { 319 {
322 const res = await listUserSubscriptionVideos(servers[0].url, feeduserAccessToken) 320 const body = await servers[0].subscriptionsCommand.listVideos({ token: feeduserAccessToken })
323 expect(res.body.total).to.equal(0) 321 expect(body.total).to.equal(0)
324 322
325 const query = { accountId: feeduserAccountId, token: feeduserFeedToken } 323 const query = { accountId: feeduserAccountId, token: feeduserFeedToken }
326 const json = await servers[0].feedCommand.getJSON({ feed: 'subscriptions', query }) 324 const json = await servers[0].feedCommand.getJSON({ feed: 'subscriptions', query })
@@ -340,8 +338,8 @@ describe('Test syndication feeds', () => {
340 }) 338 })
341 339
342 it('Should list no videos for a user with videos but no subscriptions', async function () { 340 it('Should list no videos for a user with videos but no subscriptions', async function () {
343 const res = await listUserSubscriptionVideos(servers[0].url, userAccessToken) 341 const body = await servers[0].subscriptionsCommand.listVideos({ token: userAccessToken })
344 expect(res.body.total).to.equal(0) 342 expect(body.total).to.equal(0)
345 343
346 const query = { accountId: userAccountId, token: userFeedToken } 344 const query = { accountId: userAccountId, token: userFeedToken }
347 const json = await servers[0].feedCommand.getJSON({ feed: 'subscriptions', query }) 345 const json = await servers[0].feedCommand.getJSON({ feed: 'subscriptions', query })
@@ -352,13 +350,13 @@ describe('Test syndication feeds', () => {
352 it('Should list self videos for a user with a subscription to themselves', async function () { 350 it('Should list self videos for a user with a subscription to themselves', async function () {
353 this.timeout(30000) 351 this.timeout(30000)
354 352
355 await addUserSubscription(servers[0].url, userAccessToken, 'john_channel@localhost:' + servers[0].port) 353 await servers[0].subscriptionsCommand.add({ token: userAccessToken, targetUri: 'john_channel@localhost:' + servers[0].port })
356 await waitJobs(servers) 354 await waitJobs(servers)
357 355
358 { 356 {
359 const res = await listUserSubscriptionVideos(servers[0].url, userAccessToken) 357 const body = await servers[0].subscriptionsCommand.listVideos({ token: userAccessToken })
360 expect(res.body.total).to.equal(1) 358 expect(body.total).to.equal(1)
361 expect(res.body.data[0].name).to.equal('user video') 359 expect(body.data[0].name).to.equal('user video')
362 360
363 const query = { accountId: userAccountId, token: userFeedToken, version: 1 } 361 const query = { accountId: userAccountId, token: userFeedToken, version: 1 }
364 const json = await servers[0].feedCommand.getJSON({ feed: 'subscriptions', query }) 362 const json = await servers[0].feedCommand.getJSON({ feed: 'subscriptions', query })
@@ -370,12 +368,12 @@ describe('Test syndication feeds', () => {
370 it('Should list videos of a user\'s subscription', async function () { 368 it('Should list videos of a user\'s subscription', async function () {
371 this.timeout(30000) 369 this.timeout(30000)
372 370
373 await addUserSubscription(servers[0].url, userAccessToken, 'root_channel@localhost:' + servers[0].port) 371 await servers[0].subscriptionsCommand.add({ token: userAccessToken, targetUri: 'root_channel@localhost:' + servers[0].port })
374 await waitJobs(servers) 372 await waitJobs(servers)
375 373
376 { 374 {
377 const res = await listUserSubscriptionVideos(servers[0].url, userAccessToken) 375 const body = await servers[0].subscriptionsCommand.listVideos({ token: userAccessToken })
378 expect(res.body.total).to.equal(2, "there should be 2 videos part of the subscription") 376 expect(body.total).to.equal(2, "there should be 2 videos part of the subscription")
379 377
380 const query = { accountId: userAccountId, token: userFeedToken, version: 2 } 378 const query = { accountId: userAccountId, token: userFeedToken, version: 2 }
381 const json = await servers[0].feedCommand.getJSON({ feed: 'subscriptions', query }) 379 const json = await servers[0].feedCommand.getJSON({ feed: 'subscriptions', query })
diff --git a/shared/extra-utils/server/servers.ts b/shared/extra-utils/server/servers.ts
index 3c709666d..57b37728a 100644
--- a/shared/extra-utils/server/servers.ts
+++ b/shared/extra-utils/server/servers.ts
@@ -17,7 +17,7 @@ import { OverviewsCommand } from '../overviews'
17import { makeGetRequest } from '../requests/requests' 17import { makeGetRequest } from '../requests/requests'
18import { SearchCommand } from '../search' 18import { SearchCommand } from '../search'
19import { SocketIOCommand } from '../socket' 19import { SocketIOCommand } from '../socket'
20import { AccountsCommand, BlocklistCommand } from '../users' 20import { AccountsCommand, BlocklistCommand, SubscriptionsCommand } from '../users'
21import { ConfigCommand } from './config-command' 21import { ConfigCommand } from './config-command'
22import { ContactFormCommand } from './contact-form-command' 22import { ContactFormCommand } from './contact-form-command'
23import { DebugCommand } from './debug-command' 23import { DebugCommand } from './debug-command'
@@ -98,6 +98,7 @@ interface ServerInfo {
98 socketIOCommand?: SocketIOCommand 98 socketIOCommand?: SocketIOCommand
99 accountsCommand?: AccountsCommand 99 accountsCommand?: AccountsCommand
100 blocklistCommand?: BlocklistCommand 100 blocklistCommand?: BlocklistCommand
101 subscriptionsCommand?: SubscriptionsCommand
101} 102}
102 103
103function parallelTests () { 104function parallelTests () {
@@ -322,6 +323,7 @@ async function runServer (server: ServerInfo, configOverrideArg?: any, args = []
322 server.socketIOCommand = new SocketIOCommand(server) 323 server.socketIOCommand = new SocketIOCommand(server)
323 server.accountsCommand = new AccountsCommand(server) 324 server.accountsCommand = new AccountsCommand(server)
324 server.blocklistCommand = new BlocklistCommand(server) 325 server.blocklistCommand = new BlocklistCommand(server)
326 server.subscriptionsCommand = new SubscriptionsCommand(server)
325 327
326 res(server) 328 res(server)
327 }) 329 })
diff --git a/shared/extra-utils/users/index.ts b/shared/extra-utils/users/index.ts
index ea5dbbf14..94ad37242 100644
--- a/shared/extra-utils/users/index.ts
+++ b/shared/extra-utils/users/index.ts
@@ -4,5 +4,5 @@ export * from './blocklist-command'
4 4
5export * from './login' 5export * from './login'
6export * from './user-notifications' 6export * from './user-notifications'
7export * from './user-subscriptions' 7export * from './subscriptions-command'
8export * from './users' 8export * from './users'
diff --git a/shared/extra-utils/users/subscriptions-command.ts b/shared/extra-utils/users/subscriptions-command.ts
new file mode 100644
index 000000000..94d2af67a
--- /dev/null
+++ b/shared/extra-utils/users/subscriptions-command.ts
@@ -0,0 +1,94 @@
1import { ResultList, Video, VideoChannel } from '@shared/models'
2import { HttpStatusCode } from '../../core-utils/miscs/http-error-codes'
3import { AbstractCommand, OverrideCommandOptions } from '../shared'
4
5export class SubscriptionsCommand extends AbstractCommand {
6
7 add (options: OverrideCommandOptions & {
8 targetUri: string
9 }) {
10 const path = '/api/v1/users/me/subscriptions'
11
12 return this.postBodyRequest({
13 ...options,
14
15 path,
16 fields: { uri: options.targetUri },
17 defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
18 })
19 }
20
21 list (options: OverrideCommandOptions & {
22 sort?: string // default -createdAt
23 search?: string
24 } = {}) {
25 const { sort = '-createdAt', search } = options
26 const path = '/api/v1/users/me/subscriptions'
27
28 return this.getRequestBody<ResultList<VideoChannel>>({
29 ...options,
30
31 path,
32 query: {
33 sort,
34 search
35 },
36 defaultExpectedStatus: HttpStatusCode.OK_200
37 })
38 }
39
40 listVideos (options: OverrideCommandOptions & {
41 sort?: string // default -createdAt
42 } = {}) {
43 const { sort = '-createdAt' } = options
44 const path = '/api/v1/users/me/subscriptions/videos'
45
46 return this.getRequestBody<ResultList<Video>>({
47 ...options,
48
49 path,
50 query: { sort },
51 defaultExpectedStatus: HttpStatusCode.OK_200
52 })
53 }
54
55 get (options: OverrideCommandOptions & {
56 uri: string
57 }) {
58 const path = '/api/v1/users/me/subscriptions/' + options.uri
59
60 return this.getRequestBody<VideoChannel>({
61 ...options,
62
63 path,
64 defaultExpectedStatus: HttpStatusCode.OK_200
65 })
66 }
67
68 remove (options: OverrideCommandOptions & {
69 uri: string
70 }) {
71 const path = '/api/v1/users/me/subscriptions/' + options.uri
72
73 return this.deleteRequest({
74 ...options,
75
76 path,
77 defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
78 })
79 }
80
81 exist (options: OverrideCommandOptions & {
82 uris: string[]
83 }) {
84 const path = '/api/v1/users/me/subscriptions/exist'
85
86 return this.getRequestBody<{ [id: string ]: boolean }>({
87 ...options,
88
89 path,
90 query: { 'uris[]': options.uris },
91 defaultExpectedStatus: HttpStatusCode.OK_200
92 })
93 }
94}
diff --git a/shared/extra-utils/users/user-subscriptions.ts b/shared/extra-utils/users/user-subscriptions.ts
deleted file mode 100644
index edc7a3562..000000000
--- a/shared/extra-utils/users/user-subscriptions.ts
+++ /dev/null
@@ -1,93 +0,0 @@
1import { makeDeleteRequest, makeGetRequest, makePostBodyRequest } from '../requests/requests'
2import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
3
4function addUserSubscription (url: string, token: string, targetUri: string, statusCodeExpected = HttpStatusCode.NO_CONTENT_204) {
5 const path = '/api/v1/users/me/subscriptions'
6
7 return makePostBodyRequest({
8 url,
9 path,
10 token,
11 statusCodeExpected,
12 fields: { uri: targetUri }
13 })
14}
15
16function listUserSubscriptions (parameters: {
17 url: string
18 token: string
19 sort?: string
20 search?: string
21 statusCodeExpected?: number
22}) {
23 const { url, token, sort = '-createdAt', search, statusCodeExpected = HttpStatusCode.OK_200 } = parameters
24 const path = '/api/v1/users/me/subscriptions'
25
26 return makeGetRequest({
27 url,
28 path,
29 token,
30 statusCodeExpected,
31 query: {
32 sort,
33 search
34 }
35 })
36}
37
38function listUserSubscriptionVideos (url: string, token: string, sort = '-createdAt', statusCodeExpected = HttpStatusCode.OK_200) {
39 const path = '/api/v1/users/me/subscriptions/videos'
40
41 return makeGetRequest({
42 url,
43 path,
44 token,
45 statusCodeExpected,
46 query: { sort }
47 })
48}
49
50function getUserSubscription (url: string, token: string, uri: string, statusCodeExpected = HttpStatusCode.OK_200) {
51 const path = '/api/v1/users/me/subscriptions/' + uri
52
53 return makeGetRequest({
54 url,
55 path,
56 token,
57 statusCodeExpected
58 })
59}
60
61function removeUserSubscription (url: string, token: string, uri: string, statusCodeExpected = HttpStatusCode.NO_CONTENT_204) {
62 const path = '/api/v1/users/me/subscriptions/' + uri
63
64 return makeDeleteRequest({
65 url,
66 path,
67 token,
68 statusCodeExpected
69 })
70}
71
72function areSubscriptionsExist (url: string, token: string, uris: string[], statusCodeExpected = HttpStatusCode.OK_200) {
73 const path = '/api/v1/users/me/subscriptions/exist'
74
75 return makeGetRequest({
76 url,
77 path,
78 query: { 'uris[]': uris },
79 token,
80 statusCodeExpected
81 })
82}
83
84// ---------------------------------------------------------------------------
85
86export {
87 areSubscriptionsExist,
88 addUserSubscription,
89 listUserSubscriptions,
90 getUserSubscription,
91 listUserSubscriptionVideos,
92 removeUserSubscription
93}