Skip to content

Commit

Permalink
test: Dataset preview query
Browse files Browse the repository at this point in the history
  • Loading branch information
bprusinowski committed Feb 12, 2024
1 parent a1ef79f commit e0e6d21
Show file tree
Hide file tree
Showing 2 changed files with 112 additions and 2 deletions.
111 changes: 111 additions & 0 deletions app/rdf/query-cube-preview.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
import rdf from "rdf-ext";
import ParsingClient from "sparql-http-client/ParsingClient";

import * as ns from "./namespace";
import { getCubePreview } from "./query-cube-preview";

jest.mock("rdf-cube-view-query", () => ({}));
jest.mock("./extended-cube", () => ({}));
jest.mock("@zazuko/cube-hierarchy-query/index", () => ({}));

describe("dataset preview", () => {
const dim = rdf.blankNode();
const measure = rdf.blankNode();
const observation = rdf.namedNode(
"https://environment.ld.admin.ch/foen/gefahren-waldbrand-warnung/observation/336>"
);
const quads = [
rdf.quad(
dim,
ns.sh.path,
rdf.namedNode(
"https://environment.ld.admin.ch/foen/gefahren-waldbrand-warnung/region"
)
),
rdf.quad(dim, ns.schema.name, rdf.literal("Region")),
rdf.quad(
measure,
ns.sh.path,
rdf.namedNode(
"https://environment.ld.admin.ch/foen/gefahren-waldbrand-warnung/level"
)
),
rdf.quad(measure, ns.schema.name, rdf.literal("Danger ratings")),
rdf.quad(measure, ns.rdf.type, ns.cube.MeasureDimension),
rdf.quad(
observation,
rdf.namedNode(
"https://environment.ld.admin.ch/foen/gefahren-waldbrand-warnung/region"
),
rdf.namedNode(
"https://ld.admin.ch/dimension/bgdi/biota/forestfirewarningregions/1300"
)
),
rdf.quad(
observation,
rdf.namedNode(
"https://environment.ld.admin.ch/foen/gefahren-waldbrand-warnung/region"
),
rdf.literal("Bern")
),
rdf.quad(
rdf.namedNode(
"https://ld.admin.ch/dimension/bgdi/biota/forestfirewarningregions/1300"
),
ns.schema.position,
rdf.literal("3")
),
rdf.quad(
observation,
rdf.namedNode(
"https://environment.ld.admin.ch/foen/gefahren-waldbrand-warnung/level"
),
rdf.namedNode(
"https://environment.ld.admin.ch/foen/gefahren-waldbrand-warnung/level/1"
)
),
rdf.quad(
observation,
rdf.namedNode(
"https://environment.ld.admin.ch/foen/gefahren-waldbrand-warnung/level"
),
rdf.literal("considerable danger")
),
];
const sparqlClient = {
query: {
construct: async () => Promise.resolve(quads),
},
} as any as ParsingClient;

it("should return correct preview", async () => {
const { dimensions, measures, observations } = await getCubePreview(
"awesome iri",
{
sparqlClient,
locale: "en",
latest: true,
}
);
const dim = dimensions[0];

expect(dim.iri).toEqual(
"https://environment.ld.admin.ch/foen/gefahren-waldbrand-warnung/region"
);
expect(dim.label).toEqual("Region");
expect(dim.values).toHaveLength(1);
expect(dim.values[0].position).toEqual(3);

const measure = measures[0];

expect(measure.iri).toEqual(
"https://environment.ld.admin.ch/foen/gefahren-waldbrand-warnung/level"
);
expect(measure.label).toEqual("Danger ratings");

const obs = observations[0];

expect(obs[dim.iri]).toEqual("Bern");
expect(obs[measure.iri]).toEqual("considerable danger");
});
});
3 changes: 1 addition & 2 deletions app/rdf/query-cube-preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ export const getCubePreview = async (
): Promise<DataCubePreview> => {
const { sparqlClient, locale } = options;
const qs = await sparqlClient.query.construct(
`
PREFIX cube: <https://cube.link/>
`PREFIX cube: <https://cube.link/>
PREFIX meta: <https://cube.link/meta/>
PREFIX qudt: <http://qudt.org/schema/qudt/>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
Expand Down

0 comments on commit e0e6d21

Please sign in to comment.