From 6e46de095d7169355dd83030f6ce4a582304153a Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 5 Oct 2018 11:15:06 +0200 Subject: Add user history and resume videos --- server/tests/api/check-params/index.ts | 1 + server/tests/api/check-params/videos-history.ts | 79 +++++++++++++++++++++++++ 2 files changed, 80 insertions(+) create mode 100644 server/tests/api/check-params/videos-history.ts (limited to 'server/tests/api/check-params') diff --git a/server/tests/api/check-params/index.ts b/server/tests/api/check-params/index.ts index 44460a167..71a217649 100644 --- a/server/tests/api/check-params/index.ts +++ b/server/tests/api/check-params/index.ts @@ -15,3 +15,4 @@ import './video-channels' import './video-comments' import './video-imports' import './videos' +import './videos-history' diff --git a/server/tests/api/check-params/videos-history.ts b/server/tests/api/check-params/videos-history.ts new file mode 100644 index 000000000..808c3b616 --- /dev/null +++ b/server/tests/api/check-params/videos-history.ts @@ -0,0 +1,79 @@ +/* tslint:disable:no-unused-expression */ + +import * as chai from 'chai' +import 'mocha' +import { + flushTests, + killallServers, + makePostBodyRequest, + makePutBodyRequest, + runServer, + ServerInfo, + setAccessTokensToServers, + uploadVideo +} from '../../utils' + +const expect = chai.expect + +describe('Test videos history API validator', function () { + let path: string + let server: ServerInfo + + // --------------------------------------------------------------- + + before(async function () { + this.timeout(30000) + + await flushTests() + + server = await runServer(1) + + await setAccessTokensToServers([ server ]) + + const res = await uploadVideo(server.url, server.accessToken, {}) + const videoUUID = res.body.video.uuid + + path = '/api/v1/videos/' + videoUUID + '/watching' + }) + + describe('When notifying a user is watching a video', function () { + + it('Should fail with an unauthenticated user', async function () { + const fields = { currentTime: 5 } + await makePutBodyRequest({ url: server.url, path, fields, statusCodeExpected: 401 }) + }) + + it('Should fail with an incorrect video id', async function () { + const fields = { currentTime: 5 } + const path = '/api/v1/videos/blabla/watching' + await makePutBodyRequest({ url: server.url, path, fields, token: server.accessToken, statusCodeExpected: 400 }) + }) + + it('Should fail with an unknown video', async function () { + const fields = { currentTime: 5 } + const path = '/api/v1/videos/d91fff41-c24d-4508-8e13-3bd5902c3b02/watching' + + await makePutBodyRequest({ url: server.url, path, fields, token: server.accessToken, statusCodeExpected: 404 }) + }) + + it('Should fail with a bad current time', async function () { + const fields = { currentTime: 'hello' } + await makePutBodyRequest({ url: server.url, path, fields, token: server.accessToken, statusCodeExpected: 400 }) + }) + + it('Should succeed with the correct parameters', async function () { + const fields = { currentTime: 5 } + + await makePutBodyRequest({ url: server.url, path, fields, token: server.accessToken, statusCodeExpected: 204 }) + }) + }) + + after(async function () { + killallServers([ server ]) + + // Keep the logs if the test failed + if (this['ok']) { + await flushTests() + } + }) +}) -- cgit v1.2.3