Skip to content

Commit

Permalink
refactors librarys and apps using tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Anas Abbal authored and Anas Abbal committed Jul 11, 2024
1 parent 7cd56d1 commit 9fbb9aa
Show file tree
Hide file tree
Showing 74 changed files with 832 additions and 2,345 deletions.
9 changes: 3 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,6 @@ jobs:
working-directory: apps/${{ matrix.app }}
run: nest start ${{ matrix.app }} &

#- name: Wait for service to be ready
# run: sleep 10

#- name: Run tests for ${{ matrix.app }}
# working-directory: apps/${{ matrix.app }}
# run: npm run test
- name: Run tests for ${{ matrix.app }}
working-directory: apps/${{ matrix.app }}
run: npm run test
22 changes: 0 additions & 22 deletions apps/auth/src/auth.controller.spec.ts

This file was deleted.

2 changes: 1 addition & 1 deletion apps/auth/src/auth.controller.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Body, Controller, Get } from '@nestjs/common';
import { AuthService } from './auth.service';
import { MessagePattern } from '@nestjs/microservices';
import { UserCreateCommand } from '@app/shared/commands/auth/user.create.cmd';
import { UserCreateCommand } from './command/create.user.command';

@Controller()
export class AuthController {
Expand Down
5 changes: 2 additions & 3 deletions apps/auth/src/auth.service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { UserCreateCommand } from '@app/shared/commands/auth/user.create.cmd';
import { validateCommand } from '@app/shared/utils/validate';
import { BadRequestException, Inject, Injectable, Logger } from '@nestjs/common';
import { UserCreateCommand } from './command/create.user.command';
import { Inject, Injectable, Logger } from '@nestjs/common';
import { JwtService } from '@nestjs/jwt';
import { ClientProxy } from '@nestjs/microservices';
import { firstValueFrom } from 'rxjs';
Expand Down
35 changes: 35 additions & 0 deletions apps/auth/src/command/create.user.command.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { IsString, IsEmail, MinLength, MaxLength, IsEnum, IsIn } from 'class-validator';
import { IsEqualTo } from '../util';




enum UserType {
DRIVER = 'driver',
RIDER = 'rider',
ADMIN = 'admin',
}

export class UserCreateCommand {
@IsString()
@MaxLength(50)
firstName: string;

@IsString()
@MaxLength(50)
lastName: string;

@IsEmail()
email: string;

@IsString()
@MinLength(6)
@MaxLength(20)
password: string;

@IsString()
@MinLength(6)
@MaxLength(20)
@IsEqualTo('password', { message: 'Passwords must match' }) // Use the custom validator
confirmPassword: string;
}
File renamed without changes.
22 changes: 0 additions & 22 deletions apps/driver/src/driver.controller.spec.ts

This file was deleted.

2 changes: 1 addition & 1 deletion apps/driver/src/driver.module.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Module } from '@nestjs/common';
import { DatabaseModule } from '@app/database';
import { DriverController } from './driver.controller';
import { DriverService } from './driver.service';
import * as dotenv from 'dotenv';
import { TypeOrmModule } from '@nestjs/typeorm';
import { Driver } from './models/driver.entity';
import { CacheModule } from '@nestjs/cache-manager';
import { DatabaseModule } from '@app/database';


dotenv.config();
Expand Down
1 change: 0 additions & 1 deletion apps/driver/src/utils/driver.mapper.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { DriverDto } from "@app/shared/events/driver/driver.dto";
import { Driver } from "typeorm";


35 changes: 35 additions & 0 deletions apps/gateway/src/command/create.user.command.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { IsString, IsEmail, MinLength, MaxLength, IsEnum, IsIn } from 'class-validator';
import { IsEqualTo } from '../util';




enum UserType {
DRIVER = 'driver',
RIDER = 'rider',
ADMIN = 'admin',
}

export class UserCreateCommand {
@IsString()
@MaxLength(50)
firstName: string;

@IsString()
@MaxLength(50)
lastName: string;

@IsEmail()
email: string;

@IsString()
@MinLength(6)
@MaxLength(20)
password: string;

@IsString()
@MinLength(6)
@MaxLength(20)
@IsEqualTo('password', { message: 'Passwords must match' }) // Use the custom validator
confirmPassword: string;
}
5 changes: 5 additions & 0 deletions apps/gateway/src/command/driver.cmd.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@


export class DriverCreateCmd {

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { IsEmail, IsEnum, IsNotEmpty, IsString } from 'class-validator';
import { DriverStatus } from './driver.status';



export class DriverDto {
@IsNotEmpty()
@IsString()
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
3 changes: 0 additions & 3 deletions apps/gateway/src/rest/auth.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ import { AuthService } from '../services/auth.service';






@Controller('auth')
export class AuthController {
constructor(private readonly authService: AuthService) {}
Expand Down
2 changes: 1 addition & 1 deletion apps/gateway/src/rest/driver.controller.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Controller, Get } from "@nestjs/common";
import { DriverService } from "../services/driver-service";
import { DriverDto } from "@app/shared/events/driver/driver.dto";
import { DriverDto } from "../dto/driver.dto";



Expand Down
2 changes: 1 addition & 1 deletion apps/gateway/src/rest/user.controller.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Body, Controller, Get, Param, Post, UseInterceptors } from '@nestjs/common';
import { UserCreateCommand } from '@app/shared/commands/auth/user.create.cmd';
import { UserService } from '../services/user-service';
import { CacheInterceptor, CacheKey, CacheTTL } from '@nestjs/cache-manager';
import { UserCreateCommand } from '../command/create.user.command';



Expand Down
2 changes: 1 addition & 1 deletion apps/gateway/src/rest/user.type.controller.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Controller, Get, Param } from '@nestjs/common';
import { UserTypeService } from '../services/user.type.service';
import { UserTypeDto } from '@app/shared/events/user/user.type.dto';
import { UserTypeDto } from '../dto/user.type.dto';



Expand Down
5 changes: 1 addition & 4 deletions apps/gateway/src/services/auth.service.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import { UserCreateCommand } from "@app/shared/commands/auth/user.create.cmd";
import { DriverCreateCmd } from "@app/shared/commands/driver/driver.create.cmd";
import { BadRequestException, ConflictException, Inject, Injectable, InternalServerErrorException, Logger, UnauthorizedException } from "@nestjs/common";
import { ClientProxy } from "@nestjs/microservices";
import { UserService } from "./user-service";
import { DriverService } from "./driver-service";
import { UserTypeService } from "./user.type.service";
import { WINSTON_MODULE_NEST_PROVIDER } from "nest-winston";
import { Inject, Injectable, Logger } from "@nestjs/common";



Expand Down
4 changes: 2 additions & 2 deletions apps/gateway/src/services/driver-service.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { DriverCreateCmd } from "@app/shared/commands/driver/driver.create.cmd";
import { DriverDto } from "@app/shared/events/driver/driver.dto";
import { Inject, Injectable, Logger, LoggerService } from "@nestjs/common";
import { ClientProxy } from "@nestjs/microservices";
import { WINSTON_MODULE_NEST_PROVIDER } from "nest-winston";
import { DriverCreateCmd } from "../command/driver.cmd";
import { DriverDto } from "../dto/driver.dto";



Expand Down
3 changes: 1 addition & 2 deletions apps/gateway/src/services/user-service.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { Injectable, Inject, Logger } from '@nestjs/common';
import { ClientProxy } from '@nestjs/microservices';
import { Cache } from 'cache-manager';
import { UserCreateCommand } from '@app/shared/commands/auth/user.create.cmd'; // Adjust import path as needed
import { WINSTON_MODULE_NEST_PROVIDER } from 'nest-winston';
import { CACHE_MANAGER } from '@nestjs/cache-manager';
import { UserCreateCommand } from '../command/create.user.command';

@Injectable()
export class UserService {
Expand Down
2 changes: 1 addition & 1 deletion apps/gateway/src/services/user.type.service.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { UserTypeDto } from "@app/shared/events/user/user.type.dto";
import { Inject, Injectable, Logger } from "@nestjs/common";
import { ClientProxy } from "@nestjs/microservices";
import { WINSTON_MODULE_NEST_PROVIDER } from "nest-winston";
import { UserTypeDto } from "../dto/user.type.dto";



Expand Down
37 changes: 37 additions & 0 deletions apps/gateway/src/util/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { registerDecorator, ValidationOptions, ValidationArguments } from 'class-validator';



export function mapDto<T extends Record<string, any>, U extends Record<string, any>>(source: T): U {
const result = {} as U;

for (const key in source) {
if (Object.prototype.hasOwnProperty.call(source, key)) {
result[key as keyof U] = source[key] as unknown as U[keyof U];
}
}

return result;
}



export function IsEqualTo(property: string, validationOptions?: ValidationOptions) {
return function (object: Record<string, any>, propertyName: string) {
registerDecorator({
name: 'isEqualTo',
target: object.constructor,
propertyName: propertyName,
constraints: [property],
options: validationOptions,
validator: {
validate(value: any, args: ValidationArguments) {
const [relatedPropertyName] = args.constraints;
const relatedValue = (args.object as any)[relatedPropertyName];
return value === relatedValue;
},
},
});
};
}

4 changes: 4 additions & 0 deletions apps/ride/src/ride.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,8 @@ export class RideController {
constructor(private readonly rideService: RideService) {}


@Get()
getHello(): string {
return this.rideService.getHello();
}
}
5 changes: 2 additions & 3 deletions apps/ride/src/ride.service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Injectable } from '@nestjs/common';
import { Ride } from './models/ride.schema';
import { RequestDriver } from '@app/common/ride/cmd/request.driver';



Expand All @@ -13,7 +12,7 @@ export class RideService {



async requestDrive(request: RequestDriver): Promise<any> {

getHello(): string {
return 'Hello World!';
}
}
18 changes: 0 additions & 18 deletions apps/user-service/src/auth/auth.controller.spec.ts

This file was deleted.

46 changes: 0 additions & 46 deletions apps/user-service/src/auth/auth.controller.ts

This file was deleted.

Loading

0 comments on commit 9fbb9aa

Please sign in to comment.