-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
83 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> . | ||
" | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ; | ||
. |