Add Shlink prefix to api-contract models

This commit is contained in:
Alejandro Celaya
2023-08-06 21:27:57 +02:00
parent 47dd105cd6
commit 23daa2de72
35 changed files with 160 additions and 159 deletions

View File

@@ -2,14 +2,14 @@ import { screen, waitFor } from '@testing-library/react';
import { fromPartial } from '@total-typescript/shoehorn';
import type { InvalidShortUrlDeletion } from '../../../src/api-contract';
import { ErrorTypeV2, ErrorTypeV3 } from '../../../src/api-contract';
import type { ShortUrl } from '../../../src/short-urls/data';
import type { ShlinkShortUrl } from '../../../src/short-urls/data';
import { DeleteShortUrlModal } from '../../../src/short-urls/helpers/DeleteShortUrlModal';
import type { ShortUrlDeletion } from '../../../src/short-urls/reducers/shortUrlDeletion';
import { renderWithEvents } from '../../__helpers__/setUpTest';
import { TestModalWrapper } from '../../__helpers__/TestModalWrapper';
describe('<DeleteShortUrlModal />', () => {
const shortUrl = fromPartial<ShortUrl>({
const shortUrl = fromPartial<ShlinkShortUrl>({
tags: [],
shortCode: 'abc123',
longUrl: 'https://long-domain.com/foo/bar',

View File

@@ -1,7 +1,7 @@
import { screen } from '@testing-library/react';
import { fromPartial } from '@total-typescript/shoehorn';
import { MemoryRouter } from 'react-router-dom';
import type { ShortUrl } from '../../../src/short-urls/data';
import type { ShlinkShortUrl } from '../../../src/short-urls/data';
import { ExportShortUrlsBtn as createExportShortUrlsBtn } from '../../../src/short-urls/helpers/ExportShortUrlsBtn';
import type { ReportExporter } from '../../../src/utils/services/ReportExporter';
import { renderWithEvents } from '../../__helpers__/setUpTest';
@@ -46,7 +46,7 @@ describe('<ExportShortUrlsBtn />', () => {
it('maps short URLs for exporting', async () => {
listShortUrls.mockResolvedValue({
data: [fromPartial<ShortUrl>({
data: [fromPartial<ShlinkShortUrl>({
shortUrl: 'https://s.test/short-code',
tags: [],
})],

View File

@@ -1,7 +1,7 @@
import { render, screen } from '@testing-library/react';
import { fromPartial } from '@total-typescript/shoehorn';
import { MemoryRouter } from 'react-router-dom';
import type { ShortUrl } from '../../../src/short-urls/data';
import type { ShlinkShortUrl } from '../../../src/short-urls/data';
import type { LinkSuffix } from '../../../src/short-urls/helpers/ShortUrlDetailLink';
import { ShortUrlDetailLink } from '../../../src/short-urls/helpers/ShortUrlDetailLink';
import { RoutesPrefixProvider } from '../../../src/utils/routesPrefix';
@@ -12,8 +12,8 @@ describe('<ShortUrlDetailLink />', () => {
[false, null],
[true, null],
[true, undefined],
[false, fromPartial<ShortUrl>({})],
[false, fromPartial<ShortUrl>({})],
[false, fromPartial<ShlinkShortUrl>({})],
[false, fromPartial<ShlinkShortUrl>({})],
])('only renders a plain span when either server or short URL are not set', (asLink, shortUrl) => {
render(
<ShortUrlDetailLink shortUrl={shortUrl} asLink={asLink} suffix="visits">
@@ -28,25 +28,25 @@ describe('<ShortUrlDetailLink />', () => {
it.each([
[
'/server/1',
fromPartial<ShortUrl>({ shortCode: 'abc123' }),
fromPartial<ShlinkShortUrl>({ shortCode: 'abc123' }),
'visits' as LinkSuffix,
'/server/1/short-code/abc123/visits',
],
[
'/foobar',
fromPartial<ShortUrl>({ shortCode: 'def456', domain: 'example.com' }),
fromPartial<ShlinkShortUrl>({ shortCode: 'def456', domain: 'example.com' }),
'visits' as LinkSuffix,
'/foobar/short-code/def456/visits?domain=example.com',
],
[
'/server/1',
fromPartial<ShortUrl>({ shortCode: 'abc123' }),
fromPartial<ShlinkShortUrl>({ shortCode: 'abc123' }),
'edit' as LinkSuffix,
'/server/1/short-code/abc123/edit',
],
[
'/server/3',
fromPartial<ShortUrl>({ shortCode: 'def456', domain: 'example.com' }),
fromPartial<ShlinkShortUrl>({ shortCode: 'def456', domain: 'example.com' }),
'edit' as LinkSuffix,
'/server/3/short-code/def456/edit?domain=example.com',
],

View File

@@ -2,41 +2,41 @@ import { render, screen, waitFor } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { fromPartial } from '@total-typescript/shoehorn';
import type { ShlinkVisitsSummary } from '../../../src/api-contract';
import type { ShortUrl, ShortUrlMeta } from '../../../src/short-urls/data';
import type { ShlinkShortUrlMeta, ShlinkShortUrl } from '../../../src/short-urls/data';
import { ShortUrlStatus } from '../../../src/short-urls/helpers/ShortUrlStatus';
describe('<ShortUrlStatus />', () => {
const setUp = (shortUrl: ShortUrl) => ({
const setUp = (shortUrl: ShlinkShortUrl) => ({
user: userEvent.setup(),
...render(<ShortUrlStatus shortUrl={shortUrl} />),
});
it.each([
[
fromPartial<ShortUrlMeta>({ validSince: '2099-01-01T10:30:15' }),
fromPartial<ShlinkShortUrlMeta>({ validSince: '2099-01-01T10:30:15' }),
{},
'This short URL will start working on 2099-01-01 10:30.',
],
[
fromPartial<ShortUrlMeta>({ validUntil: '2020-01-01T10:30:15' }),
fromPartial<ShlinkShortUrlMeta>({ validUntil: '2020-01-01T10:30:15' }),
{},
'This short URL cannot be visited since 2020-01-01 10:30.',
],
[
fromPartial<ShortUrlMeta>({ maxVisits: 10 }),
fromPartial<ShlinkShortUrlMeta>({ maxVisits: 10 }),
fromPartial<ShlinkVisitsSummary>({ total: 10 }),
'This short URL cannot be currently visited because it has reached the maximum amount of 10 visits.',
],
[
fromPartial<ShortUrlMeta>({ maxVisits: 1 }),
fromPartial<ShlinkShortUrlMeta>({ maxVisits: 1 }),
fromPartial<ShlinkVisitsSummary>({ total: 1 }),
'This short URL cannot be currently visited because it has reached the maximum amount of 1 visit.',
],
[{}, {}, 'This short URL can be visited normally.'],
[fromPartial<ShortUrlMeta>({ validUntil: '2099-01-01T10:30:15' }), {}, 'This short URL can be visited normally.'],
[fromPartial<ShortUrlMeta>({ validSince: '2020-01-01T10:30:15' }), {}, 'This short URL can be visited normally.'],
[fromPartial<ShlinkShortUrlMeta>({ validUntil: '2099-01-01T10:30:15' }), {}, 'This short URL can be visited normally.'],
[fromPartial<ShlinkShortUrlMeta>({ validSince: '2020-01-01T10:30:15' }), {}, 'This short URL can be visited normally.'],
[
fromPartial<ShortUrlMeta>({ maxVisits: 10 }),
fromPartial<ShlinkShortUrlMeta>({ maxVisits: 10 }),
fromPartial<ShlinkVisitsSummary>({ total: 1 }),
'This short URL can be visited normally.',
],

View File

@@ -1,11 +1,11 @@
import { render, screen, waitFor } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { fromPartial } from '@total-typescript/shoehorn';
import type { ShortUrl } from '../../../src/short-urls/data';
import type { ShlinkShortUrl } from '../../../src/short-urls/data';
import { ShortUrlVisitsCount } from '../../../src/short-urls/helpers/ShortUrlVisitsCount';
describe('<ShortUrlVisitsCount />', () => {
const setUp = (visitsCount: number, shortUrl: ShortUrl) => ({
const setUp = (visitsCount: number, shortUrl: ShlinkShortUrl) => ({
user: userEvent.setup(),
...render(
<ShortUrlVisitsCount visitsCount={visitsCount} shortUrl={shortUrl} />,

View File

@@ -4,7 +4,7 @@ import { addDays, formatISO, subDays } from 'date-fns';
import { last } from 'ramda';
import { MemoryRouter, useLocation } from 'react-router-dom';
import type { Settings } from '../../../src';
import type { ShortUrl, ShortUrlMeta } from '../../../src/short-urls/data';
import type { ShlinkShortUrlMeta, ShlinkShortUrl } from '../../../src/short-urls/data';
import { ShortUrlsRow as createShortUrlsRow } from '../../../src/short-urls/helpers/ShortUrlsRow';
import { now, parseDate } from '../../../src/utils/dates/helpers/date';
import type { TimeoutToggle } from '../../../src/utils/helpers/hooks';
@@ -15,7 +15,7 @@ import { colorGeneratorMock } from '../../utils/services/__mocks__/ColorGenerato
interface SetUpOptions {
title?: string | null;
tags?: string[];
meta?: ShortUrlMeta;
meta?: ShlinkShortUrlMeta;
settings?: Partial<Settings>;
}
@@ -27,7 +27,7 @@ vi.mock('react-router-dom', async () => ({
describe('<ShortUrlsRow />', () => {
const timeoutToggle = vi.fn(() => true);
const useTimeoutToggle = vi.fn(() => [false, timeoutToggle]) as TimeoutToggle;
const shortUrl: ShortUrl = {
const shortUrl: ShlinkShortUrl = {
shortCode: 'abc123',
shortUrl: 'https://s.test/abc123',
longUrl: 'https://foo.com/bar',

View File

@@ -1,13 +1,13 @@
import { screen } from '@testing-library/react';
import { fromPartial } from '@total-typescript/shoehorn';
import { MemoryRouter } from 'react-router-dom';
import type { ShortUrl } from '../../../src/short-urls/data';
import type { ShlinkShortUrl } from '../../../src/short-urls/data';
import { ShortUrlsRowMenu as createShortUrlsRowMenu } from '../../../src/short-urls/helpers/ShortUrlsRowMenu';
import { renderWithEvents } from '../../__helpers__/setUpTest';
describe('<ShortUrlsRowMenu />', () => {
const ShortUrlsRowMenu = createShortUrlsRowMenu(() => <i>DeleteShortUrlModal</i>, () => <i>QrCodeModal</i>);
const shortUrl = fromPartial<ShortUrl>({
const shortUrl = fromPartial<ShlinkShortUrl>({
shortCode: 'abc123',
shortUrl: 'https://s.test/abc123',
});

View File

@@ -1,5 +1,5 @@
import { fromPartial } from '@total-typescript/shoehorn';
import type { ShortUrl } from '../../../src/short-urls/data';
import type { ShlinkShortUrl } from '../../../src/short-urls/data';
import { shortUrlDataFromShortUrl, urlDecodeShortCode, urlEncodeShortCode } from '../../../src/short-urls/helpers';
describe('helpers', () => {
@@ -8,7 +8,7 @@ describe('helpers', () => {
[undefined, { validateUrls: true }, { longUrl: '', validateUrl: true }],
[undefined, undefined, { longUrl: '', validateUrl: false }],
[
fromPartial<ShortUrl>({ meta: {} }),
fromPartial<ShlinkShortUrl>({ meta: {} }),
{ validateUrls: false },
{
longUrl: undefined,

View File

@@ -1,13 +1,13 @@
import { fromPartial } from '@total-typescript/shoehorn';
import type { ShlinkApiClient } from '../../../src/api-contract';
import type { ShortUrl } from '../../../src/short-urls/data';
import type { ShlinkShortUrl } from '../../../src/short-urls/data';
import {
createShortUrl as createShortUrlCreator,
shortUrlCreationReducerCreator,
} from '../../../src/short-urls/reducers/shortUrlCreation';
describe('shortUrlCreationReducer', () => {
const shortUrl = fromPartial<ShortUrl>({});
const shortUrl = fromPartial<ShlinkShortUrl>({});
const createShortUrlCall = vi.fn();
const buildShlinkApiClient = () => fromPartial<ShlinkApiClient>({ createShortUrl: createShortUrlCall });
const createShortUrl = createShortUrlCreator(buildShlinkApiClient);

View File

@@ -1,7 +1,7 @@
import { fromPartial } from '@total-typescript/shoehorn';
import type { ShlinkApiClient } from '../../../src/api-contract';
import type { RootState } from '../../../src/container/store';
import type { ShortUrl } from '../../../src/short-urls/data';
import type { ShlinkShortUrl } from '../../../src/short-urls/data';
import { shortUrlDetailReducerCreator } from '../../../src/short-urls/reducers/shortUrlDetail';
import type { ShortUrlsList } from '../../../src/short-urls/reducers/shortUrlsList';
@@ -25,7 +25,7 @@ describe('shortUrlDetailReducer', () => {
});
it('return short URL on GET_SHORT_URL_DETAIL', () => {
const actionShortUrl = fromPartial<ShortUrl>({ longUrl: 'foo', shortCode: 'bar' });
const actionShortUrl = fromPartial<ShlinkShortUrl>({ longUrl: 'foo', shortCode: 'bar' });
const state = reducer(
{ loading: true, error: false },
getShortUrlDetail.fulfilled(actionShortUrl, '', { shortCode: '' }),
@@ -58,7 +58,7 @@ describe('shortUrlDetailReducer', () => {
}),
],
])('performs API call when short URL is not found in local state', async (shortUrlsList?: ShortUrlsList) => {
const resolvedShortUrl = fromPartial<ShortUrl>({ longUrl: 'foo', shortCode: 'abc123' });
const resolvedShortUrl = fromPartial<ShlinkShortUrl>({ longUrl: 'foo', shortCode: 'abc123' });
getShortUrlCall.mockResolvedValue(resolvedShortUrl);
await getShortUrlDetail({ shortCode: 'abc123', domain: '' })(dispatchMock, buildGetState(shortUrlsList), {});
@@ -69,8 +69,8 @@ describe('shortUrlDetailReducer', () => {
});
it('avoids API calls when short URL is found in local state', async () => {
const foundShortUrl = fromPartial<ShortUrl>({ longUrl: 'foo', shortCode: 'abc123' });
getShortUrlCall.mockResolvedValue(fromPartial<ShortUrl>({}));
const foundShortUrl = fromPartial<ShlinkShortUrl>({ longUrl: 'foo', shortCode: 'abc123' });
getShortUrlCall.mockResolvedValue(fromPartial<ShlinkShortUrl>({}));
await getShortUrlDetail(foundShortUrl)(
dispatchMock,

View File

@@ -1,5 +1,5 @@
import { fromPartial } from '@total-typescript/shoehorn';
import type { ShortUrl } from '../../../src/short-urls/data';
import type { ShlinkShortUrl } from '../../../src/short-urls/data';
import {
editShortUrl as editShortUrlCreator,
shortUrlEditionReducerCreator,
@@ -8,7 +8,7 @@ import {
describe('shortUrlEditionReducer', () => {
const longUrl = 'https://shlink.io';
const shortCode = 'abc123';
const shortUrl = fromPartial<ShortUrl>({ longUrl, shortCode });
const shortUrl = fromPartial<ShlinkShortUrl>({ longUrl, shortCode });
const updateShortUrl = vi.fn().mockResolvedValue(shortUrl);
const buildShlinkApiClient = vi.fn().mockReturnValue({ updateShortUrl });
const editShortUrl = editShortUrlCreator(buildShlinkApiClient);

View File

@@ -1,6 +1,6 @@
import { fromPartial } from '@total-typescript/shoehorn';
import type { ShlinkApiClient, ShlinkShortUrlsResponse } from '../../../src/api-contract';
import type { ShortUrl } from '../../../src/short-urls/data';
import type { ShlinkShortUrl } from '../../../src/short-urls/data';
import { createShortUrl as createShortUrlCreator } from '../../../src/short-urls/reducers/shortUrlCreation';
import { shortUrlDeleted } from '../../../src/short-urls/reducers/shortUrlDeletion';
import { editShortUrl as editShortUrlCreator } from '../../../src/short-urls/reducers/shortUrlEdition';
@@ -102,36 +102,36 @@ describe('shortUrlsListReducer', () => {
it.each([
[
[
fromPartial<ShortUrl>({ shortCode }),
fromPartial<ShortUrl>({ shortCode, domain: 'example.com' }),
fromPartial<ShortUrl>({ shortCode: 'foo' }),
fromPartial<ShlinkShortUrl>({ shortCode }),
fromPartial<ShlinkShortUrl>({ shortCode, domain: 'example.com' }),
fromPartial<ShlinkShortUrl>({ shortCode: 'foo' }),
],
[{ shortCode: 'newOne' }, { shortCode }, { shortCode, domain: 'example.com' }, { shortCode: 'foo' }],
],
[
[
fromPartial<ShortUrl>({ shortCode }),
fromPartial<ShortUrl>({ shortCode: 'code' }),
fromPartial<ShortUrl>({ shortCode: 'foo' }),
fromPartial<ShortUrl>({ shortCode: 'bar' }),
fromPartial<ShortUrl>({ shortCode: 'baz' }),
fromPartial<ShlinkShortUrl>({ shortCode }),
fromPartial<ShlinkShortUrl>({ shortCode: 'code' }),
fromPartial<ShlinkShortUrl>({ shortCode: 'foo' }),
fromPartial<ShlinkShortUrl>({ shortCode: 'bar' }),
fromPartial<ShlinkShortUrl>({ shortCode: 'baz' }),
],
[{ shortCode: 'newOne' }, { shortCode }, { shortCode: 'code' }, { shortCode: 'foo' }, { shortCode: 'bar' }],
],
[
[
fromPartial<ShortUrl>({ shortCode }),
fromPartial<ShortUrl>({ shortCode: 'code' }),
fromPartial<ShortUrl>({ shortCode: 'foo' }),
fromPartial<ShortUrl>({ shortCode: 'bar' }),
fromPartial<ShortUrl>({ shortCode: 'baz1' }),
fromPartial<ShortUrl>({ shortCode: 'baz2' }),
fromPartial<ShortUrl>({ shortCode: 'baz3' }),
fromPartial<ShlinkShortUrl>({ shortCode }),
fromPartial<ShlinkShortUrl>({ shortCode: 'code' }),
fromPartial<ShlinkShortUrl>({ shortCode: 'foo' }),
fromPartial<ShlinkShortUrl>({ shortCode: 'bar' }),
fromPartial<ShlinkShortUrl>({ shortCode: 'baz1' }),
fromPartial<ShlinkShortUrl>({ shortCode: 'baz2' }),
fromPartial<ShlinkShortUrl>({ shortCode: 'baz3' }),
],
[{ shortCode: 'newOne' }, { shortCode }, { shortCode: 'code' }, { shortCode: 'foo' }, { shortCode: 'bar' }],
],
])('prepends new short URL and increases total on CREATE_SHORT_URL', (data, expectedData) => {
const newShortUrl = fromPartial<ShortUrl>({ shortCode: 'newOne' });
const newShortUrl = fromPartial<ShlinkShortUrl>({ shortCode: 'newOne' });
const state = {
shortUrls: fromPartial<ShlinkShortUrlsResponse>({
data,
@@ -152,15 +152,15 @@ describe('shortUrlsListReducer', () => {
});
it.each([
((): [ShortUrl, ShortUrl[], ShortUrl[]] => {
const editedShortUrl = fromPartial<ShortUrl>({ shortCode: 'notMatching' });
const list: ShortUrl[] = [fromPartial({ shortCode: 'foo' }), fromPartial({ shortCode: 'bar' })];
((): [ShlinkShortUrl, ShlinkShortUrl[], ShlinkShortUrl[]] => {
const editedShortUrl = fromPartial<ShlinkShortUrl>({ shortCode: 'notMatching' });
const list: ShlinkShortUrl[] = [fromPartial({ shortCode: 'foo' }), fromPartial({ shortCode: 'bar' })];
return [editedShortUrl, list, list];
})(),
((): [ShortUrl, ShortUrl[], ShortUrl[]] => {
const editedShortUrl = fromPartial<ShortUrl>({ shortCode: 'matching', longUrl: 'new_one' });
const list: ShortUrl[] = [
((): [ShlinkShortUrl, ShlinkShortUrl[], ShlinkShortUrl[]] => {
const editedShortUrl = fromPartial<ShlinkShortUrl>({ shortCode: 'matching', longUrl: 'new_one' });
const list: ShlinkShortUrl[] = [
fromPartial({ shortCode: 'matching', longUrl: 'old_one' }),
fromPartial({ shortCode: 'bar' }),
];