Skip to content

Commit

Permalink
fix: wrong core representation loaded
Browse files Browse the repository at this point in the history
  • Loading branch information
tpluscode committed Aug 21, 2024
1 parent 1b4a7fc commit 673f9a2
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/lazy-balloons-watch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@kopflos-cms/core": patch
---

When handling object requests, Core Representation of the object was loaded instead of subject
2 changes: 1 addition & 1 deletion packages/core/lib/Kopflos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export default class Impl implements Kopflos {
const resourceShape = this.graph.node(resourceShapeMatch.resourceShape)

return responseOr(this.findResourceLoader(resourceShape), loader => {
const coreRepresentation = loader(req.iri, this)
const coreRepresentation = loader(resourceShapeMatch.subject, this)

return responseOr(this.loadHandler(req.method, resourceShapeMatch, coreRepresentation), async handler => {
const resourceGraph = this.env.clownface({
Expand Down
28 changes: 28 additions & 0 deletions packages/core/test/lib/Kopflos.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { createStore } from 'mocha-chai-rdf/store.js'
import 'mocha-chai-rdf/snapshots.js'
import rdf from '@zazuko/env-node'
import type { Stream } from '@rdfjs/types'
import sinon from 'sinon'
import type { KopflosConfig } from '../../lib/Kopflos.js'
import Kopflos from '../../lib/Kopflos.js'
import { ex } from '../../../testing-helpers/ns.js'
Expand Down Expand Up @@ -160,6 +161,33 @@ describe('lib/Kopflos', () => {
expect(response).toMatchSnapshot()
})

it('loads core representation of matched subject', async function () {
// given
const resourceLoader = sinon.stub().returns(rdf.dataset().toStream())
const kopflos = new Kopflos(config, {
dataset: this.dataset,
resourceShapeLookup: async () => [<ResourceShapeObjectMatch>{
api: ex.api,
resourceShape: ex.FooShape,
subject: ex.foo,
property: ex.bar,
object: ex.baz,
}],
handlerLookup: async () => testHandler,
resourceLoaderLookup: async () => resourceLoader,
})

// when
await kopflos.handleRequest({
iri: ex.baz,
method: 'GET',
headers: {},
})

// then
expect(resourceLoader).to.have.been.calledWith(ex.foo, kopflos)
})

context('when no handler is found', () => {
for (const method of HttpMethods) {
context('when method is ' + method, () => {
Expand Down

0 comments on commit 673f9a2

Please sign in to comment.