Skip to content

Commit

Permalink
Issue/16 should we keep using the hypermedia interface (#100)
Browse files Browse the repository at this point in the history
* Added support for N3 and derivatives with some minor hydra client factory changes
* Added setup for separate N3 module publishing
* Some fixes and minor refactorization leading to better compliance with Heracles.net
* Removed hypermedia property
* Added some tweaks to internal API and displayName and textDescription properties
  • Loading branch information
alien-mcl authored Mar 9, 2020
1 parent c74f853 commit 978d849
Show file tree
Hide file tree
Showing 49 changed files with 502 additions and 546 deletions.
1 change: 0 additions & 1 deletion index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ export { ISupportedProperty } from "./src/DataModel/ISupportedProperty";
export { ITemplatedLink } from "./src/DataModel/ITemplatedLink";
export { ITemplatedOperation } from "./src/DataModel/ITemplatedOperation";
export { ITemplatedResource } from "./src/DataModel/ITemplatedResource";
export { IWebResource } from "./src/DataModel/IWebResource";
export { default as FilterableCollection } from "./src/DataModel/Collections/FilterableCollection";
export { default as LinksCollection } from "./src/DataModel/Collections/LinksCollection";
export { default as MappingsCollection } from "./src/DataModel/Collections/MappingsCollection";
Expand Down
27 changes: 23 additions & 4 deletions integration-tests/HydraClient.ApiDocumentation.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@ describe("Having a Hydra client", () => {
.andCreate();
});

describe("while browsing the test website", () => {
describe("while browsing a website", () => {
beforeEach(
run(async () => {
this.apiDocumentation = await this.client.getApiDocumentation(this.url);
})
);

describe("and obtaining it's API documentation as in use case 2.api-documentation", () => {
/*Use case 2. API documentation.*/
describe("and obtaining it's API documentation", () => {
it("should obtain an API documentation", () => {
expect(this.apiDocumentation.getEntryPoint).toEqual(jasmine.any(Function));
});
Expand All @@ -28,7 +29,8 @@ describe("Having a Hydra client", () => {
expect(this.apiDocumentation.entryPoint).toMatch(".*/api$");
});

it("should provide class of schema:Event as in use case 2.1.api-documentation-data-structures", () => {
/*Use case 2.1. API documentation data structures.*/
it("should provide class of schema:Event", () => {
expect(this.apiDocumentation.supportedClasses.ofIri("http://schema.org/Event")).toBeLike([
{
collections: [],
Expand All @@ -41,6 +43,8 @@ describe("Having a Hydra client", () => {
supportedProperties: [
{
collections: [],
description: "",
displayName: "",
iri: "_:b0",
links: [],
operations: [],
Expand All @@ -56,11 +60,15 @@ describe("Having a Hydra client", () => {
},
readable: false,
required: false,
textDescription: "",
title: "",
type: [hydra.SupportedProperty],
writable: false
},
{
collections: [],
description: "",
displayName: "",
iri: "_:b1",
links: [],
operations: [],
Expand All @@ -76,11 +84,15 @@ describe("Having a Hydra client", () => {
},
readable: false,
required: false,
textDescription: "",
title: "",
type: [hydra.SupportedProperty],
writable: false
},
{
collections: [],
description: "",
displayName: "",
iri: "_:b2",
links: [],
operations: [],
Expand All @@ -99,11 +111,15 @@ describe("Having a Hydra client", () => {
},
readable: false,
required: false,
textDescription: "",
title: "",
type: [hydra.SupportedProperty],
writable: false
},
{
collections: [],
description: "",
displayName: "",
iri: "_:b3",
links: [],
operations: [],
Expand All @@ -122,6 +138,8 @@ describe("Having a Hydra client", () => {
},
readable: false,
required: false,
textDescription: "",
title: "",
type: [hydra.SupportedProperty],
writable: false
}
Expand Down Expand Up @@ -155,7 +173,8 @@ describe("Having a Hydra client", () => {
}
});

it("should provide all details for the user guide as in use case 2.2.api-documentation-user-document", () => {
/*Use case 2.2. API documentation user document.*/
it("should provide all details for the user guide", () => {
expect(this.userGuide.classes["http://schema.org/Event"]).toBe(
"##Class Event (http://schema.org/Event)\n\n" +
"An event happening at a certain time and location, such as a concert, lecture, or festival.\n\n" +
Expand Down
60 changes: 28 additions & 32 deletions integration-tests/HydraClient.EntryPoint.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as md5 from "js-md5";
import { IResource } from "../src/DataModel/IResource";
import HydraClientFactory from "../src/HydraClientFactory";
import { hydra } from "../src/namespaces";
import PartialCollectionCrawler from "../src/PartialCollectionCrawler";
Expand All @@ -12,56 +13,57 @@ describe("Having a Hydra client", () => {
.andCreate();
});

describe("while browsing the test website", () => {
describe("while browsing a website", () => {
beforeEach(
run(async () => {
this.apiDocumentation = await this.client.getApiDocumentation(this.url);
})
);

describe("and obtaining it's entry point as in use case 1.entry-point", () => {
/*Use case 1. Entry-point.*/
describe("and obtaining it's entry point", () => {
beforeEach(
run(async () => {
this.entryPoint = await this.apiDocumentation.getEntryPoint();
})
);

it("should obtain three hypermedia controls", () => {
expect(this.entryPoint.hypermedia.length).toBe(3);
expect(this.entryPoint.length).toBe(3);
});

it("should obtain a schema:AddAction operations", () => {
const operations = this.entryPoint.hypermedia.where(_ =>
_.operations.ofType("http://schema.org/AddAction").any()
);
const operations = this.entryPoint.where(_ => _.operations.ofType("http://schema.org/AddAction").any());
expect(operations.length).toBe(2);
});

it("should obtain a collection of events", () => {
const collection = this.entryPoint.hypermedia.collections.where(item => item.iri.match("/api/events$")).first();
const collection = this.entryPoint.collections.where(item => item.iri.match("/api/events$")).first();
expect(collection).toBeDefined();
expect(collection).not.toBeNull();
});

describe("and then obtaining events as in use case 3.obtaining-events", () => {
/*Use case 3. Obtaining events.*/
describe("and then obtaining events", () => {
beforeEach(
run(async () => {
this.events = await this.client.getResource(this.url + "api/events");
})
);

it("should obtain a collection of events", () => {
expect(this.events.hypermedia.members.ofType("http://schema.org/Event").length).toBe(3);
expect(this.events.members.ofType("http://schema.org/Event").length).toBe(3);
});

describe("and then adding a new event to that collection as in use case 5.creating-event", () => {
/*Use case 5. Creating an event*/
describe("and then adding a new event to that collection", () => {
beforeEach(
run(async () => {
try {
this.body = {
"@type": "http://schema.org/Event"
};
const operation = this.events.hypermedia.operations
const operation = this.events.operations
.ofType("http://schema.org/CreateAction")
.expecting("http://schema.org/Event")
.first();
Expand Down Expand Up @@ -96,10 +98,11 @@ describe("Having a Hydra client", () => {
);
});

describe("and then searching for events as in use case 7.searching-events", () => {
/*Use case 7. Searching events*/
describe("and then searching for events", () => {
beforeEach(
run(async () => {
const link = this.events.hypermedia.links
const link = this.events.links
.withRelationOf(hydra.search)
.withTemplate()
.first()
Expand All @@ -109,18 +112,16 @@ describe("Having a Hydra client", () => {
);

it("should obtain matching events", () => {
const matchingEvents = this.searchResult.hypermedia.collections
.where(item => item.iri.match("/api/events?"))
.first();
const matchingEvents = this.searchResult.collections.where(item => item.iri.match("/api/events?")).first();
expect(matchingEvents).toBeDefined();
expect(matchingEvents).not.toBeNull();
});
});

describe("and then using a custom arbitrarily pointed templated operation", () => {
describe("and then using some templated operation", () => {
beforeEach(
run(async () => {
const link = this.events.hypermedia.links
const link = this.events.links
.withRelationOf("http://example.com/vocab#filter")
.withTemplate()
.first()
Expand All @@ -135,7 +136,7 @@ describe("Having a Hydra client", () => {
);

it("should obtain matching events", () => {
const matchingEvents = this.filteringResult.hypermedia
const matchingEvents = this.filteringResult
.where(item => item.iri.match("/api/events?") && item.type.contains(hydra.Collection))
.first();
expect(matchingEvents).toBeDefined();
Expand All @@ -152,20 +153,15 @@ describe("Having a Hydra client", () => {
);

it("should obtain a collection of people", () => {
expect(this.people.hypermedia.members.ofType("http://schema.org/Person").length).toBe(1);
expect(this.people.members.ofType("http://schema.org/Person").length).toBe(1);
});

describe("and then obtaining all people collection members", () => {
beforeEach(
run(async () => {
this.allPeople = await PartialCollectionCrawler.from(this.people.hypermedia).getMembers();
})
);

it("should follow all links and gather all members", () => {
expect(this.allPeople.length).toBe(2);
});
});
it(
"should follow all links and gather all members",
run(async () => {
expect(((await PartialCollectionCrawler.from(this.people).getMembers()) as IResource[]).length).toBe(2);
})
);

describe("and then adding a new person to that collection", () => {
beforeEach(
Expand All @@ -175,7 +171,7 @@ describe("Having a Hydra client", () => {
"@type": "http://schema.org/Person",
"http://schema.org/name": "test-name"
};
const operation = this.people.hypermedia.operations
const operation = this.people.operations
.ofType("http://schema.org/UpdateAction")
.expecting("http://schema.org/Person")
.first();
Expand Down
8 changes: 3 additions & 5 deletions integration-tests/HydraClient.Resource.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,16 @@ describe("Having a Hydra client", () => {
);

it("should obtain four hypermedia controls", () => {
expect(this.resource.hypermedia.length).toBe(4);
expect(this.resource.length).toBe(4);
});

it("should obtain a schema:AddAction operations", () => {
const operations = this.resource.hypermedia.where(_ =>
_.operations.ofType("http://schema.org/AddAction").any()
);
const operations = this.resource.where(_ => _.operations.ofType("http://schema.org/AddAction").any());
expect(operations.length).toBe(2);
});

it("should obtain a collection of events", () => {
const collection = this.resource.hypermedia.collections.where(item => item.iri.match("/api/events$")).first();
const collection = this.resource.collections.where(item => item.iri.match("/api/events$")).first();
expect(collection).toBeDefined();
expect(collection).not.toBeNull();
});
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@hydra-cg/heracles.ts",
"version": "0.2.0",
"version": "0.5.0",
"contributors": [
{
"name": "Karol Szczepanski"
Expand Down
Loading

0 comments on commit 978d849

Please sign in to comment.