2020-01-31 10:56:52 -05:00
|
|
|
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
|
2018-10-05 05:15:06 -04:00
|
|
|
|
|
|
|
import * as chai from 'chai'
|
|
|
|
import 'mocha'
|
|
|
|
import {
|
2019-04-24 09:10:37 -04:00
|
|
|
cleanupTests,
|
2018-12-17 09:52:38 -05:00
|
|
|
createUser,
|
2019-04-24 09:10:37 -04:00
|
|
|
flushAndRunServer,
|
2018-10-05 05:15:06 -04:00
|
|
|
getVideosListWithToken,
|
|
|
|
getVideoWithToken,
|
2019-04-24 09:10:37 -04:00
|
|
|
killallServers,
|
|
|
|
reRunServer,
|
2018-12-17 09:52:38 -05:00
|
|
|
searchVideoWithToken,
|
2018-10-05 05:15:06 -04:00
|
|
|
ServerInfo,
|
|
|
|
setAccessTokensToServers,
|
2018-12-17 09:52:38 -05:00
|
|
|
updateMyUser,
|
|
|
|
uploadVideo,
|
2019-04-11 09:38:53 -04:00
|
|
|
userLogin,
|
|
|
|
wait
|
2019-04-15 09:26:15 -04:00
|
|
|
} from '../../../../shared/extra-utils'
|
2018-10-05 05:15:06 -04:00
|
|
|
import { Video, VideoDetails } from '../../../../shared/models/videos'
|
2019-04-15 09:26:15 -04:00
|
|
|
import { listMyVideosHistory, removeMyVideosHistory, userWatchVideo } from '../../../../shared/extra-utils/videos/video-history'
|
2020-12-08 15:16:10 -05:00
|
|
|
import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
|
2018-10-05 05:15:06 -04:00
|
|
|
|
|
|
|
const expect = chai.expect
|
|
|
|
|
|
|
|
describe('Test videos history', function () {
|
|
|
|
let server: ServerInfo = null
|
|
|
|
let video1UUID: string
|
|
|
|
let video2UUID: string
|
|
|
|
let video3UUID: string
|
2018-12-17 09:52:38 -05:00
|
|
|
let video3WatchedDate: Date
|
|
|
|
let userAccessToken: string
|
2018-10-05 05:15:06 -04:00
|
|
|
|
|
|
|
before(async function () {
|
|
|
|
this.timeout(30000)
|
|
|
|
|
2019-04-24 04:53:40 -04:00
|
|
|
server = await flushAndRunServer(1)
|
2018-10-05 05:15:06 -04:00
|
|
|
|
|
|
|
await setAccessTokensToServers([ server ])
|
|
|
|
|
|
|
|
{
|
|
|
|
const res = await uploadVideo(server.url, server.accessToken, { name: 'video 1' })
|
|
|
|
video1UUID = res.body.video.uuid
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
const res = await uploadVideo(server.url, server.accessToken, { name: 'video 2' })
|
|
|
|
video2UUID = res.body.video.uuid
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
const res = await uploadVideo(server.url, server.accessToken, { name: 'video 3' })
|
|
|
|
video3UUID = res.body.video.uuid
|
|
|
|
}
|
2018-12-17 09:52:38 -05:00
|
|
|
|
|
|
|
const user = {
|
|
|
|
username: 'user_1',
|
|
|
|
password: 'super password'
|
|
|
|
}
|
2019-04-15 04:49:46 -04:00
|
|
|
await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
|
2018-12-17 09:52:38 -05:00
|
|
|
userAccessToken = await userLogin(server, user)
|
2018-10-05 05:15:06 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should get videos, without watching history', async function () {
|
|
|
|
const res = await getVideosListWithToken(server.url, server.accessToken)
|
|
|
|
const videos: Video[] = res.body.data
|
|
|
|
|
|
|
|
for (const video of videos) {
|
|
|
|
const resDetail = await getVideoWithToken(server.url, server.accessToken, video.id)
|
|
|
|
const videoDetails: VideoDetails = resDetail.body
|
|
|
|
|
|
|
|
expect(video.userHistory).to.be.undefined
|
|
|
|
expect(videoDetails.userHistory).to.be.undefined
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should watch the first and second video', async function () {
|
|
|
|
await userWatchVideo(server.url, server.accessToken, video2UUID, 8)
|
2018-12-17 09:52:38 -05:00
|
|
|
await userWatchVideo(server.url, server.accessToken, video1UUID, 3)
|
2018-10-05 05:15:06 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should return the correct history when listing, searching and getting videos', async function () {
|
|
|
|
const videosOfVideos: Video[][] = []
|
|
|
|
|
|
|
|
{
|
|
|
|
const res = await getVideosListWithToken(server.url, server.accessToken)
|
|
|
|
videosOfVideos.push(res.body.data)
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
const res = await searchVideoWithToken(server.url, 'video', server.accessToken)
|
|
|
|
videosOfVideos.push(res.body.data)
|
|
|
|
}
|
|
|
|
|
|
|
|
for (const videos of videosOfVideos) {
|
|
|
|
const video1 = videos.find(v => v.uuid === video1UUID)
|
|
|
|
const video2 = videos.find(v => v.uuid === video2UUID)
|
|
|
|
const video3 = videos.find(v => v.uuid === video3UUID)
|
|
|
|
|
|
|
|
expect(video1.userHistory).to.not.be.undefined
|
|
|
|
expect(video1.userHistory.currentTime).to.equal(3)
|
|
|
|
|
|
|
|
expect(video2.userHistory).to.not.be.undefined
|
|
|
|
expect(video2.userHistory.currentTime).to.equal(8)
|
|
|
|
|
|
|
|
expect(video3.userHistory).to.be.undefined
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
const resDetail = await getVideoWithToken(server.url, server.accessToken, video1UUID)
|
|
|
|
const videoDetails: VideoDetails = resDetail.body
|
|
|
|
|
|
|
|
expect(videoDetails.userHistory).to.not.be.undefined
|
|
|
|
expect(videoDetails.userHistory.currentTime).to.equal(3)
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
const resDetail = await getVideoWithToken(server.url, server.accessToken, video2UUID)
|
|
|
|
const videoDetails: VideoDetails = resDetail.body
|
|
|
|
|
|
|
|
expect(videoDetails.userHistory).to.not.be.undefined
|
|
|
|
expect(videoDetails.userHistory.currentTime).to.equal(8)
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
const resDetail = await getVideoWithToken(server.url, server.accessToken, video3UUID)
|
|
|
|
const videoDetails: VideoDetails = resDetail.body
|
|
|
|
|
|
|
|
expect(videoDetails.userHistory).to.be.undefined
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2018-12-17 09:52:38 -05:00
|
|
|
it('Should have these videos when listing my history', async function () {
|
|
|
|
video3WatchedDate = new Date()
|
|
|
|
await userWatchVideo(server.url, server.accessToken, video3UUID, 2)
|
|
|
|
|
|
|
|
const res = await listMyVideosHistory(server.url, server.accessToken)
|
|
|
|
|
|
|
|
expect(res.body.total).to.equal(3)
|
|
|
|
|
|
|
|
const videos: Video[] = res.body.data
|
|
|
|
expect(videos[0].name).to.equal('video 3')
|
|
|
|
expect(videos[1].name).to.equal('video 1')
|
|
|
|
expect(videos[2].name).to.equal('video 2')
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should not have videos history on another user', async function () {
|
|
|
|
const res = await listMyVideosHistory(server.url, userAccessToken)
|
|
|
|
|
|
|
|
expect(res.body.total).to.equal(0)
|
|
|
|
expect(res.body.data).to.have.lengthOf(0)
|
|
|
|
})
|
|
|
|
|
2021-01-13 03:16:15 -05:00
|
|
|
it('Should be able to search through videos in my history', async function () {
|
|
|
|
const res = await listMyVideosHistory(server.url, server.accessToken, '2')
|
|
|
|
|
|
|
|
expect(res.body.total).to.equal(1)
|
|
|
|
|
|
|
|
const videos: Video[] = res.body.data
|
|
|
|
expect(videos[0].name).to.equal('video 2')
|
|
|
|
})
|
|
|
|
|
2018-12-17 09:52:38 -05:00
|
|
|
it('Should clear my history', async function () {
|
|
|
|
await removeMyVideosHistory(server.url, server.accessToken, video3WatchedDate.toISOString())
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should have my history cleared', async function () {
|
|
|
|
const res = await listMyVideosHistory(server.url, server.accessToken)
|
|
|
|
|
|
|
|
expect(res.body.total).to.equal(1)
|
|
|
|
|
|
|
|
const videos: Video[] = res.body.data
|
|
|
|
expect(videos[0].name).to.equal('video 3')
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should disable videos history', async function () {
|
|
|
|
await updateMyUser({
|
|
|
|
url: server.url,
|
|
|
|
accessToken: server.accessToken,
|
|
|
|
videosHistoryEnabled: false
|
|
|
|
})
|
|
|
|
|
2020-12-08 15:16:10 -05:00
|
|
|
await userWatchVideo(server.url, server.accessToken, video2UUID, 8, HttpStatusCode.CONFLICT_409)
|
2018-12-17 09:52:38 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should re-enable videos history', async function () {
|
|
|
|
await updateMyUser({
|
|
|
|
url: server.url,
|
|
|
|
accessToken: server.accessToken,
|
|
|
|
videosHistoryEnabled: true
|
|
|
|
})
|
|
|
|
|
|
|
|
await userWatchVideo(server.url, server.accessToken, video1UUID, 8)
|
|
|
|
|
|
|
|
const res = await listMyVideosHistory(server.url, server.accessToken)
|
|
|
|
|
|
|
|
expect(res.body.total).to.equal(2)
|
|
|
|
|
|
|
|
const videos: Video[] = res.body.data
|
|
|
|
expect(videos[0].name).to.equal('video 1')
|
|
|
|
expect(videos[1].name).to.equal('video 3')
|
|
|
|
})
|
|
|
|
|
2019-04-11 09:38:53 -04:00
|
|
|
it('Should not clean old history', async function () {
|
|
|
|
this.timeout(50000)
|
|
|
|
|
|
|
|
killallServers([ server ])
|
|
|
|
|
|
|
|
await reRunServer(server, { history: { videos: { max_age: '10 days' } } })
|
|
|
|
|
|
|
|
await wait(6000)
|
|
|
|
|
|
|
|
// Should still have history
|
|
|
|
|
|
|
|
const res = await listMyVideosHistory(server.url, server.accessToken)
|
|
|
|
|
|
|
|
expect(res.body.total).to.equal(2)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should clean old history', async function () {
|
|
|
|
this.timeout(50000)
|
|
|
|
|
|
|
|
killallServers([ server ])
|
|
|
|
|
|
|
|
await reRunServer(server, { history: { videos: { max_age: '5 seconds' } } })
|
|
|
|
|
|
|
|
await wait(6000)
|
|
|
|
|
|
|
|
const res = await listMyVideosHistory(server.url, server.accessToken)
|
|
|
|
expect(res.body.total).to.equal(0)
|
|
|
|
})
|
|
|
|
|
2019-04-24 09:10:37 -04:00
|
|
|
after(async function () {
|
|
|
|
await cleanupTests([ server ])
|
2018-10-05 05:15:06 -04:00
|
|
|
})
|
|
|
|
})
|