import { GUARDS_METADATA } from '@nestjs/common/constants';
import { RoleEnum } from '../roles/roles.enum';
import { RolesGuard } from '../roles/roles.guard';
import { CashboxExportController } from './cashbox-export.controller';

describe('CashboxExportController.runDueSubscriptionsNow', () => {
  const service = { exportForUser: jest.fn() };
  const subscriptionService = { getSubscription: jest.fn(), upsertSubscription: jest.fn() };
  const scheduler = { runDueSubscriptions: jest.fn() };
  const controller = new CashboxExportController(
    service as any,
    subscriptionService as any,
    scheduler as any,
  );

  beforeEach(() => jest.clearAllMocks());

  it('is guarded by the global admin role', () => {
    expect(
      Reflect.getMetadata('roles', CashboxExportController.prototype.runDueSubscriptionsNow),
    ).toEqual([RoleEnum.admin]);
    expect(
      Reflect.getMetadata(GUARDS_METADATA, CashboxExportController.prototype.runDueSubscriptionsNow),
    ).toContain(RolesGuard);
  });

  it('delegates to the scheduler', async () => {
    await controller.runDueSubscriptionsNow();

    expect(scheduler.runDueSubscriptions).toHaveBeenCalledTimes(1);
  });
});
