-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
144 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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([]); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 () => {}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters