Skip to content

Commit

Permalink
testing with +96
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevgonz93 committed May 16, 2024
1 parent 243265b commit 99c1370
Show file tree
Hide file tree
Showing 8 changed files with 144 additions and 30 deletions.
Binary file modified .DS_Store
Binary file not shown.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@
"main",
"module",
"dto",
"interface"
"interface",
"countries"
],
"coverageDirectory": "../coverage",
"testEnvironment": "node"
Expand Down
3 changes: 1 addition & 2 deletions src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { ClubsModule } from './clubs/clubs.module';
import { CoreModule } from './core/core.module';
import { ConfigModule } from '@nestjs/config';
import { PrismaModule } from './prisma/prisma.module';
import { CountriesService } from './countries/countries.service';

@Module({
imports: [
Expand All @@ -19,6 +18,6 @@ import { CountriesService } from './countries/countries.service';
PrismaModule,
],
controllers: [AppController],
providers: [AppService, CountriesService],
providers: [AppService],
})
export class AppModule {}
71 changes: 70 additions & 1 deletion src/clubs/clubs.controller.spec.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,87 @@
import { Test, TestingModule } from '@nestjs/testing';
import { ClubsController } from './clubs.controller';
import { CryptoService } from '../core/crypto/crypto.service';
import { JwtService } from '@nestjs/jwt';
import { ConfigService } from '@nestjs/config';
import { ClubsService } from './clubs.service';
import { FilesService } from '../core/files/files.service';
import { UpdateClubDto } from './entities/club.dto';

const mockGuard = {};

const mockClubService = {
getClubs: jest.fn().mockResolvedValue([]),
getOneClub: jest.fn().mockResolvedValue([]),
createClub: jest.fn().mockResolvedValue([]),
updateClub: jest.fn().mockResolvedValue([]),
deleteClub: jest.fn().mockResolvedValue([]),
};

const mockFileService = {
uploadImage: jest.fn().mockResolvedValue([]),
};

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

beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
controllers: [ClubsController],
}).compile();
providers: [
{ provide: ClubsService, useValue: mockClubService },
{ provide: FilesService, useValue: mockFileService },
CryptoService,
JwtService,
ConfigService,
FilesService,
],
imports: [],
})
.overrideGuard(mockGuard)
.useValue({ canActivate: jest.fn(() => true) })
.compile();

controller = module.get<ClubsController>(ClubsController);
});

it('should be defined', () => {
expect(controller).toBeDefined();
});

describe('findAll', () => {
it('should return an array of clubs', async () => {
const clubs = await controller.findAll();
expect(clubs).toEqual([]);
});
});

describe('findOne', () => {
it('should return a club', async () => {
const club = await controller.findOne('1');
expect(club).toEqual([]);
});
});

describe('update', () => {
describe('should update a club', () => {
it('without logo', async () => {
const club = await controller.update('1', {} as UpdateClubDto, null);
expect(club).toEqual([]);
});
});
});

describe('create', () => {
it('should create a club', async () => {
const club = await controller.create({} as UpdateClubDto, null);
expect(club).toEqual([]);
});
});

describe('delete', () => {
it('should delete a club', async () => {
const club = await controller.delete('1');
expect(club).toEqual([]);
});
});
});
23 changes: 2 additions & 21 deletions src/clubs/clubs.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ import {
UsePipes,
ValidationPipe,
} from '@nestjs/common';
import { FilesService } from 'src/core/files/files.service';
import { FilesService } from '../core/files/files.service';
import { ClubsService } from './clubs.service';
import { FileInterceptor } from '@nestjs/platform-express';
import { ImgData } from 'src/types/image.data';
import { UpdateClubDto } from './entities/club.dto';
import { LoggedGuard } from 'src/core/auth/logged.guard';
import { LoggedGuard } from '../core/auth/logged.guard';

@UsePipes(new ValidationPipe({ whitelist: true, forbidNonWhitelisted: true }))
@Controller('clubs')
Expand Down Expand Up @@ -93,25 +93,6 @@ export class ClubsController {
) {
const { name } = data;
let logo: ImgData | null = null;
if (file) {
const cloudinaryResponse = await this.filesService.uploadImage(
name,
file,
);
logo = {
publicId: cloudinaryResponse.public_id,
folder: cloudinaryResponse.folder,
fieldName: file.fieldname,
originalName: file.originalname,
secureUrl: cloudinaryResponse.secure_url,
resourceType: cloudinaryResponse.resource_type,
mimetype: file.mimetype,
format: cloudinaryResponse.format,
width: cloudinaryResponse.width,
height: cloudinaryResponse.height,
bytes: cloudinaryResponse.bytes,
};
}

if (file) {
const cloudinaryResponse = await this.filesService.uploadImage(
Expand Down
6 changes: 4 additions & 2 deletions src/clubs/clubs.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ import { CoreModule } from 'src/core/core.module';
import { PrismaModule } from 'src/prisma/prisma.module';
import { ClubsService } from './clubs.service';
import { ClubsController } from './clubs.controller';

import { LoggedGuard } from '../core/auth/logged.guard';
import { CryptoService } from '../core/crypto/crypto.service';
import { JwtService } from '@nestjs/jwt';
@Module({
imports: [PrismaModule, CoreModule],
providers: [ClubsService],
providers: [ClubsService, LoggedGuard, CryptoService, JwtService],
controllers: [ClubsController],
})
export class ClubsModule {}
66 changes: 64 additions & 2 deletions src/clubs/clubs.service.spec.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,80 @@
import { Test, TestingModule } from '@nestjs/testing';
import { ClubsService } from './clubs.service';
import { CreateClubDto } from './entities/club.dto';
import { PrismaService } from '../prisma/prisma.service';
import { LoggedGuard } from '../core/auth/logged.guard';
import { NotFoundException } from '@nestjs/common';

const mockPrismaService = {
club: {
findMany: jest.fn(() => []),
findUnique: jest.fn(() => ({})),
create: jest.fn(() => ({})),
update: jest.fn(() => ({})),
delete: jest.fn(() => ({})),
},
logo: {
create: jest.fn(() => ({})),
delete: jest.fn(() => ({})),
},
$transaction: jest.fn(() => ({})),
};

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

beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
providers: [ClubsService],
}).compile();
imports: [],
providers: [
ClubsService,
{ provide: PrismaService, useValue: mockPrismaService },
],
})
.overrideGuard(LoggedGuard)
.useValue({ canActivate: jest.fn(() => true) })
.compile();

service = module.get<ClubsService>(ClubsService);
});

it('should be defined', () => {
expect(service).toBeDefined();
});

describe('getClubs', () => {
it('should return an array of clubs', async () => {
const clubs = await service.getClubs();
expect(clubs).toEqual([]);
});
});

describe('getOneClub', () => {
it('should return a club', async () => {
const club = await service.getOneClub('1');
expect(club).toEqual({});
});
});

describe('createClub', () => {
it('should create a club', async () => {
const club = await service.createClub({} as CreateClubDto, null);
expect(club).toEqual({});
});
});

describe('updateClub', () => {
it('should update a club', async () => {
const club = await service.updateClub('1', {} as CreateClubDto, null);
expect(club).toEqual({});
});
});

describe('deleteClub', () => {
it('should delete a club', async () => {
await service.deleteClub('1');
expect(mockPrismaService.club.delete).toHaveBeenCalled();
});
it('should return an error if the club does not exist', async () => {});
});
});
2 changes: 1 addition & 1 deletion src/clubs/clubs.service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Injectable, NotFoundException } from '@nestjs/common';
import { PrismaService } from 'src/prisma/prisma.service';
import { PrismaService } from '../prisma/prisma.service';
import { CreateClubDto } from './entities/club.dto';
import { Club } from './entities/club.interface';
import { ImgData } from 'src/types/image.data';
Expand Down

0 comments on commit 99c1370

Please sign in to comment.