Skip to content

Commit

Permalink
test: getCoreRepresentation
Browse files Browse the repository at this point in the history
  • Loading branch information
tpluscode committed Jan 28, 2025
1 parent c3eac24 commit a74fd5e
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 0 deletions.
6 changes: 6 additions & 0 deletions packages/core/test/__snapshots__/handlers.test.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`@kopflos-cms/handlers.js getCoreRepresentation forwards core representation 1`] = `
"<http://example.org/foo> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://schema.org/Thing> .
"
`;
50 changes: 50 additions & 0 deletions packages/core/test/handlers.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import type { Stream } from '@rdfjs/types'
import { expect, use } from 'chai'
import rdf from '@zazuko/env-node'
import snapshots from 'mocha-chai-rdf/snapshots.js'
import { createStore } from 'mocha-chai-rdf/store.js'
import { getCoreRepresentation } from '../handlers.js'
import type { Body, KopflosConfig } from '../lib/Kopflos.js'
import { ex } from '../../testing-helpers/ns.js'
import Kopflos from '../lib/Kopflos.js'

describe('@kopflos-cms/handlers.js', () => {
use(snapshots)

before(createStore(import.meta.url, { format: 'trig', includeDefaultGraph: true }))

const config: KopflosConfig = {
baseIri: 'http://example.com/',
sparql: {
default: 'http://localhost:8080/sparql',
},
}
describe('getCoreRepresentation', () => {
it('forwards core representation', async function () {
// given
const kopflos = new Kopflos(config, {
dataset: this.rdf.dataset,
resourceShapeLookup: async () => [{
api: ex.api,
resourceShape: ex.FooShape,
subject: ex.foo,
}],
handlerLookup: () => [getCoreRepresentation()],
})

// when
const response = await kopflos.handleRequest({
iri: ex.foo,
method: 'GET',
headers: {},
body: {} as Body,
query: {},
}) as unknown as { status: number; body: Stream }

// then
expect(response).to.have.property('status', 200)
const dataset = await rdf.dataset().import(response.body)
expect(dataset).canonical.toMatchSnapshot()
})
})
})
27 changes: 27 additions & 0 deletions packages/core/test/handlers.test.ts.trig
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
PREFIX ex: <http://example.org/>
PREFIX code: <https://code.described.at/>
prefix kopflos: <https://kopflos.described.at/>

ex:config
a kopflos:Config ;
kopflos:api ex:api1 ;
kopflos:api ex:api2 ;
.

ex:api1 a kopflos:Api .

ex:api2 a kopflos:Api .

ex:FooShape
a kopflos:ResourceShape ;
kopflos:api ex:api1 ;
kopflos:resourceLoader """
function(iri, { env }) {
return env.clownface()
.namedNode(iri)
.addOut(env.ns.rdf.type, env.ns.schema.Thing)
.dataset
.toStream()
}
"""^^code:EcmaScript ;
.

0 comments on commit a74fd5e

Please sign in to comment.