Skip to content

Commit

Permalink
add method to create a resource (#115)
Browse files Browse the repository at this point in the history
* feature (resource): add method to create a resource

* feature (resource): create a resource with a custom timestamp

* feature (resource): update a resource's metadata

* feature (resource): delete a resource

* test (resource): create a resource

* test (resource): update a resource's metadata

* test (resource): delete a resource

* test (resource): delete a resource

* feature (resource): add e2e tests

* feature (v2 test data): sync with Knora

* feature (v2 test data): use generated v2 test data

* feature (v2 test data): use generated v2 test data for lists

* feature (v2 test data): use generated v2 test data for all onto metadata

* feature (v2 test data): use generated v2 test data for testding

* feature (v2 test data): use generated v2 test data for page

* feature (v2 test data): use generated v2 test data for search

* refactor (package.json): rewrite admin integration script in JS

* feature (resource): use generated v2 test data

* feature (resource): use generated v2 test data

* feature (resource): use generated v2 test data

* test (resource): add test data for resource preview

* test (resource): add test data for resource preview

* test (resource): add test data for resource update

* test (resource): add test data for resource update and deletion

* test (resource): do not use expanded jsonld test data for responses

* test (resource): add more tests

* test (resource): dates in test data
  • Loading branch information
tobiasschweizer committed Dec 12, 2019
1 parent df166a7 commit 56171d3
Show file tree
Hide file tree
Showing 68 changed files with 1,622 additions and 12,790 deletions.
1 change: 1 addition & 0 deletions .idea/knora-api-js-lib.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,11 @@ This package provides the following short-hand scripts:
For further development with Knora the following scripts can be used:

1. `./integrate-generated-files-admin.sh <path-to-generated-Knora-Admin-API-code`: integrate generated code for the Knora Admin API,
1. `npm run integrate-admin-code <path-to-generated-client-code`: integrate generated code for the Knora Admin API,
see <https://docs.knora.org> -> internals -> development -> generating client apis (use it without `mock=true`).
2. `npm run integrate-v2-test-data <path-to-generated-client-code>`: this scripts integrates JSON-LD test data for Knora API v2.
3. `npm run expand-jsonld-test-data`: creates versions with expanded prefixes for Knora API v2 JSON-LD test data.
see <https://docs.knora.org> -> internals -> development -> generating client apis (use it without `mock=true`).
2. `npm run integrate-vs-test-data <path-to-Knora-project-root>`: this scripts integrates JSON-LD test data for Knora API v2.
3. `npm run expand-jsonld-test-data`: creates versions with expanded prefixes for Knora API v2 JSON-LD test data.

# Documentation

Expand Down
5 changes: 5 additions & 0 deletions design-documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ This guarantees that an ontology is only requested once from Knora, keeping API
The `ResourcesEndpoint` handles requests to the Knora API that relate to resource instances.
When reading resources, resource instances are returned from Knora as JSON-LD and converted to an array of `ReadResource` using `ResourcesConversionUtil`.

### Values

The `ValuesEndpoint` handles requests to the Knora API that relate to operations on values.
When reading values, these are embedded in resource instances and converted to an array of `ReadResource` using `ResourcesConversionUtil`.

#### Search

The `SearchEndpoint` handles requests to the Knora API that relate to searches, either full-text or complex (Gravsearch).
Expand Down
17 changes: 0 additions & 17 deletions integrate-generated-files-admin.sh

This file was deleted.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@knora/api",
"version": "1.0.0",
"version": "0.1.0",
"description": "JavaScript library that handles API requests to Knora",
"main": "index.js",
"files": [
Expand All @@ -12,7 +12,8 @@
"index.js"
],
"scripts": {
"integrate-vs-test-data": "node scripts/integrate-files-v2.js",
"integrate-admin-code": "node scripts/integrate-files-admin.js",
"integrate-v2-test-data": "node scripts/integrate-files-v2.js",
"expand-jsonld-test-data": "node scripts/expand-jsonld-test-data-files.js",
"test": "karma start karma.conf.js",
"build": "tsc && mkdir -p build/ && cp CHANGELOG.md build/ && cp LICENSE build/ && cp README.md build/ && cp package.json build/",
Expand Down
23 changes: 23 additions & 0 deletions scripts/integrate-files-admin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
"use strict";

const fs = require('fs-extra');

let pathToGeneratedCode;

// expect three args
if (process.argv.length !== 3) {
console.error("Usage: npm run integrate-admin-code <generated client code>");
process.exit(1);
} else {
pathToGeneratedCode = process.argv[2];
if (!fs.existsSync(pathToGeneratedCode)) {
console.error("Specified path to generated client code is not valid");
process.exit(1);
}
}

fs.copySync(pathToGeneratedCode + "/api/admin", "./src/api/admin");
fs.copySync(pathToGeneratedCode + "/models/admin", "./src/models/admin");
fs.copySync(pathToGeneratedCode + "/test-data/admin", "./test/data/api/admin");


24 changes: 5 additions & 19 deletions scripts/integrate-files-v2.js
Original file line number Diff line number Diff line change
@@ -1,41 +1,27 @@
"use strict";

const fs = require('fs');
const fs = require('fs-extra');
const testDataConfig = require("./v2-test-data-config.json");

let pathToKnora;
let pathToGeneratedCode;

// expect three args
if (process.argv.length !== 4) {
console.error("Usage: npm run integrate-vs-test-data <Knora project root> <generated client code>");
if (process.argv.length !== 3) {
console.error("Usage: npm run integrate-v2-test-data <generated client code>");
process.exit(1);
} else {
pathToKnora = process.argv[2];
if (!fs.existsSync(pathToKnora)) {
console.error("Specified path to Knora is not valid");
process.exit(1);
}
pathToGeneratedCode = process.argv[3];
pathToGeneratedCode = process.argv[2];
if (!fs.existsSync(pathToGeneratedCode)) {
console.error("Specified path to generated client code is not valid");
process.exit(1);
}
}

// copy static test data
for (const file of testDataConfig["static-test-data"]) {
const src = pathToKnora + file["source"];
const dest = file["destination"];

fs.copyFileSync(src, dest);
}

// copy generated test data
for (const file of testDataConfig["generated-test-data"]) {
const src = pathToGeneratedCode + file["source"];
const dest = file["destination"];

fs.copyFileSync(src, dest);
fs.copySync(src, dest);
}

76 changes: 55 additions & 21 deletions scripts/v2-test-data-config.json
Original file line number Diff line number Diff line change
@@ -1,55 +1,53 @@
{
"static-test-data": [
"generated-test-data": [
{
"source": "/test-data/v2/ontologies/all-ontology-metadata.json",
"destination": "./test/data/api/v2/ontologies/all-ontology-metadata.json"
},
{
"source": "/webapi/src/test/resources/test-data/ontologyR2RV2/knoraApiOntologyWithValueObjects.jsonld",
"source": "/test-data/v2/ontologies/knora-api-ontology.json",
"destination": "./test/data/api/v2/ontologies/knora-api-ontology.json"
},
{
"source": "/webapi/src/test/resources/test-data/ontologyR2RV2/anythingOntologyWithValueObjects.jsonld",
"source": "/test-data/v2/ontologies/anything-ontology.json",
"destination": "./test/data/api/v2/ontologies/anything-ontology.json"
},
{
"source": "/webapi/src/test/resources/test-data/ontologyR2RV2/minimalOntologyWithValueObjects.jsonld",
"source": "/test-data/v2/ontologies//minimal-ontology.json",
"destination": "./test/data/api/v2/ontologies/minimal-ontology.json"
},
{
"source": "/webapi/src/test/resources/test-data/ontologyR2RV2/incunabulaOntologyWithValueObjects.jsonld",
"source": "/test-data/v2/ontologies/incunabula-ontology.json",
"destination": "./test/data/api/v2/ontologies/incunabula-ontology.json"
},
{
"source": "/webapi/src/test/resources/test-data/resourcesR2RV2/Testding.jsonld",
"source": "/test-data/v2/resources/testding.json",
"destination": "./test/data/api/v2/resources/testding.json"
},
{
"source": "/webapi/src/test/resources/test-data/searchR2RV2/ThingSmallerThanDecimal.jsonld",
"destination": "./test/data/api/v2/resources/things.json"
"source": "/test-data/v2/resources/page.json",
"destination": "./test/data/api/v2/resources/page.json"
},
{
"source": "/webapi/src/test/resources/test-data/searchR2RV2/RegionsForPage.jsonld",
"destination": "./test/data/api/v2/resources/regions.json"
"source": "/test-data/v2/search/things.json",
"destination": "./test/data/api/v2/resources/things.json"
},
{
"source": "/webapi/src/test/resources/test-data/resourcesR2RV2/NarrenschiffFirstPage.jsonld",
"destination": "./test/data/api/v2/resources/page.json"
"source": "/test-data/v2/search/regions.json",
"destination": "./test/data/api/v2/resources/regions.json"
},
{
"source": "/webapi/src/test/resources/test-data/listsR2RV2/treelist.jsonld",
"source": "/test-data/v2/lists/treelist.json",
"destination": "./test/data/api/v2/lists/treelist.json"
},
{
"source": "/webapi/src/test/resources/test-data/listsR2RV2/othertreelist.jsonld",
"source": "/test-data/v2/lists/othertreelist.json",
"destination": "./test/data/api/v2/lists/othertreelist.json"
},
{
"source": "/webapi/src/test/resources/test-data/listsR2RV2/treelistnode.jsonld",
"source": "/test-data/v2/lists/listnode.json",
"destination": "./test/data/api/v2/lists/listnode.json"
},
{
"source": "/webapi/src/test/resources/test-data/ontologyR2RV2/allOntologyMetadata.jsonld",
"destination": "./test/data/api/v2/ontologies/all-ontology-metadata.json"
}
],
"generated-test-data": [
{
"source": "/test-data/v2/values/create-int-value-request.json",
"destination": "./test/data/api/v2/values/create-int-value-request.json"
Expand Down Expand Up @@ -257,6 +255,42 @@
{
"source": "/test-data/v2/values/get-geoname-value-response.json",
"destination": "./test/data/api/v2/values/get-geoname-value-response.json"
},
{
"source": "/test-data/v2/resources/create-resource-with-values-request.json",
"destination": "./test/data/api/v2/resources/create-resource-with-values-request.json"
},
{
"source": "/test-data/v2/resources/create-resource-as-user.json",
"destination": "./test/data/api/v2/resources/create-resource-as-user.json"
},
{
"source": "/test-data/v2/resources/create-resource-with-custom-creation-date.json",
"destination": "./test/data/api/v2/resources/create-resource-with-custom-creation-date.json"
},
{
"source": "/test-data/v2/resources/update-resource-metadata-request.json",
"destination": "./test/data/api/v2/resources/update-resource-metadata-request.json"
},
{
"source": "/test-data/v2/resources/delete-resource-request.json",
"destination": "./test/data/api/v2/resources/delete-resource-request.json"
},
{
"source": "/test-data/v2/resources/resource-preview.json",
"destination": "./test/data/api/v2/resources/resource-preview.json"
},
{
"source": "/test-data/v2/resources/update-resource-metadata-request-with-last-mod-date.json",
"destination": "./test/data/api/v2/resources/update-resource-metadata-request-with-last-mod-date.json"
},
{
"source": "/test-data/v2/resources/update-resource-metadata-response.json",
"destination": "./test/data/api/v2/resources/update-resource-metadata-response.json"
},
{
"source": "/test-data/v2/resources/delete-resource-response.json",
"destination": "./test/data/api/v2/resources/delete-resource-response.json"
}
]
}
4 changes: 2 additions & 2 deletions src/api/v2/ontology/ontologies-endpoint.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe("OntologiesEndpoint", () => {

knoraApiConnection.v2.onto.getOntologiesMetadata().subscribe(
(response: OntologiesMetadata) => {
expect(response.ontologies.length).toEqual(14);
expect(response.ontologies.length).toEqual(15);
expect(response.ontologies[0].id).toEqual("http://0.0.0.0:3333/ontology/0001/anything/v2");
done();
}
Expand Down Expand Up @@ -100,7 +100,7 @@ describe("OntologiesEndpoint", () => {
expect(response.classes["http://0.0.0.0:3333/ontology/0001/anything/v2#Thing"].label).toEqual("Thing");
expect(response.classes["http://0.0.0.0:3333/ontology/0001/anything/v2#Thing"].comment).toEqual("'The whole world is full of things, which means there's a real need for someone to go searching for them. And that's exactly what a thing-searcher does.' --Pippi Longstocking");

expect(response.classes["http://0.0.0.0:3333/ontology/0001/anything/v2#Thing"].propertiesList.length).toEqual(36);
expect(response.classes["http://0.0.0.0:3333/ontology/0001/anything/v2#Thing"].propertiesList.length).toEqual(38);

expect(response.properties["http://0.0.0.0:3333/ontology/0001/anything/v2#hasDecimal"] instanceof ResourcePropertyDefinition);
expect((response.properties["http://0.0.0.0:3333/ontology/0001/anything/v2#hasDecimal"] as ResourcePropertyDefinition).isEditable).toBeTruthy();
Expand Down
Loading

0 comments on commit 56171d3

Please sign in to comment.