Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions src/http/platform/uws-platform.adapter.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -534,15 +534,19 @@ describe('UwsPlatformAdapter', () => {
it('should enable static assets and register catch-all route', () => {
adapter.useStaticAssets('/public');

// Should register a GET route for /*
// Should register both GET and HEAD routes for /*
expect(mockRegistry.register).toHaveBeenCalledTimes(2);
expect(mockRegistry.register).toHaveBeenCalledWith('GET', '/*', expect.any(Function));
expect(mockRegistry.register).toHaveBeenCalledWith('HEAD', '/*', expect.any(Function));
});

it('should respect silent option and not log', () => {
adapter.useStaticAssets('/public', { silent: true });

// Should still register the route
// Should still register both GET and HEAD routes
expect(mockRegistry.register).toHaveBeenCalledTimes(2);
expect(mockRegistry.register).toHaveBeenCalledWith('GET', '/*', expect.any(Function));
expect(mockRegistry.register).toHaveBeenCalledWith('HEAD', '/*', expect.any(Function));
});

it('should register static assets route when custom options provided', () => {
Expand All @@ -551,8 +555,10 @@ describe('UwsPlatformAdapter', () => {
etag: false,
});

// Should register the route
// Should register both GET and HEAD routes
expect(mockRegistry.register).toHaveBeenCalledTimes(2);
expect(mockRegistry.register).toHaveBeenCalledWith('GET', '/*', expect.any(Function));
expect(mockRegistry.register).toHaveBeenCalledWith('HEAD', '/*', expect.any(Function));
});

it('should register multiple static asset routes when called multiple times', () => {
Expand All @@ -572,22 +578,28 @@ describe('UwsPlatformAdapter', () => {
it('should support prefix option for scoped static routes', () => {
adapter.useStaticAssets('/public', { prefix: '/assets' });

// Should register route with prefix
// Should register both GET and HEAD routes with the prefix
expect(mockRegistry.register).toHaveBeenCalledTimes(2);
expect(mockRegistry.register).toHaveBeenCalledWith('GET', '/assets/*', expect.any(Function));
expect(mockRegistry.register).toHaveBeenCalledWith('HEAD', '/assets/*', expect.any(Function));
});

it('should normalize prefix by removing trailing slash', () => {
adapter.useStaticAssets('/public', { prefix: '/assets/' });

// Should register route with normalized prefix (no trailing slash)
// Should register both GET and HEAD routes with normalized prefix (no trailing slash)
expect(mockRegistry.register).toHaveBeenCalledTimes(2);
expect(mockRegistry.register).toHaveBeenCalledWith('GET', '/assets/*', expect.any(Function));
expect(mockRegistry.register).toHaveBeenCalledWith('HEAD', '/assets/*', expect.any(Function));
});

it('should handle empty prefix by using default catch-all', () => {
adapter.useStaticAssets('/public', { prefix: '' });

// Should register default catch-all route
// Should register both GET and HEAD default catch-all routes
expect(mockRegistry.register).toHaveBeenCalledTimes(2);
expect(mockRegistry.register).toHaveBeenCalledWith('GET', '/*', expect.any(Function));
expect(mockRegistry.register).toHaveBeenCalledWith('HEAD', '/*', expect.any(Function));
});

it('should throw error for invalid path (non-string)', () => {
Expand Down
Loading