Skip to content

Commit

Permalink
Merge pull request #19 from it-at-m/feautre/ZMS-1494-fix-missing-subs…
Browse files Browse the repository at this point in the history
…ervice

feat(ZMS-1494): fix missing sub service
  • Loading branch information
manjencic authored Oct 5, 2023
2 parents d24a72d + 215afa6 commit a3e27d8
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 16 deletions.
68 changes: 59 additions & 9 deletions frontend/__tests__/store/modules/formData/mutations.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ describe('Form data mutations', () => {
expect(state.service).toBeNull()
})

it('setService sets service in store', async () => {
it('setService sets service with subservices in store', async () => {
const state = {
service: {
id: 1,
Expand All @@ -154,30 +154,30 @@ describe('Form data mutations', () => {
count: 2,
combinable: [
1,
2,
3
2
],
subServiceCounts: {
2: 1
2: 1,
3: 1
}
})

expect(state.appointmentCounts).toStrictEqual({
1: 2,
2: 1,
3: 0
3: 1
})
expect(state.appointmentCount).toBe(2)
expect(state.service).toStrictEqual({
id: 1,
name: 'Service 1',
count: 2,
combinable: [
2,
3
2
],
subServiceCounts: {
2: 1
2: 1,
3: 1
},
subServices: [
{
Expand All @@ -186,12 +186,62 @@ describe('Form data mutations', () => {
},
{
id: 3,
count: 0
count: 1
}
]
})
})

it('setService sets service withouth subservices in store', async () => {
const state = {
service: {
id: 1,
name: 'Service',
maxQuantity: 3,
combinable: [
2,
3
]
},
appointment: {
authKey: 'aaa',
processId: 'bbb'
},
appointmentCounts: {
1: 3
},
appointmentCount: 3
}

mutations.setService(state, {
id: 1,
name: 'Service 1',
count: 2,
combinable: [
1,
2,
3
],
subServiceCounts: {}
})

expect(state.appointmentCounts).toStrictEqual({
1: 2
})
expect(state.appointmentCount).toBe(2)
expect(state.service).toStrictEqual({
id: 1,
name: 'Service 1',
count: 2,
combinable: [
2,
3
],
subServiceCounts: {},
subServices: []
})
})

it('setAppointment sets appointment in store', async () => {
state.appointment = {
authKey: 'aaa',
Expand Down
22 changes: 15 additions & 7 deletions frontend/src/store/modules/formData/mutations.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,22 @@ export default {
}

if (! service.subServices) {
service.subServices = combinable.map((subServiceId) => {
return {
id: subServiceId,
count: service.subServiceCounts && service.subServiceCounts[subServiceId]
? service.subServiceCounts[subServiceId]
: 0
if (service.subServiceCounts) {
service.subServices = []
for (const [subServiceId, subServiceCount] of Object.entries(service.subServiceCounts)) {
service.subServices.push({
id: parseInt(subServiceId),
count: subServiceCount
})
}
})
} else {
service.subServices = combinable.map((subServiceId) => {
return {
id: subServiceId,
count: 0
}
})
}
}

service.subServices.forEach((service) => {
Expand Down

0 comments on commit a3e27d8

Please sign in to comment.