Commit c5ab4d41 authored by Jean Rabreau's avatar Jean Rabreau
Browse files

馃悰 project template patch, update current stored template

parent 73a0bff7
......@@ -35,12 +35,12 @@ import i18n from '@/plugins/vue-i18n'
* @property {string} id
* @property {string} name
* @property {number} scope
* @property {Object} creator
* @property {Object} project
* @property {Object | null} creator
* @property {Object} [project]
* @property {UsfField[]} fields
* @property {Object} messages
* @property {String} createdAt
* @property {String} updatedAt
* @property {String} [createdAt]
* @property {String} [updatedAt]
*/
/**
......@@ -107,10 +107,10 @@ const Template = {
id: '',
name: '',
scope: TEMPLATE_SCOPE.SET,
fields: [{}],
creator: '',
fields: [],
creator: null,
messages: {
default: 'fr',
defaultLocale: 'fr',
locales: {
fr: {}
}
......@@ -156,10 +156,6 @@ const Template = {
ADD_PROJECT_TEMPLATE(state, template) {
state.projectList = [ ...state.projectList, template]
},
UPDATE_PROJECT_TEMPLATE(state, template) {
const templateIndex = state.projectList.findIndex(t => t.id === template.id)
state.projectList.splice(templateIndex, 1, template)
},
},
actions: {
/**
......@@ -311,12 +307,7 @@ const Template = {
privateFields: getPrivateFields(templatePatch.fields)
})
.then(response => {
const template = response.data
if (template.scope === TEMPLATE_SCOPE.SET) {
commit('SET_CURRENT', response.data)
} else if (template.scope === TEMPLATE_SCOPE.PROJECT) {
commit('UPDATE_PROJECT_TEMPLATE', template)
}
commit('SET_CURRENT', response.data)
return dispatch(
'dialog/displayInfo',
i18n.t('template.updated'),
......
......@@ -45,21 +45,33 @@ describe('store/template', () => {
const axiosError = new Error('failed')
beforeEach(() => {
store.state.template = {
/**
* @type {PountTemplate}
*/
current: {
id: '',
name: '',
scope: TEMPLATE_SCOPE.SET,
fields: [{}],
creator: '',
fields: [],
creator: null,
messages: {
default: 'fr',
defaultLocale: 'fr',
locales: {
fr: {}
}
}
},
/**
* @type {PountTemplate[]}
*/
publicList: [],
/**
* @type {PountTemplate[]}
*/
projectList: [],
/**
* @type {PountTemplate[]}
*/
templateList: [],
}
store.state.project.current.id = projectId
......@@ -279,23 +291,12 @@ describe('store/template', () => {
'patch data check'
)
})
it('should update current template, if scope is SET', async () => {
it('should update current template', async () => {
store.state.template.current = { ...retrieveTemplate, name: 'previous name'}
authStub.patch.returns(Promise.resolve({data: retrieveTemplate}))
await store.dispatch('template/updateTemplate', {id: '', ...patchData})
expect(store.getters['template/current'].name).to.equal('patched')
})
it('should update project template, if scope is PROJECT', async () => {
store.state.template.projectList = [
{id: '3637', name: 'thunaplate'},
{id: '118218', name: 'complate'},
{ ...retrieveTemplate, name: 'previous name'},
{id: '007', name: 'goldplate'},
]
authStub.patch.returns(Promise.resolve({data: { ...retrieveTemplate, scope: TEMPLATE_SCOPE.PROJECT}}))
await store.dispatch('template/updateTemplate', {id: '', ...patchData})
expect(store.getters['template/projectList'][2].name).to.equal('patched')
})
it('should notify explicit error', async () => {
authStub.patch.returns(Promise.reject(axiosError))
await store.dispatch('template/updateTemplate', {id: '', ...patchData})
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment