mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2024-12-23 09:30:31 +03:00
Added support to fetch full response from list domains endpoint
This commit is contained in:
parent
7a320c9574
commit
8d476e0729
5 changed files with 7 additions and 9 deletions
|
@ -11,7 +11,6 @@ import {
|
|||
ShlinkVisits,
|
||||
ShlinkVisitsParams,
|
||||
ShlinkShortUrlData,
|
||||
ShlinkDomain,
|
||||
ShlinkDomainsResponse,
|
||||
ShlinkVisitsOverview,
|
||||
ShlinkEditDomainRedirects,
|
||||
|
@ -107,8 +106,8 @@ export default class ShlinkApiClient {
|
|||
this.performRequest<ShlinkMercureInfo>('/mercure-info', 'GET')
|
||||
.then((resp) => resp.data);
|
||||
|
||||
public readonly listDomains = async (): Promise<ShlinkDomain[]> =>
|
||||
this.performRequest<{ domains: ShlinkDomainsResponse }>('/domains', 'GET').then(({ data }) => data.domains.data);
|
||||
public readonly listDomains = async (): Promise<ShlinkDomainsResponse> =>
|
||||
this.performRequest<{ domains: ShlinkDomainsResponse }>('/domains', 'GET').then(({ data }) => data.domains);
|
||||
|
||||
public readonly editDomainRedirects = async (
|
||||
domainRedirects: ShlinkEditDomainRedirects,
|
||||
|
|
|
@ -84,6 +84,7 @@ export interface ShlinkDomain {
|
|||
|
||||
export interface ShlinkDomainsResponse {
|
||||
data: ShlinkDomain[];
|
||||
defaultRedirects?: ShlinkDomainRedirects; // Optional only for Shlink older than 2.10
|
||||
}
|
||||
|
||||
export interface ShlinkShortUrlsListParams {
|
||||
|
|
|
@ -68,7 +68,7 @@ export const listDomains = (buildShlinkApiClient: ShlinkApiClientBuilder) => ()
|
|||
const { listDomains } = buildShlinkApiClient(getState);
|
||||
|
||||
try {
|
||||
const domains = await listDomains();
|
||||
const { data: domains } = await listDomains();
|
||||
|
||||
dispatch<ListDomainsAction>({ type: LIST_DOMAINS, domains });
|
||||
} catch (e: any) {
|
||||
|
|
|
@ -256,10 +256,8 @@ describe('ShlinkApiClient', () => {
|
|||
|
||||
describe('listDomains', () => {
|
||||
it('returns domains', async () => {
|
||||
const expectedData = [ Mock.all<ShlinkDomain>(), Mock.all<ShlinkDomain>() ];
|
||||
const resp = {
|
||||
domains: { data: expectedData },
|
||||
};
|
||||
const expectedData = { data: [ Mock.all<ShlinkDomain>(), Mock.all<ShlinkDomain>() ] };
|
||||
const resp = { domains: expectedData };
|
||||
const axiosSpy = createAxiosMock({ data: resp });
|
||||
const { listDomains } = new ShlinkApiClient(axiosSpy, '', '');
|
||||
|
||||
|
|
|
@ -88,7 +88,7 @@ describe('domainsList', () => {
|
|||
});
|
||||
|
||||
it('dispatches domains once loaded', async () => {
|
||||
listDomains.mockResolvedValue(domains);
|
||||
listDomains.mockResolvedValue({ data: domains });
|
||||
|
||||
await listDomainsAction(buildShlinkApiClient)()(dispatch, getState);
|
||||
|
||||
|
|
Loading…
Reference in a new issue