aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests/api')
-rw-r--r--server/tests/api/check-params/videos-history.ts37
-rw-r--r--server/tests/api/videos/videos-history.ts36
2 files changed, 64 insertions, 9 deletions
diff --git a/server/tests/api/check-params/videos-history.ts b/server/tests/api/check-params/videos-history.ts
index 31a0752c7..82f38b7b4 100644
--- a/server/tests/api/check-params/videos-history.ts
+++ b/server/tests/api/check-params/videos-history.ts
@@ -6,6 +6,7 @@ import { HttpStatusCode } from '@shared/models'
6import { 6import {
7 cleanupTests, 7 cleanupTests,
8 createSingleServer, 8 createSingleServer,
9 makeDeleteRequest,
9 makeGetRequest, 10 makeGetRequest,
10 makePostBodyRequest, 11 makePostBodyRequest,
11 makePutBodyRequest, 12 makePutBodyRequest,
@@ -18,6 +19,7 @@ describe('Test videos history API validator', function () {
18 const myHistoryRemove = myHistoryPath + '/remove' 19 const myHistoryRemove = myHistoryPath + '/remove'
19 let watchingPath: string 20 let watchingPath: string
20 let server: PeerTubeServer 21 let server: PeerTubeServer
22 let videoId: number
21 23
22 // --------------------------------------------------------------- 24 // ---------------------------------------------------------------
23 25
@@ -28,8 +30,9 @@ describe('Test videos history API validator', function () {
28 30
29 await setAccessTokensToServers([ server ]) 31 await setAccessTokensToServers([ server ])
30 32
31 const { uuid } = await server.videos.upload() 33 const { id, uuid } = await server.videos.upload()
32 watchingPath = '/api/v1/videos/' + uuid + '/watching' 34 watchingPath = '/api/v1/videos/' + uuid + '/watching'
35 videoId = id
33 }) 36 })
34 37
35 describe('When notifying a user is watching a video', function () { 38 describe('When notifying a user is watching a video', function () {
@@ -106,7 +109,37 @@ describe('Test videos history API validator', function () {
106 }) 109 })
107 }) 110 })
108 111
109 describe('When removing user videos history', function () { 112 describe('When removing a specific user video history element', function () {
113 let path: string
114
115 before(function () {
116 path = myHistoryPath + '/' + videoId
117 })
118
119 it('Should fail with an unauthenticated user', async function () {
120 await makeDeleteRequest({ url: server.url, path, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
121 })
122
123 it('Should fail with a bad videoId parameter', async function () {
124 await makeDeleteRequest({
125 url: server.url,
126 token: server.accessToken,
127 path: myHistoryRemove + '/hi',
128 expectedStatus: HttpStatusCode.BAD_REQUEST_400
129 })
130 })
131
132 it('Should succeed with the correct parameters', async function () {
133 await makeDeleteRequest({
134 url: server.url,
135 token: server.accessToken,
136 path,
137 expectedStatus: HttpStatusCode.NO_CONTENT_204
138 })
139 })
140 })
141
142 describe('When removing all user videos history', function () {
110 it('Should fail with an unauthenticated user', async function () { 143 it('Should fail with an unauthenticated user', async function () {
111 await makePostBodyRequest({ url: server.url, path: myHistoryPath + '/remove', expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) 144 await makePostBodyRequest({ url: server.url, path: myHistoryPath + '/remove', expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
112 }) 145 })
diff --git a/server/tests/api/videos/videos-history.ts b/server/tests/api/videos/videos-history.ts
index 4e5ba13aa..8648c97f0 100644
--- a/server/tests/api/videos/videos-history.ts
+++ b/server/tests/api/videos/videos-history.ts
@@ -17,6 +17,7 @@ const expect = chai.expect
17 17
18describe('Test videos history', function () { 18describe('Test videos history', function () {
19 let server: PeerTubeServer = null 19 let server: PeerTubeServer = null
20 let video1Id: number
20 let video1UUID: string 21 let video1UUID: string
21 let video2UUID: string 22 let video2UUID: string
22 let video3UUID: string 23 let video3UUID: string
@@ -34,8 +35,9 @@ describe('Test videos history', function () {
34 command = server.history 35 command = server.history
35 36
36 { 37 {
37 const { uuid } = await server.videos.upload({ attributes: { name: 'video 1' } }) 38 const { id, uuid } = await server.videos.upload({ attributes: { name: 'video 1' } })
38 video1UUID = uuid 39 video1UUID = uuid
40 video1Id = id
39 } 41 }
40 42
41 { 43 {
@@ -68,8 +70,8 @@ describe('Test videos history', function () {
68 }) 70 })
69 71
70 it('Should watch the first and second video', async function () { 72 it('Should watch the first and second video', async function () {
71 await command.wathVideo({ videoId: video2UUID, currentTime: 8 }) 73 await command.watchVideo({ videoId: video2UUID, currentTime: 8 })
72 await command.wathVideo({ videoId: video1UUID, currentTime: 3 }) 74 await command.watchVideo({ videoId: video1UUID, currentTime: 3 })
73 }) 75 })
74 76
75 it('Should return the correct history when listing, searching and getting videos', async function () { 77 it('Should return the correct history when listing, searching and getting videos', async function () {
@@ -122,7 +124,7 @@ describe('Test videos history', function () {
122 124
123 it('Should have these videos when listing my history', async function () { 125 it('Should have these videos when listing my history', async function () {
124 video3WatchedDate = new Date() 126 video3WatchedDate = new Date()
125 await command.wathVideo({ videoId: video3UUID, currentTime: 2 }) 127 await command.watchVideo({ videoId: video3UUID, currentTime: 2 })
126 128
127 const body = await command.list() 129 const body = await command.list()
128 130
@@ -150,7 +152,7 @@ describe('Test videos history', function () {
150 }) 152 })
151 153
152 it('Should clear my history', async function () { 154 it('Should clear my history', async function () {
153 await command.remove({ beforeDate: video3WatchedDate.toISOString() }) 155 await command.removeAll({ beforeDate: video3WatchedDate.toISOString() })
154 }) 156 })
155 157
156 it('Should have my history cleared', async function () { 158 it('Should have my history cleared', async function () {
@@ -166,7 +168,7 @@ describe('Test videos history', function () {
166 videosHistoryEnabled: false 168 videosHistoryEnabled: false
167 }) 169 })
168 170
169 await command.wathVideo({ videoId: video2UUID, currentTime: 8, expectedStatus: HttpStatusCode.CONFLICT_409 }) 171 await command.watchVideo({ videoId: video2UUID, currentTime: 8, expectedStatus: HttpStatusCode.CONFLICT_409 })
170 }) 172 })
171 173
172 it('Should re-enable videos history', async function () { 174 it('Should re-enable videos history', async function () {
@@ -174,7 +176,7 @@ describe('Test videos history', function () {
174 videosHistoryEnabled: true 176 videosHistoryEnabled: true
175 }) 177 })
176 178
177 await command.wathVideo({ videoId: video1UUID, currentTime: 8 }) 179 await command.watchVideo({ videoId: video1UUID, currentTime: 8 })
178 180
179 const body = await command.list() 181 const body = await command.list()
180 expect(body.total).to.equal(2) 182 expect(body.total).to.equal(2)
@@ -212,6 +214,26 @@ describe('Test videos history', function () {
212 expect(body.total).to.equal(0) 214 expect(body.total).to.equal(0)
213 }) 215 })
214 216
217 it('Should delete a specific history element', async function () {
218 {
219 await command.watchVideo({ videoId: video1UUID, currentTime: 4 })
220 await command.watchVideo({ videoId: video2UUID, currentTime: 8 })
221 }
222
223 {
224 const body = await command.list()
225 expect(body.total).to.equal(2)
226 }
227
228 {
229 await command.removeElement({ videoId: video1Id })
230
231 const body = await command.list()
232 expect(body.total).to.equal(1)
233 expect(body.data[0].uuid).to.equal(video2UUID)
234 }
235 })
236
215 after(async function () { 237 after(async function () {
216 await cleanupTests([ server ]) 238 await cleanupTests([ server ])
217 }) 239 })