aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/notifications/notifications-api.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2023-07-31 14:34:36 +0200
committerChocobozzz <me@florianbigard.com>2023-08-11 15:02:33 +0200
commit3a4992633ee62d5edfbb484d9c6bcb3cf158489d (patch)
treee4510b39bdac9c318fdb4b47018d08f15368b8f0 /server/tests/api/notifications/notifications-api.ts
parent04d1da5621d25d59bd5fa1543b725c497bf5d9a8 (diff)
downloadPeerTube-3a4992633ee62d5edfbb484d9c6bcb3cf158489d.tar.gz
PeerTube-3a4992633ee62d5edfbb484d9c6bcb3cf158489d.tar.zst
PeerTube-3a4992633ee62d5edfbb484d9c6bcb3cf158489d.zip
Migrate server to ESM
Sorry for the very big commit that may lead to git log issues and merge conflicts, but it's a major step forward: * Server can be faster at startup because imports() are async and we can easily lazy import big modules * Angular doesn't seem to support ES import (with .js extension), so we had to correctly organize peertube into a monorepo: * Use yarn workspace feature * Use typescript reference projects for dependencies * Shared projects have been moved into "packages", each one is now a node module (with a dedicated package.json/tsconfig.json) * server/tools have been moved into apps/ and is now a dedicated app bundled and published on NPM so users don't have to build peertube cli tools manually * server/tests have been moved into packages/ so we don't compile them every time we want to run the server * Use isolatedModule option: * Had to move from const enum to const (https://www.typescriptlang.org/docs/handbook/enums.html#objects-vs-enums) * Had to explictely specify "type" imports when used in decorators * Prefer tsx (that uses esbuild under the hood) instead of ts-node to load typescript files (tests with mocha or scripts): * To reduce test complexity as esbuild doesn't support decorator metadata, we only test server files that do not import server models * We still build tests files into js files for a faster CI * Remove unmaintained peertube CLI import script * Removed some barrels to speed up execution (less imports)
Diffstat (limited to 'server/tests/api/notifications/notifications-api.ts')
-rw-r--r--server/tests/api/notifications/notifications-api.ts206
1 files changed, 0 insertions, 206 deletions
diff --git a/server/tests/api/notifications/notifications-api.ts b/server/tests/api/notifications/notifications-api.ts
deleted file mode 100644
index 1fc861160..000000000
--- a/server/tests/api/notifications/notifications-api.ts
+++ /dev/null
@@ -1,206 +0,0 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3import { expect } from 'chai'
4import {
5 CheckerBaseParams,
6 checkNewVideoFromSubscription,
7 getAllNotificationsSettings,
8 MockSmtpServer,
9 prepareNotificationsTest
10} from '@server/tests/shared'
11import { UserNotification, UserNotificationSettingValue } from '@shared/models'
12import { cleanupTests, PeerTubeServer, waitJobs } from '@shared/server-commands'
13
14describe('Test notifications API', function () {
15 let server: PeerTubeServer
16 let userNotifications: UserNotification[] = []
17 let userToken: string
18 let emails: object[] = []
19
20 before(async function () {
21 this.timeout(120000)
22
23 const res = await prepareNotificationsTest(1)
24 emails = res.emails
25 userToken = res.userAccessToken
26 userNotifications = res.userNotifications
27 server = res.servers[0]
28
29 await server.subscriptions.add({ token: userToken, targetUri: 'root_channel@' + server.host })
30
31 for (let i = 0; i < 10; i++) {
32 await server.videos.randomUpload({ wait: false })
33 }
34
35 await waitJobs([ server ])
36 })
37
38 describe('Notification list & count', function () {
39
40 it('Should correctly list notifications', async function () {
41 const { data, total } = await server.notifications.list({ token: userToken, start: 0, count: 2 })
42
43 expect(data).to.have.lengthOf(2)
44 expect(total).to.equal(10)
45 })
46 })
47
48 describe('Mark as read', function () {
49
50 it('Should mark as read some notifications', async function () {
51 const { data } = await server.notifications.list({ token: userToken, start: 2, count: 3 })
52 const ids = data.map(n => n.id)
53
54 await server.notifications.markAsRead({ token: userToken, ids })
55 })
56
57 it('Should have the notifications marked as read', async function () {
58 const { data } = await server.notifications.list({ token: userToken, start: 0, count: 10 })
59
60 expect(data[0].read).to.be.false
61 expect(data[1].read).to.be.false
62 expect(data[2].read).to.be.true
63 expect(data[3].read).to.be.true
64 expect(data[4].read).to.be.true
65 expect(data[5].read).to.be.false
66 })
67
68 it('Should only list read notifications', async function () {
69 const { data } = await server.notifications.list({ token: userToken, start: 0, count: 10, unread: false })
70
71 for (const notification of data) {
72 expect(notification.read).to.be.true
73 }
74 })
75
76 it('Should only list unread notifications', async function () {
77 const { data } = await server.notifications.list({ token: userToken, start: 0, count: 10, unread: true })
78
79 for (const notification of data) {
80 expect(notification.read).to.be.false
81 }
82 })
83
84 it('Should mark as read all notifications', async function () {
85 await server.notifications.markAsReadAll({ token: userToken })
86
87 const body = await server.notifications.list({ token: userToken, start: 0, count: 10, unread: true })
88
89 expect(body.total).to.equal(0)
90 expect(body.data).to.have.lengthOf(0)
91 })
92 })
93
94 describe('Notification settings', function () {
95 let baseParams: CheckerBaseParams
96
97 before(() => {
98 baseParams = {
99 server,
100 emails,
101 socketNotifications: userNotifications,
102 token: userToken
103 }
104 })
105
106 it('Should not have notifications', async function () {
107 this.timeout(20000)
108
109 await server.notifications.updateMySettings({
110 token: userToken,
111 settings: { ...getAllNotificationsSettings(), newVideoFromSubscription: UserNotificationSettingValue.NONE }
112 })
113
114 {
115 const info = await server.users.getMyInfo({ token: userToken })
116 expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.NONE)
117 }
118
119 const { name, shortUUID } = await server.videos.randomUpload()
120
121 const check = { web: true, mail: true }
122 await checkNewVideoFromSubscription({ ...baseParams, check, videoName: name, shortUUID, checkType: 'absence' })
123 })
124
125 it('Should only have web notifications', async function () {
126 this.timeout(20000)
127
128 await server.notifications.updateMySettings({
129 token: userToken,
130 settings: { ...getAllNotificationsSettings(), newVideoFromSubscription: UserNotificationSettingValue.WEB }
131 })
132
133 {
134 const info = await server.users.getMyInfo({ token: userToken })
135 expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.WEB)
136 }
137
138 const { name, shortUUID } = await server.videos.randomUpload()
139
140 {
141 const check = { mail: true, web: false }
142 await checkNewVideoFromSubscription({ ...baseParams, check, videoName: name, shortUUID, checkType: 'absence' })
143 }
144
145 {
146 const check = { mail: false, web: true }
147 await checkNewVideoFromSubscription({ ...baseParams, check, videoName: name, shortUUID, checkType: 'presence' })
148 }
149 })
150
151 it('Should only have mail notifications', async function () {
152 this.timeout(20000)
153
154 await server.notifications.updateMySettings({
155 token: userToken,
156 settings: { ...getAllNotificationsSettings(), newVideoFromSubscription: UserNotificationSettingValue.EMAIL }
157 })
158
159 {
160 const info = await server.users.getMyInfo({ token: userToken })
161 expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.EMAIL)
162 }
163
164 const { name, shortUUID } = await server.videos.randomUpload()
165
166 {
167 const check = { mail: false, web: true }
168 await checkNewVideoFromSubscription({ ...baseParams, check, videoName: name, shortUUID, checkType: 'absence' })
169 }
170
171 {
172 const check = { mail: true, web: false }
173 await checkNewVideoFromSubscription({ ...baseParams, check, videoName: name, shortUUID, checkType: 'presence' })
174 }
175 })
176
177 it('Should have email and web notifications', async function () {
178 this.timeout(20000)
179
180 await server.notifications.updateMySettings({
181 token: userToken,
182 settings: {
183 ...getAllNotificationsSettings(),
184 newVideoFromSubscription: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL
185 }
186 })
187
188 {
189 const info = await server.users.getMyInfo({ token: userToken })
190 expect(info.notificationSettings.newVideoFromSubscription).to.equal(
191 UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL
192 )
193 }
194
195 const { name, shortUUID } = await server.videos.randomUpload()
196
197 await checkNewVideoFromSubscription({ ...baseParams, videoName: name, shortUUID, checkType: 'presence' })
198 })
199 })
200
201 after(async function () {
202 MockSmtpServer.Instance.kill()
203
204 await cleanupTests([ server ])
205 })
206})