From 394d1ef40e5966f5c4495290a076714c138a25a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89tienne=20Charignon?= Date: Wed, 7 Sep 2022 17:45:25 +0200 Subject: [PATCH] Migration vers l'enregistrement du useragent dans les conditions de passation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On ne fait plus de parsing du user agent coté appli On a aussi repris le calcul de la taille de la fenêtre de navigation --- package-lock.json | 14 ------- package.json | 1 - .../vues/formulaire_identification.vue | 21 +++------- .../commun/infra/registre_utilisateur.js | 2 +- .../vues/formulaire_identification.test.js | 42 ++++++++----------- 5 files changed, 25 insertions(+), 55 deletions(-) diff --git a/package-lock.json b/package-lock.json index 70be17513..b9bdca55c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,6 @@ "version": "0.0.1", "license": "AGPL-3.0-only", "dependencies": { - "device-detector-js": "^3.0.3", "express": "^4.17.1", "gsap": "^3.7.1", "i18next": "^21.6", @@ -5917,14 +5916,6 @@ "integrity": "sha512-T0NIuQpnTvFDATNuHN5roPwSBG83rFsuO+MXXH9/3N1eFbn4wcPjttvjMLEPWJ0RGUYgQE7cGgS3tNxbqCGM7g==", "dev": true }, - "node_modules/device-detector-js": { - "version": "3.0.3", - "resolved": "https://registry.npmjs.org/device-detector-js/-/device-detector-js-3.0.3.tgz", - "integrity": "sha512-jM89LJAvP6uOd84at8OlD9dWP8KeYCCHUde0RT0HQo/stdoRH4b54Xl/fntx2nEXCmqiFhmo+/cJetS2VGUHPw==", - "engines": { - "node": ">= 8.11.4" - } - }, "node_modules/diff-sequences": { "version": "27.5.1", "resolved": "https://registry.npmjs.org/diff-sequences/-/diff-sequences-27.5.1.tgz", @@ -21074,11 +21065,6 @@ "integrity": "sha512-T0NIuQpnTvFDATNuHN5roPwSBG83rFsuO+MXXH9/3N1eFbn4wcPjttvjMLEPWJ0RGUYgQE7cGgS3tNxbqCGM7g==", "dev": true }, - "device-detector-js": { - "version": "3.0.3", - "resolved": "https://registry.npmjs.org/device-detector-js/-/device-detector-js-3.0.3.tgz", - "integrity": "sha512-jM89LJAvP6uOd84at8OlD9dWP8KeYCCHUde0RT0HQo/stdoRH4b54Xl/fntx2nEXCmqiFhmo+/cJetS2VGUHPw==" - }, "diff-sequences": { "version": "27.5.1", "resolved": "https://registry.npmjs.org/diff-sequences/-/diff-sequences-27.5.1.tgz", diff --git a/package.json b/package.json index e490dc6c0..d5e766579 100644 --- a/package.json +++ b/package.json @@ -64,7 +64,6 @@ "workbox-webpack-plugin": "^6.4" }, "dependencies": { - "device-detector-js": "^3.0.3", "express": "^4.17.1", "gsap": "^3.7.1", "i18next": "^21.6", diff --git a/src/situations/accueil/vues/formulaire_identification.vue b/src/situations/accueil/vues/formulaire_identification.vue index 689d67156..4f93f2e0c 100644 --- a/src/situations/accueil/vues/formulaire_identification.vue +++ b/src/situations/accueil/vues/formulaire_identification.vue @@ -71,8 +71,6 @@ import 'commun/styles/champ.scss'; import 'accueil/styles/formulaire.scss'; import 'commun/styles/boutons.scss'; import TransitionFade from 'commun/vues/transition_fade'; -import DeviceDetector from "device-detector-js"; -import { browserName, browserVersion } from 'mobile-device-detect'; export default { components: { TransitionFade }, @@ -118,18 +116,6 @@ export default { if (this.erreurFormulaireIdentification) { return false; } if (this.campagneForcee) { return true; } return false; - }, - - conditionsDePassation () { - const deviceDetector = new DeviceDetector(); - const deviceInformations = deviceDetector.parse(window.navigator.userAgent); - return { - materiel_utilise: deviceInformations.device.type, - modele_materiel: deviceInformations.device.model, - nom_navigateur : browserName, - version_navigateur: browserVersion, - resolution_ecran: `${window.screen.availWidth}x${window.screen.availHeight}` - }; } }, @@ -151,7 +137,12 @@ export default { }, envoieFormulaireInscription () { - this.$store.commit('metsAJourConditionsDePassation', { conditionsDePassation: this.conditionsDePassation }); + const conditionsDePassation = { + user_agent: window.navigator.userAgent, + hauteur_fenetre_navigation: window.innerHeight, + largeur_fenetre_navigation: window.innerWidth + }; + this.$store.commit('metsAJourConditionsDePassation', { conditionsDePassation }); return this.$store.dispatch('inscris', { nom: this.nom, campagne: this.campagne diff --git a/src/situations/commun/infra/registre_utilisateur.js b/src/situations/commun/infra/registre_utilisateur.js index ea7772f51..c2972ea28 100644 --- a/src/situations/commun/infra/registre_utilisateur.js +++ b/src/situations/commun/infra/registre_utilisateur.js @@ -35,7 +35,7 @@ export default class RegistreUtilisateur extends BaseRegistre { } inscris (nom, codeCampagne, conditionsDePassation) { - const data = { nom: nom, code_campagne: codeCampagne, debutee_le: new Date(), condition_passation_attributes: conditionsDePassation }; + const data = { nom: nom, code_campagne: codeCampagne, debutee_le: new Date(), conditions_passation_attributes: conditionsDePassation }; return new Promise((resolve, reject) => { this.creeEvaluation(data) .then((utilisateur) => { diff --git a/tests/situations/accueil/vues/formulaire_identification.test.js b/tests/situations/accueil/vues/formulaire_identification.test.js index 207ed7fab..c1b12a2e1 100644 --- a/tests/situations/accueil/vues/formulaire_identification.test.js +++ b/tests/situations/accueil/vues/formulaire_identification.test.js @@ -8,6 +8,7 @@ describe("Le formulaire d'identification", function () { let promesse; let store; let localVue; + const unUserAgent = "Mozilla/5.0 (platform; rv:geckoversion) Gecko/geckotrail Firefox/firefoxversion"; beforeEach(function () { localVue = createLocalVue(); @@ -28,25 +29,7 @@ describe("Le formulaire d'identification", function () { store.dispatch = () => promesse; wrapper = mount(FormulaireIdentification, { store, - localVue, - data() { - return { - computedSwitcher: { - materiel_utilise: "desktop", - modele_materiel: 'mac', - nom_navigateur: "chrome", - version_navigateur: 56, - resolution_ecran: "1366x768" - } - }; - }, - computed: { - conditionsDePassation: { - get() { - return this.computedSwitcher; - } - } - } + localVue }); }); @@ -72,6 +55,16 @@ describe("Le formulaire d'identification", function () { }); describe('#envoieFormulaire', function () { + let userAgentGetter; + + beforeEach(function () { + userAgentGetter = jest.spyOn(window.navigator, 'userAgent', 'get'); + }); + + afterEach(() => { + userAgentGetter.mockRestore(); + }); + it("inscrit la personne avec le nom et la campagne à l'appui sur le bouton", function (done) { store.dispatch = (action, { codeCampagne }) => { expect(action).toBe('recupereCampagne'); @@ -95,14 +88,15 @@ describe("Le formulaire d'identification", function () { }); it("envoie les conditions de passation au store", function (done) { + userAgentGetter.mockReturnValue(unUserAgent); + window.innerWidth = 1366; + window.innerHeight = 768; wrapper.vm.envoieFormulaireInscription(); wrapper.vm.$nextTick(() => { expect(store.state.conditionsDePassation).toEqual({ - materiel_utilise: "desktop", - modele_materiel: 'mac', - nom_navigateur: "chrome", - version_navigateur: 56, - resolution_ecran: "1366x768" + user_agent: unUserAgent, + hauteur_fenetre_navigation: 768, + largeur_fenetre_navigation: 1366 }); done(); });