Skip to content

Commit 94af0c1

Browse files
committed
refactor(settings): serialize birthday date explicitly
`savePrimaryAccountProperty` does only allow `string | boolean`. Incidentally, relying on `@nextcloud/axios` default serialization, `Date`s where serialized using `toISOString`. See https://github.com/axios/axios/blob/a7d7a714498452e611943d9d8e5c2ed8b00aa6b9/lib/helpers/toFormData.js#L134 This change corrects the usage of `savePrimaryAccountProperty` and makes serialization explicit. Signed-off-by: Oleksandr Dzhychko <hey@oleks.dev>
1 parent cf73e9f commit 94af0c1

2 files changed

Lines changed: 63 additions & 1 deletion

File tree

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/**
2+
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
3+
* SPDX-License-Identifier: AGPL-3.0-or-later
4+
*/
5+
6+
import { mount } from '@vue/test-utils'
7+
import { afterEach, describe, expect, it, vi } from 'vitest'
8+
9+
let personalInfoParameters
10+
vi.mock('@nextcloud/initial-state', () => ({
11+
loadState(app, key, fallback) {
12+
if (app === 'settings' && key === 'personalInfoParameters' && personalInfoParameters !== undefined) {
13+
return personalInfoParameters
14+
}
15+
if (fallback !== undefined) {
16+
return fallback
17+
}
18+
19+
console.error('Unexpected loadState call without fallback', { app, key })
20+
throw new Error()
21+
},
22+
}))
23+
24+
const savePrimaryAccountProperty = vi.hoisted(() => vi.fn())
25+
vi.mock('../../service/PersonalInfo/PersonalInfoService.js', () => ({
26+
savePrimaryAccountProperty,
27+
}))
28+
29+
afterEach(() => {
30+
personalInfoParameters = undefined
31+
vi.resetModules()
32+
})
33+
34+
describe('BirthdaySection', () => {
35+
it('saves value', async () => {
36+
personalInfoParameters = {
37+
birthdate: {
38+
name: 'birthdate',
39+
value: null,
40+
},
41+
}
42+
savePrimaryAccountProperty.mockReturnValue(Promise.resolve({
43+
ocs: { meta: { status: 'ok' } },
44+
}))
45+
const BirthdaySection = await import('./BirthdaySection.vue')
46+
const wrapper = mount(BirthdaySection.default, {
47+
mocks: {
48+
t: (_app, text) => text,
49+
},
50+
})
51+
52+
const input = wrapper.find('input')
53+
await input.setValue('1987-12-01')
54+
55+
await expect.poll(() => savePrimaryAccountProperty.mock.calls.length).toBe(1)
56+
expect(savePrimaryAccountProperty).toHaveBeenCalledWith(
57+
'birthdate',
58+
'1987-12-01T00:00:00.000Z',
59+
)
60+
expect(input.element.value).toBe('1987-12-01')
61+
})
62+
})

apps/settings/src/components/PersonalInfo/BirthdaySection.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ export default {
9191
try {
9292
const responseData = await savePrimaryAccountProperty(
9393
this.birthdate.name,
94-
value,
94+
value.toISOString(),
9595
)
9696
this.handleResponse({
9797
value,

0 commit comments

Comments
 (0)