Skip to content

Commit

Permalink
test(connectors): add mocks test update scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
douglasduteil committed Oct 30, 2024
1 parent 8e50aa0 commit 07791ac
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 153 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"test:lint": "prettier '**/*.ts' --list-different",
"test:type-check": "tsc --noEmit",
"test:unit": "NODE_ENV=test mocha --require tsx test/*.ts",
"test:update-mocks": "UPDATE_MOCKS=true mocha --require tsx test/api-annuaire-service-public-data/*.ts",
"test:workspaces": "npm run test --if-present --workspaces",
"update-organization-info": "tsx scripts/update-organizations-info.ts",
"watch:assets": "NODE_ENV=development vite build --clearScreen false --watch",
Expand Down
61 changes: 61 additions & 0 deletions test/api-annuaire-service-public-data/mock.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
//

import { assert } from "chai";
import { writeFile } from "fs/promises";
import { join } from "path";
import { format } from "prettier";

describe("https://api-lannuaire.service-public.fr", () => {
if (!process.env["UPDATE_MOCKS"]) {
// NOTE(douglasduteil): This test is disabled by default.
// To enable it, you need to set the `UPDATE_MOCKS` environment variable to `true`.
return;
}

it("one-mairie.json", async () => {
const input = new URL(
"/api/explore/v2.1/catalog/datasets/api-lannuaire-administration/records",
"https://api-lannuaire.service-public.fr",
);
input.searchParams.append(
"where",
'code_insee_commune LIKE "15014" and pivot LIKE "mairie"',
);
const response = await fetch(input, {
headers: {
accept: "application/json",
},
});

assert.isTrue(response.ok);

await writeFile(
join(import.meta.dirname, "/one-mairie.json"),
await format(await response.text(), { parser: "json" }),
);
});

it("two-mairies.json", async () => {
const input = new URL(
"/api/explore/v2.1/catalog/datasets/api-lannuaire-administration/records",
"https://api-lannuaire.service-public.fr",
);
input.searchParams.append(
"where",
'code_insee_commune LIKE "38253" and pivot LIKE "mairie"',
);

const response = await fetch(input, {
headers: {
accept: "application/json",
},
});

assert.isTrue(response.ok);

await writeFile(
join(import.meta.dirname, "/two-mairies.json"),
await format(await response.text(), { parser: "json" }),
);
});
});
87 changes: 11 additions & 76 deletions test/api-annuaire-service-public-data/one-mairie.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,105 +2,40 @@
"total_count": 1,
"results": [
{
"plage_ouverture": [
{
"nom_jour_debut": "Lundi",
"nom_jour_fin": "Lundi",
"valeur_heure_debut_1": "09:00:00",
"valeur_heure_fin_1": "17:00:00",
"valeur_heure_debut_2": "",
"valeur_heure_fin_2": "",
"commentaire": "Uniquement pour l'accueil et l'état civil. Accueil fermé en juillet et août."
},
{
"nom_jour_debut": "Mardi",
"nom_jour_fin": "Vendredi",
"valeur_heure_debut_1": "09:00:00",
"valeur_heure_fin_1": "12:00:00",
"valeur_heure_debut_2": "13:30:00",
"valeur_heure_fin_2": "17:00:00",
"commentaire": ""
},
{
"nom_jour_debut": "Samedi",
"nom_jour_fin": "Samedi",
"valeur_heure_debut_1": "09:00:00",
"valeur_heure_fin_1": "12:00:00",
"valeur_heure_debut_2": "",
"valeur_heure_fin_2": "",
"commentaire": "Uniquement pour l'accueil, l'état civil et le stationnement. Accueil fermé en juillet et août."
}
],
"site_internet": [
{
"libelle": "",
"valeur": "https://www.aurillac.fr/"
}
],
"copyright": "Direction de l'information légale et administrative (Premier ministre)",
"plage_ouverture": "[{\"nom_jour_debut\": \"Lundi\", \"nom_jour_fin\": \"Lundi\", \"valeur_heure_debut_1\": \"09:00:00\", \"valeur_heure_fin_1\": \"17:00:00\", \"valeur_heure_debut_2\": \"\", \"valeur_heure_fin_2\": \"\", \"commentaire\": \"Uniquement pour l'accueil et l'\u00e9tat civil. Accueil ferm\u00e9 en juillet et ao\u00fbt.\"}, {\"nom_jour_debut\": \"Mardi\", \"nom_jour_fin\": \"Vendredi\", \"valeur_heure_debut_1\": \"09:00:00\", \"valeur_heure_fin_1\": \"12:00:00\", \"valeur_heure_debut_2\": \"13:30:00\", \"valeur_heure_fin_2\": \"17:00:00\", \"commentaire\": \"\"}, {\"nom_jour_debut\": \"Samedi\", \"nom_jour_fin\": \"Samedi\", \"valeur_heure_debut_1\": \"09:00:00\", \"valeur_heure_fin_1\": \"12:00:00\", \"valeur_heure_debut_2\": \"\", \"valeur_heure_fin_2\": \"\", \"commentaire\": \"Uniquement pour l'accueil, l'\u00e9tat civil et le stationnement. Accueil ferm\u00e9 en juillet et ao\u00fbt.\"}]",
"site_internet": "[{\"libelle\": \"\", \"valeur\": \"https://www.aurillac.fr/\"}]",
"copyright": "Direction de l'information l\u00e9gale et administrative (Premier ministre)",
"siren": "211500145",
"ancien_code_pivot": "mairie-15014-01",
"reseau_social": [
{
"valeur": "https://www.facebook.com/mairiedaurillac",
"description": "",
"custom_dico2": "Facebook"
},
{
"valeur": "https://www.instagram.com/mairiedaurillac/",
"description": "",
"custom_dico2": "Instagram"
},
{
"valeur": "https://www.youtube.com/user/villeaurillac15",
"description": "",
"custom_dico2": "YouTube"
}
],
"reseau_social": "[{\"valeur\": \"https://www.facebook.com/mairiedaurillac\", \"description\": \"\", \"custom_dico2\": \"Facebook\"}, {\"valeur\": \"https://www.instagram.com/mairiedaurillac/\", \"description\": \"\", \"custom_dico2\": \"Instagram\"}, {\"valeur\": \"https://www.youtube.com/user/villeaurillac15\", \"description\": \"\", \"custom_dico2\": \"YouTube\"}]",
"texte_reference": null,
"partenaire": null,
"telecopie": "04 71 45 46 90",
"telecopie": null,
"nom": "Mairie - Aurillac",
"siret": "21150014500019",
"itm_identifiant": "317955",
"sigle": null,
"affectation_personne": null,
"date_modification": "06/06/2024 15:25:42",
"date_modification": "26/08/2024 15:30:06",
"adresse_courriel": "[email protected]",
"service_disponible": null,
"organigramme": null,
"pivot": [
{
"type_service_local": "mairie",
"code_insee_commune": ["15014"]
}
],
"pivot": "[{\"type_service_local\": \"mairie\", \"code_insee_commune\": [\"15014\"]}]",
"partenaire_identifiant": null,
"ancien_identifiant": null,
"id": "36cb4285-18ee-45f8-b781-2bfe3b352986",
"ancien_nom": null,
"commentaire_plage_ouverture": "Uniquement pour l'accueil et l'état civil. Accueil fermé en juillet et août.",
"commentaire_plage_ouverture": "Uniquement pour l'accueil et l'\u00e9tat civil. Accueil ferm\u00e9 en juillet et ao\u00fbt.",
"annuaire": null,
"tchat": null,
"hierarchie": null,
"categorie": "SL",
"sve": null,
"telephone_accessible": [
{
"valeur": "https://www.acce-o.fr/client/aurillac",
"description": "Du lundi au vendredi de 9h à 17h et le samedi de 9h à 12h. Fermé lundi et samedi en Juillet et Août.",
"custom_dico1": []
}
],
"telephone_accessible": "[{\"valeur\": \"https://www.acce-o.fr/client/aurillac\", \"description\": \"Du lundi au vendredi de 9h \u00e0 17h et le samedi de 9h \u00e0 12h. Ferm\u00e9 lundi et samedi en Juillet et Ao\u00fbt.\", \"custom_dico1\": []}]",
"application_mobile": null,
"version_type": "Publiable",
"type_repertoire": null,
"telephone": [
{
"valeur": "04 71 45 46 46",
"description": ""
}
],
"telephone": "[{\"valeur\": \"04 71 45 46 46\", \"description\": \"\"}]",
"version_etat_modification": null,
"date_creation": "18/01/2012 00:00:00",
"partenaire_date_modification": null,
Expand All @@ -110,7 +45,7 @@
"type_organisme": null,
"code_insee_commune": "15014",
"statut_de_diffusion": "true",
"adresse": "[{\"type_adresse\":\"Adresse\",\"complement1\":\"\",\"complement2\":\"\",\"numero_voie\":\"Place de l'Hôtel-de-Ville\",\"service_distribution\":\"\",\"code_postal\":\"15000\",\"nom_commune\":\"Aurillac\",\"pays\":\"France\",\"continent\":\"Europe\",\"longitude\":\"2.444953\",\"latitude\":\"44.930317\",\"accessibilite\":\"ACC\",\"note_accessibilite\":\"ascenseurs\"},{\"type_adresse\":\"Adresse postale\",\"complement1\":\"\",\"complement2\":\"Hôtel de Ville\",\"numero_voie\":\"Place de l'Hôtel-de-Ville\",\"service_distribution\":\"BP 509\",\"code_postal\":\"15005\",\"nom_commune\":\"Aurillac Cedex\",\"pays\":\"France\",\"continent\":\"Europe\",\"longitude\":\"\",\"latitude\":\"\",\"accessibilite\":\"\",\"note_accessibilite\":\"\"}]",
"adresse": "[{\"type_adresse\": \"Adresse\", \"complement1\": \"\", \"complement2\": \"\", \"numero_voie\": \"Place de l'H\u00f4tel-de-Ville\", \"service_distribution\": \"\", \"code_postal\": \"15000\", \"nom_commune\": \"Aurillac\", \"pays\": \"France\", \"continent\": \"Europe\", \"longitude\": \"2.444953\", \"latitude\": \"44.930317\", \"accessibilite\": \"ACC\", \"note_accessibilite\": \"ascenseurs\"}, {\"type_adresse\": \"Adresse postale\", \"complement1\": \"\", \"complement2\": \"H\u00f4tel de Ville\", \"numero_voie\": \"Place de l'H\u00f4tel-de-Ville\", \"service_distribution\": \"BP 509\", \"code_postal\": \"15005\", \"nom_commune\": \"Aurillac Cedex\", \"pays\": \"France\", \"continent\": \"Europe\", \"longitude\": \"\", \"latitude\": \"\", \"accessibilite\": \"\", \"note_accessibilite\": \"\"}]",
"url_service_public": "https://lannuaire.service-public.fr/auvergne-rhone-alpes/cantal/36cb4285-18ee-45f8-b781-2bfe3b352986",
"information_complementaire": null,
"date_diffusion": null
Expand Down
92 changes: 15 additions & 77 deletions test/api-annuaire-service-public-data/two-mairies.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,12 @@
"total_count": 2,
"results": [
{
"plage_ouverture": [
{
"nom_jour_debut": "Lundi",
"nom_jour_fin": "Vendredi",
"valeur_heure_debut_1": "08:30:00",
"valeur_heure_fin_1": "12:00:00",
"valeur_heure_debut_2": "14:00:00",
"valeur_heure_fin_2": "17:00:00",
"commentaire": ""
}
],
"site_internet": [
{
"libelle": "",
"valeur": "https://www.mairie2alpes.fr/"
}
],
"copyright": "Direction de l'information légale et administrative (Premier ministre)",
"plage_ouverture": "[{\"nom_jour_debut\": \"Lundi\", \"nom_jour_fin\": \"Vendredi\", \"valeur_heure_debut_1\": \"08:30:00\", \"valeur_heure_fin_1\": \"12:00:00\", \"valeur_heure_debut_2\": \"14:00:00\", \"valeur_heure_fin_2\": \"17:00:00\", \"commentaire\": \"\"}]",
"site_internet": "[{\"libelle\": \"\", \"valeur\": \"https://www.mairie2alpes.fr/\"}]",
"copyright": "Direction de l'information l\u00e9gale et administrative (Premier ministre)",
"siren": "200064434",
"ancien_code_pivot": "mairie-38253-01",
"reseau_social": [
{
"valeur": "https://www.facebook.com/communelesdeuxalpes",
"description": "",
"custom_dico2": "Facebook"
}
],
"reseau_social": "[{\"valeur\": \"https://www.facebook.com/communelesdeuxalpes\", \"description\": \"\", \"custom_dico2\": \"Facebook\"}]",
"texte_reference": null,
"partenaire": null,
"telecopie": "04 76 79 57 09",
Expand All @@ -41,12 +20,7 @@
"adresse_courriel": "[email protected]",
"service_disponible": null,
"organigramme": null,
"pivot": [
{
"type_service_local": "mairie",
"code_insee_commune": ["38253"]
}
],
"pivot": "[{\"type_service_local\": \"mairie\", \"code_insee_commune\": [\"38253\"]}]",
"partenaire_identifiant": null,
"ancien_identifiant": null,
"id": "b6947613-6ec3-4986-b27a-4137ae96425c",
Expand All @@ -61,12 +35,7 @@
"application_mobile": null,
"version_type": "Publiable",
"type_repertoire": null,
"telephone": [
{
"valeur": "04 76 79 24 24",
"description": ""
}
],
"telephone": "[{\"valeur\": \"04 76 79 24 24\", \"description\": \"\"}]",
"version_etat_modification": null,
"date_creation": "18/01/2012 00:00:00",
"partenaire_date_modification": null,
Expand All @@ -76,43 +45,22 @@
"type_organisme": null,
"code_insee_commune": "38253",
"statut_de_diffusion": "true",
"adresse": "[{\"type_adresse\":\"Adresse\",\"complement1\":\"\",\"complement2\":\"\",\"numero_voie\":\"48 avenue de la Muzelle\",\"service_distribution\":\"BP 12\",\"code_postal\":\"38860\",\"nom_commune\":\"Les Deux Alpes\",\"pays\":\"France\",\"continent\":\"Europe\",\"longitude\":\"6.12974023819\",\"latitude\":\"45.0360565186\",\"accessibilite\":\"ACC\",\"note_accessibilite\":\"rampe, ascenseur\"}]",
"adresse": "[{\"type_adresse\": \"Adresse\", \"complement1\": \"\", \"complement2\": \"\", \"numero_voie\": \"48 avenue de la Muzelle\", \"service_distribution\": \"BP 12\", \"code_postal\": \"38860\", \"nom_commune\": \"Les Deux Alpes\", \"pays\": \"France\", \"continent\": \"Europe\", \"longitude\": \"6.12974023819\", \"latitude\": \"45.0360565186\", \"accessibilite\": \"ACC\", \"note_accessibilite\": \"rampe, ascenseur\"}]",
"url_service_public": "https://lannuaire.service-public.fr/auvergne-rhone-alpes/isere/b6947613-6ec3-4986-b27a-4137ae96425c",
"information_complementaire": null,
"date_diffusion": null
},
{
"plage_ouverture": [
{
"nom_jour_debut": "Lundi",
"nom_jour_fin": "Vendredi",
"valeur_heure_debut_1": "08:30:00",
"valeur_heure_fin_1": "12:00:00",
"valeur_heure_debut_2": "14:00:00",
"valeur_heure_fin_2": "16:30:00",
"commentaire": ""
}
],
"site_internet": [
{
"libelle": "",
"valeur": "https://www.mairie2alpes.fr/"
}
],
"copyright": "Direction de l'information légale et administrative (Premier ministre)",
"plage_ouverture": "[{\"nom_jour_debut\": \"Lundi\", \"nom_jour_fin\": \"Vendredi\", \"valeur_heure_debut_1\": \"08:30:00\", \"valeur_heure_fin_1\": \"12:00:00\", \"valeur_heure_debut_2\": \"14:00:00\", \"valeur_heure_fin_2\": \"16:30:00\", \"commentaire\": \"\"}]",
"site_internet": "[{\"libelle\": \"\", \"valeur\": \"https://www.mairie2alpes.fr/\"}]",
"copyright": "Direction de l'information l\u00e9gale et administrative (Premier ministre)",
"siren": "200064434",
"ancien_code_pivot": "mairie-38253-02",
"reseau_social": [
{
"valeur": "https://www.facebook.com/communelesdeuxalpes",
"description": "",
"custom_dico2": "Facebook"
}
],
"reseau_social": "[{\"valeur\": \"https://www.facebook.com/communelesdeuxalpes\", \"description\": \"\", \"custom_dico2\": \"Facebook\"}]",
"texte_reference": null,
"partenaire": null,
"telecopie": null,
"nom": "Mairie déléguée - Venosc",
"nom": "Mairie d\u00e9l\u00e9gu\u00e9e - Venosc",
"siret": "20006443400018",
"itm_identifiant": "315979",
"sigle": null,
Expand All @@ -121,12 +69,7 @@
"adresse_courriel": "[email protected]",
"service_disponible": null,
"organigramme": null,
"pivot": [
{
"type_service_local": "mairie",
"code_insee_commune": ["38253"]
}
],
"pivot": "[{\"type_service_local\": \"mairie\", \"code_insee_commune\": [\"38253\"]}]",
"partenaire_identifiant": null,
"ancien_identifiant": null,
"id": "c93cb8a9-7535-44d6-bf28-36cc3f5fbc74",
Expand All @@ -141,12 +84,7 @@
"application_mobile": null,
"version_type": "Publiable",
"type_repertoire": null,
"telephone": [
{
"valeur": "04 76 80 06 75",
"description": ""
}
],
"telephone": "[{\"valeur\": \"04 76 80 06 75\", \"description\": \"\"}]",
"version_etat_modification": null,
"date_creation": "18/01/2012 00:00:00",
"partenaire_date_modification": null,
Expand All @@ -156,7 +94,7 @@
"type_organisme": null,
"code_insee_commune": "38253",
"statut_de_diffusion": "true",
"adresse": "[{\"type_adresse\":\"Adresse\",\"complement1\":\"Venosc\",\"complement2\":\"\",\"numero_voie\":\"5 rue du Câble\",\"service_distribution\":\"\",\"code_postal\":\"38520\",\"nom_commune\":\"Les Deux Alpes\",\"pays\":\"France\",\"continent\":\"Europe\",\"longitude\":\"6.116463\",\"latitude\":\"44.989936\",\"accessibilite\":\"ACC\",\"note_accessibilite\":\"\"}]",
"adresse": "[{\"type_adresse\": \"Adresse\", \"complement1\": \"Venosc\", \"complement2\": \"\", \"numero_voie\": \"5 rue du C\u00e2ble\", \"service_distribution\": \"\", \"code_postal\": \"38520\", \"nom_commune\": \"Les Deux Alpes\", \"pays\": \"France\", \"continent\": \"Europe\", \"longitude\": \"6.116463\", \"latitude\": \"44.989936\", \"accessibilite\": \"ACC\", \"note_accessibilite\": \"\"}]",
"url_service_public": "https://lannuaire.service-public.fr/auvergne-rhone-alpes/isere/c93cb8a9-7535-44d6-bf28-36cc3f5fbc74",
"information_complementaire": null,
"date_diffusion": null
Expand Down

0 comments on commit 07791ac

Please sign in to comment.