Skip to content

High performance self-hosted photo and video management solution.

1.6 KB
Raw Blame
import request from 'supertest';
import { PluginController } from 'src/controllers/plugin.controller.js';
import { LoggingRepository } from 'src/repositories/logging.repository.js';
import { PluginService } from 'src/services/plugin.service.js';
import { errorDto } from 'test/medium/responses.js';
import { ControllerContext, automock, controllerSetup, mockBaseService } from 'test/utils.js';

describe(PluginController.name, () => {
  let ctx: ControllerContext;
  const service = mockBaseService(PluginService);

  beforeAll(async () => {
    ctx = await controllerSetup(PluginController, [
      { provide: PluginService, useValue: service },
      { provide: LoggingRepository, useValue: automock(LoggingRepository, { strict: false }) },
    ]);
    return () => ctx.close();
  });

  beforeEach(() => {
    service.resetAllMocks();
    ctx.reset();
  });

  describe('GET /plugins', () => {
    it(`should require id to be a uuid`, async () => {
      const { status, body } = await request(ctx.getHttpServer())
        .get(`/plugins`)
        .query({ id: 'invalid' })
        .set('Authorization', `Bearer token`);
      expect(status).toBe(400);
      expect(body).toEqual(errorDto.validationError([{ path: ['id'], message: 'Invalid UUID' }]));
    });
  });

  describe('GET /plugins/:id', () => {
    it(`should require id to be a uuid`, async () => {
      const { status, body } = await request(ctx.getHttpServer())
        .get(`/plugins/invalid`)
        .set('Authorization', `Bearer token`);
      expect(status).toBe(400);
      expect(body).toEqual(errorDto.validationError([{ path: ['id'], message: 'Invalid UUID' }]));
    });
  });
});