You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
32 lines
1.8 KiB
32 lines
1.8 KiB
import { describe, expect, test } from 'bun:test'
|
|
import { buildPublicCanonicalUrl } from './public-canonical-url'
|
|
|
|
describe('buildPublicCanonicalUrl', () => {
|
|
test('builds canonical with full path', () => {
|
|
expect(buildPublicCanonicalUrl('https://example.com', '/@alice/posts?page=2')).toBe('https://example.com/@alice/posts?page=2')
|
|
})
|
|
|
|
test('drops hash fragment', () => {
|
|
expect(buildPublicCanonicalUrl('https://example.com', '/@alice/reading#section')).toBe('https://example.com/@alice/reading')
|
|
})
|
|
|
|
test('removes page=1 from canonical', () => {
|
|
expect(buildPublicCanonicalUrl('https://example.com', '/@alice/timeline?page=1')).toBe('https://example.com/@alice/timeline')
|
|
})
|
|
|
|
test('removes page=1 equivalent query forms from canonical', () => {
|
|
expect(buildPublicCanonicalUrl('https://example.com', '/@alice/timeline?page=01')).toBe('https://example.com/@alice/timeline')
|
|
expect(buildPublicCanonicalUrl('https://example.com', '/@alice/timeline?page=%2B1')).toBe('https://example.com/@alice/timeline')
|
|
expect(buildPublicCanonicalUrl('https://example.com', '/@alice/timeline?foo=bar&page=1.0')).toBe('https://example.com/@alice/timeline?foo=bar')
|
|
expect(buildPublicCanonicalUrl('https://example.com', '/@alice/timeline?page=1&page=001')).toBe('https://example.com/@alice/timeline')
|
|
})
|
|
|
|
test('keeps non-first-page values', () => {
|
|
expect(buildPublicCanonicalUrl('https://example.com', '/@alice/timeline?page=2')).toBe('https://example.com/@alice/timeline?page=2')
|
|
expect(buildPublicCanonicalUrl('https://example.com', '/@alice/timeline?page=1&page=2')).toBe('https://example.com/@alice/timeline?page=1&page=2')
|
|
})
|
|
|
|
test('returns null when siteUrl is invalid', () => {
|
|
expect(buildPublicCanonicalUrl('not-a-url', '/@alice')).toBeNull()
|
|
})
|
|
})
|
|
|