]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/check-params/videos-history.ts
3739e3fad8151e9b9cab280992ffb38edc42c011
[github/Chocobozzz/PeerTube.git] / server / tests / api / check-params / videos-history.ts
1 /* tslint:disable:no-unused-expression */
2
3 import * as chai from 'chai'
4 import 'mocha'
5 import {
6 checkBadCountPagination,
7 checkBadStartPagination,
8 cleanupTests,
9 flushAndRunServer,
10 makeGetRequest,
11 makePostBodyRequest,
12 makePutBodyRequest,
13 ServerInfo,
14 setAccessTokensToServers,
15 uploadVideo
16 } from '../../../../shared/extra-utils'
17
18 const expect = chai.expect
19
20 describe('Test videos history API validator', function () {
21 let watchingPath: string
22 let myHistoryPath = '/api/v1/users/me/history/videos'
23 let myHistoryRemove = myHistoryPath + '/remove'
24 let server: ServerInfo
25
26 // ---------------------------------------------------------------
27
28 before(async function () {
29 this.timeout(30000)
30
31 server = await flushAndRunServer(1)
32
33 await setAccessTokensToServers([ server ])
34
35 const res = await uploadVideo(server.url, server.accessToken, {})
36 const videoUUID = res.body.video.uuid
37
38 watchingPath = '/api/v1/videos/' + videoUUID + '/watching'
39 })
40
41 describe('When notifying a user is watching a video', function () {
42
43 it('Should fail with an unauthenticated user', async function () {
44 const fields = { currentTime: 5 }
45 await makePutBodyRequest({ url: server.url, path: watchingPath, fields, statusCodeExpected: 401 })
46 })
47
48 it('Should fail with an incorrect video id', async function () {
49 const fields = { currentTime: 5 }
50 const path = '/api/v1/videos/blabla/watching'
51 await makePutBodyRequest({ url: server.url, path, fields, token: server.accessToken, statusCodeExpected: 400 })
52 })
53
54 it('Should fail with an unknown video', async function () {
55 const fields = { currentTime: 5 }
56 const path = '/api/v1/videos/d91fff41-c24d-4508-8e13-3bd5902c3b02/watching'
57
58 await makePutBodyRequest({ url: server.url, path, fields, token: server.accessToken, statusCodeExpected: 404 })
59 })
60
61 it('Should fail with a bad current time', async function () {
62 const fields = { currentTime: 'hello' }
63 await makePutBodyRequest({ url: server.url, path: watchingPath, fields, token: server.accessToken, statusCodeExpected: 400 })
64 })
65
66 it('Should succeed with the correct parameters', async function () {
67 const fields = { currentTime: 5 }
68
69 await makePutBodyRequest({ url: server.url, path: watchingPath, fields, token: server.accessToken, statusCodeExpected: 204 })
70 })
71 })
72
73 describe('When listing user videos history', function () {
74 it('Should fail with a bad start pagination', async function () {
75 await checkBadStartPagination(server.url, myHistoryPath, server.accessToken)
76 })
77
78 it('Should fail with a bad count pagination', async function () {
79 await checkBadCountPagination(server.url, myHistoryPath, server.accessToken)
80 })
81
82 it('Should fail with an unauthenticated user', async function () {
83 await makeGetRequest({ url: server.url, path: myHistoryPath, statusCodeExpected: 401 })
84 })
85
86 it('Should succeed with the correct params', async function () {
87 await makeGetRequest({ url: server.url, token: server.accessToken, path: myHistoryPath, statusCodeExpected: 200 })
88 })
89 })
90
91 describe('When removing user videos history', function () {
92 it('Should fail with an unauthenticated user', async function () {
93 await makePostBodyRequest({ url: server.url, path: myHistoryPath + '/remove', statusCodeExpected: 401 })
94 })
95
96 it('Should fail with a bad beforeDate parameter', async function () {
97 const body = { beforeDate: '15' }
98 await makePostBodyRequest({
99 url: server.url,
100 token: server.accessToken,
101 path: myHistoryRemove,
102 fields: body,
103 statusCodeExpected: 400
104 })
105 })
106
107 it('Should succeed with a valid beforeDate param', async function () {
108 const body = { beforeDate: new Date().toISOString() }
109 await makePostBodyRequest({
110 url: server.url,
111 token: server.accessToken,
112 path: myHistoryRemove,
113 fields: body,
114 statusCodeExpected: 204
115 })
116 })
117
118 it('Should succeed without body', async function () {
119 await makePostBodyRequest({
120 url: server.url,
121 token: server.accessToken,
122 path: myHistoryRemove,
123 statusCodeExpected: 204
124 })
125 })
126 })
127
128 after(async function () {
129 await cleanupTests([ server ])
130 })
131 })