Skip to content

Commit

Permalink
feat(searchLore): support baseUrl
Browse files Browse the repository at this point in the history
  • Loading branch information
zhyupe committed Apr 4, 2020
1 parent 9346bb2 commit 4807286
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
22 changes: 15 additions & 7 deletions src/xivapi.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,20 @@ export class XivapiService {
* @param allLanguages should it include Text_*?
* @param dataColumns Additional data you want to fetch.
* @param page data page to get
* @param options Options of the request.
*/
public searchLore(query: string, lang: string = 'en', allLanguages: boolean = false,
dataColumns: string[] = [], page: number = 1): Observable<LoreSearchResult> {
let httpParams: HttpParams = new HttpParams()
.set('string', query)
.set('language', lang)
.set('page', page.toString());
dataColumns: string[] = [], page: number = 1, options: XivapiOptions = {}): Observable<LoreSearchResult> {
if (!options.extraQueryParams) {
options.extraQueryParams = {};
}

Object.assign(options.extraQueryParams, {
string: query,
language: lang,
page: page.toString()
});

if (dataColumns && dataColumns.length > 0) {
const columns: string[] = [
'Context',
Expand All @@ -65,9 +72,10 @@ export class XivapiService {
if (allLanguages) {
columns.push('Text_*');
}
httpParams = httpParams.set('columns', columns.join(','));

options.extraQueryParams.columns = columns.join(',');
}
return this.doGet<LoreSearchResult>(`${XivapiService.API_BASE_URL}/lore`, httpParams);
return this.request<LoreSearchResult>('/lore', options);
}

/**
Expand Down
12 changes: 12 additions & 0 deletions test/xivapi.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,16 @@ describe('Client tests', () => {
.find(row => row.request.url === 'https://example.org/Item/12087');
expect(req).not.toBeUndefined();
});

it('Should search Lore with custom baseUrl', () => {
const service: XivapiService = new XivapiService(httpClient);
service.searchLore('legendary', 'en', false, [], 1, {
baseUrl: 'https://example.org',
}).subscribe();
const req: TestRequest = <TestRequest>httpMock.match({method: 'GET'})
.find(row => row.request.url === 'https://example.org/lore');
expect(req).not.toBeUndefined();
expect(req.request.params.has('string')).toBeTruthy();
expect(req.request.params.get('string')).toEqual('legendary');
});
});

0 comments on commit 4807286

Please sign in to comment.