Skip to content

Commit

Permalink
[back-end] Add test data and fix tests (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
rogup committed Oct 28, 2024
1 parent 3d0a8c7 commit 328f013
Show file tree
Hide file tree
Showing 12 changed files with 224 additions and 44 deletions.
13 changes: 10 additions & 3 deletions apps/back-end/src/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@ export function MykomapRouter(
async getDatasetLocations({ params: { datasetId }, request, reply }) {
// Validate the parameters some more

if (!sendJson(request, reply, filePath("datasets", datasetId)))
if (
!sendJson(request, reply, filePath("datasets", datasetId, "locations"))
)
throw new TsRestResponseError(contract.getDatasetLocations, {
status: 404,
body: { message: `unknown datasetId '${datasetId}'` },
Expand Down Expand Up @@ -128,7 +130,12 @@ export function MykomapRouter(
!sendJson(
request,
reply,
filePath("datasets", datasetId, "items", String(datasetItemIdOrIx)),
filePath(
"datasets",
datasetId,
"initiatives",
String(datasetItemIdOrIx),
),
)
)
throw new TsRestResponseError(contract.getDatasetItem, {
Expand All @@ -142,7 +149,7 @@ export function MykomapRouter(
async getConfig({ params: { datasetId }, request, reply }) {
// Validate the parameters some more

if (!sendJson(request, reply, filePath("datasets", datasetId, "config")))
if (!sendJson(request, reply, filePath("config", datasetId, "config")))
throw new TsRestResponseError(contract.getConfig, {
status: 404,
body: { message: `unknown datasetId '${datasetId}'` },
Expand Down
156 changes: 156 additions & 0 deletions apps/back-end/test/data/config/dataset-A/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
{
"prefixes": {
"https://dev.lod.coop/essglobal/2.1/standard/activities-ica/": "aci",
"https://dev.lod.coop/essglobal/2.1/standard/base-membership-type/": "bmt",
"https://dev.lod.coop/essglobal/2.1/standard/organisational-structure/": "os"
},
"languages": ["en", "fr"],
"fields": {
"uid": "value",
"name": "value",
"description": "value",
"website": {
"type": "multi",
"of": {
"type": "value"
}
},
"dc_domains": {
"type": "multi",
"of": { "type": "value" }
},
"country_id": {
"type": "vocab",
"uri": "coun"
},
"primary_activity": {
"type": "vocab",
"uri": "aci",
"titleUri": "ui:primary_activity"
},
"organisational_structure": {
"type": "vocab",
"uri": "os",
"titleUri": "ui:organisational_structure"
},
"typology": {
"type": "vocab",
"uri": "bmt",
"titleUri": "ui:typology"
},
"latitude": "value",
"longitude": "value",
"geocontainer_lat": "value",
"geocontainer_lon": "value",
"geocoded_addr": "value",
"data_sources": {
"type": "multi",
"of": { "type": "vocab", "uri": "dso" }
}
},
"vocabs": {
"aci": {
"en": {
"title": "Economic Activity",
"terms": {
"ICA210": "Housing",
"ICA220": "Transport",
"ICA230": "Utilities"
}
},
"fr": {
"title": "Secteur économique",
"terms": {
"ICA210": "Logement",
"ICA220": "Transports",
"ICA230": "Services publics"
}
}
},
"bmt": {
"en": {
"title": "Typology",
"terms": {
"BMT10": "Consumer/Users",
"BMT20": "Producers",
"BMT30": "Workers"
}
},
"fr": {
"title": "Typologie",
"terms": {
"BMT10": "Consommateurs/usagers",
"BMT20": "Producteurs",
"BMT30": "Travailleurs"
}
}
},
"os": {
"en": {
"title": "Structure Type",
"terms": {
"OS60": "Workers cooperative",
"OS80": "Consumer/User coops",
"OS90": "Producer cooperative"
}
},
"fr": {
"title": "Type de structure",
"terms": {
"OS50": "Entreprise (autre)",
"OS60": "Coopératives de travail associé",
"OS80": "Coopératives de consommateurs",
"OS90": "Coopératives de producteurs"
}
}
},
"coun": {
"en": {
"title": "Country",
"terms": {
"GB": "United Kingdom",
"FR": "France"
}
},
"fr": {
"title": "Pays",
"terms": {
"GB": "Royaume-Uni",
"FR": "France"
}
}
},
"dso": {
"en": {
"title": "Data Source",
"terms": {
"CUK": "Co-operatives UK",
"DC": "DotCoop",
"ICA": "International Cooperative Alliance",
"NCBA": "National Cooperative Business Association (USA)"
}
},
"fr": {
"title": "Source de données",
"terms": {
"CUK": "Co-operatives UK",
"DC": "DotCoop",
"ICA": "Alliance coopérative internationale",
"NCBA": "National Cooperative Business Association (USA)"
}
}
},
"ui": {
"en": {
"primary_activity": "Primary Activity",
"organisational_structure": "Organisational Structure",
"typology": "Typology"
},
"fr": {
"primary_activity": "Activité principale",
"organisational_structure": "Structure organisationnelle",
"typology": "Typologie"
}
}
}
}
17 changes: 17 additions & 0 deletions apps/back-end/test/data/datasets/dataset-A/initiatives/0.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"uid": "test/cuk/R000001",
"name": "Apples Co-op",
"description": "We sell apples",
"website": "https://apples.coop",
"dc_domains": ["apples.coop", "orchards.coop"],
"country_id": "coun:GB",
"primary_activity": "aci:ICA210",
"organisational_structure": "os:OS60",
"typology": "bmt:BMT20",
"latitude": 51.507476,
"longitude": -0.127825,
"geocontainer_lat": 51.50747643,
"geocontainer_lon": -0.12782464,
"geocoded_addr": "1 West Street, Sheffield, S1 2AB, UK",
"data_sources": ["dso:DC", "dso:CUK"]
}
17 changes: 17 additions & 0 deletions apps/back-end/test/data/datasets/dataset-A/initiatives/1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"uid": "test/cuk/R000002",
"name": "Pears United",
"description": "We sell pears",
"website": "https://pears.coop",
"dc_domains": ["pears.coop", "pearsunited.coop"],
"country_id": "coun:FR",
"primary_activity": "aci:ICA230",
"organisational_structure": "os:OS90",
"typology": "bmt:BMT30",
"latitude": 50.850452,
"longitude": 0.924728,
"geocontainer_lat": 50.85045216,
"geocontainer_lon": 0.92472819,
"geocoded_addr": "79 rue de la Mare aux Carats, 34090 Montpellier, France",
"data_sources": ["dso:DC"]
}
4 changes: 4 additions & 0 deletions apps/back-end/test/data/datasets/dataset-A/locations.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[
[-0.12783, 51.50748],
[0.92473, 50.85045]
]
16 changes: 16 additions & 0 deletions apps/back-end/test/data/datasets/dataset-A/searchable.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[
{
"country_id": "coun:GB",
"primary_activity": "aci:ICA210",
"organisational_structure": "os:OS60",
"typology": "bmt:BMT20",
"searchString": "test co-op 1 west street sheffield s1 2ab uk test.coop"
},
{
"country_id": "coun:FR",
"primary_activity": "aci:ICA230",
"organisational_structure": "os:OS90",
"typology": "bmt:BMT30",
"searchString": "pears united 79 rue de la mare aux carats 34090 montpellier france pears.coop"
}
]
1 change: 0 additions & 1 deletion apps/back-end/test/data/datasets/test-A.json

This file was deleted.

30 changes: 0 additions & 30 deletions apps/back-end/test/data/datasets/test-A/config.json

This file was deleted.

1 change: 0 additions & 1 deletion apps/back-end/test/data/datasets/test-A/items/0.json

This file was deleted.

This file was deleted.

This file was deleted.

11 changes: 4 additions & 7 deletions apps/back-end/test/plugin.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
/// <reference types="vitest"/>
// this file contains a test harness that was auto-generated by fastify-openapi-glue
// running the tests directly after generation will probably fail as the parameters
// need to be manually added.

import { expect, test } from "vitest";
import Fastify from "fastify";
Expand All @@ -24,7 +21,7 @@ test("testing getDatasetLocations", async (t) => {

const res = await fastify.inject({
method: "GET",
url: "/dataset/test-A/locations",
url: "/dataset/dataset-A/locations",
payload: undefined,
headers: undefined,
});
Expand All @@ -37,7 +34,7 @@ test("testing searchDataset", async (t) => {

const res = await fastify.inject({
method: "GET",
url: "/dataset/test-A/search?filter=a:foo",
url: "/dataset/dataset-A/search?filter=a:foo",
payload: undefined,
headers: undefined,
});
Expand All @@ -50,7 +47,7 @@ test("testing getDatasetItem", async (t) => {

const res = await fastify.inject({
method: "GET",
url: "/dataset/test-A/item/0",
url: "/dataset/dataset-A/item/0",
payload: undefined,
headers: undefined,
});
Expand All @@ -63,7 +60,7 @@ test("testing getConfig", async (t) => {

const res = await fastify.inject({
method: "GET",
url: "/dataset/test-A/config",
url: "/dataset/dataset-A/config",
payload: undefined,
headers: undefined,
});
Expand Down

0 comments on commit 328f013

Please sign in to comment.