Vincent GUFFON před 3 roky
rodič
revize
587cc066ce

+ 4 - 5
components/Ui/Form.vue

@@ -78,7 +78,6 @@ import {useForm} from "~/composables/form/useForm";
 import * as _ from 'lodash'
 import Form from "~/services/store/form";
 import Page from "~/services/store/page";
-import ApiError from "~/services/exception/apiError";
 
 export default defineComponent({
   props: {
@@ -134,7 +133,7 @@ export default defineComponent({
             query: props.query
           })
 
-          page.addAlerts(TYPE_ALERT.SUCCESS, [i18n.t('saveSuccess') as string])
+          page.addAlerts(TYPE_ALERT.SUCCESS, ['saveSuccess'])
           nextStep(next, response.data)
         } catch (error: any) {
 
@@ -144,16 +143,16 @@ export default defineComponent({
               let fields:AnyJson = {}
               for(const violation of error.response.data['violations']){
                 violations.push(i18n.t(violation['message']) as string)
-                fields = Object.assign({}, {[violation['propertyPath']] : violation['message']})
+                fields = Object.assign(fields, {[violation['propertyPath']] : violation['message']})
               }
 
               new Form(store).addViolations(fields)
-              page.addAlerts(TYPE_ALERT.ALERT, [i18n.t('invalide_form') as string])
+              page.addAlerts(TYPE_ALERT.ALERT, ['invalide_form'])
             }
           }
         }
       }else{
-        page.addAlerts(TYPE_ALERT.ALERT, [i18n.t('invalide_form') as string])
+        page.addAlerts(TYPE_ALERT.ALERT, ['invalide_form'])
       }
     }
 

+ 1 - 1
components/Ui/Map.vue

@@ -66,7 +66,7 @@ export default defineComponent({
         address.value.longitude = data[0].longitude
         emit('updateAddress', address.value)
       } else {
-        new Page(store).addAlerts(TYPE_ALERT.ALERT, [i18n.t('no_coordinate_corresponding') as string])
+        new Page(store).addAlerts(TYPE_ALERT.ALERT, ['no_coordinate_corresponding'])
       }
     }
 

+ 1 - 1
plugins/Data/axios.js

@@ -29,7 +29,7 @@ export default function ({ $axios, redirect, store }) {
       redirect('/login')
     }
     if (error.response.status === 403) {
-      console.debug('forbidden')
+      new Page(store).addAlerts(TYPE_ALERT.ALERT, ['forbidden'])
     }
 
     if (error.response.status === 500) {

+ 4 - 4
tests/unit/composables/form/useError.spec.ts

@@ -10,19 +10,19 @@ const emit = jest.fn()
 beforeAll(() => {
   store = createStore()
   store.registerModule('form', formModule)
-  store.commit('form/setViolations', ['foo', 'bar'])
+  store.commit('form/setViolations', {'foo': 'bob', 'bar': 'alice'})
 
   useErrorMount = useError('foo', emit, store)
 })
 
 describe('onChange()', () => {
   it('delete foo inside store', () => {
-    useErrorMount.onChange('bob')
-    expect(store.state.form.violations).toHaveLength(1)
+    useErrorMount.onChange('event')
+    expect(store.state.form.violations).toStrictEqual({'bar': 'alice'})
   })
 
   it('emit is called', () => {
-    useErrorMount.onChange('bob')
+    useErrorMount.onChange('event')
     expect(emit).toHaveBeenCalled
   })
 })