user-notifications.ts 46 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307
  1. /* tslint:disable:no-unused-expression */
  2. import * as chai from 'chai'
  3. import 'mocha'
  4. import {
  5. addVideoToBlacklist,
  6. cleanupTests,
  7. createUser,
  8. doubleFollow,
  9. flushAndRunMultipleServers,
  10. follow,
  11. getCustomConfig,
  12. getMyUserInformation,
  13. getVideoCommentThreads,
  14. getVideoThreadComments,
  15. immutableAssign,
  16. registerUser,
  17. removeVideoFromBlacklist,
  18. reportVideoAbuse,
  19. updateCustomConfig,
  20. updateMyUser,
  21. updateVideo,
  22. updateVideoChannel,
  23. userLogin,
  24. wait
  25. } from '../../../../shared/extra-utils'
  26. import { ServerInfo, uploadVideo } from '../../../../shared/extra-utils/index'
  27. import { setAccessTokensToServers } from '../../../../shared/extra-utils/users/login'
  28. import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
  29. import { getUserNotificationSocket } from '../../../../shared/extra-utils/socket/socket-io'
  30. import {
  31. checkCommentMention,
  32. CheckerBaseParams,
  33. checkMyVideoImportIsFinished,
  34. checkNewActorFollow,
  35. checkNewBlacklistOnMyVideo,
  36. checkNewCommentOnMyVideo,
  37. checkNewInstanceFollower,
  38. checkNewVideoAbuseForModerators,
  39. checkNewVideoFromSubscription,
  40. checkUserRegistered,
  41. checkVideoAutoBlacklistForModerators,
  42. checkVideoIsPublished,
  43. getLastNotification,
  44. getUserNotifications,
  45. markAsReadAllNotifications,
  46. markAsReadNotifications,
  47. updateMyNotificationSettings
  48. } from '../../../../shared/extra-utils/users/user-notifications'
  49. import {
  50. User,
  51. UserNotification,
  52. UserNotificationSetting,
  53. UserNotificationSettingValue,
  54. UserNotificationType
  55. } from '../../../../shared/models/users'
  56. import { MockSmtpServer } from '../../../../shared/extra-utils/miscs/email'
  57. import { addUserSubscription, removeUserSubscription } from '../../../../shared/extra-utils/users/user-subscriptions'
  58. import { VideoPrivacy } from '../../../../shared/models/videos'
  59. import { getBadVideoUrl, getYoutubeVideoUrl, importVideo } from '../../../../shared/extra-utils/videos/video-imports'
  60. import { addVideoCommentReply, addVideoCommentThread } from '../../../../shared/extra-utils/videos/video-comments'
  61. import * as uuidv4 from 'uuid/v4'
  62. import { addAccountToAccountBlocklist, removeAccountFromAccountBlocklist } from '../../../../shared/extra-utils/users/blocklist'
  63. import { CustomConfig } from '../../../../shared/models/server'
  64. import { VideoCommentThreadTree } from '../../../../shared/models/videos/video-comment.model'
  65. const expect = chai.expect
  66. async function uploadVideoByRemoteAccount (servers: ServerInfo[], additionalParams: any = {}) {
  67. const name = 'remote video ' + uuidv4()
  68. const data = Object.assign({ name }, additionalParams)
  69. const res = await uploadVideo(servers[ 1 ].url, servers[ 1 ].accessToken, data)
  70. await waitJobs(servers)
  71. return { uuid: res.body.video.uuid, name }
  72. }
  73. async function uploadVideoByLocalAccount (servers: ServerInfo[], additionalParams: any = {}) {
  74. const name = 'local video ' + uuidv4()
  75. const data = Object.assign({ name }, additionalParams)
  76. const res = await uploadVideo(servers[ 0 ].url, servers[ 0 ].accessToken, data)
  77. await waitJobs(servers)
  78. return { uuid: res.body.video.uuid, name }
  79. }
  80. describe('Test users notifications', function () {
  81. let servers: ServerInfo[] = []
  82. let userAccessToken: string
  83. let userNotifications: UserNotification[] = []
  84. let adminNotifications: UserNotification[] = []
  85. let adminNotificationsServer2: UserNotification[] = []
  86. const emails: object[] = []
  87. let channelId: number
  88. const allNotificationSettings: UserNotificationSetting = {
  89. newVideoFromSubscription: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
  90. newCommentOnMyVideo: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
  91. videoAbuseAsModerator: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
  92. videoAutoBlacklistAsModerator: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
  93. blacklistOnMyVideo: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
  94. myVideoImportFinished: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
  95. myVideoPublished: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
  96. commentMention: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
  97. newFollow: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
  98. newUserRegistration: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
  99. newInstanceFollower: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL
  100. }
  101. before(async function () {
  102. this.timeout(120000)
  103. await MockSmtpServer.Instance.collectEmails(emails)
  104. const overrideConfig = {
  105. smtp: {
  106. hostname: 'localhost'
  107. }
  108. }
  109. servers = await flushAndRunMultipleServers(3, overrideConfig)
  110. // Get the access tokens
  111. await setAccessTokensToServers(servers)
  112. // Server 1 and server 2 follow each other
  113. await doubleFollow(servers[0], servers[1])
  114. await waitJobs(servers)
  115. const user = {
  116. username: 'user_1',
  117. password: 'super password'
  118. }
  119. await createUser({
  120. url: servers[ 0 ].url,
  121. accessToken: servers[ 0 ].accessToken,
  122. username: user.username,
  123. password: user.password,
  124. videoQuota: 10 * 1000 * 1000
  125. })
  126. userAccessToken = await userLogin(servers[0], user)
  127. await updateMyNotificationSettings(servers[0].url, userAccessToken, allNotificationSettings)
  128. await updateMyNotificationSettings(servers[0].url, servers[0].accessToken, allNotificationSettings)
  129. await updateMyNotificationSettings(servers[1].url, servers[1].accessToken, allNotificationSettings)
  130. {
  131. const socket = getUserNotificationSocket(servers[ 0 ].url, userAccessToken)
  132. socket.on('new-notification', n => userNotifications.push(n))
  133. }
  134. {
  135. const socket = getUserNotificationSocket(servers[ 0 ].url, servers[0].accessToken)
  136. socket.on('new-notification', n => adminNotifications.push(n))
  137. }
  138. {
  139. const socket = getUserNotificationSocket(servers[ 1 ].url, servers[1].accessToken)
  140. socket.on('new-notification', n => adminNotificationsServer2.push(n))
  141. }
  142. {
  143. const resChannel = await getMyUserInformation(servers[0].url, servers[0].accessToken)
  144. channelId = resChannel.body.videoChannels[0].id
  145. }
  146. })
  147. describe('New video from my subscription notification', function () {
  148. let baseParams: CheckerBaseParams
  149. before(() => {
  150. baseParams = {
  151. server: servers[0],
  152. emails,
  153. socketNotifications: userNotifications,
  154. token: userAccessToken
  155. }
  156. })
  157. it('Should not send notifications if the user does not follow the video publisher', async function () {
  158. this.timeout(10000)
  159. await uploadVideoByLocalAccount(servers)
  160. const notification = await getLastNotification(servers[ 0 ].url, userAccessToken)
  161. expect(notification).to.be.undefined
  162. expect(emails).to.have.lengthOf(0)
  163. expect(userNotifications).to.have.lengthOf(0)
  164. })
  165. it('Should send a new video notification if the user follows the local video publisher', async function () {
  166. this.timeout(15000)
  167. await addUserSubscription(servers[0].url, userAccessToken, 'root_channel@localhost:9001')
  168. await waitJobs(servers)
  169. const { name, uuid } = await uploadVideoByLocalAccount(servers)
  170. await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
  171. })
  172. it('Should send a new video notification from a remote account', async function () {
  173. this.timeout(50000) // Server 2 has transcoding enabled
  174. await addUserSubscription(servers[0].url, userAccessToken, 'root_channel@localhost:9002')
  175. await waitJobs(servers)
  176. const { name, uuid } = await uploadVideoByRemoteAccount(servers)
  177. await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
  178. })
  179. it('Should send a new video notification on a scheduled publication', async function () {
  180. this.timeout(20000)
  181. // In 2 seconds
  182. let updateAt = new Date(new Date().getTime() + 2000)
  183. const data = {
  184. privacy: VideoPrivacy.PRIVATE,
  185. scheduleUpdate: {
  186. updateAt: updateAt.toISOString(),
  187. privacy: VideoPrivacy.PUBLIC
  188. }
  189. }
  190. const { name, uuid } = await uploadVideoByLocalAccount(servers, data)
  191. await wait(6000)
  192. await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
  193. })
  194. it('Should send a new video notification on a remote scheduled publication', async function () {
  195. this.timeout(50000)
  196. // In 2 seconds
  197. let updateAt = new Date(new Date().getTime() + 2000)
  198. const data = {
  199. privacy: VideoPrivacy.PRIVATE,
  200. scheduleUpdate: {
  201. updateAt: updateAt.toISOString(),
  202. privacy: VideoPrivacy.PUBLIC
  203. }
  204. }
  205. const { name, uuid } = await uploadVideoByRemoteAccount(servers, data)
  206. await waitJobs(servers)
  207. await wait(6000)
  208. await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
  209. })
  210. it('Should not send a notification before the video is published', async function () {
  211. this.timeout(20000)
  212. let updateAt = new Date(new Date().getTime() + 1000000)
  213. const data = {
  214. privacy: VideoPrivacy.PRIVATE,
  215. scheduleUpdate: {
  216. updateAt: updateAt.toISOString(),
  217. privacy: VideoPrivacy.PUBLIC
  218. }
  219. }
  220. const { name, uuid } = await uploadVideoByLocalAccount(servers, data)
  221. await wait(6000)
  222. await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence')
  223. })
  224. it('Should send a new video notification when a video becomes public', async function () {
  225. this.timeout(10000)
  226. const data = { privacy: VideoPrivacy.PRIVATE }
  227. const { name, uuid } = await uploadVideoByLocalAccount(servers, data)
  228. await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence')
  229. await updateVideo(servers[0].url, servers[0].accessToken, uuid, { privacy: VideoPrivacy.PUBLIC })
  230. await wait(500)
  231. await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
  232. })
  233. it('Should send a new video notification when a remote video becomes public', async function () {
  234. this.timeout(20000)
  235. const data = { privacy: VideoPrivacy.PRIVATE }
  236. const { name, uuid } = await uploadVideoByRemoteAccount(servers, data)
  237. await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence')
  238. await updateVideo(servers[1].url, servers[1].accessToken, uuid, { privacy: VideoPrivacy.PUBLIC })
  239. await waitJobs(servers)
  240. await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
  241. })
  242. it('Should not send a new video notification when a video becomes unlisted', async function () {
  243. this.timeout(20000)
  244. const data = { privacy: VideoPrivacy.PRIVATE }
  245. const { name, uuid } = await uploadVideoByLocalAccount(servers, data)
  246. await updateVideo(servers[0].url, servers[0].accessToken, uuid, { privacy: VideoPrivacy.UNLISTED })
  247. await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence')
  248. })
  249. it('Should not send a new video notification when a remote video becomes unlisted', async function () {
  250. this.timeout(20000)
  251. const data = { privacy: VideoPrivacy.PRIVATE }
  252. const { name, uuid } = await uploadVideoByRemoteAccount(servers, data)
  253. await updateVideo(servers[1].url, servers[1].accessToken, uuid, { privacy: VideoPrivacy.UNLISTED })
  254. await waitJobs(servers)
  255. await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence')
  256. })
  257. it('Should send a new video notification after a video import', async function () {
  258. this.timeout(100000)
  259. const name = 'video import ' + uuidv4()
  260. const attributes = {
  261. name,
  262. channelId,
  263. privacy: VideoPrivacy.PUBLIC,
  264. targetUrl: getYoutubeVideoUrl()
  265. }
  266. const res = await importVideo(servers[0].url, servers[0].accessToken, attributes)
  267. const uuid = res.body.video.uuid
  268. await waitJobs(servers)
  269. await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
  270. })
  271. })
  272. describe('Comment on my video notifications', function () {
  273. let baseParams: CheckerBaseParams
  274. before(() => {
  275. baseParams = {
  276. server: servers[0],
  277. emails,
  278. socketNotifications: userNotifications,
  279. token: userAccessToken
  280. }
  281. })
  282. it('Should not send a new comment notification after a comment on another video', async function () {
  283. this.timeout(10000)
  284. const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' })
  285. const uuid = resVideo.body.video.uuid
  286. const resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, 'comment')
  287. const commentId = resComment.body.comment.id
  288. await wait(500)
  289. await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'absence')
  290. })
  291. it('Should not send a new comment notification if I comment my own video', async function () {
  292. this.timeout(10000)
  293. const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' })
  294. const uuid = resVideo.body.video.uuid
  295. const resComment = await addVideoCommentThread(servers[0].url, userAccessToken, uuid, 'comment')
  296. const commentId = resComment.body.comment.id
  297. await wait(500)
  298. await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'absence')
  299. })
  300. it('Should not send a new comment notification if the account is muted', async function () {
  301. this.timeout(10000)
  302. await addAccountToAccountBlocklist(servers[ 0 ].url, userAccessToken, 'root')
  303. const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' })
  304. const uuid = resVideo.body.video.uuid
  305. const resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, 'comment')
  306. const commentId = resComment.body.comment.id
  307. await wait(500)
  308. await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'absence')
  309. await removeAccountFromAccountBlocklist(servers[ 0 ].url, userAccessToken, 'root')
  310. })
  311. it('Should send a new comment notification after a local comment on my video', async function () {
  312. this.timeout(10000)
  313. const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' })
  314. const uuid = resVideo.body.video.uuid
  315. const resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, 'comment')
  316. const commentId = resComment.body.comment.id
  317. await wait(500)
  318. await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'presence')
  319. })
  320. it('Should send a new comment notification after a remote comment on my video', async function () {
  321. this.timeout(10000)
  322. const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' })
  323. const uuid = resVideo.body.video.uuid
  324. await waitJobs(servers)
  325. await addVideoCommentThread(servers[1].url, servers[1].accessToken, uuid, 'comment')
  326. await waitJobs(servers)
  327. const resComment = await getVideoCommentThreads(servers[0].url, uuid, 0, 5)
  328. expect(resComment.body.data).to.have.lengthOf(1)
  329. const commentId = resComment.body.data[0].id
  330. await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'presence')
  331. })
  332. it('Should send a new comment notification after a local reply on my video', async function () {
  333. this.timeout(10000)
  334. const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' })
  335. const uuid = resVideo.body.video.uuid
  336. const resThread = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, 'comment')
  337. const threadId = resThread.body.comment.id
  338. const resComment = await addVideoCommentReply(servers[0].url, servers[0].accessToken, uuid, threadId, 'reply')
  339. const commentId = resComment.body.comment.id
  340. await wait(500)
  341. await checkNewCommentOnMyVideo(baseParams, uuid, commentId, threadId, 'presence')
  342. })
  343. it('Should send a new comment notification after a remote reply on my video', async function () {
  344. this.timeout(10000)
  345. const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' })
  346. const uuid = resVideo.body.video.uuid
  347. await waitJobs(servers)
  348. {
  349. const resThread = await addVideoCommentThread(servers[ 1 ].url, servers[ 1 ].accessToken, uuid, 'comment')
  350. const threadId = resThread.body.comment.id
  351. await addVideoCommentReply(servers[ 1 ].url, servers[ 1 ].accessToken, uuid, threadId, 'reply')
  352. }
  353. await waitJobs(servers)
  354. const resThread = await getVideoCommentThreads(servers[0].url, uuid, 0, 5)
  355. expect(resThread.body.data).to.have.lengthOf(1)
  356. const threadId = resThread.body.data[0].id
  357. const resComments = await getVideoThreadComments(servers[0].url, uuid, threadId)
  358. const tree = resComments.body as VideoCommentThreadTree
  359. expect(tree.children).to.have.lengthOf(1)
  360. const commentId = tree.children[0].comment.id
  361. await checkNewCommentOnMyVideo(baseParams, uuid, commentId, threadId, 'presence')
  362. })
  363. })
  364. describe('Mention notifications', function () {
  365. let baseParams: CheckerBaseParams
  366. before(async () => {
  367. baseParams = {
  368. server: servers[0],
  369. emails,
  370. socketNotifications: userNotifications,
  371. token: userAccessToken
  372. }
  373. await updateMyUser({
  374. url: servers[0].url,
  375. accessToken: servers[0].accessToken,
  376. displayName: 'super root name'
  377. })
  378. await updateMyUser({
  379. url: servers[1].url,
  380. accessToken: servers[1].accessToken,
  381. displayName: 'super root 2 name'
  382. })
  383. })
  384. it('Should not send a new mention comment notification if I mention the video owner', async function () {
  385. this.timeout(10000)
  386. const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' })
  387. const uuid = resVideo.body.video.uuid
  388. const resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, '@user_1 hello')
  389. const commentId = resComment.body.comment.id
  390. await wait(500)
  391. await checkCommentMention(baseParams, uuid, commentId, commentId, 'super root name', 'absence')
  392. })
  393. it('Should not send a new mention comment notification if I mention myself', async function () {
  394. this.timeout(10000)
  395. const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' })
  396. const uuid = resVideo.body.video.uuid
  397. const resComment = await addVideoCommentThread(servers[0].url, userAccessToken, uuid, '@user_1 hello')
  398. const commentId = resComment.body.comment.id
  399. await wait(500)
  400. await checkCommentMention(baseParams, uuid, commentId, commentId, 'super root name', 'absence')
  401. })
  402. it('Should not send a new mention notification if the account is muted', async function () {
  403. this.timeout(10000)
  404. await addAccountToAccountBlocklist(servers[ 0 ].url, userAccessToken, 'root')
  405. const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' })
  406. const uuid = resVideo.body.video.uuid
  407. const resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, '@user_1 hello')
  408. const commentId = resComment.body.comment.id
  409. await wait(500)
  410. await checkCommentMention(baseParams, uuid, commentId, commentId, 'super root name', 'absence')
  411. await removeAccountFromAccountBlocklist(servers[ 0 ].url, userAccessToken, 'root')
  412. })
  413. it('Should not send a new mention notification if the remote account mention a local account', async function () {
  414. this.timeout(20000)
  415. const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' })
  416. const uuid = resVideo.body.video.uuid
  417. await waitJobs(servers)
  418. const resThread = await addVideoCommentThread(servers[1].url, servers[1].accessToken, uuid, '@user_1 hello')
  419. const threadId = resThread.body.comment.id
  420. await waitJobs(servers)
  421. await checkCommentMention(baseParams, uuid, threadId, threadId, 'super root 2 name', 'absence')
  422. })
  423. it('Should send a new mention notification after local comments', async function () {
  424. this.timeout(10000)
  425. const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' })
  426. const uuid = resVideo.body.video.uuid
  427. const resThread = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, '@user_1 hello 1')
  428. const threadId = resThread.body.comment.id
  429. await wait(500)
  430. await checkCommentMention(baseParams, uuid, threadId, threadId, 'super root name', 'presence')
  431. const resComment = await addVideoCommentReply(servers[0].url, servers[0].accessToken, uuid, threadId, 'hello 2 @user_1')
  432. const commentId = resComment.body.comment.id
  433. await wait(500)
  434. await checkCommentMention(baseParams, uuid, commentId, threadId, 'super root name', 'presence')
  435. })
  436. it('Should send a new mention notification after remote comments', async function () {
  437. this.timeout(20000)
  438. const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' })
  439. const uuid = resVideo.body.video.uuid
  440. await waitJobs(servers)
  441. const resThread = await addVideoCommentThread(servers[1].url, servers[1].accessToken, uuid, 'hello @user_1@localhost:9001 1')
  442. const server2ThreadId = resThread.body.comment.id
  443. await waitJobs(servers)
  444. const resThread2 = await getVideoCommentThreads(servers[0].url, uuid, 0, 5)
  445. expect(resThread2.body.data).to.have.lengthOf(1)
  446. const server1ThreadId = resThread2.body.data[0].id
  447. await checkCommentMention(baseParams, uuid, server1ThreadId, server1ThreadId, 'super root 2 name', 'presence')
  448. const text = '@user_1@localhost:9001 hello 2 @root@localhost:9001'
  449. await addVideoCommentReply(servers[1].url, servers[1].accessToken, uuid, server2ThreadId, text)
  450. await waitJobs(servers)
  451. const resComments = await getVideoThreadComments(servers[0].url, uuid, server1ThreadId)
  452. const tree = resComments.body as VideoCommentThreadTree
  453. expect(tree.children).to.have.lengthOf(1)
  454. const commentId = tree.children[0].comment.id
  455. await checkCommentMention(baseParams, uuid, commentId, server1ThreadId, 'super root 2 name', 'presence')
  456. })
  457. })
  458. describe('Video abuse for moderators notification' , function () {
  459. let baseParams: CheckerBaseParams
  460. before(() => {
  461. baseParams = {
  462. server: servers[0],
  463. emails,
  464. socketNotifications: adminNotifications,
  465. token: servers[0].accessToken
  466. }
  467. })
  468. it('Should send a notification to moderators on local video abuse', async function () {
  469. this.timeout(10000)
  470. const name = 'video for abuse ' + uuidv4()
  471. const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name })
  472. const uuid = resVideo.body.video.uuid
  473. await reportVideoAbuse(servers[0].url, servers[0].accessToken, uuid, 'super reason')
  474. await waitJobs(servers)
  475. await checkNewVideoAbuseForModerators(baseParams, uuid, name, 'presence')
  476. })
  477. it('Should send a notification to moderators on remote video abuse', async function () {
  478. this.timeout(10000)
  479. const name = 'video for abuse ' + uuidv4()
  480. const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name })
  481. const uuid = resVideo.body.video.uuid
  482. await waitJobs(servers)
  483. await reportVideoAbuse(servers[1].url, servers[1].accessToken, uuid, 'super reason')
  484. await waitJobs(servers)
  485. await checkNewVideoAbuseForModerators(baseParams, uuid, name, 'presence')
  486. })
  487. })
  488. describe('Video blacklist on my video', function () {
  489. let baseParams: CheckerBaseParams
  490. before(() => {
  491. baseParams = {
  492. server: servers[0],
  493. emails,
  494. socketNotifications: userNotifications,
  495. token: userAccessToken
  496. }
  497. })
  498. it('Should send a notification to video owner on blacklist', async function () {
  499. this.timeout(10000)
  500. const name = 'video for abuse ' + uuidv4()
  501. const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name })
  502. const uuid = resVideo.body.video.uuid
  503. await addVideoToBlacklist(servers[0].url, servers[0].accessToken, uuid)
  504. await waitJobs(servers)
  505. await checkNewBlacklistOnMyVideo(baseParams, uuid, name, 'blacklist')
  506. })
  507. it('Should send a notification to video owner on unblacklist', async function () {
  508. this.timeout(10000)
  509. const name = 'video for abuse ' + uuidv4()
  510. const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name })
  511. const uuid = resVideo.body.video.uuid
  512. await addVideoToBlacklist(servers[0].url, servers[0].accessToken, uuid)
  513. await waitJobs(servers)
  514. await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, uuid)
  515. await waitJobs(servers)
  516. await wait(500)
  517. await checkNewBlacklistOnMyVideo(baseParams, uuid, name, 'unblacklist')
  518. })
  519. })
  520. describe('My video is published', function () {
  521. let baseParams: CheckerBaseParams
  522. before(() => {
  523. baseParams = {
  524. server: servers[1],
  525. emails,
  526. socketNotifications: adminNotificationsServer2,
  527. token: servers[1].accessToken
  528. }
  529. })
  530. it('Should not send a notification if transcoding is not enabled', async function () {
  531. this.timeout(10000)
  532. const { name, uuid } = await uploadVideoByLocalAccount(servers)
  533. await waitJobs(servers)
  534. await checkVideoIsPublished(baseParams, name, uuid, 'absence')
  535. })
  536. it('Should not send a notification if the wait transcoding is false', async function () {
  537. this.timeout(50000)
  538. await uploadVideoByRemoteAccount(servers, { waitTranscoding: false })
  539. await waitJobs(servers)
  540. const notification = await getLastNotification(servers[ 0 ].url, userAccessToken)
  541. if (notification) {
  542. expect(notification.type).to.not.equal(UserNotificationType.MY_VIDEO_PUBLISHED)
  543. }
  544. })
  545. it('Should send a notification even if the video is not transcoded in other resolutions', async function () {
  546. this.timeout(50000)
  547. const { name, uuid } = await uploadVideoByRemoteAccount(servers, { waitTranscoding: true, fixture: 'video_short_240p.mp4' })
  548. await waitJobs(servers)
  549. await checkVideoIsPublished(baseParams, name, uuid, 'presence')
  550. })
  551. it('Should send a notification with a transcoded video', async function () {
  552. this.timeout(50000)
  553. const { name, uuid } = await uploadVideoByRemoteAccount(servers, { waitTranscoding: true })
  554. await waitJobs(servers)
  555. await checkVideoIsPublished(baseParams, name, uuid, 'presence')
  556. })
  557. it('Should send a notification when an imported video is transcoded', async function () {
  558. this.timeout(50000)
  559. const name = 'video import ' + uuidv4()
  560. const attributes = {
  561. name,
  562. channelId,
  563. privacy: VideoPrivacy.PUBLIC,
  564. targetUrl: getYoutubeVideoUrl(),
  565. waitTranscoding: true
  566. }
  567. const res = await importVideo(servers[1].url, servers[1].accessToken, attributes)
  568. const uuid = res.body.video.uuid
  569. await waitJobs(servers)
  570. await checkVideoIsPublished(baseParams, name, uuid, 'presence')
  571. })
  572. it('Should send a notification when the scheduled update has been proceeded', async function () {
  573. this.timeout(70000)
  574. // In 2 seconds
  575. let updateAt = new Date(new Date().getTime() + 2000)
  576. const data = {
  577. privacy: VideoPrivacy.PRIVATE,
  578. scheduleUpdate: {
  579. updateAt: updateAt.toISOString(),
  580. privacy: VideoPrivacy.PUBLIC
  581. }
  582. }
  583. const { name, uuid } = await uploadVideoByRemoteAccount(servers, data)
  584. await wait(6000)
  585. await checkVideoIsPublished(baseParams, name, uuid, 'presence')
  586. })
  587. it('Should not send a notification before the video is published', async function () {
  588. this.timeout(20000)
  589. let updateAt = new Date(new Date().getTime() + 100000)
  590. const data = {
  591. privacy: VideoPrivacy.PRIVATE,
  592. scheduleUpdate: {
  593. updateAt: updateAt.toISOString(),
  594. privacy: VideoPrivacy.PUBLIC
  595. }
  596. }
  597. const { name, uuid } = await uploadVideoByRemoteAccount(servers, data)
  598. await wait(6000)
  599. await checkVideoIsPublished(baseParams, name, uuid, 'absence')
  600. })
  601. })
  602. describe('My video is imported', function () {
  603. let baseParams: CheckerBaseParams
  604. before(() => {
  605. baseParams = {
  606. server: servers[0],
  607. emails,
  608. socketNotifications: adminNotifications,
  609. token: servers[0].accessToken
  610. }
  611. })
  612. it('Should send a notification when the video import failed', async function () {
  613. this.timeout(70000)
  614. const name = 'video import ' + uuidv4()
  615. const attributes = {
  616. name,
  617. channelId,
  618. privacy: VideoPrivacy.PRIVATE,
  619. targetUrl: getBadVideoUrl()
  620. }
  621. const res = await importVideo(servers[0].url, servers[0].accessToken, attributes)
  622. const uuid = res.body.video.uuid
  623. await waitJobs(servers)
  624. await checkMyVideoImportIsFinished(baseParams, name, uuid, getBadVideoUrl(), false, 'presence')
  625. })
  626. it('Should send a notification when the video import succeeded', async function () {
  627. this.timeout(70000)
  628. const name = 'video import ' + uuidv4()
  629. const attributes = {
  630. name,
  631. channelId,
  632. privacy: VideoPrivacy.PRIVATE,
  633. targetUrl: getYoutubeVideoUrl()
  634. }
  635. const res = await importVideo(servers[0].url, servers[0].accessToken, attributes)
  636. const uuid = res.body.video.uuid
  637. await waitJobs(servers)
  638. await checkMyVideoImportIsFinished(baseParams, name, uuid, getYoutubeVideoUrl(), true, 'presence')
  639. })
  640. })
  641. describe('New registration', function () {
  642. let baseParams: CheckerBaseParams
  643. before(() => {
  644. baseParams = {
  645. server: servers[0],
  646. emails,
  647. socketNotifications: adminNotifications,
  648. token: servers[0].accessToken
  649. }
  650. })
  651. it('Should send a notification only to moderators when a user registers on the instance', async function () {
  652. this.timeout(10000)
  653. await registerUser(servers[0].url, 'user_45', 'password')
  654. await waitJobs(servers)
  655. await checkUserRegistered(baseParams, 'user_45', 'presence')
  656. const userOverride = { socketNotifications: userNotifications, token: userAccessToken, check: { web: true, mail: false } }
  657. await checkUserRegistered(immutableAssign(baseParams, userOverride), 'user_45', 'absence')
  658. })
  659. })
  660. describe('New instance follower', function () {
  661. let baseParams: CheckerBaseParams
  662. before(async () => {
  663. baseParams = {
  664. server: servers[0],
  665. emails,
  666. socketNotifications: adminNotifications,
  667. token: servers[0].accessToken
  668. }
  669. })
  670. it('Should send a notification only to admin when there is a new instance follower', async function () {
  671. this.timeout(20000)
  672. await follow(servers[2].url, [ servers[0].url ], servers[2].accessToken)
  673. await waitJobs(servers)
  674. await checkNewInstanceFollower(baseParams, 'localhost:9003', 'presence')
  675. const userOverride = { socketNotifications: userNotifications, token: userAccessToken, check: { web: true, mail: false } }
  676. await checkNewInstanceFollower(immutableAssign(baseParams, userOverride), 'localhost:9003', 'absence')
  677. })
  678. })
  679. describe('New actor follow', function () {
  680. let baseParams: CheckerBaseParams
  681. let myChannelName = 'super channel name'
  682. let myUserName = 'super user name'
  683. before(async () => {
  684. baseParams = {
  685. server: servers[0],
  686. emails,
  687. socketNotifications: userNotifications,
  688. token: userAccessToken
  689. }
  690. await updateMyUser({
  691. url: servers[0].url,
  692. accessToken: servers[0].accessToken,
  693. displayName: 'super root name'
  694. })
  695. await updateMyUser({
  696. url: servers[0].url,
  697. accessToken: userAccessToken,
  698. displayName: myUserName
  699. })
  700. await updateMyUser({
  701. url: servers[1].url,
  702. accessToken: servers[1].accessToken,
  703. displayName: 'super root 2 name'
  704. })
  705. await updateVideoChannel(servers[0].url, userAccessToken, 'user_1_channel', { displayName: myChannelName })
  706. })
  707. it('Should notify when a local channel is following one of our channel', async function () {
  708. this.timeout(10000)
  709. await addUserSubscription(servers[0].url, servers[0].accessToken, 'user_1_channel@localhost:9001')
  710. await waitJobs(servers)
  711. await checkNewActorFollow(baseParams, 'channel', 'root', 'super root name', myChannelName, 'presence')
  712. await removeUserSubscription(servers[0].url, servers[0].accessToken, 'user_1_channel@localhost:9001')
  713. })
  714. it('Should notify when a remote channel is following one of our channel', async function () {
  715. this.timeout(10000)
  716. await addUserSubscription(servers[1].url, servers[1].accessToken, 'user_1_channel@localhost:9001')
  717. await waitJobs(servers)
  718. await checkNewActorFollow(baseParams, 'channel', 'root', 'super root 2 name', myChannelName, 'presence')
  719. await removeUserSubscription(servers[1].url, servers[1].accessToken, 'user_1_channel@localhost:9001')
  720. })
  721. it('Should notify when a local account is following one of our channel', async function () {
  722. this.timeout(10000)
  723. await addUserSubscription(servers[0].url, servers[0].accessToken, 'user_1@localhost:9001')
  724. await waitJobs(servers)
  725. await checkNewActorFollow(baseParams, 'account', 'root', 'super root name', myUserName, 'presence')
  726. })
  727. it('Should notify when a remote account is following one of our channel', async function () {
  728. this.timeout(10000)
  729. await addUserSubscription(servers[1].url, servers[1].accessToken, 'user_1@localhost:9001')
  730. await waitJobs(servers)
  731. await checkNewActorFollow(baseParams, 'account', 'root', 'super root 2 name', myUserName, 'presence')
  732. })
  733. })
  734. describe('Video-related notifications when video auto-blacklist is enabled', function () {
  735. let userBaseParams: CheckerBaseParams
  736. let adminBaseParamsServer1: CheckerBaseParams
  737. let adminBaseParamsServer2: CheckerBaseParams
  738. let videoUUID: string
  739. let videoName: string
  740. let currentCustomConfig: CustomConfig
  741. before(async () => {
  742. adminBaseParamsServer1 = {
  743. server: servers[0],
  744. emails,
  745. socketNotifications: adminNotifications,
  746. token: servers[0].accessToken
  747. }
  748. adminBaseParamsServer2 = {
  749. server: servers[1],
  750. emails,
  751. socketNotifications: adminNotificationsServer2,
  752. token: servers[1].accessToken
  753. }
  754. userBaseParams = {
  755. server: servers[0],
  756. emails,
  757. socketNotifications: userNotifications,
  758. token: userAccessToken
  759. }
  760. const resCustomConfig = await getCustomConfig(servers[0].url, servers[0].accessToken)
  761. currentCustomConfig = resCustomConfig.body
  762. const autoBlacklistTestsCustomConfig = immutableAssign(currentCustomConfig, {
  763. autoBlacklist: {
  764. videos: {
  765. ofUsers: {
  766. enabled: true
  767. }
  768. }
  769. }
  770. })
  771. // enable transcoding otherwise own publish notification after transcoding not expected
  772. autoBlacklistTestsCustomConfig.transcoding.enabled = true
  773. await updateCustomConfig(servers[0].url, servers[0].accessToken, autoBlacklistTestsCustomConfig)
  774. await addUserSubscription(servers[0].url, servers[0].accessToken, 'user_1_channel@localhost:9001')
  775. await addUserSubscription(servers[1].url, servers[1].accessToken, 'user_1_channel@localhost:9001')
  776. })
  777. it('Should send notification to moderators on new video with auto-blacklist', async function () {
  778. this.timeout(20000)
  779. videoName = 'video with auto-blacklist ' + uuidv4()
  780. const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: videoName })
  781. videoUUID = resVideo.body.video.uuid
  782. await waitJobs(servers)
  783. await checkVideoAutoBlacklistForModerators(adminBaseParamsServer1, videoUUID, videoName, 'presence')
  784. })
  785. it('Should not send video publish notification if auto-blacklisted', async function () {
  786. await checkVideoIsPublished(userBaseParams, videoName, videoUUID, 'absence')
  787. })
  788. it('Should not send a local user subscription notification if auto-blacklisted', async function () {
  789. await checkNewVideoFromSubscription(adminBaseParamsServer1, videoName, videoUUID, 'absence')
  790. })
  791. it('Should not send a remote user subscription notification if auto-blacklisted', async function () {
  792. await checkNewVideoFromSubscription(adminBaseParamsServer2, videoName, videoUUID, 'absence')
  793. })
  794. it('Should send video published and unblacklist after video unblacklisted', async function () {
  795. this.timeout(20000)
  796. await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, videoUUID)
  797. await waitJobs(servers)
  798. // FIXME: Can't test as two notifications sent to same user and util only checks last one
  799. // One notification might be better anyways
  800. // await checkNewBlacklistOnMyVideo(userBaseParams, videoUUID, videoName, 'unblacklist')
  801. // await checkVideoIsPublished(userBaseParams, videoName, videoUUID, 'presence')
  802. })
  803. it('Should send a local user subscription notification after removed from blacklist', async function () {
  804. await checkNewVideoFromSubscription(adminBaseParamsServer1, videoName, videoUUID, 'presence')
  805. })
  806. it('Should send a remote user subscription notification after removed from blacklist', async function () {
  807. await checkNewVideoFromSubscription(adminBaseParamsServer2, videoName, videoUUID, 'presence')
  808. })
  809. it('Should send unblacklist but not published/subscription notes after unblacklisted if scheduled update pending', async function () {
  810. this.timeout(20000)
  811. let updateAt = new Date(new Date().getTime() + 100000)
  812. const name = 'video with auto-blacklist and future schedule ' + uuidv4()
  813. const data = {
  814. name,
  815. privacy: VideoPrivacy.PRIVATE,
  816. scheduleUpdate: {
  817. updateAt: updateAt.toISOString(),
  818. privacy: VideoPrivacy.PUBLIC
  819. }
  820. }
  821. const resVideo = await uploadVideo(servers[0].url, userAccessToken, data)
  822. const uuid = resVideo.body.video.uuid
  823. await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, uuid)
  824. await waitJobs(servers)
  825. await checkNewBlacklistOnMyVideo(userBaseParams, uuid, name, 'unblacklist')
  826. // FIXME: Can't test absence as two notifications sent to same user and util only checks last one
  827. // One notification might be better anyways
  828. // await checkVideoIsPublished(userBaseParams, name, uuid, 'absence')
  829. await checkNewVideoFromSubscription(adminBaseParamsServer1, name, uuid, 'absence')
  830. await checkNewVideoFromSubscription(adminBaseParamsServer2, name, uuid, 'absence')
  831. })
  832. it('Should not send publish/subscription notifications after scheduled update if video still auto-blacklisted', async function () {
  833. this.timeout(20000)
  834. // In 2 seconds
  835. let updateAt = new Date(new Date().getTime() + 2000)
  836. const name = 'video with schedule done and still auto-blacklisted ' + uuidv4()
  837. const data = {
  838. name,
  839. privacy: VideoPrivacy.PRIVATE,
  840. scheduleUpdate: {
  841. updateAt: updateAt.toISOString(),
  842. privacy: VideoPrivacy.PUBLIC
  843. }
  844. }
  845. const resVideo = await uploadVideo(servers[0].url, userAccessToken, data)
  846. const uuid = resVideo.body.video.uuid
  847. await wait(6000)
  848. await checkVideoIsPublished(userBaseParams, name, uuid, 'absence')
  849. await checkNewVideoFromSubscription(adminBaseParamsServer1, name, uuid, 'absence')
  850. await checkNewVideoFromSubscription(adminBaseParamsServer2, name, uuid, 'absence')
  851. })
  852. it('Should not send a notification to moderators on new video without auto-blacklist', async function () {
  853. this.timeout(20000)
  854. const name = 'video without auto-blacklist ' + uuidv4()
  855. // admin with blacklist right will not be auto-blacklisted
  856. const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name })
  857. const uuid = resVideo.body.video.uuid
  858. await waitJobs(servers)
  859. await checkVideoAutoBlacklistForModerators(adminBaseParamsServer1, uuid, name, 'absence')
  860. })
  861. after(async () => {
  862. await updateCustomConfig(servers[0].url, servers[0].accessToken, currentCustomConfig)
  863. await removeUserSubscription(servers[0].url, servers[0].accessToken, 'user_1_channel@localhost:9001')
  864. await removeUserSubscription(servers[1].url, servers[1].accessToken, 'user_1_channel@localhost:9001')
  865. })
  866. })
  867. describe('Mark as read', function () {
  868. it('Should mark as read some notifications', async function () {
  869. const res = await getUserNotifications(servers[ 0 ].url, userAccessToken, 2, 3)
  870. const ids = res.body.data.map(n => n.id)
  871. await markAsReadNotifications(servers[ 0 ].url, userAccessToken, ids)
  872. })
  873. it('Should have the notifications marked as read', async function () {
  874. const res = await getUserNotifications(servers[ 0 ].url, userAccessToken, 0, 10)
  875. const notifications = res.body.data as UserNotification[]
  876. expect(notifications[ 0 ].read).to.be.false
  877. expect(notifications[ 1 ].read).to.be.false
  878. expect(notifications[ 2 ].read).to.be.true
  879. expect(notifications[ 3 ].read).to.be.true
  880. expect(notifications[ 4 ].read).to.be.true
  881. expect(notifications[ 5 ].read).to.be.false
  882. })
  883. it('Should only list read notifications', async function () {
  884. const res = await getUserNotifications(servers[ 0 ].url, userAccessToken, 0, 10, false)
  885. const notifications = res.body.data as UserNotification[]
  886. for (const notification of notifications) {
  887. expect(notification.read).to.be.true
  888. }
  889. })
  890. it('Should only list unread notifications', async function () {
  891. const res = await getUserNotifications(servers[ 0 ].url, userAccessToken, 0, 10, true)
  892. const notifications = res.body.data as UserNotification[]
  893. for (const notification of notifications) {
  894. expect(notification.read).to.be.false
  895. }
  896. })
  897. it('Should mark as read all notifications', async function () {
  898. await markAsReadAllNotifications(servers[ 0 ].url, userAccessToken)
  899. const res = await getUserNotifications(servers[ 0 ].url, userAccessToken, 0, 10, true)
  900. expect(res.body.total).to.equal(0)
  901. expect(res.body.data).to.have.lengthOf(0)
  902. })
  903. })
  904. describe('Notification settings', function () {
  905. let baseParams: CheckerBaseParams
  906. before(() => {
  907. baseParams = {
  908. server: servers[0],
  909. emails,
  910. socketNotifications: userNotifications,
  911. token: userAccessToken
  912. }
  913. })
  914. it('Should not have notifications', async function () {
  915. this.timeout(20000)
  916. await updateMyNotificationSettings(servers[0].url, userAccessToken, immutableAssign(allNotificationSettings, {
  917. newVideoFromSubscription: UserNotificationSettingValue.NONE
  918. }))
  919. {
  920. const res = await getMyUserInformation(servers[0].url, userAccessToken)
  921. const info = res.body as User
  922. expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.NONE)
  923. }
  924. const { name, uuid } = await uploadVideoByLocalAccount(servers)
  925. const check = { web: true, mail: true }
  926. await checkNewVideoFromSubscription(immutableAssign(baseParams, { check }), name, uuid, 'absence')
  927. })
  928. it('Should only have web notifications', async function () {
  929. this.timeout(20000)
  930. await updateMyNotificationSettings(servers[0].url, userAccessToken, immutableAssign(allNotificationSettings, {
  931. newVideoFromSubscription: UserNotificationSettingValue.WEB
  932. }))
  933. {
  934. const res = await getMyUserInformation(servers[0].url, userAccessToken)
  935. const info = res.body as User
  936. expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.WEB)
  937. }
  938. const { name, uuid } = await uploadVideoByLocalAccount(servers)
  939. {
  940. const check = { mail: true, web: false }
  941. await checkNewVideoFromSubscription(immutableAssign(baseParams, { check }), name, uuid, 'absence')
  942. }
  943. {
  944. const check = { mail: false, web: true }
  945. await checkNewVideoFromSubscription(immutableAssign(baseParams, { check }), name, uuid, 'presence')
  946. }
  947. })
  948. it('Should only have mail notifications', async function () {
  949. this.timeout(20000)
  950. await updateMyNotificationSettings(servers[0].url, userAccessToken, immutableAssign(allNotificationSettings, {
  951. newVideoFromSubscription: UserNotificationSettingValue.EMAIL
  952. }))
  953. {
  954. const res = await getMyUserInformation(servers[0].url, userAccessToken)
  955. const info = res.body as User
  956. expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.EMAIL)
  957. }
  958. const { name, uuid } = await uploadVideoByLocalAccount(servers)
  959. {
  960. const check = { mail: false, web: true }
  961. await checkNewVideoFromSubscription(immutableAssign(baseParams, { check }), name, uuid, 'absence')
  962. }
  963. {
  964. const check = { mail: true, web: false }
  965. await checkNewVideoFromSubscription(immutableAssign(baseParams, { check }), name, uuid, 'presence')
  966. }
  967. })
  968. it('Should have email and web notifications', async function () {
  969. this.timeout(20000)
  970. await updateMyNotificationSettings(servers[0].url, userAccessToken, immutableAssign(allNotificationSettings, {
  971. newVideoFromSubscription: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL
  972. }))
  973. {
  974. const res = await getMyUserInformation(servers[0].url, userAccessToken)
  975. const info = res.body as User
  976. expect(info.notificationSettings.newVideoFromSubscription).to.equal(
  977. UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL
  978. )
  979. }
  980. const { name, uuid } = await uploadVideoByLocalAccount(servers)
  981. await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
  982. })
  983. })
  984. after(async function () {
  985. MockSmtpServer.Instance.kill()
  986. await cleanupTests(servers)
  987. })
  988. })