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