From 994fe341a356a360331795a6406382c90bb7e5bb Mon Sep 17 00:00:00 2001 From: Flaminel Date: Mon, 19 Oct 2026 23:55:51 +0300 Subject: [PATCH] added search stats api spec --- .../src/app/core/api/search-stats.api.spec.ts | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 code/frontend/src/app/core/api/search-stats.api.spec.ts diff --git a/code/frontend/src/app/core/api/search-stats.api.spec.ts b/code/frontend/src/app/core/api/search-stats.api.spec.ts new file mode 100644 index 00000000..cc37248e --- /dev/null +++ b/code/frontend/src/app/core/api/search-stats.api.spec.ts @@ -0,0 +1,51 @@ +import { HttpClient, HttpParams } from '@angular/common/http'; +import { TestBed } from '@angular/core/testing'; +import { Observable, of } from 'rxjs'; +import { SeekerContentKind } from '@core/models/search-stats.models'; +import { SearchStatsApi } from './search-stats.api'; + +interface HttpGetOptions { + params?: HttpParams; +} + +type HttpGetStub = (url: string, options?: HttpGetOptions) => Observable; + +describe('SearchStatsApi', () => { + function setup() { + const get = vi.fn(() => of(null)); + TestBed.configureTestingModule({ + providers: [{ provide: HttpClient, useValue: { get } }], + }); + return { api: TestBed.inject(SearchStatsApi), get }; + } + + function sentParams(get: ReturnType['get']): HttpParams { + const options = get.mock.calls[0][1]; + return options?.params ?? new HttpParams(); + } + + it('sends the first page of 50 when called without a query', () => { + const { api, get } = setup(); + + api.getEvents(); + + expect(get).toHaveBeenCalledWith('/api/seeker/search-stats/events', { params: expect.anything() }); + expect(sentParams(get).toString()).toBe('page=1&pageSize=50'); + }); + + it('sends the content kind filter', () => { + const { api, get } = setup(); + + api.getEvents({ contentKind: SeekerContentKind.Anime }); + + expect(sentParams(get).get('contentKind')).toBe(SeekerContentKind.Anime); + }); + + it('omits the content kind filter when unset', () => { + const { api, get } = setup(); + + api.getEvents({}); + + expect(sentParams(get).has('contentKind')).toBe(false); + }); +});