Skip to content

Commit

Permalink
Merge e7f7524 into b179558
Browse files Browse the repository at this point in the history
  • Loading branch information
vhf committed Dec 2, 2019
2 parents b179558 + e7f7524 commit bffd9d7
Show file tree
Hide file tree
Showing 74 changed files with 2,328 additions and 300 deletions.
114 changes: 57 additions & 57 deletions __tests__/__snapshots__/query.test.ts.snap

Large diffs are not rendered by default.

32 changes: 13 additions & 19 deletions __tests__/datacube.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,34 +22,26 @@ describe("dataCube", () => {
describe("methods", () => {
it(".componentValues()", async () => {
const entryPoint = newCube("https://trifid-lindas.test.cluster.ldbar.ch/query");
const dataCubes = await entryPoint.dataCubes();
const dataCube = dataCubes[0];

const dataCube = await entryPoint.dataCubeByIri("http://environment.ld.admin.ch/foen/px/0703030000_124/dataset");
const dimensions = await dataCube.dimensions();

const sizeClasses = dimensions[1];

const values = await dataCube.componentValues(sizeClasses);

expect(values).toMatchSnapshot();
});

it(".componentsValues()", async () => {
const entryPoint = newCube("https://trifid-lindas.test.cluster.ldbar.ch/query");
const dataCubes = await entryPoint.dataCubes();
const dataCube = dataCubes[0];

const dataCube = await entryPoint.dataCubeByIri("http://environment.ld.admin.ch/foen/px/0703030000_124/dataset");
const dimensions = await dataCube.dimensions();

const values = await dataCube.componentsValues(dimensions);

expect(dimensions.map((dim) => values.get(dim))).toMatchSnapshot();
});

it(".componentValues() gets same result as Query.componentValues()", async () => {
const entryPoint = newCube("https://trifid-lindas.test.cluster.ldbar.ch/query");
const dataCubes = await entryPoint.dataCubes();
const dataCube = dataCubes[0];
const dataCube = await entryPoint.dataCubeByIri("http://environment.ld.admin.ch/foen/px/0703030000_124/dataset");

const dimensions = await dataCube.dimensions();

Expand Down Expand Up @@ -163,14 +155,14 @@ describe("dataCube", () => {
{ variable: "temporalCoverage", iri: "http://schema.org/temporalCoverage", multilang: true },
{ variable: "description", iri: "http://www.w3.org/2000/01/rdf-schema#comment", multilang: true },
]);
const dataCube = (await entryPoint.dataCubes())[0];
const dataCube = await entryPoint.dataCubeByIri("http://environment.ld.admin.ch/foen/px/0703030000_124/dataset");
const serialized = dataCube.toJSON();
expect(serialized).toMatchSnapshot();
});

it("de/serializes loaded components", async () => {
const entryPoint = newCube("https://ld.stadt-zuerich.ch/query", ["de", "en"]);
const dataCube = (await entryPoint.dataCubes())[0];
const dataCube = await entryPoint.dataCubeByIri("http://environment.data.admin.ch/ubd/28/qb/ubd28");
await dataCube.dimensions();
const serialized = dataCube.toJSON();
expect(serialized).toMatchSnapshot();
Expand All @@ -191,7 +183,7 @@ describe("dataCube", () => {
{ variable: "temporalCoverage", iri: "http://schema.org/temporalCoverage", multilang: true },
{ variable: "description", iri: "http://www.w3.org/2000/01/rdf-schema#comment", multilang: true },
]);
const dataCube = (await entryPoint.dataCubes())[0];
const dataCube = await entryPoint.dataCubeByIri("http://environment.ld.admin.ch/foen/px/0703030000_124/dataset");
const serialized = dataCube.toJSON();
expect(DataCube.fromJSON(serialized).toJSON()).toBe(serialized);
});
Expand All @@ -210,7 +202,7 @@ describe("dataCube", () => {
{ variable: "temporalCoverage", iri: "http://schema.org/temporalCoverage", multilang: true },
{ variable: "description", iri: "http://www.w3.org/2000/01/rdf-schema#comment", multilang: true },
]);
const dataCube = (await entryPoint.dataCubes())[0];
const dataCube = await entryPoint.dataCubeByIri("http://environment.ld.admin.ch/foen/px/0703030000_124/dataset");
const serialized = dataCube.toJSON();
expect(DataCube.fromJSON(serialized)).toBeInstanceOf(DataCube);
});
Expand All @@ -236,13 +228,15 @@ describe("dataCube", () => {
["fr", "de"],
extraMetadata);
const dataCubes = await entryPoint.dataCubes();
dataCubes.forEach((dataCube) => {
expect(Array.from(dataCube.extraMetadata.keys())).toEqual(extraMetadataKeys);
dataCubes.forEach((cube) => {
expect(Array.from(cube.extraMetadata.keys())).toEqual(extraMetadataKeys);
});
expect(dataCubes[0].extraMetadata).toMatchSnapshot();

const dataCube = await entryPoint.dataCubeByIri("http://environment.ld.admin.ch/foen/px/0703030000_124/dataset");
expect(dataCube.extraMetadata).toMatchSnapshot();

extraMetadataKeys.forEach((key) => {
expect(dataCubes[0].extraMetadata.get(key)).toBeInstanceOf(literal("").constructor);
expect(dataCube.extraMetadata.get(key)).toBeInstanceOf(literal("").constructor);
});
});
});
23 changes: 16 additions & 7 deletions __tests__/filter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,24 @@ import { Dimension } from "../src/components";
import { DataCube } from "../src/datacube";
import { fetch } from "./utils/fetch-mock";

export function extractKeyword(keyword: string, sparql: string): string {
const lastMatchingLine = sparql
export function extractKeywords(keyword: string, sparql: string, includes = false): string[] {
return sparql
.split("\n")
.filter((line: string) => line.trim().startsWith(keyword))
.filter((line: string) => {
if (includes) {
return line.trim().includes(keyword);
}
return line.trim().startsWith(keyword);
})
.map((line) => line.trim());
}
export function extractKeyword(keyword: string, sparql: string, includes = false): string {
const lastMatchingLine = extractKeywords(keyword, sparql, includes)
.slice(-1)[0];
if (lastMatchingLine) {
return lastMatchingLine.trim();
}
return "";
return lastMatchingLine || "";
}
export function extractSelect(sparql: string) {
return extractKeyword("SELECT", sparql);
}
export function extractFilter(sparql: string) {
return extractKeyword("FILTER", sparql);
Expand Down

0 comments on commit bffd9d7

Please sign in to comment.