Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('excludes objects of hydra:member property by default', () => {
// given
const topLevel = new TestOperationFinder([ ], {
[expand('hydra:member')]: new TestOperationFinder([ {} ], {
child: new TestOperationFinder([ {} ]),
}),
})
// when
const operations = topLevel.getOperationsDeep()
// then
expect(operations).toHaveLength(0)
})
it('includes by expected class id', () => {
// given
const deleteOperation = { expects: { id: expand('owl:Nothing') } }
const getOperation = { expects: { id: expand('owl:Nothing') } }
const postOperation = { expects: { id: 'http://example.com/Person' } }
const resource = new TestOperationFinder([
deleteOperation, getOperation, postOperation,
])
// when
const operations = resource.findOperations({
expecting: 'http://example.com/Person',
})
// then
expect(operations).toHaveLength(1)
expect(operations).toContain(postOperation)
})
return async () => {
const dataset = rdf.dataset()
const stream = stringToStream(`
BASE
PREFIX rdf: <${prefixes.rdf}>
PREFIX rdfs: <${prefixes.rdfs}>
PREFIX foaf: <${prefixes.foaf}>
PREFIX hydra: <${prefixes.hydra}>
${ntriples}`)
return dataset.import(await parser.import(stream))
}
}
return async () => {
const dataset = rdf.dataset()
const stream = stringToStream(`
BASE
PREFIX rdf: <${prefixes.rdf}>
PREFIX rdfs: <${prefixes.rdfs}>
PREFIX foaf: <${prefixes.foaf}>
PREFIX hydra: <${prefixes.hydra}>
${ntriples}`)
return dataset.import(await parser.import(stream))
}
}
return async () => {
const dataset = rdf.dataset()
const stream = stringToStream(`
BASE
PREFIX rdf: <${prefixes.rdf}>
PREFIX rdfs: <${prefixes.rdfs}>
PREFIX foaf: <${prefixes.foaf}>
PREFIX hydra: <${prefixes.hydra}>
${ntriples}`)
return dataset.import(await parser.import(stream))
}
}
return async () => {
const dataset = rdf.dataset()
const stream = stringToStream(`
BASE
PREFIX rdf: <${prefixes.rdf}>
PREFIX rdfs: <${prefixes.rdfs}>
PREFIX foaf: <${prefixes.foaf}>
PREFIX hydra: <${prefixes.hydra}>
${ntriples}`)
return dataset.import(await parser.import(stream))
}
}
public getOperationsDeep (
stopConditions: RecursiveStopConditions = { excludedProperties: expand('hydra:member') },
previousResources: OperationFinderMixinClass[] = []) {
return Object.entries(this)
.reduce(toResourceWithOperations(stopConditions), [] as OperationFinderMixinClass[])
.reduce((operations, resource, index, resources) => {
if (previousResources.includes(resource)) return operations
const currentlyVisited = [...resources, ...previousResources, this]
return [
...operations,
...resource.getOperationsDeep(stopConditions, currentlyVisited),
]
}, this.operations)
}