]>
Commit | Line | Data |
---|---|---|
8eb07b01 C |
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
2 | ||
3 | import 'mocha' | |
4 | import * as chai from 'chai' | |
8eb07b01 C |
5 | import { |
6 | CheckerBaseParams, | |
7 | checkNewVideoFromSubscription, | |
2c27e704 | 8 | cleanupTests, |
8eb07b01 | 9 | getAllNotificationsSettings, |
2c27e704 | 10 | getMyUserInformation, |
2c27e704 | 11 | MockSmtpServer, |
8eb07b01 | 12 | prepareNotificationsTest, |
2c27e704 | 13 | ServerInfo, |
2c27e704 C |
14 | uploadRandomVideo, |
15 | waitJobs | |
16 | } from '@shared/extra-utils' | |
17 | import { User, UserNotification, UserNotificationSettingValue } from '@shared/models' | |
8eb07b01 C |
18 | |
19 | const expect = chai.expect | |
20 | ||
21 | describe('Test notifications API', function () { | |
22 | let server: ServerInfo | |
23 | let userNotifications: UserNotification[] = [] | |
dd0ebb71 | 24 | let userToken: string |
8eb07b01 C |
25 | let emails: object[] = [] |
26 | ||
27 | before(async function () { | |
28 | this.timeout(120000) | |
29 | ||
30 | const res = await prepareNotificationsTest(1) | |
31 | emails = res.emails | |
dd0ebb71 | 32 | userToken = res.userAccessToken |
8eb07b01 C |
33 | userNotifications = res.userNotifications |
34 | server = res.servers[0] | |
35 | ||
dd0ebb71 | 36 | await server.subscriptionsCommand.add({ token: userToken, targetUri: 'root_channel@localhost:' + server.port }) |
8eb07b01 C |
37 | |
38 | for (let i = 0; i < 10; i++) { | |
39 | await uploadRandomVideo(server, false) | |
40 | } | |
41 | ||
42 | await waitJobs([ server ]) | |
43 | }) | |
44 | ||
45 | describe('Mark as read', function () { | |
46 | ||
47 | it('Should mark as read some notifications', async function () { | |
dd0ebb71 C |
48 | const { data } = await server.notificationsCommand.list({ token: userToken, start: 2, count: 3 }) |
49 | const ids = data.map(n => n.id) | |
8eb07b01 | 50 | |
dd0ebb71 | 51 | await server.notificationsCommand.markAsRead({ token: userToken, ids }) |
8eb07b01 C |
52 | }) |
53 | ||
54 | it('Should have the notifications marked as read', async function () { | |
dd0ebb71 C |
55 | const { data } = await server.notificationsCommand.list({ token: userToken, start: 0, count: 10 }) |
56 | ||
57 | expect(data[0].read).to.be.false | |
58 | expect(data[1].read).to.be.false | |
59 | expect(data[2].read).to.be.true | |
60 | expect(data[3].read).to.be.true | |
61 | expect(data[4].read).to.be.true | |
62 | expect(data[5].read).to.be.false | |
8eb07b01 C |
63 | }) |
64 | ||
65 | it('Should only list read notifications', async function () { | |
dd0ebb71 | 66 | const { data } = await server.notificationsCommand.list({ token: userToken, start: 0, count: 10, unread: false }) |
8eb07b01 | 67 | |
dd0ebb71 | 68 | for (const notification of data) { |
8eb07b01 C |
69 | expect(notification.read).to.be.true |
70 | } | |
71 | }) | |
72 | ||
73 | it('Should only list unread notifications', async function () { | |
dd0ebb71 | 74 | const { data } = await server.notificationsCommand.list({ token: userToken, start: 0, count: 10, unread: true }) |
8eb07b01 | 75 | |
dd0ebb71 | 76 | for (const notification of data) { |
8eb07b01 C |
77 | expect(notification.read).to.be.false |
78 | } | |
79 | }) | |
80 | ||
81 | it('Should mark as read all notifications', async function () { | |
dd0ebb71 | 82 | await server.notificationsCommand.markAsReadAll({ token: userToken }) |
8eb07b01 | 83 | |
dd0ebb71 | 84 | const body = await server.notificationsCommand.list({ token: userToken, start: 0, count: 10, unread: true }) |
8eb07b01 | 85 | |
dd0ebb71 C |
86 | expect(body.total).to.equal(0) |
87 | expect(body.data).to.have.lengthOf(0) | |
8eb07b01 C |
88 | }) |
89 | }) | |
90 | ||
91 | describe('Notification settings', function () { | |
92 | let baseParams: CheckerBaseParams | |
93 | ||
94 | before(() => { | |
95 | baseParams = { | |
96 | server: server, | |
97 | emails, | |
98 | socketNotifications: userNotifications, | |
dd0ebb71 | 99 | token: userToken |
8eb07b01 C |
100 | } |
101 | }) | |
102 | ||
103 | it('Should not have notifications', async function () { | |
104 | this.timeout(20000) | |
105 | ||
dd0ebb71 C |
106 | await server.notificationsCommand.updateMySettings({ |
107 | token: userToken, | |
108 | settings: { ...getAllNotificationsSettings(), newVideoFromSubscription: UserNotificationSettingValue.NONE } | |
109 | }) | |
8eb07b01 C |
110 | |
111 | { | |
dd0ebb71 | 112 | const res = await getMyUserInformation(server.url, userToken) |
8eb07b01 C |
113 | const info = res.body as User |
114 | expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.NONE) | |
115 | } | |
116 | ||
117 | const { name, uuid } = await uploadRandomVideo(server) | |
118 | ||
119 | const check = { web: true, mail: true } | |
6c5065a0 | 120 | await checkNewVideoFromSubscription({ ...baseParams, ...check }, name, uuid, 'absence') |
8eb07b01 C |
121 | }) |
122 | ||
123 | it('Should only have web notifications', async function () { | |
124 | this.timeout(20000) | |
125 | ||
dd0ebb71 C |
126 | await server.notificationsCommand.updateMySettings({ |
127 | token: userToken, | |
128 | settings: { ...getAllNotificationsSettings(), newVideoFromSubscription: UserNotificationSettingValue.WEB } | |
129 | }) | |
8eb07b01 C |
130 | |
131 | { | |
dd0ebb71 | 132 | const res = await getMyUserInformation(server.url, userToken) |
8eb07b01 C |
133 | const info = res.body as User |
134 | expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.WEB) | |
135 | } | |
136 | ||
137 | const { name, uuid } = await uploadRandomVideo(server) | |
138 | ||
139 | { | |
140 | const check = { mail: true, web: false } | |
6c5065a0 | 141 | await checkNewVideoFromSubscription({ ...baseParams, ...check }, name, uuid, 'absence') |
8eb07b01 C |
142 | } |
143 | ||
144 | { | |
145 | const check = { mail: false, web: true } | |
6c5065a0 | 146 | await checkNewVideoFromSubscription({ ...baseParams, ...check }, name, uuid, 'presence') |
8eb07b01 C |
147 | } |
148 | }) | |
149 | ||
150 | it('Should only have mail notifications', async function () { | |
151 | this.timeout(20000) | |
152 | ||
dd0ebb71 C |
153 | await server.notificationsCommand.updateMySettings({ |
154 | token: userToken, | |
155 | settings: { ...getAllNotificationsSettings(), newVideoFromSubscription: UserNotificationSettingValue.EMAIL } | |
156 | }) | |
8eb07b01 C |
157 | |
158 | { | |
dd0ebb71 | 159 | const res = await getMyUserInformation(server.url, userToken) |
8eb07b01 C |
160 | const info = res.body as User |
161 | expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.EMAIL) | |
162 | } | |
163 | ||
164 | const { name, uuid } = await uploadRandomVideo(server) | |
165 | ||
166 | { | |
167 | const check = { mail: false, web: true } | |
6c5065a0 | 168 | await checkNewVideoFromSubscription({ ...baseParams, ...check }, name, uuid, 'absence') |
8eb07b01 C |
169 | } |
170 | ||
171 | { | |
172 | const check = { mail: true, web: false } | |
6c5065a0 | 173 | await checkNewVideoFromSubscription({ ...baseParams, ...check }, name, uuid, 'presence') |
8eb07b01 C |
174 | } |
175 | }) | |
176 | ||
177 | it('Should have email and web notifications', async function () { | |
178 | this.timeout(20000) | |
179 | ||
dd0ebb71 C |
180 | await server.notificationsCommand.updateMySettings({ |
181 | token: userToken, | |
182 | settings: { | |
183 | ...getAllNotificationsSettings(), | |
184 | newVideoFromSubscription: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL | |
185 | } | |
186 | }) | |
8eb07b01 C |
187 | |
188 | { | |
dd0ebb71 | 189 | const res = await getMyUserInformation(server.url, userToken) |
8eb07b01 C |
190 | const info = res.body as User |
191 | expect(info.notificationSettings.newVideoFromSubscription).to.equal( | |
192 | UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL | |
193 | ) | |
194 | } | |
195 | ||
196 | const { name, uuid } = await uploadRandomVideo(server) | |
197 | ||
198 | await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence') | |
199 | }) | |
200 | }) | |
201 | ||
202 | after(async function () { | |
203 | MockSmtpServer.Instance.kill() | |
204 | ||
205 | await cleanupTests([ server ]) | |
206 | }) | |
207 | }) |