1 /* tslint:disable:no-unused-expression */
3 import * as chai from 'chai'
6 checkBadCountPagination,
7 checkBadStartPagination,
15 setAccessTokensToServers,
17 } from '../../../../shared/utils'
19 const expect = chai.expect
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
27 // ---------------------------------------------------------------
29 before(async function () {
34 server = await runServer(1)
36 await setAccessTokensToServers([ server ])
38 const res = await uploadVideo(server.url, server.accessToken, {})
39 const videoUUID = res.body.video.uuid
41 watchingPath = '/api/v1/videos/' + videoUUID + '/watching'
44 describe('When notifying a user is watching a video', function () {
46 it('Should fail with an unauthenticated user', async function () {
47 const fields = { currentTime: 5 }
48 await makePutBodyRequest({ url: server.url, path: watchingPath, fields, statusCodeExpected: 401 })
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 })
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'
61 await makePutBodyRequest({ url: server.url, path, fields, token: server.accessToken, statusCodeExpected: 404 })
64 it('Should fail with a bad current time', async function () {
65 const fields = { currentTime: 'hello' }
66 await makePutBodyRequest({ url: server.url, path: watchingPath, fields, token: server.accessToken, statusCodeExpected: 400 })
69 it('Should succeed with the correct parameters', async function () {
70 const fields = { currentTime: 5 }
72 await makePutBodyRequest({ url: server.url, path: watchingPath, fields, token: server.accessToken, statusCodeExpected: 204 })
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)
81 it('Should fail with a bad count pagination', async function () {
82 await checkBadCountPagination(server.url, myHistoryPath, server.accessToken)
85 it('Should fail with an unauthenticated user', async function () {
86 await makeGetRequest({ url: server.url, path: myHistoryPath, statusCodeExpected: 401 })
89 it('Should succeed with the correct params', async function () {
90 await makeGetRequest({ url: server.url, token: server.accessToken, path: myHistoryPath, statusCodeExpected: 200 })
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 })
99 it('Should fail with a bad beforeDate parameter', async function () {
100 const body = { beforeDate: '15' }
101 await makePostBodyRequest({
103 token: server.accessToken,
104 path: myHistoryRemove,
106 statusCodeExpected: 400
110 it('Should succeed with a valid beforeDate param', async function () {
111 const body = { beforeDate: new Date().toISOString() }
112 await makePostBodyRequest({
114 token: server.accessToken,
115 path: myHistoryRemove,
117 statusCodeExpected: 204
121 it('Should succeed without body', async function () {
122 await makePostBodyRequest({
124 token: server.accessToken,
125 path: myHistoryRemove,
126 statusCodeExpected: 204
131 after(async function () {
132 killallServers([ server ])
134 // Keep the logs if the test failed