Switched to the <field>-<dir> notation in orderBy param for short URLs list

This commit is contained in:
Alejandro Celaya
2021-12-14 23:01:19 +01:00
parent 654b36ab08
commit 17e4e06fcc
4 changed files with 41 additions and 3 deletions

View File

@@ -5,6 +5,7 @@ import { OptionalString } from '../../../src/utils/utils';
import { ShlinkDomain, ShlinkVisitsOverview } from '../../../src/api/types';
import { ShortUrl } from '../../../src/short-urls/data';
import { Visit } from '../../../src/visits/types';
import { OrderDir } from '../../../src/utils/helpers/ordering';
describe('ShlinkApiClient', () => {
const createAxios = (data: AxiosRequestConfig) => (async () => Promise.resolve(data)) as unknown as AxiosInstance;
@@ -17,9 +18,9 @@ describe('ShlinkApiClient', () => {
];
describe('listShortUrls', () => {
it('properly returns short URLs list', async () => {
const expectedList = [ 'foo', 'bar' ];
const expectedList = [ 'foo', 'bar' ];
it('properly returns short URLs list', async () => {
const { listShortUrls } = createApiClient({
data: {
shortUrls: expectedList,
@@ -30,6 +31,23 @@ describe('ShlinkApiClient', () => {
expect(expectedList).toEqual(actualList);
});
it.each([
[{ visits: 'DESC' as OrderDir }, 'visits-DESC' ],
[{ longUrl: 'ASC' as OrderDir }, 'longUrl-ASC' ],
[{ longUrl: undefined as OrderDir }, undefined ],
])('parses orderBy in params', async (orderBy, expectedOrderBy) => {
const axiosSpy = createAxiosMock({
data: expectedList,
});
const { listShortUrls } = new ShlinkApiClient(axiosSpy, '', '');
await listShortUrls({ orderBy });
expect(axiosSpy).toHaveBeenCalledWith(expect.objectContaining({
params: { orderBy: expectedOrderBy },
}));
});
});
describe('createShortUrl', () => {