47 lines
2.2 KiB
JavaScript
47 lines
2.2 KiB
JavaScript
import test from 'node:test'
|
|
import assert from 'node:assert/strict'
|
|
import { folderImageCount, libraryAfterWipe, libraryMediaUrl, mergeLibraryRows, replaceLibraryRows } from '../shared/studio2/viewer.mjs'
|
|
|
|
test('folderImageCount trusts a server count of 0', () => {
|
|
assert.equal(folderImageCount({ id: 'inbox', imageCount: 0 }, 1762), 0)
|
|
assert.equal(folderImageCount({ id: 'inbox', imageCount: 4 }, 1), 4)
|
|
assert.equal(folderImageCount(undefined, 3), 3)
|
|
})
|
|
|
|
test('libraryMediaUrl always changes the pre-deploy cache key', () => {
|
|
assert.equal(libraryMediaUrl('/api/library/stills/abc/thumb', 0), '/api/library/stills/abc/thumb?v=0')
|
|
assert.equal(libraryMediaUrl('/api/library/stills/abc/preview', 4), '/api/library/stills/abc/preview?v=4')
|
|
assert.equal(libraryMediaUrl('/api/library/clips/abc/first-frame?thumb=1', 2), '/api/library/clips/abc/first-frame?thumb=1&v=2')
|
|
assert.notEqual(libraryMediaUrl('/api/library/stills/abc/thumb', 0), '/api/library/stills/abc/thumb')
|
|
})
|
|
|
|
test('libraryAfterWipe replaces the folder from the response and does not keep a suppression list', () => {
|
|
const previous = {
|
|
folders: [{ id: 'inbox', imageCount: 2 }],
|
|
stills: [{ id: 'new-1', folderId: 'inbox' }, { id: 'new-2', folderId: 'inbox' }],
|
|
clips: [],
|
|
tracks: [],
|
|
suppressedIds: ['already-gone']
|
|
}
|
|
const stale = {
|
|
folders: [{ id: 'inbox', imageCount: 0 }, { id: 'other', imageCount: 1 }],
|
|
stills: [
|
|
{ id: 'ghost', folderId: 'inbox' },
|
|
{ id: 'new-1', folderId: 'inbox' },
|
|
{ id: 'kept', folderId: 'other' }
|
|
],
|
|
clips: [{ id: 'clip-ghost', folderId: 'inbox' }],
|
|
tracks: [],
|
|
deletedIds: ['new-1', 'new-2']
|
|
}
|
|
const next = libraryAfterWipe(previous, stale, 'inbox')
|
|
assert.deepEqual(next.stills.map(item => item.id), ['kept'])
|
|
assert.deepEqual(next.clips, [])
|
|
assert.equal(next.folders[0].imageCount, 0)
|
|
assert.deepEqual(next.suppressedIds, [])
|
|
const replaced = replaceLibraryRows(next.stills, [])
|
|
assert.deepEqual(replaced.map(item => item.id), ['kept'])
|
|
const page = mergeLibraryRows(replaced, [{ id: 'kept', folderId: 'other' }, { id: 'fresh', folderId: 'other' }], [])
|
|
assert.deepEqual(page.map(item => item.id), ['kept', 'fresh'])
|
|
})
|