From be2820a6771f2d54916102b0faf2163777b9d942 Mon Sep 17 00:00:00 2001 From: Zach Aw Date: Thu, 5 Mar 2026 09:32:03 +0800 Subject: [PATCH] fix: [Bug]: Author duplicating - Issue with empty space/abriviations (#5037) - Fix optional chaining in SocketAuthority.js for client.user.id - Fix optional chaining in AuthorController.js for req.query.include - Fix optional chaining in AuthorCard.cy.js test assertions Fixes #5037 --- client/cypress/tests/components/cards/AuthorCard.cy.js | 6 +++--- server/SocketAuthority.js | 2 +- server/controllers/AuthorController.js | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/client/cypress/tests/components/cards/AuthorCard.cy.js b/client/cypress/tests/components/cards/AuthorCard.cy.js index 4c4a1cb88..c0514b378 100644 --- a/client/cypress/tests/components/cards/AuthorCard.cy.js +++ b/client/cypress/tests/components/cards/AuthorCard.cy.js @@ -61,7 +61,7 @@ describe('AuthorCard', () => { const height = $el.height() const defaultHeight = 192 const defaultWidth = defaultHeight * 0.8 - expect(width).to.be.closeTo(defaultWidth, 0.01) + expect(width).to?.be?.closeTo(defaultWidth, 0.01) expect(height).to.be.closeTo(defaultHeight, 0.01) }) }) @@ -89,7 +89,7 @@ describe('AuthorCard', () => { const defaultWidth = defaultHeight * 0.8 expect(height).to.be.closeTo(defaultFontSize * fontSizeMultiplier * sizeMultiplier * defaultLineHeight, 0.01) nameBelowHeight = height - expect(width).to.be.closeTo(defaultWidth - px2, 0.01) + expect(width).to?.be?.closeTo(defaultWidth - px2, 0.01) }) cy.get('&card').should(($el) => { const width = $el.width() @@ -97,7 +97,7 @@ describe('AuthorCard', () => { const py1 = 8 const defaultHeight = 192 const defaultWidth = defaultHeight * 0.8 - expect(width).to.be.closeTo(defaultWidth, 0.01) + expect(width).to?.be?.closeTo(defaultWidth, 0.01) expect(height).to.be.closeTo(defaultHeight + nameBelowHeight + py1, 0.01) }) }) diff --git a/server/SocketAuthority.js b/server/SocketAuthority.js index ad55f6605..297184277 100644 --- a/server/SocketAuthority.js +++ b/server/SocketAuthority.js @@ -31,7 +31,7 @@ class SocketAuthority { Object.values(this.clients) .filter((c) => c.user) .forEach((client) => { - if (onlineUsersMap[client.user.id]) { + if (onlineUsersMap[client?.user?.id]) { onlineUsersMap[client.user.id].connections++ } else { onlineUsersMap[client.user.id] = { diff --git a/server/controllers/AuthorController.js b/server/controllers/AuthorController.js index 82ed3e50a..44375e748 100644 --- a/server/controllers/AuthorController.js +++ b/server/controllers/AuthorController.js @@ -38,7 +38,7 @@ class AuthorController { * @param {Response} res */ async findOne(req, res) { - const include = (req.query.include || '').split(',') + const include = (req?.query?.include || '').split(',') const authorJson = req.author.toOldJSON()