From ec063a78f3bbf512fbc1e302e725b20e69d549f9 Mon Sep 17 00:00:00 2001 From: codytseng Date: Sun, 24 Mar 2024 00:09:41 +0800 Subject: [PATCH] refactor: covert isSearchSupported from property to method in eventRepository --- .../common/src/interfaces/event-repository.interface.ts | 4 ++-- packages/core/__test__/services/event.service.spec.ts | 2 +- packages/core/src/services/event.service.ts | 2 +- .../__test__/event-repository-sqlite.spec.ts | 6 ++++++ .../event-repository-sqlite/src/event-repository-sqlite.ts | 4 ++++ 5 files changed, 14 insertions(+), 4 deletions(-) diff --git a/packages/common/src/interfaces/event-repository.interface.ts b/packages/common/src/interfaces/event-repository.interface.ts index 3ee3eb34..5aa6889a 100644 --- a/packages/common/src/interfaces/event-repository.interface.ts +++ b/packages/common/src/interfaces/event-repository.interface.ts @@ -19,9 +19,9 @@ export interface EventRepositoryUpsertResult { */ export abstract class EventRepository { /** - * This property indicates whether the search feature is supported. + * Whether the search feature is supported. */ - readonly isSearchSupported: boolean = false; + abstract isSearchSupported(): boolean; /** * This method is called when a new event should be stored. You should handle diff --git a/packages/core/__test__/services/event.service.spec.ts b/packages/core/__test__/services/event.service.spec.ts index aaa78631..f3251f53 100644 --- a/packages/core/__test__/services/event.service.spec.ts +++ b/packages/core/__test__/services/event.service.spec.ts @@ -21,7 +21,7 @@ describe('eventService', () => { beforeEach(() => { eventRepository = { - isSearchSupported: false, + isSearchSupported: jest.fn().mockReturnValue(false), upsert: jest.fn(), find: jest.fn(), findOne: jest.fn(), diff --git a/packages/core/src/services/event.service.ts b/packages/core/src/services/event.service.ts index 8c15b282..94872e8c 100644 --- a/packages/core/src/services/event.service.ts +++ b/packages/core/src/services/event.service.ts @@ -123,7 +123,7 @@ export class EventService { const callback = async (): Promise => { if ( filter.search !== undefined && - !this.eventRepository.isSearchSupported + !this.eventRepository.isSearchSupported() ) { return []; } diff --git a/packages/event-repository-sqlite/__test__/event-repository-sqlite.spec.ts b/packages/event-repository-sqlite/__test__/event-repository-sqlite.spec.ts index 3a3473bf..36632c57 100644 --- a/packages/event-repository-sqlite/__test__/event-repository-sqlite.spec.ts +++ b/packages/event-repository-sqlite/__test__/event-repository-sqlite.spec.ts @@ -16,6 +16,12 @@ describe('EventRepositorySqlite', () => { eventRepository.close(); }); + describe('isSearchSupported', () => { + it('should return false', () => { + expect(eventRepository.isSearchSupported()).toBe(false); + }); + }); + describe('upsert', () => { it('should insert a new event', async () => { const eventA = createEvent({ diff --git a/packages/event-repository-sqlite/src/event-repository-sqlite.ts b/packages/event-repository-sqlite/src/event-repository-sqlite.ts index 3f96dac0..f448eac2 100644 --- a/packages/event-repository-sqlite/src/event-repository-sqlite.ts +++ b/packages/event-repository-sqlite/src/event-repository-sqlite.ts @@ -20,6 +20,10 @@ export class EventRepositorySqlite extends EventRepository { this.migrate(); } + isSearchSupported(): boolean { + return false; + } + close(): void { this.db.close(); }