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,