Skip to content

Commit

Permalink
Migration vers l'enregistrement du useragent dans les conditions de p…
Browse files Browse the repository at this point in the history
…assation

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
  • Loading branch information
etienneCharignon authored and marouria committed Sep 9, 2022
1 parent 5c1f264 commit 394d1ef
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 55 deletions.
14 changes: 0 additions & 14 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
21 changes: 6 additions & 15 deletions src/situations/accueil/vues/formulaire_identification.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand Down Expand Up @@ -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}`
};
}
},
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/situations/commun/infra/registre_utilisateur.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
42 changes: 18 additions & 24 deletions tests/situations/accueil/vues/formulaire_identification.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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
});
});

Expand All @@ -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');
Expand All @@ -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();
});
Expand Down

0 comments on commit 394d1ef

Please sign in to comment.