diff options
Diffstat (limited to 'server/tests/api/notifications/notifications-api.ts')
-rw-r--r-- | server/tests/api/notifications/notifications-api.ts | 92 |
1 files changed, 46 insertions, 46 deletions
diff --git a/server/tests/api/notifications/notifications-api.ts b/server/tests/api/notifications/notifications-api.ts index 1ed98ae7a..447492c5f 100644 --- a/server/tests/api/notifications/notifications-api.ts +++ b/server/tests/api/notifications/notifications-api.ts | |||
@@ -8,14 +8,10 @@ import { | |||
8 | cleanupTests, | 8 | cleanupTests, |
9 | getAllNotificationsSettings, | 9 | getAllNotificationsSettings, |
10 | getMyUserInformation, | 10 | getMyUserInformation, |
11 | getUserNotifications, | ||
12 | immutableAssign, | 11 | immutableAssign, |
13 | markAsReadAllNotifications, | ||
14 | markAsReadNotifications, | ||
15 | MockSmtpServer, | 12 | MockSmtpServer, |
16 | prepareNotificationsTest, | 13 | prepareNotificationsTest, |
17 | ServerInfo, | 14 | ServerInfo, |
18 | updateMyNotificationSettings, | ||
19 | uploadRandomVideo, | 15 | uploadRandomVideo, |
20 | waitJobs | 16 | waitJobs |
21 | } from '@shared/extra-utils' | 17 | } from '@shared/extra-utils' |
@@ -26,7 +22,7 @@ const expect = chai.expect | |||
26 | describe('Test notifications API', function () { | 22 | describe('Test notifications API', function () { |
27 | let server: ServerInfo | 23 | let server: ServerInfo |
28 | let userNotifications: UserNotification[] = [] | 24 | let userNotifications: UserNotification[] = [] |
29 | let userAccessToken: string | 25 | let userToken: string |
30 | let emails: object[] = [] | 26 | let emails: object[] = [] |
31 | 27 | ||
32 | before(async function () { | 28 | before(async function () { |
@@ -34,11 +30,11 @@ describe('Test notifications API', function () { | |||
34 | 30 | ||
35 | const res = await prepareNotificationsTest(1) | 31 | const res = await prepareNotificationsTest(1) |
36 | emails = res.emails | 32 | emails = res.emails |
37 | userAccessToken = res.userAccessToken | 33 | userToken = res.userAccessToken |
38 | userNotifications = res.userNotifications | 34 | userNotifications = res.userNotifications |
39 | server = res.servers[0] | 35 | server = res.servers[0] |
40 | 36 | ||
41 | await server.subscriptionsCommand.add({ token: userAccessToken, targetUri: 'root_channel@localhost:' + server.port }) | 37 | await server.subscriptionsCommand.add({ token: userToken, targetUri: 'root_channel@localhost:' + server.port }) |
42 | 38 | ||
43 | for (let i = 0; i < 10; i++) { | 39 | for (let i = 0; i < 10; i++) { |
44 | await uploadRandomVideo(server, false) | 40 | await uploadRandomVideo(server, false) |
@@ -50,49 +46,46 @@ describe('Test notifications API', function () { | |||
50 | describe('Mark as read', function () { | 46 | describe('Mark as read', function () { |
51 | 47 | ||
52 | it('Should mark as read some notifications', async function () { | 48 | it('Should mark as read some notifications', async function () { |
53 | const res = await getUserNotifications(server.url, userAccessToken, 2, 3) | 49 | const { data } = await server.notificationsCommand.list({ token: userToken, start: 2, count: 3 }) |
54 | const ids = res.body.data.map(n => n.id) | 50 | const ids = data.map(n => n.id) |
55 | 51 | ||
56 | await markAsReadNotifications(server.url, userAccessToken, ids) | 52 | await server.notificationsCommand.markAsRead({ token: userToken, ids }) |
57 | }) | 53 | }) |
58 | 54 | ||
59 | it('Should have the notifications marked as read', async function () { | 55 | it('Should have the notifications marked as read', async function () { |
60 | const res = await getUserNotifications(server.url, userAccessToken, 0, 10) | 56 | const { data } = await server.notificationsCommand.list({ token: userToken, start: 0, count: 10 }) |
61 | 57 | ||
62 | const notifications = res.body.data as UserNotification[] | 58 | expect(data[0].read).to.be.false |
63 | expect(notifications[0].read).to.be.false | 59 | expect(data[1].read).to.be.false |
64 | expect(notifications[1].read).to.be.false | 60 | expect(data[2].read).to.be.true |
65 | expect(notifications[2].read).to.be.true | 61 | expect(data[3].read).to.be.true |
66 | expect(notifications[3].read).to.be.true | 62 | expect(data[4].read).to.be.true |
67 | expect(notifications[4].read).to.be.true | 63 | expect(data[5].read).to.be.false |
68 | expect(notifications[5].read).to.be.false | ||
69 | }) | 64 | }) |
70 | 65 | ||
71 | it('Should only list read notifications', async function () { | 66 | it('Should only list read notifications', async function () { |
72 | const res = await getUserNotifications(server.url, userAccessToken, 0, 10, false) | 67 | const { data } = await server.notificationsCommand.list({ token: userToken, start: 0, count: 10, unread: false }) |
73 | 68 | ||
74 | const notifications = res.body.data as UserNotification[] | 69 | for (const notification of data) { |
75 | for (const notification of notifications) { | ||
76 | expect(notification.read).to.be.true | 70 | expect(notification.read).to.be.true |
77 | } | 71 | } |
78 | }) | 72 | }) |
79 | 73 | ||
80 | it('Should only list unread notifications', async function () { | 74 | it('Should only list unread notifications', async function () { |
81 | const res = await getUserNotifications(server.url, userAccessToken, 0, 10, true) | 75 | const { data } = await server.notificationsCommand.list({ token: userToken, start: 0, count: 10, unread: true }) |
82 | 76 | ||
83 | const notifications = res.body.data as UserNotification[] | 77 | for (const notification of data) { |
84 | for (const notification of notifications) { | ||
85 | expect(notification.read).to.be.false | 78 | expect(notification.read).to.be.false |
86 | } | 79 | } |
87 | }) | 80 | }) |
88 | 81 | ||
89 | it('Should mark as read all notifications', async function () { | 82 | it('Should mark as read all notifications', async function () { |
90 | await markAsReadAllNotifications(server.url, userAccessToken) | 83 | await server.notificationsCommand.markAsReadAll({ token: userToken }) |
91 | 84 | ||
92 | const res = await getUserNotifications(server.url, userAccessToken, 0, 10, true) | 85 | const body = await server.notificationsCommand.list({ token: userToken, start: 0, count: 10, unread: true }) |
93 | 86 | ||
94 | expect(res.body.total).to.equal(0) | 87 | expect(body.total).to.equal(0) |
95 | expect(res.body.data).to.have.lengthOf(0) | 88 | expect(body.data).to.have.lengthOf(0) |
96 | }) | 89 | }) |
97 | }) | 90 | }) |
98 | 91 | ||
@@ -104,19 +97,20 @@ describe('Test notifications API', function () { | |||
104 | server: server, | 97 | server: server, |
105 | emails, | 98 | emails, |
106 | socketNotifications: userNotifications, | 99 | socketNotifications: userNotifications, |
107 | token: userAccessToken | 100 | token: userToken |
108 | } | 101 | } |
109 | }) | 102 | }) |
110 | 103 | ||
111 | it('Should not have notifications', async function () { | 104 | it('Should not have notifications', async function () { |
112 | this.timeout(20000) | 105 | this.timeout(20000) |
113 | 106 | ||
114 | await updateMyNotificationSettings(server.url, userAccessToken, immutableAssign(getAllNotificationsSettings(), { | 107 | await server.notificationsCommand.updateMySettings({ |
115 | newVideoFromSubscription: UserNotificationSettingValue.NONE | 108 | token: userToken, |
116 | })) | 109 | settings: { ...getAllNotificationsSettings(), newVideoFromSubscription: UserNotificationSettingValue.NONE } |
110 | }) | ||
117 | 111 | ||
118 | { | 112 | { |
119 | const res = await getMyUserInformation(server.url, userAccessToken) | 113 | const res = await getMyUserInformation(server.url, userToken) |
120 | const info = res.body as User | 114 | const info = res.body as User |
121 | expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.NONE) | 115 | expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.NONE) |
122 | } | 116 | } |
@@ -130,12 +124,13 @@ describe('Test notifications API', function () { | |||
130 | it('Should only have web notifications', async function () { | 124 | it('Should only have web notifications', async function () { |
131 | this.timeout(20000) | 125 | this.timeout(20000) |
132 | 126 | ||
133 | await updateMyNotificationSettings(server.url, userAccessToken, immutableAssign(getAllNotificationsSettings(), { | 127 | await server.notificationsCommand.updateMySettings({ |
134 | newVideoFromSubscription: UserNotificationSettingValue.WEB | 128 | token: userToken, |
135 | })) | 129 | settings: { ...getAllNotificationsSettings(), newVideoFromSubscription: UserNotificationSettingValue.WEB } |
130 | }) | ||
136 | 131 | ||
137 | { | 132 | { |
138 | const res = await getMyUserInformation(server.url, userAccessToken) | 133 | const res = await getMyUserInformation(server.url, userToken) |
139 | const info = res.body as User | 134 | const info = res.body as User |
140 | expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.WEB) | 135 | expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.WEB) |
141 | } | 136 | } |
@@ -156,12 +151,13 @@ describe('Test notifications API', function () { | |||
156 | it('Should only have mail notifications', async function () { | 151 | it('Should only have mail notifications', async function () { |
157 | this.timeout(20000) | 152 | this.timeout(20000) |
158 | 153 | ||
159 | await updateMyNotificationSettings(server.url, userAccessToken, immutableAssign(getAllNotificationsSettings(), { | 154 | await server.notificationsCommand.updateMySettings({ |
160 | newVideoFromSubscription: UserNotificationSettingValue.EMAIL | 155 | token: userToken, |
161 | })) | 156 | settings: { ...getAllNotificationsSettings(), newVideoFromSubscription: UserNotificationSettingValue.EMAIL } |
157 | }) | ||
162 | 158 | ||
163 | { | 159 | { |
164 | const res = await getMyUserInformation(server.url, userAccessToken) | 160 | const res = await getMyUserInformation(server.url, userToken) |
165 | const info = res.body as User | 161 | const info = res.body as User |
166 | expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.EMAIL) | 162 | expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.EMAIL) |
167 | } | 163 | } |
@@ -182,12 +178,16 @@ describe('Test notifications API', function () { | |||
182 | it('Should have email and web notifications', async function () { | 178 | it('Should have email and web notifications', async function () { |
183 | this.timeout(20000) | 179 | this.timeout(20000) |
184 | 180 | ||
185 | await updateMyNotificationSettings(server.url, userAccessToken, immutableAssign(getAllNotificationsSettings(), { | 181 | await server.notificationsCommand.updateMySettings({ |
186 | newVideoFromSubscription: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL | 182 | token: userToken, |
187 | })) | 183 | settings: { |
184 | ...getAllNotificationsSettings(), | ||
185 | newVideoFromSubscription: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL | ||
186 | } | ||
187 | }) | ||
188 | 188 | ||
189 | { | 189 | { |
190 | const res = await getMyUserInformation(server.url, userAccessToken) | 190 | const res = await getMyUserInformation(server.url, userToken) |
191 | const info = res.body as User | 191 | const info = res.body as User |
192 | expect(info.notificationSettings.newVideoFromSubscription).to.equal( | 192 | expect(info.notificationSettings.newVideoFromSubscription).to.equal( |
193 | UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL | 193 | UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL |