Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { AdminService } from "../admin.service";
- import { Test, TestingModule } from '@nestjs/testing';
- import { User } from "../../entity/User";
- import { getRepositoryToken } from "@nestjs/typeorm";
- import { async } from "rxjs/internal/scheduler/async";
- import { BanStatus } from "../../entity/ban-status";
- import { PostEntity } from "../../entity/Post";
- import { FlagPost } from "../../entity/Flag";
- describe('AuthService', () => {
- let service: AdminService;
- let userRepo = {
- findOne: () => { },
- save: (_) => { }
- }
- let banRepo = {
- findOne: () => { },
- save: (_) => { }
- }
- beforeEach(async () => {
- const module: TestingModule = await Test.createTestingModule({
- providers: [
- AdminService, BanStatus, PostEntity, FlagPost,
- {
- provide: getRepositoryToken(User),
- useValue: userRepo,
- },
- {
- provide: getRepositoryToken(BanStatus),
- useValue: banRepo,
- },
- ],
- }).compile();
- service = module.get<AdminService>(AdminService);
- });
- describe('banUser', async () => {
- it('should call findOne ones', async () => {
- const user = {
- id: '3',
- email: 'asdf@abv.bg',
- username: 'Pesho',
- password: '123450',
- isDeleted: false,
- banStatus: { id: '1', description: 'asfasd', expDate: '123.23.123', isBanned: false }
- }
- const spyOnBan = jest.spyOn(banRepo, 'save');
- await service.banUser('1','12341');
- expect(spyOnBan).toHaveBeenCalledTimes(1);
- spyOnBan.mockRestore();
- })
- })
- })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement