Files
twenty/packages/twenty-server/src/engine/integrations/captcha/captcha.module.ts
Charles Bochet 158e7a31f4 Improve tests (#5994)
Our tests on FE are red, which is a threat to code quality. I'm adding a
few unit tests to improve the coverage and lowering a bit the lines
coverage threshold
2024-06-23 20:12:18 +02:00

43 lines
1.3 KiB
TypeScript

import { DynamicModule, Global } from '@nestjs/common';
import { CAPTCHA_DRIVER } from 'src/engine/integrations/captcha/captcha.constants';
import { CaptchaService } from 'src/engine/integrations/captcha/captcha.service';
import { GoogleRecaptchaDriver } from 'src/engine/integrations/captcha/drivers/google-recaptcha.driver';
import { TurnstileDriver } from 'src/engine/integrations/captcha/drivers/turnstile.driver';
import {
CaptchaDriverType,
CaptchaModuleAsyncOptions,
} from 'src/engine/integrations/captcha/interfaces';
@Global()
export class CaptchaModule {
static forRoot(options: CaptchaModuleAsyncOptions): DynamicModule {
const provider = {
provide: CAPTCHA_DRIVER,
useFactory: async (...args: any[]) => {
const config = await options.useFactory(...args);
if (!config) {
return;
}
switch (config.type) {
case CaptchaDriverType.GoogleRecaptcha:
return new GoogleRecaptchaDriver(config.options);
case CaptchaDriverType.Turnstile:
return new TurnstileDriver(config.options);
default:
return;
}
},
inject: options.inject || [],
};
return {
module: CaptchaModule,
providers: [CaptchaService, provider],
exports: [CaptchaService],
};
}
}