Skip to content

Self-hosted personal gallery application with online photo management and albums, supporting Live/Motion Photos, EXIF parsing, geolocation recognition, and an explore map.

test(site): cover slug navigation in middleware regressions

Timothy Yin24a487f5ca88
diff --git a/tests/portal-review-regressions.test.ts b/tests/portal-review-regressions.test.ts
index 92b79609..34a2c9fd 100644
--- a/tests/portal-review-regressions.test.ts
+++ b/tests/portal-review-regressions.test.ts
@@ -3,6 +3,7 @@ import { readFileSync } from 'node:fs'
import test from 'node:test'
import vm from 'node:vm'
import ts from 'typescript'
+import { isAlbumPagePath } from '../packages/gallery/shared/utils/albumPath.ts'
import { ref, reactive, computed, readonly, watch, effectScope } from 'vue'
function load(
@@ -202,20 +203,36 @@ test('shuffle options react to the scoped selection without mutating another ent
test('public navigation accepts case-preserving photo IDs while rejecting invalid and oversized paths', async () => {
let context: any = { value: null }
- const module = load('apps/site/app/middleware/site.global.ts', {
- defineNuxtRouteMiddleware: (fn: unknown) => fn,
- useEntryContext: () => context,
- useRequestFetch: () => async () => ({ scope: 'public:one' }),
- navigateTo: () => {},
- abortNavigation: (error: unknown) => error,
- createError: (error: unknown) => error,
- })
- for (const path of ['/IMG_1234', '/Mixed-Case_1', '/photos', '/albums/1'])
+ const module = load(
+ 'apps/site/app/middleware/site.global.ts',
+ {
+ defineNuxtRouteMiddleware: (fn: unknown) => fn,
+ useEntryContext: () => context,
+ useRequestFetch: () => async () => ({ scope: 'public:one' }),
+ navigateTo: () => {},
+ abortNavigation: (error: unknown) => error,
+ createError: (error: unknown) => error,
+ },
+ {
+ '@chronoframe/gallery/shared/utils/albumPath': { isAlbumPagePath },
+ },
+ )
+ for (const path of [
+ '/IMG_1234',
+ '/Mixed-Case_1',
+ '/photos',
+ '/albums/1',
+ '/albums/my-gallery',
+ '/albums/' + 'a'.repeat(80),
+ ])
assert.equal(await module.default({ path }), undefined, path)
for (const path of [
'/bad!',
'/' + 'A'.repeat(129),
'/nested/path',
+ '/albums/Mixed-Case',
+ '/albums/bad--slug',
+ '/albums/' + 'a'.repeat(81),
'/dashboard',
])
assert.equal((await module.default({ path })).statusCode, 404, path)
diff --git a/tests/site-middleware.test.ts b/tests/site-middleware.test.ts
index a9fffebb..4e66aa0d 100644
--- a/tests/site-middleware.test.ts
+++ b/tests/site-middleware.test.ts
@@ -3,6 +3,7 @@ import test from 'node:test'
import { readFileSync } from 'node:fs'
import vm from 'node:vm'
import ts from 'typescript'
+import { isAlbumPagePath } from '../packages/gallery/shared/utils/albumPath.ts'
import { ref, watch } from 'vue'
test('same-Site hydration preserves state; scope changes and rejected navigation clear it', async () => {
@@ -21,6 +22,10 @@ test('same-Site hydration preserves state; scope changes and rejected navigation
).outputText
vm.runInNewContext(code, {
exports,
+ require: (name: string) => {
+ assert.equal(name, '@chronoframe/gallery/shared/utils/albumPath')
+ return { isAlbumPagePath }
+ },
defineNuxtRouteMiddleware: (fn: unknown) => fn,
useEntryContext: () => context,
useRequestFetch: () => async () => {