0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-20 22:42:53 -05:00
ghost/apps/admin-x-settings/test/unit/utils/url.test.ts
Sag 8515bdf587
Updated uniqueness validation for the Recommendations URL (#18253)
closes https://github.com/TryGhost/Product/issues/3818

- instead of fetching all recommendations and matching URLs on the frontend, we now query the database directly to find an existing Recommendation by URL. When comparing URLs, we don't take into account the protocol, www, query parameters nor hash fragments
2023-09-20 16:53:10 +00:00

29 lines
1 KiB
TypeScript

import * as assert from 'assert/strict';
import {trimHash, trimSearch, trimSearchAndHash} from '../../../src/utils/url';
describe('trimSearch', function () {
it('removes the query parameters from a URL', function () {
const url = 'https://example.com/?foo=bar&baz=qux';
const parsedUrl = new URL(url);
assert.equal(trimSearch(parsedUrl).toString(), 'https://example.com/');
});
});
describe('trimHash', function () {
it('removes the hash fragment from a URL', function () {
const url = 'https://example.com/path#section-1';
const parsedUrl = new URL(url);
assert.equal(trimHash(parsedUrl).toString(), 'https://example.com/path');
});
});
describe('trimSearchAndHash', function () {
it('removes the hash fragment from a URL', function () {
const url = 'https://example.com/path#section-1?foo=bar&baz=qux';
const parsedUrl = new URL(url);
assert.equal(trimSearchAndHash(parsedUrl).toString(), 'https://example.com/path');
});
});