From 86fc380fa22d058046da4ca150c73f357de243b4 Mon Sep 17 00:00:00 2001 From: Sharon Stratsianis Date: Sat, 7 Nov 2026 14:32:46 +1100 Subject: [PATCH] fix recursive delete --- src/resource/resourceLogic.ts | 2 +- test/resourceLogic.test.ts | 19 +++++++++++++++++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/resource/resourceLogic.ts b/src/resource/resourceLogic.ts index 5df5d0f7..c2e7bc0d 100644 --- a/src/resource/resourceLogic.ts +++ b/src/resource/resourceLogic.ts @@ -269,7 +269,7 @@ export function createResourceLogic(store, aclLogic: AclLogic, containerLogic, t } if (resourceParent) { - store.removeMatches(resourceParent, ns.ldp('contains'), resourceNode, resourceParent.doc()) + store.removeMatches(resourceParent, ns.ldp('contains'), resourceNode) } store.removeDocument(resourceNode) diff --git a/test/resourceLogic.test.ts b/test/resourceLogic.test.ts index 1bc176ac..38d38e01 100644 --- a/test/resourceLogic.test.ts +++ b/test/resourceLogic.test.ts @@ -96,8 +96,8 @@ describe('resourceLogic', () => { expect(store.fetcher._fetch).toHaveBeenCalledWith(member.value, { method: 'DELETE' }) expect(store.fetcher._fetch).toHaveBeenCalledWith(container.value, { method: 'DELETE' }) expect(store.removeMatches).toHaveBeenCalledTimes(2) - expect(store.removeMatches).toHaveBeenNthCalledWith(1, container, sym('http://www.w3.org/ns/ldp#contains'), member, container.doc()) - expect(store.removeMatches).toHaveBeenNthCalledWith(2, sym('https://example.com/'), sym('http://www.w3.org/ns/ldp#contains'), container, sym('https://example.com/').doc()) + expect(store.removeMatches).toHaveBeenNthCalledWith(1, container, sym('http://www.w3.org/ns/ldp#contains'), member) + expect(store.removeMatches).toHaveBeenNthCalledWith(2, sym('https://example.com/'), sym('http://www.w3.org/ns/ldp#contains'), container) expect(store.removeDocument).toHaveBeenCalledWith(member) expect(store.removeDocument).toHaveBeenCalledWith(container) }) @@ -125,6 +125,21 @@ describe('resourceLogic', () => { expect(store.removeDocument).toHaveBeenCalledWith(resource) }) + it('surfaces document cleanup failures instead of reporting success', async () => { + const resourceLogic = createResourceLogic(store, aclLogic, containerLogic, typeIndexLogic) + const resource = sym('https://example.com/resource.ttl') + + containerLogic.isContainer.mockReturnValue(false) + store.removeDocument.mockImplementation(() => { + throw new Error( + 'Statement to be removed is not on store: "https://example.com/resource.ttl"' + ) + }) + + await expect(resourceLogic.recursiveDelete(resource)).rejects.toThrow('Statement to be removed is not on store:') + expect(store.fetcher.unload).not.toHaveBeenCalled() + }) + it('recognizes only profile-card.ttl WebIDs', () => { const resourceLogic = createResourceLogic(store, aclLogic, containerLogic, typeIndexLogic)