Tofu/scripts/import-recipes/tests/listOdtHrefs.test.js
2026-09-18 01:41:02 +02:00

29 lines
1.3 KiB
JavaScript

import { test } from 'node:test'
import assert from 'node:assert/strict'
import { listOdtHrefs } from '#import-recipes/webdav/listOdtHrefs.js'
const PROPFIND_ANSWER = `<?xml version="1.0"?>
<d:multistatus xmlns:d="DAV:">
<d:response><d:href>/remote.php/dav/files/marie/Recettes/</d:href></d:response>
<d:response><d:href>/remote.php/dav/files/marie/Recettes/Gnocchis%20%C3%A0%20la%20sauge.odt</d:href></d:response>
<d:response><d:href>/remote.php/dav/files/marie/Recettes/Notes.txt</d:href></d:response>
<d:response><D:href>/remote.php/dav/files/marie/Recettes/Sel%20&amp;%20poivre.ODT</D:href></d:response>
</d:multistatus>`
test('keeps the .odt entries, folders and other files aside', () => {
assert.deepEqual(listOdtHrefs(PROPFIND_ANSWER), [
'/remote.php/dav/files/marie/Recettes/Gnocchis%20%C3%A0%20la%20sauge.odt',
'/remote.php/dav/files/marie/Recettes/Sel%20&%20poivre.ODT'
])
})
test('leaves the path percent-encoded, as the server gave it', () => {
const [first] = listOdtHrefs(PROPFIND_ANSWER)
assert.ok(first.includes('%20'))
assert.equal(decodeURIComponent(first.split('/').pop()), 'Gnocchis à la sauge.odt')
})
test('returns an empty list for an answer it cannot read', () => {
assert.deepEqual(listOdtHrefs('not xml at all'), [])
assert.deepEqual(listOdtHrefs(null), [])
})