Skip to content
Permalink
Browse files

feat: added support for lore search

  • Loading branch information
Supamiu committed May 13, 2019
1 parent 1d3e8fd commit f8f9840c2895671cb90eca7b588a8aa4ee3337a8
Showing with 31 additions and 0 deletions.
  1. +11 −0 src/model/lore-search-result.ts
  2. +10 −0 src/xivapi.service.ts
  3. +10 −0 test/xivapi.service.spec.ts
@@ -0,0 +1,11 @@
import { Pagination } from './pagination';

export interface LoreSearchResult {
Results: {
Context: string;
Source: string;
SourceID: number;
Text: string;
};
Pagination: Pagination;
}
@@ -15,6 +15,7 @@ import {
import { CharacterResponse, CharacterVerification } from './model/schema/character';
import { MarketboardItem } from './model/schema/market/marketboard-item';
import { GCF_URL } from './xivapi-client.module';
import { LoreSearchResult } from './model/lore-search-result';

@Injectable()
export class XivapiService {
@@ -39,6 +40,15 @@ export class XivapiService {
return this.request<T>(`/${endpoint}/${id}`, options);
}

/**
* Makes a request on a given endpoint with an id.
*
* @param query Text to search inside the lore.
*/
public searchLore(query: string): Observable<LoreSearchResult> {
return this.doGet<LoreSearchResult>(`${XivapiService.API_BASE_URL}/lore`, new HttpParams().set('string', query));
}

/**
* Makes a request to a given endpoint to list resources available.
*
@@ -43,4 +43,14 @@ describe('Client tests', () => {
expect(req.request.params.has('url')).toBeTruthy();
expect(req.request.params.get('url')).toEqual('aHR0cHM6Ly94aXZhcGkuY29tL0l0ZW0vMTIwODc=');
});

it('Should search Lore properly', () => {
const service: XivapiService = new XivapiService(httpClient);
service.searchLore('legendary').subscribe();
const req: TestRequest = <TestRequest>httpMock.match({method: 'GET'})
.find(row => row.request.url === `${XivapiService.API_BASE_URL}/lore`);
expect(req).not.toBeUndefined();
expect(req.request.params.has('string')).toBeTruthy();
expect(req.request.params.get('string')).toEqual('legendary');
});
});

0 comments on commit f8f9840

Please sign in to comment.
You can’t perform that action at this time.