Skip to content

Commit

Permalink
Merge pull request #13 from UwUClub/AW-35-Tests-unitaires
Browse files Browse the repository at this point in the history
Aw 35 tests unitaires
  • Loading branch information
GlassAlo authored Dec 13, 2023
2 parents b30ae55 + edf67cd commit abb23f6
Show file tree
Hide file tree
Showing 18 changed files with 273 additions and 56 deletions.
43 changes: 43 additions & 0 deletions .github/workflows/back.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: NestJS CI

on:
push:
branches:
- main
- dev
paths:
- "api/**"
pull_request:
branches:
- main
- dev
paths:
- "api/**"

jobs:
build-and-test:
runs-on: ubuntu-latest

steps:
- name: Checkout Repository
uses: actions/checkout@v4

- name: Set up Node.js
uses: actions/setup-node@v4.0.0
with:
node-version: "21"

- name: Install pnpm
run: npm install -g pnpm

- name: Install Dependencies
run: pnpm install --no-frozen-lockfile
working-directory: ./api

- name: Build
run: pnpm run build
working-directory: ./api

- name: Run Tests
run: pnpm test
working-directory: ./api
53 changes: 53 additions & 0 deletions .github/workflows/front.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: Flutter APK Build

on:
push:
branches:
- main
- dev
paths:
- "flutter_area/**"
tags:
- "*"
pull_request:
branches:
- main
- dev
paths:
- "flutter_area/**"

jobs:
build-apk:
runs-on: ubuntu-latest

steps:
- name: Checkout Repository
uses: actions/checkout@v4

- name: Set up Flutter
uses: subosito/flutter-action@v2.12.0
with:
flutter-version: "3.16"

- name: Install Dependencies
run: flutter pub get
working-directory: ./flutter_area

- name: Build APK
run: |
flutter build apk --release
mv build/app/outputs/flutter-apk/app-release.apk build/app/outputs/flutter-apk/maker.apk
working-directory: ./flutter_area

- name: Upload APK
uses: actions/upload-artifact@v3.1.3
with:
name: maker.apk
path: ./flutter_area/build/app/outputs/flutter-apk/maker.apk

- name: Publish Tagged Release
uses: softprops/action-gh-release@v1
if: ${{ startsWith(github.ref, 'refs/tags/') }}
with:
files: |
./flutter_area/build/app/outputs/flutter-apk/maker.apk
2 changes: 2 additions & 0 deletions api/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@ COPY . .

RUN pnpm run build

RUN pnpm test

CMD [ "pnpm", "start" ]
22 changes: 0 additions & 22 deletions api/src/app.controller.spec.ts

This file was deleted.

12 changes: 0 additions & 12 deletions api/src/app.controller.ts

This file was deleted.

6 changes: 2 additions & 4 deletions api/src/app.module.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Module } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService, TasksService } from './app.service';
import { TasksService } from './task.service';
import { UsersModule } from './users/users.module';
import { MongooseModule } from '@nestjs/mongoose';
import { AuthModule } from './auth/auth.module';
Expand All @@ -23,7 +22,6 @@ import { EnvironementVariables, validateEnv } from './_utils/config';
AuthModule,
ConfigModule.forRoot({ validate: validateEnv, isGlobal: true }),
],
controllers: [AppController],
providers: [AppService, TasksService],
providers: [TasksService],
})
export class AppModule {}
2 changes: 1 addition & 1 deletion api/src/auth/_utils/dto/request/sign-in.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { ApiProperty } from '@nestjs/swagger';
import { IsString } from 'class-validator';

export class SignInDto {
@ApiProperty({ example: 'moi' })
@IsString()
@ApiProperty({ example: 'moi' })
usernameOrEmail: string;

@IsString()
Expand Down
17 changes: 17 additions & 0 deletions api/src/auth/auth.controller.spec.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,29 @@
import { Test, TestingModule } from '@nestjs/testing';
import { AuthController } from './auth.controller';
import { AuthService } from './auth.service';
import { UsersRepository } from '../users/users.repository';
import { UsersMapper } from '../users/users.mapper';
import { JwtService } from '@nestjs/jwt';
import { UsersService } from '../users/users.service';
import { Model } from 'mongoose';

describe('AuthController', () => {
let controller: AuthController;

beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
controllers: [AuthController],
providers: [
AuthService,
UsersRepository,
UsersMapper,
JwtService,
UsersService,
{
provide: 'UserModel',
useValue: Model,
},
],
}).compile();

controller = module.get<AuthController>(AuthController);
Expand Down
5 changes: 5 additions & 0 deletions api/src/auth/auth.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ import { ApiTags } from '@nestjs/swagger';
export class AuthController {
constructor(private readonly authService: AuthService) {}

/**
* Endpoint for user login.
* @param signInDto - The sign-in data transfer object.
* @returns The result of the sign-in operation.
*/
@Post('login')
signIn(@Body() signInDto: SignInDto) {
return this.authService.signIn(signInDto);
Expand Down
17 changes: 16 additions & 1 deletion api/src/auth/auth.service.spec.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,27 @@
import { Test, TestingModule } from '@nestjs/testing';
import { AuthService } from './auth.service';
import { UsersRepository } from '../users/users.repository';
import { UsersMapper } from '../users/users.mapper';
import { JwtService } from '@nestjs/jwt';
import { UsersService } from '../users/users.service';
import { Model } from 'mongoose';

describe('AuthService', () => {
let service: AuthService;

beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
providers: [AuthService],
providers: [
AuthService,
UsersRepository,
{
provide: 'UserModel',
useValue: Model,
},
UsersMapper,
JwtService,
UsersService,
],
}).compile();

service = module.get<AuthService>(AuthService);
Expand Down
2 changes: 1 addition & 1 deletion api/src/auth/jwt/jwt.startegy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Injectable } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import { PassportStrategy } from '@nestjs/passport';
import { ExtractJwt, Strategy } from 'passport-jwt';
import { UsersRepository } from 'src/users/users.repository';
import { UsersRepository } from '../../users/users.repository';
import { EnvironementVariables } from '../../_utils/config';

@Injectable()
Expand Down
13 changes: 8 additions & 5 deletions api/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,21 @@ import { AppModule } from './app.module';
import { SwaggerModule, DocumentBuilder } from '@nestjs/swagger';
import { ValidationPipe } from '@nestjs/common';

async function bootstrap() {
async function main() {
const app = await NestFactory.create(AppModule);
app.useGlobalPipes(new ValidationPipe());

const config = new DocumentBuilder()
.setTitle('Maker')
.setDescription('Api for Maker')
.setVersion('1.0')
.setTitle('MakerAPI')
.setDescription(
'This is the API used by the server of Maker AREA project. It should show you all the endpoints available to use.',
)
.setVersion('0.2')
.addBearerAuth()
.build();
const document = SwaggerModule.createDocument(app, config);
SwaggerModule.setup('api', app, document);
await app.listen(8080);
}
bootstrap();

main();
7 changes: 0 additions & 7 deletions api/src/app.service.ts → api/src/task.service.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
import { Injectable, Logger } from '@nestjs/common';
import { Cron } from '@nestjs/schedule';

@Injectable()
export class AppService {
getHello(): string {
return 'Hello World!';
}
}

@Injectable()
export class TasksService {
private readonly logger = new Logger(TasksService.name);
Expand Down
16 changes: 15 additions & 1 deletion api/src/users/users.controller.spec.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,34 @@
import { Test, TestingModule } from '@nestjs/testing';
import { UsersController } from './users.controller';
import { UsersService } from './users.service';
import { UsersRepository } from './users.repository';
import { Model } from 'mongoose';
import { UsersMapper } from './users.mapper';

describe('UsersController', () => {
let controller: UsersController;
let service: UsersService;

beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
controllers: [UsersController],
providers: [UsersService],
providers: [
UsersService,
UsersMapper,
UsersRepository,
{
provide: 'UserModel',
useValue: Model,
},
],
}).compile();

controller = module.get<UsersController>(UsersController);
service = module.get<UsersService>(UsersService);
});

it('should be defined', () => {
expect(controller).toBeDefined();
expect(service).toBeDefined();
});
});
2 changes: 1 addition & 1 deletion api/src/users/users.controller.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Controller, Get } from '@nestjs/common';
import { UsersMapper } from './users.mapper';
import { Protect } from '../auth/_utils/decorators/protect.decorator';
import { ConnectedUser } from 'src/auth/_utils/decorators/connected-user.decorator';
import { ConnectedUser } from '../auth/_utils/decorators/connected-user.decorator';
import { UserDocument } from './users.schema';

@Controller('users')
Expand Down
11 changes: 10 additions & 1 deletion api/src/users/users.service.spec.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
import { Test, TestingModule } from '@nestjs/testing';
import { UsersService } from './users.service';
import { UsersRepository } from './users.repository';
import { Model } from 'mongoose';

describe('UsersService', () => {
let service: UsersService;

beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
providers: [UsersService],
providers: [
UsersService,
UsersRepository,
{
provide: 'UserModel',
useValue: Model,
},
],
}).compile();

service = module.get<UsersService>(UsersService);
Expand Down
Loading

0 comments on commit abb23f6

Please sign in to comment.