Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('should reject if entrypoint missing', async () => {
// given
const apiDoc = Object.assign({}, Documentations.classWithOperation)
delete apiDoc.entrypoint
const expanded = await jsonld.compact(apiDoc, {})
const docs = new ApiDocumentation(fakeAlcaeusResources(expanded))
alcaeus.loadResource.returns(Promise.resolve(null))
// when
try {
docs.loadEntrypoint()
.then(() => {
throw new Error('Operation should not succeed')
})
} catch (e) {
throw new Error('Should not throw unhandled exception')
}
})
})
it('should use hydra:description for title property', async () => {
// given
const compacted = await jsonld.compact(hydraDescriptionJsonLd, {})
// when
const op = new DocumentedResource(compacted)
// then
expect(op.description).toBe('The longer description')
})
it('should return operations', async () => {
// then
const compacted = await jsonld.compact(hydraClass, {})
// when
const clas = new Class(compacted)
// then
expect(clas.supportedOperations.length).toBe(1)
})
it('should link to domain', async () => {
// given
const compacted = await jsonld.compact(testProperty, {})
// when
const property = new RdfProperty(compacted)
// then
expect(property.domain!['@id']).toBe(xsd.integer)
})
it('should return false for GET operation', async () => {
// given
const operation = {
'@context': Context,
'method': 'GET',
}
const compacted = await jsonld.compact(operation, {})
// when
const op = new SupportedOperation(compacted)
// then
expect(op.requiresInput).toBe(false)
})
it('should return only unique value', async () => {
// given
const expanded = await jsonld.compact(Documentations.classWithOperation, {})
const docs = new ApiDocumentation(fakeAlcaeusResources(expanded))
// when
const ops = docs.getOperations('http://example.com/api#UndomcumentedClass')
// then
expect(_.isArray(ops)).toBe(true)
expect(ops.length).toBe(0)
})
})
it('should expose operation method', async () => {
// given
const compacted = await jsonld.compact(operationJsonLd, {})
// wehen
const op = new SupportedOperation(compacted)
// then
expect(op.method).toBe('TRACE')
})
it('should return classes from documentation', (done: any) => {
jsonld.compact(Documentations.classWithOperation, {}).then((expanded) => {
const docs = new ApiDocumentation(fakeAlcaeusResources(expanded))
expect(docs.classes.length).toBe(1)
expect(docs.classes[0]['@id']).toBe('http://example.com/api#Class')
done()
}).catch(done.fail)
})
compact(context:any = null) {
return jsonld.compact(this, context || Core.Context);
}
}