2023-04-13 22:48:29 +03:00
|
|
|
import { fromPartial } from '@total-typescript/shoehorn';
|
2023-07-24 21:14:59 +03:00
|
|
|
import type { ShortUrl } from '../../../shlink-web-component/short-urls/data';
|
|
|
|
import { shortUrlDataFromShortUrl, urlDecodeShortCode, urlEncodeShortCode } from '../../../shlink-web-component/short-urls/helpers';
|
2022-06-12 21:41:40 +03:00
|
|
|
|
|
|
|
describe('helpers', () => {
|
|
|
|
describe('shortUrlDataFromShortUrl', () => {
|
|
|
|
it.each([
|
|
|
|
[undefined, { validateUrls: true }, { longUrl: '', validateUrl: true }],
|
|
|
|
[undefined, undefined, { longUrl: '', validateUrl: false }],
|
|
|
|
[
|
2023-04-13 22:48:29 +03:00
|
|
|
fromPartial<ShortUrl>({ meta: {} }),
|
2022-06-12 21:41:40 +03:00
|
|
|
{ validateUrls: false },
|
|
|
|
{
|
|
|
|
longUrl: undefined,
|
|
|
|
tags: undefined,
|
|
|
|
title: undefined,
|
|
|
|
domain: undefined,
|
|
|
|
validSince: undefined,
|
|
|
|
validUntil: undefined,
|
|
|
|
maxVisits: undefined,
|
|
|
|
validateUrl: false,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
])('returns expected data', (shortUrl, settings, expectedInitialState) => {
|
|
|
|
expect(shortUrlDataFromShortUrl(shortUrl, settings)).toEqual(expectedInitialState);
|
|
|
|
});
|
|
|
|
});
|
2022-08-07 19:19:53 +03:00
|
|
|
|
|
|
|
describe('urlEncodeShortCode', () => {
|
|
|
|
it.each([
|
|
|
|
['foo', 'foo'],
|
|
|
|
['foo/bar', 'foo__bar'],
|
|
|
|
['foo/bar/baz', 'foo__bar__baz'],
|
|
|
|
])('parses shortCode as expected', (shortCode, result) => {
|
|
|
|
expect(urlEncodeShortCode(shortCode)).toEqual(result);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('urlDecodeShortCode', () => {
|
|
|
|
it.each([
|
|
|
|
['foo', 'foo'],
|
|
|
|
['foo__bar', 'foo/bar'],
|
|
|
|
['foo__bar__baz', 'foo/bar/baz'],
|
|
|
|
])('parses shortCode as expected', (shortCode, result) => {
|
|
|
|
expect(urlDecodeShortCode(shortCode)).toEqual(result);
|
|
|
|
});
|
|
|
|
});
|
2022-06-12 21:41:40 +03:00
|
|
|
});
|