1 /* tslint:disable:no-unused-expression */
3 import * as chai from 'chai'
6 checkBadCountPagination,
7 checkBadStartPagination,
14 setAccessTokensToServers,
16 } from '../../../../shared/extra-utils'
18 const expect = chai.expect
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
26 // ---------------------------------------------------------------
28 before(async function () {
31 server = await flushAndRunServer(1)
33 await setAccessTokensToServers([ server ])
35 const res = await uploadVideo(server.url, server.accessToken, {})
36 const videoUUID = res.body.video.uuid
38 watchingPath = '/api/v1/videos/' + videoUUID + '/watching'
41 describe('When notifying a user is watching a video', function () {
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 })
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 })
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'
58 await makePutBodyRequest({ url: server.url, path, fields, token: server.accessToken, statusCodeExpected: 404 })
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 })
66 it('Should succeed with the correct parameters', async function () {
67 const fields = { currentTime: 5 }
69 await makePutBodyRequest({ url: server.url, path: watchingPath, fields, token: server.accessToken, statusCodeExpected: 204 })
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)
78 it('Should fail with a bad count pagination', async function () {
79 await checkBadCountPagination(server.url, myHistoryPath, server.accessToken)
82 it('Should fail with an unauthenticated user', async function () {
83 await makeGetRequest({ url: server.url, path: myHistoryPath, statusCodeExpected: 401 })
86 it('Should succeed with the correct params', async function () {
87 await makeGetRequest({ url: server.url, token: server.accessToken, path: myHistoryPath, statusCodeExpected: 200 })
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 })
96 it('Should fail with a bad beforeDate parameter', async function () {
97 const body = { beforeDate: '15' }
98 await makePostBodyRequest({
100 token: server.accessToken,
101 path: myHistoryRemove,
103 statusCodeExpected: 400
107 it('Should succeed with a valid beforeDate param', async function () {
108 const body = { beforeDate: new Date().toISOString() }
109 await makePostBodyRequest({
111 token: server.accessToken,
112 path: myHistoryRemove,
114 statusCodeExpected: 204
118 it('Should succeed without body', async function () {
119 await makePostBodyRequest({
121 token: server.accessToken,
122 path: myHistoryRemove,
123 statusCodeExpected: 204
128 after(async function () {
129 await cleanupTests([ server ])