← Public packages
@kentcdodds/audible
Personal Audible library app — browser re-auth, library, wishlist, NAS archive stub.
src/__tests__/mediarss-nas-match.test.ts
118 lines · 2.9 KB · TypeScriptimport assert from 'node:assert/strict'
import { test } from 'node:test'
import {
isStrictTitleDashOrExactM4b,
leftOfTitleDash,
pickStrictMediarssM4bMatch,
} from '../mediarss-nas-match.ts'
test('strict Title - prefix and exact m4b', () => {
assert.equal(
isStrictTitleDashOrExactM4b(
'Edgedancer',
'Edgedancer - From the Stormlight Archive.m4b',
),
true,
)
assert.equal(isStrictTitleDashOrExactM4b('Elantris', 'Elantris.m4b'), true)
assert.equal(
isStrictTitleDashOrExactM4b('Elantris', 'Elantris (Dramatized).mp3'),
false,
)
assert.equal(
isStrictTitleDashOrExactM4b(
'Meltdown',
'Meltdown - Why Our Systems Fail and What We Can Do About It.mp3',
),
false,
)
})
test('left of dash equals full Audible title (Fablehaven, Book N)', () => {
assert.equal(
leftOfTitleDash('Fablehaven, Book 2 - Rise of the Evening Star'),
'Fablehaven, Book 2',
)
assert.equal(
isStrictTitleDashOrExactM4b(
'Fablehaven, Book 2',
'Fablehaven, Book 2 - Rise of the Evening Star.m4b',
),
true,
)
assert.equal(
isStrictTitleDashOrExactM4b(
'Fablehaven, Book 3',
'Fablehaven, Book 3 - The Grip of the Shadow Plague.m4b',
),
true,
)
assert.equal(
isStrictTitleDashOrExactM4b(
'Keys to the Demon Prison',
'Keys to the Demon Prison - Fablehaven, Book 5.m4b',
),
true,
)
// Must not match on series name before the comma alone.
assert.equal(
isStrictTitleDashOrExactM4b(
'Fablehaven, Book 2',
'Fablehaven - Rise of the Evening Star.m4b',
),
false,
)
})
test('rejects Full-Cast edition as match for Book N classic title', () => {
assert.equal(
isStrictTitleDashOrExactM4b(
"Harry Potter and the Sorcerer's Stone, Book 1",
'Harry Potter and the Sorcerer’s Stone (Full-Cast Edition).m4b',
),
false,
)
})
test('pickStrictMediarssM4bMatch prefers audiobooks m4b Title - hit', () => {
const picked = pickStrictMediarssM4bMatch('Meltdown', [
{
mediaRoot: 'music',
relativePath: 'Stephanie Smith/02 Middle of the Meltdown.mp3',
},
{
mediaRoot: 'audiobooks',
relativePath:
'Meltdown - Why Our Systems Fail and What We Can Do About It.m4b',
},
])
assert.equal(
picked,
'Meltdown - Why Our Systems Fail and What We Can Do About It.m4b',
)
})
test('pickStrictMediarssM4bMatch ignores fuzzy non-prefix siblings', () => {
const picked = pickStrictMediarssM4bMatch('Skyward', [
{ mediaRoot: 'audiobooks', relativePath: 'Cytonic.m4b' },
{ mediaRoot: 'audiobooks', relativePath: 'Skyward.m4b' },
])
assert.equal(picked, 'Skyward.m4b')
})
test('rejects Title - Full-Cast suffix for classic Book N title', () => {
assert.equal(
isStrictTitleDashOrExactM4b(
"Harry Potter and the Sorcerer's Stone, Book 1",
"Harry Potter and the Sorcerer's Stone, Book 1 - Full-Cast Edition.m4b",
),
false,
)
assert.equal(
isStrictTitleDashOrExactM4b(
"Harry Potter and the Sorcerer's Stone (Full-Cast Edition)",
"Harry Potter and the Sorcerer's Stone (Full-Cast Edition).m4b",
),
true,
)
})