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