Add Redirect.isMatch tests.

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

View File

@ -57,3 +57,35 @@ test('Redirect.redirect', (t) => {
);
}
});
test('Redirect.isMatch', (t) => {
type UrlSamples = Array<[string, boolean]>;
const hostnameRedirect = new HostnameRedirect({
hostname: 'example.org',
matchType: 'hostname',
toMatch: 'example.com',
type: 'hostname',
});
const hostnameSamples: UrlSamples = [
['https://example.com', true],
['https://www.example.com', false],
['https://example.org', false],
];
const invalidRedirect = new HostnameRedirect({
test: 'invalid',
} as unknown as Redirects['parameters']);
const samples: Array<[Redirects, UrlSamples]> = [
[invalidRedirect, [['https://example.org', false]]],
[hostnameRedirect, hostnameSamples],
];
for (const [redirect, urlSamples] of samples) {
for (const [sample, expected] of urlSamples) {
t.is(redirect.isMatch(new URL(sample)), expected);
}
}
});