2026-04-18 16:32:30 +02:00
|
|
|
import { describe, it, expect } from 'vitest';
|
|
|
|
|
import { resolveStrategy } from '../../src/lib/sw/cache-strategy';
|
|
|
|
|
|
|
|
|
|
describe('resolveStrategy', () => {
|
|
|
|
|
it('images bucket for /images/*', () => {
|
|
|
|
|
expect(resolveStrategy({ url: '/images/favicon-abc.png', method: 'GET' })).toBe('images');
|
|
|
|
|
});
|
|
|
|
|
|
2026-04-20 08:29:00 +02:00
|
|
|
it('network-first for recipe HTML pages', () => {
|
|
|
|
|
expect(resolveStrategy({ url: '/recipes/42', method: 'GET' })).toBe('network-first');
|
2026-04-18 16:32:30 +02:00
|
|
|
});
|
|
|
|
|
|
2026-04-20 08:29:00 +02:00
|
|
|
it('network-first for recipe API reads', () => {
|
|
|
|
|
expect(resolveStrategy({ url: '/api/recipes/42', method: 'GET' })).toBe('network-first');
|
|
|
|
|
expect(resolveStrategy({ url: '/api/recipes/all?sort=name', method: 'GET' })).toBe(
|
|
|
|
|
'network-first'
|
|
|
|
|
);
|
|
|
|
|
expect(resolveStrategy({ url: '/api/wishlist', method: 'GET' })).toBe('network-first');
|
2026-04-18 16:32:30 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('network-only for write methods', () => {
|
|
|
|
|
expect(resolveStrategy({ url: '/api/recipes/42', method: 'PATCH' })).toBe('network-only');
|
|
|
|
|
expect(resolveStrategy({ url: '/api/recipes/42/favorite', method: 'PUT' })).toBe('network-only');
|
|
|
|
|
expect(resolveStrategy({ url: '/api/wishlist', method: 'POST' })).toBe('network-only');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('network-only for online-only endpoints even on GET', () => {
|
|
|
|
|
expect(resolveStrategy({ url: '/api/recipes/import', method: 'GET' })).toBe('network-only');
|
|
|
|
|
expect(resolveStrategy({ url: '/api/recipes/preview?url=x', method: 'GET' })).toBe('network-only');
|
|
|
|
|
expect(resolveStrategy({ url: '/api/recipes/search/web?q=x', method: 'GET' })).toBe('network-only');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('shell bucket for build/static assets', () => {
|
|
|
|
|
expect(resolveStrategy({ url: '/_app/immutable/chunks/x.js', method: 'GET' })).toBe('shell');
|
|
|
|
|
expect(resolveStrategy({ url: '/icon-192.png', method: 'GET' })).toBe('shell');
|
|
|
|
|
expect(resolveStrategy({ url: '/manifest.webmanifest', method: 'GET' })).toBe('shell');
|
|
|
|
|
});
|
|
|
|
|
|
2026-04-20 08:29:00 +02:00
|
|
|
it('falls through to network-first for other same-origin GETs (e.g. root page)', () => {
|
|
|
|
|
expect(resolveStrategy({ url: '/', method: 'GET' })).toBe('network-first');
|
|
|
|
|
expect(resolveStrategy({ url: '/wishlist', method: 'GET' })).toBe('network-first');
|
2026-04-18 16:32:30 +02:00
|
|
|
});
|
|
|
|
|
});
|