2020-06-16 09:52:05 -04:00
|
|
|
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
|
|
|
|
|
|
|
|
import 'mocha'
|
|
|
|
import * as chai from 'chai'
|
|
|
|
import {
|
|
|
|
CheckerBaseParams,
|
|
|
|
checkNewVideoFromSubscription,
|
2021-07-07 10:40:49 -04:00
|
|
|
cleanupTests,
|
2020-06-16 09:52:05 -04:00
|
|
|
getAllNotificationsSettings,
|
2021-07-07 10:40:49 -04:00
|
|
|
MockSmtpServer,
|
2021-07-16 03:47:51 -04:00
|
|
|
PeerTubeServer,
|
2021-07-16 08:27:30 -04:00
|
|
|
prepareNotificationsTest,
|
2021-07-07 10:40:49 -04:00
|
|
|
waitJobs
|
|
|
|
} from '@shared/extra-utils'
|
2021-07-13 08:23:01 -04:00
|
|
|
import { UserNotification, UserNotificationSettingValue } from '@shared/models'
|
2020-06-16 09:52:05 -04:00
|
|
|
|
|
|
|
const expect = chai.expect
|
|
|
|
|
|
|
|
describe('Test notifications API', function () {
|
2021-07-16 03:47:51 -04:00
|
|
|
let server: PeerTubeServer
|
2020-06-16 09:52:05 -04:00
|
|
|
let userNotifications: UserNotification[] = []
|
2021-07-09 10:23:01 -04:00
|
|
|
let userToken: string
|
2020-06-16 09:52:05 -04:00
|
|
|
let emails: object[] = []
|
|
|
|
|
|
|
|
before(async function () {
|
|
|
|
this.timeout(120000)
|
|
|
|
|
|
|
|
const res = await prepareNotificationsTest(1)
|
|
|
|
emails = res.emails
|
2021-07-09 10:23:01 -04:00
|
|
|
userToken = res.userAccessToken
|
2020-06-16 09:52:05 -04:00
|
|
|
userNotifications = res.userNotifications
|
|
|
|
server = res.servers[0]
|
|
|
|
|
2021-07-16 03:04:35 -04:00
|
|
|
await server.subscriptions.add({ token: userToken, targetUri: 'root_channel@localhost:' + server.port })
|
2020-06-16 09:52:05 -04:00
|
|
|
|
|
|
|
for (let i = 0; i < 10; i++) {
|
2021-07-16 03:04:35 -04:00
|
|
|
await server.videos.randomUpload({ wait: false })
|
2020-06-16 09:52:05 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
await waitJobs([ server ])
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('Mark as read', function () {
|
|
|
|
|
|
|
|
it('Should mark as read some notifications', async function () {
|
2021-07-16 03:04:35 -04:00
|
|
|
const { data } = await server.notifications.list({ token: userToken, start: 2, count: 3 })
|
2021-07-09 10:23:01 -04:00
|
|
|
const ids = data.map(n => n.id)
|
2020-06-16 09:52:05 -04:00
|
|
|
|
2021-07-16 03:04:35 -04:00
|
|
|
await server.notifications.markAsRead({ token: userToken, ids })
|
2020-06-16 09:52:05 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should have the notifications marked as read', async function () {
|
2021-07-16 03:04:35 -04:00
|
|
|
const { data } = await server.notifications.list({ token: userToken, start: 0, count: 10 })
|
2021-07-09 10:23:01 -04:00
|
|
|
|
|
|
|
expect(data[0].read).to.be.false
|
|
|
|
expect(data[1].read).to.be.false
|
|
|
|
expect(data[2].read).to.be.true
|
|
|
|
expect(data[3].read).to.be.true
|
|
|
|
expect(data[4].read).to.be.true
|
|
|
|
expect(data[5].read).to.be.false
|
2020-06-16 09:52:05 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should only list read notifications', async function () {
|
2021-07-16 03:04:35 -04:00
|
|
|
const { data } = await server.notifications.list({ token: userToken, start: 0, count: 10, unread: false })
|
2020-06-16 09:52:05 -04:00
|
|
|
|
2021-07-09 10:23:01 -04:00
|
|
|
for (const notification of data) {
|
2020-06-16 09:52:05 -04:00
|
|
|
expect(notification.read).to.be.true
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should only list unread notifications', async function () {
|
2021-07-16 03:04:35 -04:00
|
|
|
const { data } = await server.notifications.list({ token: userToken, start: 0, count: 10, unread: true })
|
2020-06-16 09:52:05 -04:00
|
|
|
|
2021-07-09 10:23:01 -04:00
|
|
|
for (const notification of data) {
|
2020-06-16 09:52:05 -04:00
|
|
|
expect(notification.read).to.be.false
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should mark as read all notifications', async function () {
|
2021-07-16 03:04:35 -04:00
|
|
|
await server.notifications.markAsReadAll({ token: userToken })
|
2020-06-16 09:52:05 -04:00
|
|
|
|
2021-07-16 03:04:35 -04:00
|
|
|
const body = await server.notifications.list({ token: userToken, start: 0, count: 10, unread: true })
|
2020-06-16 09:52:05 -04:00
|
|
|
|
2021-07-09 10:23:01 -04:00
|
|
|
expect(body.total).to.equal(0)
|
|
|
|
expect(body.data).to.have.lengthOf(0)
|
2020-06-16 09:52:05 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('Notification settings', function () {
|
|
|
|
let baseParams: CheckerBaseParams
|
|
|
|
|
|
|
|
before(() => {
|
|
|
|
baseParams = {
|
|
|
|
server: server,
|
|
|
|
emails,
|
|
|
|
socketNotifications: userNotifications,
|
2021-07-09 10:23:01 -04:00
|
|
|
token: userToken
|
2020-06-16 09:52:05 -04:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should not have notifications', async function () {
|
|
|
|
this.timeout(20000)
|
|
|
|
|
2021-07-16 03:04:35 -04:00
|
|
|
await server.notifications.updateMySettings({
|
2021-07-09 10:23:01 -04:00
|
|
|
token: userToken,
|
|
|
|
settings: { ...getAllNotificationsSettings(), newVideoFromSubscription: UserNotificationSettingValue.NONE }
|
|
|
|
})
|
2020-06-16 09:52:05 -04:00
|
|
|
|
|
|
|
{
|
2021-07-16 03:04:35 -04:00
|
|
|
const info = await server.users.getMyInfo({ token: userToken })
|
2020-06-16 09:52:05 -04:00
|
|
|
expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.NONE)
|
|
|
|
}
|
|
|
|
|
2021-07-27 03:07:38 -04:00
|
|
|
const { name, shortUUID } = await server.videos.randomUpload()
|
2020-06-16 09:52:05 -04:00
|
|
|
|
|
|
|
const check = { web: true, mail: true }
|
2021-07-27 03:07:38 -04:00
|
|
|
await checkNewVideoFromSubscription({ ...baseParams, check, videoName: name, shortUUID, checkType: 'absence' })
|
2020-06-16 09:52:05 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should only have web notifications', async function () {
|
|
|
|
this.timeout(20000)
|
|
|
|
|
2021-07-16 03:04:35 -04:00
|
|
|
await server.notifications.updateMySettings({
|
2021-07-09 10:23:01 -04:00
|
|
|
token: userToken,
|
|
|
|
settings: { ...getAllNotificationsSettings(), newVideoFromSubscription: UserNotificationSettingValue.WEB }
|
|
|
|
})
|
2020-06-16 09:52:05 -04:00
|
|
|
|
|
|
|
{
|
2021-07-16 03:04:35 -04:00
|
|
|
const info = await server.users.getMyInfo({ token: userToken })
|
2020-06-16 09:52:05 -04:00
|
|
|
expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.WEB)
|
|
|
|
}
|
|
|
|
|
2021-07-27 03:07:38 -04:00
|
|
|
const { name, shortUUID } = await server.videos.randomUpload()
|
2020-06-16 09:52:05 -04:00
|
|
|
|
|
|
|
{
|
|
|
|
const check = { mail: true, web: false }
|
2021-07-27 03:07:38 -04:00
|
|
|
await checkNewVideoFromSubscription({ ...baseParams, check, videoName: name, shortUUID, checkType: 'absence' })
|
2020-06-16 09:52:05 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
const check = { mail: false, web: true }
|
2021-07-27 03:07:38 -04:00
|
|
|
await checkNewVideoFromSubscription({ ...baseParams, check, videoName: name, shortUUID, checkType: 'presence' })
|
2020-06-16 09:52:05 -04:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should only have mail notifications', async function () {
|
|
|
|
this.timeout(20000)
|
|
|
|
|
2021-07-16 03:04:35 -04:00
|
|
|
await server.notifications.updateMySettings({
|
2021-07-09 10:23:01 -04:00
|
|
|
token: userToken,
|
|
|
|
settings: { ...getAllNotificationsSettings(), newVideoFromSubscription: UserNotificationSettingValue.EMAIL }
|
|
|
|
})
|
2020-06-16 09:52:05 -04:00
|
|
|
|
|
|
|
{
|
2021-07-16 03:04:35 -04:00
|
|
|
const info = await server.users.getMyInfo({ token: userToken })
|
2020-06-16 09:52:05 -04:00
|
|
|
expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.EMAIL)
|
|
|
|
}
|
|
|
|
|
2021-07-27 03:07:38 -04:00
|
|
|
const { name, shortUUID } = await server.videos.randomUpload()
|
2020-06-16 09:52:05 -04:00
|
|
|
|
|
|
|
{
|
|
|
|
const check = { mail: false, web: true }
|
2021-07-27 03:07:38 -04:00
|
|
|
await checkNewVideoFromSubscription({ ...baseParams, check, videoName: name, shortUUID, checkType: 'absence' })
|
2020-06-16 09:52:05 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
const check = { mail: true, web: false }
|
2021-07-27 03:07:38 -04:00
|
|
|
await checkNewVideoFromSubscription({ ...baseParams, check, videoName: name, shortUUID, checkType: 'presence' })
|
2020-06-16 09:52:05 -04:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should have email and web notifications', async function () {
|
|
|
|
this.timeout(20000)
|
|
|
|
|
2021-07-16 03:04:35 -04:00
|
|
|
await server.notifications.updateMySettings({
|
2021-07-09 10:23:01 -04:00
|
|
|
token: userToken,
|
|
|
|
settings: {
|
|
|
|
...getAllNotificationsSettings(),
|
|
|
|
newVideoFromSubscription: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL
|
|
|
|
}
|
|
|
|
})
|
2020-06-16 09:52:05 -04:00
|
|
|
|
|
|
|
{
|
2021-07-16 03:04:35 -04:00
|
|
|
const info = await server.users.getMyInfo({ token: userToken })
|
2020-06-16 09:52:05 -04:00
|
|
|
expect(info.notificationSettings.newVideoFromSubscription).to.equal(
|
|
|
|
UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2021-07-27 03:07:38 -04:00
|
|
|
const { name, shortUUID } = await server.videos.randomUpload()
|
2020-06-16 09:52:05 -04:00
|
|
|
|
2021-07-27 03:07:38 -04:00
|
|
|
await checkNewVideoFromSubscription({ ...baseParams, videoName: name, shortUUID, checkType: 'presence' })
|
2020-06-16 09:52:05 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
after(async function () {
|
|
|
|
MockSmtpServer.Instance.kill()
|
|
|
|
|
|
|
|
await cleanupTests([ server ])
|
|
|
|
})
|
|
|
|
})
|