Reduce duplication.

This commit is contained in:
Bauke 2022-10-13 00:23:32 +02:00
parent 814c718c41
commit aa9a7121f8
Signed by: Bauke
GPG Key ID: C1C0F29952BCF558
1 changed files with 10 additions and 19 deletions

View File

@ -10,17 +10,19 @@ import {
RedirectParameters, RedirectParameters,
} from '../source/redirect/exports.js'; } from '../source/redirect/exports.js';
const hostnameParameters: HostnameRedirect['parameters'] = {
hostname: 'example.org',
matchType: 'hostname',
toMatch: 'example.com',
type: 'hostname',
};
test('parseRedirect', (t) => { test('parseRedirect', (t) => {
const samples: Array<Redirects['parameters']> = [ const samples: Array<Redirects['parameters']> = [
{ {
test: 'Invalid parameters', test: 'Invalid parameters',
} as unknown as Redirects['parameters'], } as unknown as Redirects['parameters'],
{ hostnameParameters,
hostname: 'example.org',
matchType: 'hostname',
toMatch: 'example.com',
type: 'hostname',
},
]; ];
for (const sample of samples) { for (const sample of samples) {
@ -35,12 +37,7 @@ test('parseRedirect', (t) => {
}); });
test('Redirect.redirect', (t) => { test('Redirect.redirect', (t) => {
const hostnameRedirect = new HostnameRedirect({ const hostnameRedirect = new HostnameRedirect(hostnameParameters);
matchType: 'hostname',
toMatch: 'example.com',
hostname: 'example.org',
type: 'hostname',
});
const samples: Array<[string, Redirect<RedirectParameters>]> = [ const samples: Array<[string, Redirect<RedirectParameters>]> = [
['https://example.com', hostnameRedirect], ['https://example.com', hostnameRedirect],
@ -61,13 +58,7 @@ test('Redirect.redirect', (t) => {
test('Redirect.isMatch', (t) => { test('Redirect.isMatch', (t) => {
type UrlSamples = Array<[string, boolean]>; type UrlSamples = Array<[string, boolean]>;
const hostnameRedirect = new HostnameRedirect({ const hostnameRedirect = new HostnameRedirect(hostnameParameters);
hostname: 'example.org',
matchType: 'hostname',
toMatch: 'example.com',
type: 'hostname',
});
const hostnameSamples: UrlSamples = [ const hostnameSamples: UrlSamples = [
['https://example.com', true], ['https://example.com', true],
['https://www.example.com', false], ['https://www.example.com', false],