Skip to content

Commit 4807286

Browse files
committed
feat(searchLore): support baseUrl
1 parent 9346bb2 commit 4807286

File tree

2 files changed

+27
-7
lines changed

2 files changed

+27
-7
lines changed

src/xivapi.service.ts

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,20 @@ export class XivapiService {
4747
* @param allLanguages should it include Text_*?
4848
* @param dataColumns Additional data you want to fetch.
4949
* @param page data page to get
50+
* @param options Options of the request.
5051
*/
5152
public searchLore(query: string, lang: string = 'en', allLanguages: boolean = false,
52-
dataColumns: string[] = [], page: number = 1): Observable<LoreSearchResult> {
53-
let httpParams: HttpParams = new HttpParams()
54-
.set('string', query)
55-
.set('language', lang)
56-
.set('page', page.toString());
53+
dataColumns: string[] = [], page: number = 1, options: XivapiOptions = {}): Observable<LoreSearchResult> {
54+
if (!options.extraQueryParams) {
55+
options.extraQueryParams = {};
56+
}
57+
58+
Object.assign(options.extraQueryParams, {
59+
string: query,
60+
language: lang,
61+
page: page.toString()
62+
});
63+
5764
if (dataColumns && dataColumns.length > 0) {
5865
const columns: string[] = [
5966
'Context',
@@ -65,9 +72,10 @@ export class XivapiService {
6572
if (allLanguages) {
6673
columns.push('Text_*');
6774
}
68-
httpParams = httpParams.set('columns', columns.join(','));
75+
76+
options.extraQueryParams.columns = columns.join(',');
6977
}
70-
return this.doGet<LoreSearchResult>(`${XivapiService.API_BASE_URL}/lore`, httpParams);
78+
return this.request<LoreSearchResult>('/lore', options);
7179
}
7280

7381
/**

test/xivapi.service.spec.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,4 +85,16 @@ describe('Client tests', () => {
8585
.find(row => row.request.url === 'https://example.org/Item/12087');
8686
expect(req).not.toBeUndefined();
8787
});
88+
89+
it('Should search Lore with custom baseUrl', () => {
90+
const service: XivapiService = new XivapiService(httpClient);
91+
service.searchLore('legendary', 'en', false, [], 1, {
92+
baseUrl: 'https://example.org',
93+
}).subscribe();
94+
const req: TestRequest = <TestRequest>httpMock.match({method: 'GET'})
95+
.find(row => row.request.url === 'https://example.org/lore');
96+
expect(req).not.toBeUndefined();
97+
expect(req.request.params.has('string')).toBeTruthy();
98+
expect(req.request.params.get('string')).toEqual('legendary');
99+
});
88100
});

0 commit comments

Comments
 (0)