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