import { GUARDS_METADATA } from '@nestjs/common/constants';
import { JwtAuthGuard } from '../../common/guards/jwt-auth.guard';
import { DirectMediaUploadController } from './direct-media-upload.controller';

describe('DirectMediaUploadController', () => {
  it('delegates the authenticated user id and validated request fields', async () => {
    const mediaStorageService = {
      createPresignedUpload: jest.fn().mockResolvedValue({ uploadUrl: 'signed' }),
    };
    const controller = new DirectMediaUploadController(mediaStorageService as never);

    await expect(
      controller.createPresignedUpload(
        { sub: 'user-1', username: 'artist', tokenType: 'access' },
        { folder: 'posts/images', mimeType: 'image/jpeg', size: 2048 },
      ),
    ).resolves.toEqual({ uploadUrl: 'signed' });
    expect(mediaStorageService.createPresignedUpload).toHaveBeenCalledWith({
      userId: 'user-1',
      folder: 'posts/images',
      mimeType: 'image/jpeg',
      size: 2048,
    });
  });

  it('is protected by the JWT guard at controller level', () => {
    const guards = Reflect.getMetadata(GUARDS_METADATA, DirectMediaUploadController) as unknown[];

    expect(guards).toContain(JwtAuthGuard);
  });
});
