36 lines
1.6 KiB
JavaScript
36 lines
1.6 KiB
JavaScript
import assert from 'node:assert/strict'
|
|
import test from 'node:test'
|
|
import { loadTestModule } from './load-test-module.mjs'
|
|
|
|
const { currentTask, findActiveOfflineTask, pruneFinishedTasks, upsertTask } =
|
|
await loadTestModule(`export * from './lib/tasks'`)
|
|
|
|
const task = (id, overrides = {}) => ({
|
|
id, kind: 'vm-create', subject: id, status: 'running', started_at: 10, updated_at: 20,
|
|
installer_kind: 'offline', installer_version: '26.7.3', installer_phase: 'downloading', ...overrides,
|
|
})
|
|
|
|
test('late progress cannot replace a newer completed task', () => {
|
|
const completed = task('vm', { status: 'done', updated_at: 30 })
|
|
const tasks = { vm: completed }
|
|
assert.deepEqual(upsertTask(tasks, task('vm')), tasks)
|
|
assert.deepEqual(pruneFinishedTasks(tasks, 30), tasks)
|
|
assert.deepEqual(pruneFinishedTasks(tasks, 31), {})
|
|
})
|
|
|
|
test('the status bar favors active work over a newer queued download', () => {
|
|
const vm = task('vm')
|
|
const queued = task('queued', { installer_phase: 'queued', updated_at: 25 })
|
|
const finished = task('done', { status: 'done', updated_at: 30 })
|
|
assert.deepEqual(currentTask({ queued, vm, finished }), { task: vm, running: 2 })
|
|
})
|
|
|
|
test('one installer download represents the VM creations waiting for it', () => {
|
|
const download = task('download', { kind: 'installer-download', started_at: 15 })
|
|
const vm = task('vm', { vm: 'vm one' })
|
|
const other = task('other', { installer_version: '15.8.3' })
|
|
assert.deepEqual(findActiveOfflineTask([vm, other, download], '26.7.3'), {
|
|
primary: download, waitingVMs: ['vm one'], matchedIDs: ['download', 'vm'],
|
|
})
|
|
})
|