-
Notifications
You must be signed in to change notification settings - Fork 1
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
7 changed files
with
125 additions
and
15 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
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
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
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
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,15 @@ | ||
import { NamedNode, Stream } from 'rdf-js' | ||
import { StreamClient } from 'sparql-http-client/StreamClient' | ||
import { CONSTRUCT } from '@tpluscode/sparql-builder' | ||
import { hydra } from '@tpluscode/rdf-ns-builders' | ||
|
||
export function loadClasses(api: NamedNode, client: StreamClient): Promise<Stream> { | ||
return CONSTRUCT`?s ?p ?o . ?c ?cp ?co. ${api} ${hydra.supportedClass} ?c` | ||
.WHERE` | ||
?c a ${hydra.Class} ; | ||
${hydra.apiDocumentation} ${api} ; | ||
?cp ?co . | ||
?c (<>|!<>)+ ?s . | ||
?s ?p ?o . | ||
`.execute(client.query) | ||
} |
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,82 @@ | ||
import factory from 'knossos/lib/api' | ||
import sinon from 'sinon' | ||
import { ResourceStore } from 'knossos/lib/store' | ||
import { expect } from 'chai' | ||
import $rdf from 'rdf-ext' | ||
import { Api } from 'hydra-box/Api' | ||
import { namedNode } from '@labyrinth/testing/nodeFactory' | ||
|
||
describe('@hydrofoil/knossos/lib/api', () => { | ||
const term = $rdf.namedNode('/api/docs') | ||
const codePath = './lib/hydra' | ||
const path = '/api/path' | ||
const sparql: any = {} | ||
let store: sinon.SinonStubbedInstance<ResourceStore> | ||
let loadClasses: sinon.SinonStub | ||
|
||
describe('API', () => { | ||
let api: Api | ||
|
||
beforeEach(async () => { | ||
loadClasses = sinon.stub().resolves($rdf.dataset().toStream()) | ||
store = { | ||
exists: sinon.stub(), | ||
load: sinon.stub(), | ||
delete: sinon.stub(), | ||
save: sinon.stub(), | ||
} | ||
|
||
api = await factory({ | ||
log: sinon.spy() as any, | ||
store, | ||
loadClasses, | ||
})({ | ||
codePath, | ||
path, | ||
sparql, | ||
}) | ||
api.term = term | ||
}) | ||
|
||
afterEach(() => { | ||
sinon.restore() | ||
}) | ||
|
||
describe('.init', () => { | ||
it('loads resource from store if it exists', async () => { | ||
// given | ||
store.exists.resolves(true) | ||
store.load.resolves(namedNode(term)) | ||
|
||
// when | ||
await api.init() | ||
|
||
// then | ||
expect(store.load).to.have.been.calledWith(sinon.match(term)) | ||
}) | ||
|
||
it('does not load if API resource does not exist', async () => { | ||
// given | ||
store.exists.resolves(false) | ||
|
||
// when | ||
await api.init() | ||
|
||
// then | ||
expect(store.load).not.to.have.been.called | ||
}) | ||
|
||
it('sets initialized', async () => { | ||
// given | ||
store.exists.resolves(true) | ||
store.load.resolves(namedNode(term)) | ||
|
||
// when | ||
await api.init() | ||
|
||
// then | ||
expect(api.initialized).to.eq(true) | ||
}) | ||
}) | ||
}) | ||
}) |
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