From 47aef526d5d0aeff401615a05b42e273d7044afb Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 2 Jan 2024 22:27:33 +0200 Subject: [PATCH] fix(research): fix sort by comments --- src/utils/helpers.test.ts | 8 ++++---- src/utils/helpers.ts | 8 +++++--- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/utils/helpers.test.ts b/src/utils/helpers.test.ts index 5a72a6f073..35989f8a8c 100644 --- a/src/utils/helpers.test.ts +++ b/src/utils/helpers.test.ts @@ -208,7 +208,7 @@ describe('src/utils/helpers', () => { describe('calculateTotalComments Function', () => { it('should return 0 when item has no updates', () => { const item = { item: {} } as any - expect(calculateTotalComments(item)).toBe('0') + expect(calculateTotalComments(item)).toBe(0) }) it('should return 0 when updates have no comments', () => { @@ -221,7 +221,7 @@ describe('src/utils/helpers', () => { }), ), } as IResearch.ItemDB | IItem - expect(calculateTotalComments(item)).toBe('0') + expect(calculateTotalComments(item)).toBe(0) }) it('should return the correct amount of comments', () => { @@ -234,7 +234,7 @@ describe('src/utils/helpers', () => { }), ), } as IResearch.ItemDB | IItem - expect(calculateTotalComments(item)).toBe('9') + expect(calculateTotalComments(item)).toBe(9) }) it('should ignore deleted and draft updates', () => { @@ -260,7 +260,7 @@ describe('src/utils/helpers', () => { }), ]), } as IResearch.ItemDB | IItem - expect(calculateTotalComments(item)).toBe('4') + expect(calculateTotalComments(item)).toBe(4) }) }) diff --git a/src/utils/helpers.ts b/src/utils/helpers.ts index 55db65bb25..1af440b198 100644 --- a/src/utils/helpers.ts +++ b/src/utils/helpers.ts @@ -167,7 +167,9 @@ export const isAllowedToPin = (pin: IMapPin, user?: IUser) => { } } -export const calculateTotalComments = (item: IResearch.ItemDB | IItem) => { +export const calculateTotalComments = ( + item: IResearch.ItemDB | IItem, +): number => { if (item.updates) { const commentOnUpdates = item.updates.reduce((totalComments, update) => { const updateCommentsLength = @@ -177,9 +179,9 @@ export const calculateTotalComments = (item: IResearch.ItemDB | IItem) => { return totalComments + updateCommentsLength }, 0) - return commentOnUpdates ? String(commentOnUpdates) : '0' + return commentOnUpdates ? commentOnUpdates : 0 } else { - return '0' + return 0 } }