Skip to content

Commit

Permalink
fix(rgpd): add tests and fix detection issue (#186)
Browse files Browse the repository at this point in the history
* tests(rgpd): add tests

* fix(rgpd): only use a.text to evaluate best candidates

* fix(rgpd): handle relative links

* fix(rgpd): improve errors messages and always show default message

* tests: update sample data and snaps

* fix(stats): show recommandation
  • Loading branch information
Julien Bouquillon authored May 29, 2022
1 parent ed78e6e commit b41587b
Show file tree
Hide file tree
Showing 19 changed files with 33,113 additions and 29,027 deletions.
19 changes: 19 additions & 0 deletions .github/workflows/declaration-rgpd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
on:
push:
branches: ["*"]
paths:
- declaration-rgpd
pull_request:
branches: ["*"]

name: Test declaration-rgpd
jobs:
tests:
runs-on: ubuntu-latest
name: Test
steps:
- uses: actions/checkout@v2
- run: |
cd declaration-rgpd
yarn
yarn test
148 changes: 148 additions & 0 deletions declaration-rgpd/__test__/__snapshots__/analyseFile.test.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`1000jours-blues: should return ml and pc 1`] = `
Array [
Object {
"declarationUrl": "https://1000jours-blues.fabrique.social.gouv.fr/mentions-legales",
"maxScore": 4,
"mention": "Mentions légales",
"missingTrackers": Array [],
"missingWords": Array [],
"score": 4,
"slug": "ml",
},
Object {
"declarationUrl": "https://1000jours-blues.fabrique.social.gouv.fr/politique-confidentialite",
"maxScore": 4,
"mention": "Politique de confidentialité",
"missingTrackers": Array [],
"missingWords": Array [],
"score": 4,
"slug": "pc",
},
]
`;

exports[`egapro: should return ml and pc 1`] = `
Array [
Object {
"declarationUrl": "https://index-egapro.travail.gouv.fr/mentions-legales",
"maxScore": 4,
"mention": "Mentions légales",
"missingTrackers": Array [],
"missingWords": Array [],
"score": 4,
"slug": "ml",
},
Object {
"declarationUrl": "https://index-egapro.travail.gouv.fr/politique-confidentialite",
"maxScore": 4,
"mention": "Politique de confidentialité",
"missingTrackers": Array [],
"missingWords": Array [],
"score": 4,
"slug": "pc",
},
]
`;

exports[`ressourcerie: should return ml and pc 1`] = `
Array [
Object {
"declarationUrl": "https://ressourcerie.fabrique.social.gouv.fr/mentions-legales",
"maxScore": 4,
"mention": "Mentions légales",
"missingTrackers": Array [],
"missingWords": Array [],
"score": 4,
"slug": "ml",
},
Object {
"declarationUrl": "https://ressourcerie.fabrique.social.gouv.fr/politique-confidentialite",
"maxScore": 4,
"mention": "Politique de confidentialité",
"missingTrackers": Array [],
"missingWords": Array [],
"score": 4,
"slug": "pc",
},
]
`;

exports[`should detect ml : mentions légales 1`] = `
Array [
Object {
"declarationUrl": "https://ressourcerie.fabrique.social.gouv.fr/mentions",
"maxScore": 4,
"mention": "Mentions légales",
"missingTrackers": Array [],
"missingWords": Array [
"directeur (ou) directrice",
"publication",
"hébergeur (ou) hébergement",
"éditeur (ou) édité par (ou) editeur (ou) edité par",
],
"score": 0,
"slug": "ml",
},
Object {
"maxScore": 0,
"mention": null,
"missingTrackers": Array [],
"missingWords": Array [],
"score": 0,
"slug": "pc",
},
]
`;

exports[`should detect pc : Données personnelles 1`] = `
Array [
Object {
"maxScore": 0,
"mention": null,
"missingTrackers": Array [],
"missingWords": Array [],
"score": 0,
"slug": "ml",
},
Object {
"declarationUrl": "https://ressourcerie.fabrique.social.gouv.fr/some",
"maxScore": 4,
"mention": "Données personnelles",
"missingTrackers": Array [],
"missingWords": Array [
"finalité",
"durée de conservation",
"sous-traitants (ou) sous traitants",
],
"score": 1,
"slug": "pc",
},
]
`;

exports[`should return ml and pc and thirdparties data 1`] = `
Array [
Object {
"declarationUrl": "https://ressourcerie.fabrique.social.gouv.fr/mentions-legales",
"maxScore": 4,
"mention": "Mentions légales",
"missingTrackers": Array [],
"missingWords": Array [],
"score": 4,
"slug": "ml",
},
Object {
"declarationUrl": "https://ressourcerie.fabrique.social.gouv.fr/politique-confidentialite",
"maxScore": 5,
"mention": "Politique de confidentialité",
"missingTrackers": Array [
"jQuery",
],
"missingWords": Array [],
"score": 4,
"slug": "pc",
},
]
`;
66 changes: 66 additions & 0 deletions declaration-rgpd/__test__/analyseFile.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
const { analyseFile, analyseDom } = require("..");
const fs = require("fs");
const { JSDOM } = require("jsdom");

test("ressourcerie: should return ml and pc", async () => {
const output = await analyseFile("./__test__/samples/ressourcerie.html", {
url: "https://ressourcerie.fabrique.social.gouv.fr",
});
expect(output).toMatchSnapshot();
});

test("egapro: should return ml and pc", async () => {
const output = await analyseFile("./__test__/samples/egapro.html", {
url: "https://index-egapro.travail.gouv.fr",
});
expect(output).toMatchSnapshot();
});

test("1000jours-blues: should return ml and pc", async () => {
const output = await analyseFile("./__test__/samples/1000jours-blues.html", {
url: "https://1000jours-blues.fabrique.social.gouv.fr",
});
expect(output).toMatchSnapshot();
});

test("should return ml and pc and thirdparties data", async () => {
const thirdPartiesOutput = fs
.readFileSync("./__test__/samples/thirdparties.json")
.toString();
const output = await analyseFile("./__test__/samples/ressourcerie.html", {
thirdPartiesOutput,
url: "https://ressourcerie.fabrique.social.gouv.fr",
});
expect(output).toMatchSnapshot();
});


test("should not detect ml nor pc", async () => {
const html = `Some content Without efficient, transparent bloatware, you will lack architectures. Quick: do you have a plan to become customized. Our feature set is unparalleled, but our sexy raw bandwidth and easy configuration is usually considered a terrific achievement. Imagine a combination of VOIP and Flash. What does the industry jargon '60/24/7/365' really mean? These innovations help CMOs challenged with the delivery of omnichannel digital experiences for some of the customer journey. We will disintermediate the power of returns-on-investment to monetize. Is it more important for something to be customer-directed? What does the industry jargon '60/24/7/365' really mean? Think granular. Without macro-vertical CAE, you will lack synergies. Our infinitely reconfigurable feature set is unparalleled, but our robust feature set, but our capability to upgrade. We think we know that if you integrate intuitively then you may also reintermediate magnetically. That is a remarkable achievement taking into account this month's financial state of things! If all of this may seem confounding to you, that's because it is! If you incentivize dynamically, you may have to exploit vertically. What do we brand? Anything and everything, regardless of semidarkness! Our technology takes the best aspects of VOIP and Dynamic HTML. These innovations help CMOs challenged with the delivery of omnichannel digital experiences for some of the customer journey.`;
const dom = await new JSDOM(html);
const output = await analyseDom(dom, {
url: "https://ressourcerie.fabrique.social.gouv.fr",
});
expect(output.find((o) => o.slug === "ml").mention).toEqual(null);
expect(output.find((o) => o.slug === "ml").score).toEqual(0);
expect(output.find((o) => o.slug === "pc").mention).toEqual(null);
expect(output.find((o) => o.slug === "pc").score).toEqual(0);
});

test("should detect ml : mentions légales", async () => {
const html = `Some content Without efficient, transparent bloatware, you will lack architectures. Quick: do you have a plan to become customized. Our feature set is unparalleled, <a href="/mentions">Nos mentions légales blablal</a> raw bandwidth and easy configuration is usually considered a terrific achievement. Imagine a combination of VOIP and Flash. What does the industry jargon '60/24/7/365' really mean? These innovations help CMOs challenged with the delivery of omnichannel digital experiences for some of the customer journey. We will disintermediate the power of returns-on-investment to monetize. Is it more important for something to be customer-directed? What does the industry jargon '60/24/7/365' really mean? Think granular. Without macro-vertical CAE, you will lack synergies. Our infinitely reconfigurable feature set is unparalleled, but our robust feature set, but our capability to upgrade. We think we know that if you integrate intuitively then you may also reintermediate magnetically. That is a remarkable achievement taking into account this month's financial state of things! If all of this may seem confounding to you, that's because it is! If you incentivize dynamically, you may have to exploit vertically. What do we brand? Anything and everything, regardless of semidarkness! Our technology takes the best aspects of VOIP and Dynamic HTML. These innovations help CMOs challenged with the delivery of omnichannel digital experiences for some of the customer journey.`;
const dom = await new JSDOM(html);
const output = await analyseDom(dom, {
url: "https://ressourcerie.fabrique.social.gouv.fr",
});
expect(output).toMatchSnapshot();
});

test("should detect pc : Données personnelles", async () => {
const html = `Some content Without efficient, transparent bloatware, you will lack architectures. Quick: do you have a plan to become customized. Our feature set is unparalleled, <a href="/some">Données personnelles</a> raw bandwidth and easy configuration is usually considered a terrific achievement. Imagine a combination of VOIP and Flash. What does the industry jargon '60/24/7/365' really mean? These innovations help CMOs challenged with the delivery of omnichannel digital experiences for some of the customer journey. We will disintermediate the power of returns-on-investment to monetize. Is it more important for something to be customer-directed? What does the industry jargon '60/24/7/365' really mean? Think granular. Without macro-vertical CAE, you will lack synergies. Our infinitely reconfigurable feature set is unparalleled, but our robust feature set, but our capability to upgrade. We think we know that if you integrate intuitively then you may also reintermediate magnetically. That is a remarkable achievement taking into account this month's financial state of things! If all of this may seem confounding to you, that's because it is! If you incentivize dynamically, you may have to exploit vertically. What do we brand? Anything and everything, regardless of semidarkness! Our technology takes the best aspects of VOIP and Dynamic HTML. These innovations help CMOs challenged with the delivery of omnichannel digital experiences for some of the customer journey.`;
const dom = await new JSDOM(html);
const output = await analyseDom(dom, {
url: "https://ressourcerie.fabrique.social.gouv.fr",
});
expect(output).toMatchSnapshot();
});
Loading

0 comments on commit b41587b

Please sign in to comment.