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,
|
ShlinkVisits,
|
||||||
ShlinkVisitsParams,
|
ShlinkVisitsParams,
|
||||||
ShlinkShortUrlData,
|
ShlinkShortUrlData,
|
||||||
ShlinkDomain,
|
|
||||||
ShlinkDomainsResponse,
|
ShlinkDomainsResponse,
|
||||||
ShlinkVisitsOverview,
|
ShlinkVisitsOverview,
|
||||||
ShlinkEditDomainRedirects,
|
ShlinkEditDomainRedirects,
|
||||||
|
@ -107,8 +106,8 @@ export default class ShlinkApiClient {
|
||||||
this.performRequest<ShlinkMercureInfo>('/mercure-info', 'GET')
|
this.performRequest<ShlinkMercureInfo>('/mercure-info', 'GET')
|
||||||
.then((resp) => resp.data);
|
.then((resp) => resp.data);
|
||||||
|
|
||||||
public readonly listDomains = async (): Promise<ShlinkDomain[]> =>
|
public readonly listDomains = async (): Promise<ShlinkDomainsResponse> =>
|
||||||
this.performRequest<{ domains: ShlinkDomainsResponse }>('/domains', 'GET').then(({ data }) => data.domains.data);
|
this.performRequest<{ domains: ShlinkDomainsResponse }>('/domains', 'GET').then(({ data }) => data.domains);
|
||||||
|
|
||||||
public readonly editDomainRedirects = async (
|
public readonly editDomainRedirects = async (
|
||||||
domainRedirects: ShlinkEditDomainRedirects,
|
domainRedirects: ShlinkEditDomainRedirects,
|
||||||
|
|
|
@ -84,6 +84,7 @@ export interface ShlinkDomain {
|
||||||
|
|
||||||
export interface ShlinkDomainsResponse {
|
export interface ShlinkDomainsResponse {
|
||||||
data: ShlinkDomain[];
|
data: ShlinkDomain[];
|
||||||
|
defaultRedirects?: ShlinkDomainRedirects; // Optional only for Shlink older than 2.10
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ShlinkShortUrlsListParams {
|
export interface ShlinkShortUrlsListParams {
|
||||||
|
|
|
@ -68,7 +68,7 @@ export const listDomains = (buildShlinkApiClient: ShlinkApiClientBuilder) => ()
|
||||||
const { listDomains } = buildShlinkApiClient(getState);
|
const { listDomains } = buildShlinkApiClient(getState);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const domains = await listDomains();
|
const { data: domains } = await listDomains();
|
||||||
|
|
||||||
dispatch<ListDomainsAction>({ type: LIST_DOMAINS, domains });
|
dispatch<ListDomainsAction>({ type: LIST_DOMAINS, domains });
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
|
|
|
@ -256,10 +256,8 @@ describe('ShlinkApiClient', () => {
|
||||||
|
|
||||||
describe('listDomains', () => {
|
describe('listDomains', () => {
|
||||||
it('returns domains', async () => {
|
it('returns domains', async () => {
|
||||||
const expectedData = [ Mock.all<ShlinkDomain>(), Mock.all<ShlinkDomain>() ];
|
const expectedData = { data: [ Mock.all<ShlinkDomain>(), Mock.all<ShlinkDomain>() ] };
|
||||||
const resp = {
|
const resp = { domains: expectedData };
|
||||||
domains: { data: expectedData },
|
|
||||||
};
|
|
||||||
const axiosSpy = createAxiosMock({ data: resp });
|
const axiosSpy = createAxiosMock({ data: resp });
|
||||||
const { listDomains } = new ShlinkApiClient(axiosSpy, '', '');
|
const { listDomains } = new ShlinkApiClient(axiosSpy, '', '');
|
||||||
|
|
||||||
|
|
|
@ -88,7 +88,7 @@ describe('domainsList', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('dispatches domains once loaded', async () => {
|
it('dispatches domains once loaded', async () => {
|
||||||
listDomains.mockResolvedValue(domains);
|
listDomains.mockResolvedValue({ data: domains });
|
||||||
|
|
||||||
await listDomainsAction(buildShlinkApiClient)()(dispatch, getState);
|
await listDomainsAction(buildShlinkApiClient)()(dispatch, getState);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue