d1d5984e30
* refactor(server emails): email transports module refactor to TypeScript * refactor(docker-compose deps): move local email server to common dev compose file * chore(server launch.json): add ts-node script running example * chore(server deps): add nodemailer types package * refactor(server activitystream): add strongly typed activity definitions * feat(server activitystream): add activity repository * feat(server info): add canonical url on the service level * feat(server): add static file serving route to server core * feat(server): add dependencies for periodical email digests * feat(server activity stream): call the initialization step from the activity stream module * feat(server activity digest): add WIP weekly email digest implementation * feat(server digest email): smul upgrades and fixes to the email template and its contents * just for Fabs to test * chore(root package.json): remove deleted docker-compose references * feat(frontend profile): add notification preferences panel * feat(server digest emails): set prod ready cron tab and timespan * refactor(server email digest): move templates into the email module * refactor(server activity digests): refactor to use notifications infrastructure * test(server activities): add tests and some refactor to activities and notification preferences * refactor(notification preferences): fix minor issues * test(server notification preferences test): fix describe nesting * fix(server activities): add missing action types * fix(server activities): fix errors after merging main * test(server activity notifications): add test coverage for activity notifications service * refactor(server activities): fixing tests and some cleanup * feat(server cli): add summary notification command to cli * chore(dev env db versions): upgrade local dev env versions * chore(server deps): upgrade local dev db to pg 14 * fix(docker-compose): bind maildev to localhost * process-scoped notifications test queues * test(activity tests): add sleep to fix flaky CI * feat(activity digests): add demo date for digest trigger * feat(activity digest): add UK timezone trigger date Co-authored-by: Iain Sproat <68657+iainsproat@users.noreply.github.com> Co-authored-by: Fabians <fabis94@live.com>
85 lines
3.0 KiB
TypeScript
85 lines
3.0 KiB
TypeScript
import { truncateTables } from '@/test/hooks'
|
|
import { UserNotificationPreferences, Users } from '@/modules/core/dbSchema'
|
|
import { BasicTestUser, createTestUsers } from '@/test/authHelper'
|
|
import * as repo from '@/modules/notifications/repositories'
|
|
import * as services from '@/modules/notifications/services/notificationPreferences'
|
|
import { expect } from 'chai'
|
|
import {
|
|
NotificationType,
|
|
NotificationChannel
|
|
} from '@/modules/notifications/helpers/types'
|
|
import { BaseError } from '@/modules/shared/errors'
|
|
|
|
const cleanup = async () => {
|
|
await truncateTables([Users.name, UserNotificationPreferences.name])
|
|
}
|
|
|
|
describe('User notification preferences @notifications', () => {
|
|
const userA: BasicTestUser = {
|
|
name: 'd1',
|
|
email: 'd.1@speckle.systems',
|
|
id: ''
|
|
}
|
|
|
|
before(async () => {
|
|
await cleanup()
|
|
await createTestUsers([userA])
|
|
})
|
|
|
|
describe('services', () => {
|
|
it('gets default preferences if none saved', async () => {
|
|
const savedPreferences = await repo.getUserNotificationPreferences(userA.id)
|
|
expect(savedPreferences).to.deep.equal({})
|
|
expect(savedPreferences).to.be.empty
|
|
const preferences = await services.getUserNotificationPreferences(userA.id)
|
|
expect(preferences).to.not.be.empty
|
|
for (const val of Object.values(preferences)) {
|
|
for (const setting of Object.values(val)) {
|
|
expect(setting).to.be.true
|
|
}
|
|
}
|
|
})
|
|
it('store notification settings', async () => {
|
|
await services.updateNotificationPreferences(userA.id, {
|
|
activityDigest: { email: false }
|
|
})
|
|
let preferences = await services.getUserNotificationPreferences(userA.id)
|
|
expect(preferences).to.not.be.empty
|
|
expect(preferences.activityDigest?.email).to.be.false
|
|
await services.updateNotificationPreferences(userA.id, {
|
|
activityDigest: { email: true }
|
|
})
|
|
preferences = await services.getUserNotificationPreferences(userA.id)
|
|
expect(preferences.activityDigest?.email).to.be.true
|
|
})
|
|
it("doesn't store invalid preference keys", async () => {
|
|
const invalidKeys = [
|
|
[NotificationType.ActivityDigest, 'mailPigeon', true],
|
|
['birthdayParty', NotificationChannel.Email, false],
|
|
[
|
|
NotificationType.MentionedInComment,
|
|
NotificationChannel.Email,
|
|
'PleaseDontSpamMe'
|
|
]
|
|
]
|
|
for (const [nt, nc, value] of invalidKeys) {
|
|
try {
|
|
const preferences: Partial<Record<string, Partial<Record<string, boolean>>>> =
|
|
{}
|
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
//@ts-ignore
|
|
preferences[nt] = {}
|
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
//@ts-ignore
|
|
preferences[nt][nc] = value
|
|
await services.updateNotificationPreferences(userA.id, preferences)
|
|
} catch (err) {
|
|
expect(err instanceof BaseError)
|
|
const error = err as BaseError
|
|
expect(error.message).to.contain('Notification preferences input')
|
|
}
|
|
}
|
|
})
|
|
})
|
|
})
|