1 /* tslint:disable:no-unused-expression */
3 import * as chai from 'chai'
6 checkBadCountPagination,
7 checkBadStartPagination,
15 setAccessTokensToServers,
17 } from '../../../../shared/extra-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 () {
32 server = await flushAndRunServer(1)
34 await setAccessTokensToServers([ server ])
36 const res = await uploadVideo(server.url, server.accessToken, {})
37 const videoUUID = res.body.video.uuid
39 watchingPath = '/api/v1/videos/' + videoUUID + '/watching'
42 describe('When notifying a user is watching a video', function () {
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 })
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 })
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'
59 await makePutBodyRequest({ url: server.url, path, fields, token: server.accessToken, statusCodeExpected: 404 })
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 })
67 it('Should succeed with the correct parameters', async function () {
68 const fields = { currentTime: 5 }
70 await makePutBodyRequest({ url: server.url, path: watchingPath, fields, token: server.accessToken, statusCodeExpected: 204 })
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)
79 it('Should fail with a bad count pagination', async function () {
80 await checkBadCountPagination(server.url, myHistoryPath, server.accessToken)
83 it('Should fail with an unauthenticated user', async function () {
84 await makeGetRequest({ url: server.url, path: myHistoryPath, statusCodeExpected: 401 })
87 it('Should succeed with the correct params', async function () {
88 await makeGetRequest({ url: server.url, token: server.accessToken, path: myHistoryPath, statusCodeExpected: 200 })
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 })
97 it('Should fail with a bad beforeDate parameter', async function () {
98 const body = { beforeDate: '15' }
99 await makePostBodyRequest({
101 token: server.accessToken,
102 path: myHistoryRemove,
104 statusCodeExpected: 400
108 it('Should succeed with a valid beforeDate param', async function () {
109 const body = { beforeDate: new Date().toISOString() }
110 await makePostBodyRequest({
112 token: server.accessToken,
113 path: myHistoryRemove,
115 statusCodeExpected: 204
119 it('Should succeed without body', async function () {
120 await makePostBodyRequest({
122 token: server.accessToken,
123 path: myHistoryRemove,
124 statusCodeExpected: 204
130 killallServers([ server ])