aboutsummaryrefslogtreecommitdiffhomepage
path: root/shared/extra-utils
diff options
context:
space:
mode:
Diffstat (limited to 'shared/extra-utils')
-rw-r--r--shared/extra-utils/index.ts1
-rw-r--r--shared/extra-utils/instances-index/mock-instances-index.ts38
-rw-r--r--shared/extra-utils/server/config.ts29
-rw-r--r--shared/extra-utils/users/user-notifications.ts41
-rw-r--r--shared/extra-utils/users/users.ts29
5 files changed, 106 insertions, 32 deletions
diff --git a/shared/extra-utils/index.ts b/shared/extra-utils/index.ts
index 53ddaa681..78acf72aa 100644
--- a/shared/extra-utils/index.ts
+++ b/shared/extra-utils/index.ts
@@ -24,4 +24,5 @@ export * from './videos/video-streaming-playlists'
24export * from './videos/videos' 24export * from './videos/videos'
25export * from './videos/video-change-ownership' 25export * from './videos/video-change-ownership'
26export * from './feeds/feeds' 26export * from './feeds/feeds'
27export * from './instances-index/mock-instances-index'
27export * from './search/videos' 28export * from './search/videos'
diff --git a/shared/extra-utils/instances-index/mock-instances-index.ts b/shared/extra-utils/instances-index/mock-instances-index.ts
new file mode 100644
index 000000000..cfa4523c1
--- /dev/null
+++ b/shared/extra-utils/instances-index/mock-instances-index.ts
@@ -0,0 +1,38 @@
1import * as express from 'express'
2
3export class MockInstancesIndex {
4 private indexInstances: { host: string, createdAt: string }[] = []
5
6 initialize () {
7 return new Promise(res => {
8 const app = express()
9
10 app.use('/', (req: express.Request, res: express.Response, next: express.NextFunction) => {
11 if (process.env.DEBUG) console.log('Receiving request on mocked server %s.', req.url)
12
13 return next()
14 })
15
16 app.get('/api/v1/instances/hosts', (req: express.Request, res: express.Response) => {
17 const since = req.query.since
18
19 const filtered = this.indexInstances.filter(i => {
20 if (!since) return true
21
22 return i.createdAt > since
23 })
24
25 return res.json({
26 total: filtered.length,
27 data: filtered
28 })
29 })
30
31 app.listen(42100, () => res())
32 })
33 }
34
35 addInstance (host: string) {
36 this.indexInstances.push({ host, createdAt: new Date().toISOString() })
37 }
38}
diff --git a/shared/extra-utils/server/config.ts b/shared/extra-utils/server/config.ts
index 8736f083f..578dd35cf 100644
--- a/shared/extra-utils/server/config.ts
+++ b/shared/extra-utils/server/config.ts
@@ -1,5 +1,7 @@
1import { makeDeleteRequest, makeGetRequest, makePutBodyRequest } from '../requests/requests' 1import { makeDeleteRequest, makeGetRequest, makePutBodyRequest } from '../requests/requests'
2import { CustomConfig } from '../../models/server/custom-config.model' 2import { CustomConfig } from '../../models/server/custom-config.model'
3import { DeepPartial } from '@server/typings/utils'
4import { merge } from 'lodash'
3 5
4function getConfig (url: string) { 6function getConfig (url: string) {
5 const path = '/api/v1/config' 7 const path = '/api/v1/config'
@@ -44,13 +46,25 @@ function updateCustomConfig (url: string, token: string, newCustomConfig: Custom
44 }) 46 })
45} 47}
46 48
47function updateCustomSubConfig (url: string, token: string, newConfig: any) { 49function updateCustomSubConfig (url: string, token: string, newConfig: DeepPartial<CustomConfig>) {
48 const updateParams: CustomConfig = { 50 const updateParams: CustomConfig = {
49 instance: { 51 instance: {
50 name: 'PeerTube updated', 52 name: 'PeerTube updated',
51 shortDescription: 'my short description', 53 shortDescription: 'my short description',
52 description: 'my super description', 54 description: 'my super description',
53 terms: 'my super terms', 55 terms: 'my super terms',
56 codeOfConduct: 'my super coc',
57
58 creationReason: 'my super creation reason',
59 moderationInformation: 'my super moderation information',
60 administrator: 'Kuja',
61 maintenanceLifetime: 'forever',
62 businessModel: 'my super business model',
63 hardwareInformation: '2vCore 3GB RAM',
64
65 languages: [ 'en', 'es' ],
66 categories: [ 1, 2 ],
67
54 defaultClientRoute: '/videos/recently-added', 68 defaultClientRoute: '/videos/recently-added',
55 isNSFW: true, 69 isNSFW: true,
56 defaultNSFWPolicy: 'blur', 70 defaultNSFWPolicy: 'blur',
@@ -130,10 +144,21 @@ function updateCustomSubConfig (url: string, token: string, newConfig: any) {
130 enabled: true, 144 enabled: true,
131 manualApproval: false 145 manualApproval: false
132 } 146 }
147 },
148 followings: {
149 instance: {
150 autoFollowBack: {
151 enabled: false
152 },
153 autoFollowIndex: {
154 indexUrl: 'https://instances.joinpeertube.org',
155 enabled: false
156 }
157 }
133 } 158 }
134 } 159 }
135 160
136 Object.assign(updateParams, newConfig) 161 merge(updateParams, newConfig)
137 162
138 return updateCustomConfig(url, token, updateParams) 163 return updateCustomConfig(url, token, updateParams)
139} 164}
diff --git a/shared/extra-utils/users/user-notifications.ts b/shared/extra-utils/users/user-notifications.ts
index f7de542bf..9a5fd7e86 100644
--- a/shared/extra-utils/users/user-notifications.ts
+++ b/shared/extra-utils/users/user-notifications.ts
@@ -279,8 +279,9 @@ async function checkNewActorFollow (
279 expect(notification.actorFollow.follower.name).to.equal(followerName) 279 expect(notification.actorFollow.follower.name).to.equal(followerName)
280 expect(notification.actorFollow.follower.host).to.not.be.undefined 280 expect(notification.actorFollow.follower.host).to.not.be.undefined
281 281
282 expect(notification.actorFollow.following.displayName).to.equal(followingDisplayName) 282 const following = notification.actorFollow.following
283 expect(notification.actorFollow.following.type).to.equal(followType) 283 expect(following.displayName).to.equal(followingDisplayName)
284 expect(following.type).to.equal(followType)
284 } else { 285 } else {
285 expect(notification).to.satisfy(n => { 286 expect(notification).to.satisfy(n => {
286 return n.type !== notificationType || 287 return n.type !== notificationType ||
@@ -327,6 +328,37 @@ async function checkNewInstanceFollower (base: CheckerBaseParams, followerHost:
327 await checkNotification(base, notificationChecker, emailFinder, type) 328 await checkNotification(base, notificationChecker, emailFinder, type)
328} 329}
329 330
331async function checkAutoInstanceFollowing (base: CheckerBaseParams, followerHost: string, followingHost: string, type: CheckerType) {
332 const notificationType = UserNotificationType.AUTO_INSTANCE_FOLLOWING
333
334 function notificationChecker (notification: UserNotification, type: CheckerType) {
335 if (type === 'presence') {
336 expect(notification).to.not.be.undefined
337 expect(notification.type).to.equal(notificationType)
338
339 const following = notification.actorFollow.following
340 checkActor(following)
341 expect(following.name).to.equal('peertube')
342 expect(following.host).to.equal(followingHost)
343
344 expect(notification.actorFollow.follower.name).to.equal('peertube')
345 expect(notification.actorFollow.follower.host).to.equal(followerHost)
346 } else {
347 expect(notification).to.satisfy(n => {
348 return n.type !== notificationType || n.actorFollow.following.host !== followingHost
349 })
350 }
351 }
352
353 function emailFinder (email: object) {
354 const text: string = email[ 'text' ]
355
356 return text.includes(' automatically followed a new instance') && text.includes(followingHost)
357 }
358
359 await checkNotification(base, notificationChecker, emailFinder, type)
360}
361
330async function checkCommentMention ( 362async function checkCommentMention (
331 base: CheckerBaseParams, 363 base: CheckerBaseParams,
332 uuid: string, 364 uuid: string,
@@ -427,8 +459,8 @@ async function checkVideoAutoBlacklistForModerators (base: CheckerBaseParams, vi
427 expect(notification).to.not.be.undefined 459 expect(notification).to.not.be.undefined
428 expect(notification.type).to.equal(notificationType) 460 expect(notification.type).to.equal(notificationType)
429 461
430 expect(notification.video.id).to.be.a('number') 462 expect(notification.videoBlacklist.video.id).to.be.a('number')
431 checkVideo(notification.video, videoName, videoUUID) 463 checkVideo(notification.videoBlacklist.video, videoName, videoUUID)
432 } else { 464 } else {
433 expect(notification).to.satisfy((n: UserNotification) => { 465 expect(notification).to.satisfy((n: UserNotification) => {
434 return n === undefined || n.video === undefined || n.video.uuid !== videoUUID 466 return n === undefined || n.video === undefined || n.video.uuid !== videoUUID
@@ -480,6 +512,7 @@ export {
480 markAsReadAllNotifications, 512 markAsReadAllNotifications,
481 checkMyVideoImportIsFinished, 513 checkMyVideoImportIsFinished,
482 checkUserRegistered, 514 checkUserRegistered,
515 checkAutoInstanceFollowing,
483 checkVideoIsPublished, 516 checkVideoIsPublished,
484 checkNewVideoFromSubscription, 517 checkNewVideoFromSubscription,
485 checkNewActorFollow, 518 checkNewActorFollow,
diff --git a/shared/extra-utils/users/users.ts b/shared/extra-utils/users/users.ts
index 30ed1bf4a..9959fd074 100644
--- a/shared/extra-utils/users/users.ts
+++ b/shared/extra-utils/users/users.ts
@@ -1,12 +1,12 @@
1import * as request from 'supertest' 1import * as request from 'supertest'
2import { makePostBodyRequest, makePutBodyRequest, updateAvatarRequest } from '../requests/requests' 2import { makePostBodyRequest, makePutBodyRequest, updateAvatarRequest } from '../requests/requests'
3import { NSFWPolicyType } from '../../models/videos/nsfw-policy.type'
4import { UserAdminFlag } from '../../models/users/user-flag.model' 3import { UserAdminFlag } from '../../models/users/user-flag.model'
5import { UserRegister } from '../../models/users/user-register.model' 4import { UserRegister } from '../../models/users/user-register.model'
6import { UserRole } from '../../models/users/user-role' 5import { UserRole } from '../../models/users/user-role'
7import { ServerInfo } from '../server/servers' 6import { ServerInfo } from '../server/servers'
8import { userLogin } from './login' 7import { userLogin } from './login'
9import { UserUpdateMe } from '../../models/users' 8import { UserUpdateMe } from '../../models/users'
9import { omit } from 'lodash'
10 10
11type CreateUserArgs = { url: string, 11type CreateUserArgs = { url: string,
12 accessToken: string, 12 accessToken: string,
@@ -214,33 +214,10 @@ function unblockUser (url: string, userId: number | string, accessToken: string,
214 .expect(expectedStatus) 214 .expect(expectedStatus)
215} 215}
216 216
217function updateMyUser (options: { 217function updateMyUser (options: { url: string, accessToken: string } & UserUpdateMe) {
218 url: string
219 accessToken: string
220 currentPassword?: string
221 newPassword?: string
222 nsfwPolicy?: NSFWPolicyType
223 email?: string
224 autoPlayVideo?: boolean
225 displayName?: string
226 description?: string
227 videosHistoryEnabled?: boolean
228 theme?: string
229}) {
230 const path = '/api/v1/users/me' 218 const path = '/api/v1/users/me'
231 219
232 const toSend: UserUpdateMe = {} 220 const toSend: UserUpdateMe = omit(options, 'url', 'accessToken')
233 if (options.currentPassword !== undefined && options.currentPassword !== null) toSend.currentPassword = options.currentPassword
234 if (options.newPassword !== undefined && options.newPassword !== null) toSend.password = options.newPassword
235 if (options.nsfwPolicy !== undefined && options.nsfwPolicy !== null) toSend.nsfwPolicy = options.nsfwPolicy
236 if (options.autoPlayVideo !== undefined && options.autoPlayVideo !== null) toSend.autoPlayVideo = options.autoPlayVideo
237 if (options.email !== undefined && options.email !== null) toSend.email = options.email
238 if (options.description !== undefined && options.description !== null) toSend.description = options.description
239 if (options.displayName !== undefined && options.displayName !== null) toSend.displayName = options.displayName
240 if (options.theme !== undefined && options.theme !== null) toSend.theme = options.theme
241 if (options.videosHistoryEnabled !== undefined && options.videosHistoryEnabled !== null) {
242 toSend.videosHistoryEnabled = options.videosHistoryEnabled
243 }
244 221
245 return makePutBodyRequest({ 222 return makePutBodyRequest({
246 url: options.url, 223 url: options.url,