mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2026-05-13 06:51:29 +00:00
Fix Smart Speed playback time contract
This commit is contained in:
parent
5c747a7f8f
commit
97c5d6341e
9 changed files with 205 additions and 17 deletions
46
test/server/models/MediaProgress.test.js
Normal file
46
test/server/models/MediaProgress.test.js
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
const { expect } = require('chai')
|
||||
const { Sequelize } = require('sequelize')
|
||||
|
||||
const Database = require('../../../server/Database')
|
||||
|
||||
describe('MediaProgress', () => {
|
||||
beforeEach(async () => {
|
||||
global.ServerSettings = {}
|
||||
Database.sequelize = new Sequelize({ dialect: 'sqlite', storage: ':memory:', logging: false })
|
||||
Database.sequelize.uppercaseFirst = (str) => (str ? `${str[0].toUpperCase()}${str.substr(1)}` : '')
|
||||
await Database.buildModels()
|
||||
await Database.sequelize.sync({ force: true })
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
await Database.sequelize.close()
|
||||
})
|
||||
|
||||
it('marks progress finished using coherent wall-clock currentTime and duration values', async () => {
|
||||
const user = await Database.userModel.create({
|
||||
username: 'user1',
|
||||
pash: 'hashed_password_1',
|
||||
type: 'user',
|
||||
isActive: true
|
||||
})
|
||||
|
||||
const progress = await Database.mediaProgressModel.create({
|
||||
userId: user.id,
|
||||
mediaItemId: '00000000-0000-0000-0000-000000000001',
|
||||
mediaItemType: 'book',
|
||||
duration: 10,
|
||||
currentTime: 0,
|
||||
isFinished: false,
|
||||
extraData: {}
|
||||
})
|
||||
|
||||
await progress.applyProgressUpdate({
|
||||
currentTime: 9.5,
|
||||
duration: 10,
|
||||
markAsFinishedTimeRemaining: 1
|
||||
})
|
||||
|
||||
expect(progress.isFinished).to.equal(true)
|
||||
expect(progress.progress).to.equal(0.95)
|
||||
})
|
||||
})
|
||||
Loading…
Add table
Add a link
Reference in a new issue