From df4a63812e1b4987147596fdaf271f86d815f925 Mon Sep 17 00:00:00 2001 From: kakkokari-gtyih <67428053+kakkokari-gtyih@users.noreply.github.com> Date: Tue, 2 Jul 2024 18:37:33 +0900 Subject: [PATCH] =?UTF-8?q?fix(backend):=20=E5=90=8D=E5=89=8D=E3=82=92?= =?UTF-8?q?=E7=A9=BA=E7=99=BD=E6=96=87=E5=AD=97=E5=88=97=E3=81=A0=E3=81=91?= =?UTF-8?q?=E3=81=AB=E3=81=A7=E3=81=8D=E3=82=8B=E5=95=8F=E9=A1=8C=E3=82=92?= =?UTF-8?q?=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/backend/src/server/api/endpoints/i/update.ts | 9 ++++++++- packages/backend/test/e2e/users.ts | 7 +++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/packages/backend/src/server/api/endpoints/i/update.ts b/packages/backend/src/server/api/endpoints/i/update.ts index a8e702f328..b39b52bc41 100644 --- a/packages/backend/src/server/api/endpoints/i/update.ts +++ b/packages/backend/src/server/api/endpoints/i/update.ts @@ -257,7 +257,14 @@ export default class extends Endpoint { // eslint- const profile = await this.userProfilesRepository.findOneByOrFail({ userId: user.id }); - if (ps.name !== undefined) updates.name = ps.name; + if (ps.name !== undefined) { + if (ps.name === null) { + updates.name = null; + } else { + const trimmedName = ps.name.trim(); + updates.name = trimmedName === '' ? null : trimmedName; + } + } if (ps.description !== undefined) profileUpdates.description = ps.description; if (ps.lang !== undefined) profileUpdates.lang = ps.lang; if (ps.location !== undefined) profileUpdates.location = ps.location; diff --git a/packages/backend/test/e2e/users.ts b/packages/backend/test/e2e/users.ts index 3458e06384..5fb9642367 100644 --- a/packages/backend/test/e2e/users.ts +++ b/packages/backend/test/e2e/users.ts @@ -409,6 +409,9 @@ describe('ユーザー', () => { { parameters: () => ({ name: 'x'.repeat(50) }) }, { parameters: () => ({ name: 'x' }) }, { parameters: () => ({ name: 'My name' }) }, + { parameters: () => ({ name: '' }), expect: { name: null } }, + { parameters: () => ({ name: ' name with spaces ' }), expect: { name: 'name with spaces' } }, + { parameters: () => ({ name: ' ' }), expect: { name: null } }, { parameters: () => ({ description: null }) }, { parameters: () => ({ description: 'x'.repeat(1500) }) }, { parameters: () => ({ description: 'x' }) }, @@ -465,9 +468,9 @@ describe('ユーザー', () => { { parameters: () => ({ notificationRecieveConfig: {} }) }, { parameters: () => ({ emailNotificationTypes: ['mention', 'reply', 'quote', 'follow', 'receiveFollowRequest'] }) }, { parameters: () => ({ emailNotificationTypes: [] }) }, - ] as const)('を書き換えることができる($#)', async ({ parameters }) => { + ] as const)('を書き換えることができる($#)', async ({ parameters, expect }) => { const response = await successfulApiCall({ endpoint: 'i/update', parameters: parameters(), user: alice }); - const expected = { ...meDetailed(alice, true), ...parameters() }; + const expected = { ...meDetailed(alice, true), ...parameters(), ...expect }; assert.deepStrictEqual(response, expected, inspect(parameters())); });