Skip to content

Commit

Permalink
chore: mr changes
Browse files Browse the repository at this point in the history
  • Loading branch information
tnramalho committed Jan 10, 2025
1 parent 4008b0f commit 29c7a08
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 132 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ import { UserFixture } from '../user.fixture';
export class UserMutateServiceFixture
implements AuthVerifyUserMutateServiceInterface
{
// ReferenceIdInterface & ReferenceActiveInterface,
// ReferenceIdInterface & ReferenceEmailInterface & ReferenceActiveInterface,
async update(
object: ReferenceIdInterface<string> & ReferenceActiveInterface,
): ReturnType<AuthVerifyUserMutateServiceInterface['update']> {
Expand Down
124 changes: 9 additions & 115 deletions packages/nestjs-auth-verify/src/auth-verify.module.spec.ts
Original file line number Diff line number Diff line change
@@ -1,40 +1,25 @@
import { mock } from 'jest-mock-extended';
import {
DynamicModule,
Inject,
Injectable,
Module,
ModuleMetadata,
} from '@nestjs/common';
import { DynamicModule, ModuleMetadata } from '@nestjs/common';
import { Test, TestingModule } from '@nestjs/testing';
import { mock } from 'jest-mock-extended';

import { EmailModule, EmailService } from '@concepta/nestjs-email';

import {
AUTH_VERIFY_MODULE_EMAIL_SERVICE_TOKEN,
AUTH_VERIFY_MODULE_OTP_SERVICE_TOKEN,
AUTH_VERIFY_MODULE_SETTINGS_TOKEN,
AUTH_VERIFY_MODULE_USER_LOOKUP_SERVICE_TOKEN,
AUTH_VERIFY_MODULE_USER_MUTATE_SERVICE_TOKEN,
} from './auth-verify.constants';

import { AuthVerifySettingsInterface } from './interfaces/auth-verify-settings.interface';
import { AuthVerifyOtpServiceInterface } from './interfaces/auth-verify-otp.service.interface';
import { AuthVerifyController } from './auth-verify.controller';
import { AuthVerifyModule } from './auth-verify.module';
import { AuthVerifyEmailServiceInterface } from './interfaces/auth-verify-email.service.interface';
import { AuthVerifyOtpServiceInterface } from './interfaces/auth-verify-otp.service.interface';
import { AuthVerifyUserLookupServiceInterface } from './interfaces/auth-verify-user-lookup.service.interface';
import { AuthVerifyUserMutateServiceInterface } from './interfaces/auth-verify-user-mutate.service.interface';
import { AuthVerifyServiceInterface } from './interfaces/auth-verify.service.interface';
import { AuthVerifyController } from './auth-verify.controller';
import { AuthVerifyModule } from './auth-verify.module';
import { AuthVerifyService } from './services/auth-verify.service';

import { UserLookupServiceFixture } from './__fixtures__/user/services/user-lookup.service.fixture';
import { UserModuleFixture } from './__fixtures__/user/user.module.fixture';
import { MailerServiceFixture } from './__fixtures__/email/mailer.service.fixture';
import { OtpModuleFixture } from './__fixtures__/otp/otp.module.fixture';
import { UserMutateServiceFixture } from './__fixtures__/user/services/user-mutate.service.fixture';
import { OtpServiceFixture } from './__fixtures__/otp/otp.service.fixture';
import { MailerServiceFixture } from './__fixtures__/email/mailer.service.fixture';
import { TypeOrmModuleFixture } from './__fixtures__/typeorm.module.fixture';
import { UserLookupServiceFixture } from './__fixtures__/user/services/user-lookup.service.fixture';
import { UserMutateServiceFixture } from './__fixtures__/user/services/user-mutate.service.fixture';
import { UserModuleFixture } from './__fixtures__/user/user.module.fixture';

describe(AuthVerifyModule, () => {
let testModule: TestingModule;
Expand Down Expand Up @@ -154,97 +139,6 @@ describe(AuthVerifyModule, () => {
});
});

describe(AuthVerifyModule.forFeature, () => {
@Module({})
class GlobalModule {}

@Module({})
class ForFeatureModule {}

@Injectable()
class TestService {
constructor(
@Inject(AUTH_VERIFY_MODULE_SETTINGS_TOKEN)
public settings: AuthVerifySettingsInterface,
@Inject(AUTH_VERIFY_MODULE_EMAIL_SERVICE_TOKEN)
public emailService: AuthVerifyEmailServiceInterface,
@Inject(AUTH_VERIFY_MODULE_OTP_SERVICE_TOKEN)
public otpService: AuthVerifyOtpServiceInterface,
@Inject(AUTH_VERIFY_MODULE_USER_LOOKUP_SERVICE_TOKEN)
public userLookupService: AuthVerifyUserLookupServiceInterface,
@Inject(AUTH_VERIFY_MODULE_USER_MUTATE_SERVICE_TOKEN)
public userMutateService: AuthVerifyUserMutateServiceInterface,
) {}
}

let testService: TestService;
const ffEmailService = mock<AuthVerifyEmailServiceInterface>();
const ffOtpService = new OtpServiceFixture();
const ffUserLookupService = new UserLookupServiceFixture();
const ffUserMutateService = new UserMutateServiceFixture();

beforeEach(async () => {
const globalModule = testModuleFactory([
AuthVerifyModule.forRootAsync({
inject: [
UserLookupServiceFixture,
UserMutateServiceFixture,
OtpServiceFixture,
EmailService,
],
useFactory: (
userLookupService,
userMutateService,
otpService,
emailService,
) => ({
userLookupService,
userMutateService,
otpService,
emailService,
}),
}),
]);

testModule = await Test.createTestingModule({
imports: [
{ module: GlobalModule, ...globalModule },
{
module: ForFeatureModule,
imports: [
AuthVerifyModule.forFeature({
emailService: ffEmailService,
otpService: ffOtpService,
userLookupService: ffUserLookupService,
userMutateService: ffUserMutateService,
}),
],
providers: [TestService],
},
],
}).compile();

testService = testModule.get(TestService);
});

it('module should be loaded', async () => {
commonVars();
commonTests();
});

it('should have custom providers', async () => {
commonVars();
expect(testService.emailService).toBe(ffEmailService);
expect(testService.emailService).not.toBe(emailService);
expect(testService.otpService).toBe(ffOtpService);
expect(testService.otpService).not.toBe(otpService);
expect(testService.userLookupService).toBe(ffUserLookupService);
expect(testService.userLookupService).not.toBe(userLookupService);
expect(testService.userMutateService).toBe(ffUserMutateService);
expect(testService.userMutateService).not.toBe(userMutateService);
});
});

function commonVars() {
authVerifyModule = testModule.get<AuthVerifyModule>(AuthVerifyModule);
otpService =
Expand Down
14 changes: 0 additions & 14 deletions packages/nestjs-auth-verify/src/auth-verify.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@ import {
AuthVerifyAsyncOptions,
AuthVerifyModuleClass,
AuthVerifyOptions,
createAuthVerifyControllers,
createAuthVerifyExports,
createAuthVerifyImports,
createAuthVerifyProviders,
} from './auth-verify.module-definition';

@Module({})
Expand All @@ -27,14 +23,4 @@ export class AuthVerifyModule extends AuthVerifyModuleClass {
static forRootAsync(options: AuthVerifyAsyncOptions): DynamicModule {
return super.registerAsync({ ...options, global: true });
}

static forFeature(options: AuthVerifyOptions): DynamicModule {
return {
module: AuthVerifyModule,
imports: createAuthVerifyImports(),
providers: createAuthVerifyProviders({ overrides: options }),
controllers: createAuthVerifyControllers(options),
exports: createAuthVerifyExports(),
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { AuthVerifySendParamsInterface } from '../interfaces/auth-verify-send-pa
import { AuthVerifyConfirmParamsInterface } from '../interfaces/auth-verify-confirm-params.interface';
import { AuthVerifyRevokeParamsInterface } from '../interfaces/auth-verify-revoke-params.interface';
import { AuthVerifyValidateParamsInterface } from '../interfaces/auth-verify-validate-params.interface';
import { AuthVerifyNotificationServiceInterface } from '../interfaces/auth-verify-notification.service.interface';

@Injectable()
export class AuthVerifyService implements AuthVerifyServiceInterface {
Expand All @@ -34,7 +35,8 @@ export class AuthVerifyService implements AuthVerifyServiceInterface {
private readonly userLookupService: AuthVerifyUserLookupServiceInterface,
@Inject(AUTH_VERIFY_MODULE_USER_MUTATE_SERVICE_TOKEN)
private readonly userMutateService: AuthVerifyUserMutateServiceInterface,
private readonly notificationService: AuthVerifyNotificationService,
@Inject(AuthVerifyNotificationService)
private readonly notificationService: AuthVerifyNotificationServiceInterface,
@Inject(AUTH_VERIFY_MODULE_ENTITY_MANAGER_PROXY_TOKEN)
private readonly entityManagerProxy: EntityManagerProxy,
) {}
Expand Down

0 comments on commit 29c7a08

Please sign in to comment.