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