Skip to content

Commit

Permalink
fix: fixed imports on automated tests modules
Browse files Browse the repository at this point in the history
  • Loading branch information
odavibatista committed Jul 25, 2024
1 parent b9a8e14 commit 6a6d120
Show file tree
Hide file tree
Showing 9 changed files with 74 additions and 11 deletions.
11 changes: 11 additions & 0 deletions src/modules/activity/services/activity.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,18 @@ import { JWTProvider } from '../../user/providers/jwt.provider';
import { CourseNotFoundException } from '../../course/domain/errors/CourseNotFound.exception';
import { UnprocessableDataException } from '../../../shared/domain/errors/UnprocessableData.exception';
import { ActivityNotFoundException } from '../domain/errors/ActivityNotFound.exception';
import { UserRepository } from '../../user/repository/user.repository';

describe('Activity Service Tests Suite', () => {
let activityService: ActivityService;

beforeEach(() => {
jest.useFakeTimers({ doNotFake: ['nextTick'] })
})

afterAll(() => {
jest.useRealTimers()
})

beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
Expand All @@ -30,6 +39,8 @@ describe('Activity Service Tests Suite', () => {
UserCourseConcludedRepository,
ActivityRepository,
UserActivityAnsweredRepository,
UserRepository,
ActivityService,
JWTProvider,
],
}).compile();
Expand Down
11 changes: 10 additions & 1 deletion src/modules/course/services/course.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,19 @@ import {
import { UserNotFoundException } from '../../user/domain/errors/UserNotFound.exception';
import { CourseNotFoundException } from '../domain/errors/CourseNotFound.exception';
import { UnprocessableDataException } from '../../../shared/domain/errors/UnprocessableData.exception';
import { UserRepository } from '../../user/repository/user.repository';

describe('Course Service Automated Tests', () => {
let courseService: CourseService;

beforeEach(() => {
jest.useFakeTimers({ doNotFake: ['nextTick'] })
})

afterAll(() => {
jest.useRealTimers()
})

beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
imports: [
Expand All @@ -34,6 +43,7 @@ describe('Course Service Automated Tests', () => {
ActivityRepository,
UserActivityAnsweredRepository,
JWTProvider,
UserRepository
],
}).compile();

Expand All @@ -43,7 +53,6 @@ describe('Course Service Automated Tests', () => {
it('should bring a page of courses', async () => {
const courses = await courseService.getCourses(1);
expect(courses).toBeInstanceOf(Array);
expect(courses).toBeInstanceOf(FindCoursesResponseDTO);
});

it('should not bring the course data for an user if the user does not exist', async () => {
Expand Down
14 changes: 6 additions & 8 deletions src/modules/course/services/course.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
} from '../domain/requests/FindCourses.request.dto';
import { ActivityRepository } from '../../activity/repository/activity.repository';
import { CourseNotFoundException } from '../domain/errors/CourseNotFound.exception';
import { UserActivityAnsweredRepository } from '../../user-activities-answered/repository/user-activities-answered.repository';
import {
CreateCourseRequestDTO,
CreateCourseResponseDTO,
Expand All @@ -28,7 +27,6 @@ export class CourseService {
private readonly userCourseConcludedRepository: UserCourseConcludedRepository,
private readonly activitiesRepository: ActivityRepository,
private readonly userRepository: UserRepository,
private readonly userActivityAnsweredRepository: UserActivityAnsweredRepository,
) {}

async getCourses(skip: number): Promise<FindCoursesResponseDTO[]> {
Expand Down Expand Up @@ -141,6 +139,12 @@ export class CourseService {
): Promise<
EditCourseResponseDTO | CourseNotFoundException | UnprocessableDataException
> {
const course = await this.courseRepository.findOne({
where: { id_course: id },
});

if (!course) throw new CourseNotFoundException();

if (!nameValidate(courseData.course_name))
throw new UnprocessableDataException('Nome do curso inválido');

Expand All @@ -153,12 +157,6 @@ export class CourseService {
'Total de pontos deve ser um número inteiro positivo maior que 0 e não pode conter mais de 5 casas numéricas.',
);

const course = await this.courseRepository.findOne({
where: { id_course: id },
});

if (!course) throw new CourseNotFoundException();

course.course_name = courseData.course_name;
course.points_worth = courseData.points_worth;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Test, TestingModule } from '@nestjs/testing';
import { TypeOrmModule } from '@nestjs/typeorm';
import { UserActivitiesAnsweredService } from './user-activities-answered.service';
import { DatabaseModule } from '../../../database/database.module';
import { UserModule } from '../../user/user.module';
import { TypeOrmModule } from '@nestjs/typeorm';
import { User } from '../../user/entity/user.entity';
import { UserScore } from '../../user-score/entity/user-score.entity';
import { UserScoreService } from '../../user-score/services/user-score.service';
Expand All @@ -13,9 +13,21 @@ import { UserNotFoundException } from '../../user/domain/errors/UserNotFound.exc
import { ActivityNotFoundException } from '../domain/errors/ActivityNotFound.exception';
import { ActivityAlreadyAnsweredException } from '../domain/errors/ActivityAlreadyAnswered.exception';
import { WrongAnswerException } from '../domain/errors/WrongAnswer.exception';
import { UserActivityAnsweredRepository } from '../repository/user-activities-answered.repository';
import { ActivityRepository } from '../../activity/repository/activity.repository';
import { UserCourseConcludedRepository } from '../../user-courses-concluded/repository/user-courses-concluded.repository';
import { CourseRepository } from '../../course/repository/course.repository';

describe('UserActivitiesAnsweredService', () => {
let userActivitiesAnsweredService: UserActivitiesAnsweredService;

beforeEach(() => {
jest.useFakeTimers({ doNotFake: ['nextTick'] })
})

afterAll(() => {
jest.useRealTimers()
})

beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
Expand All @@ -28,7 +40,12 @@ describe('UserActivitiesAnsweredService', () => {
UserScoreService,
UserScoreRepository,
UserRepository,
ActivityRepository,
CourseRepository,
JWTProvider,
UserActivitiesAnsweredService,
UserCourseConcludedRepository,
UserActivityAnsweredRepository
],
}).compile();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { WrongAnswerException } from '../domain/errors/WrongAnswer.exception';
import { ActivityNotFoundException } from '../domain/errors/ActivityNotFound.exception';
import { ActivityAlreadyAnsweredException } from '../domain/errors/ActivityAlreadyAnswered.exception';
import { UserCourseConcludedRepository } from '../../user-courses-concluded/repository/user-courses-concluded.repository';
import { UserScoreRepository } from '../../user-score/repository/user-score-repository';
import { UserScoreService } from '../../user-score/services/user-score.service';
import { CourseRepository } from '../../course/repository/course.repository';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ import { UserCoursesConcludedDtoService } from './user-courses-concluded.dto.ser
describe('UserCoursesConcludedDtoService', () => {
let service: UserCoursesConcludedDtoService;

beforeEach(() => {
jest.useFakeTimers({ doNotFake: ['nextTick'] })
})

afterAll(() => {
jest.useRealTimers()
})

beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
providers: [UserCoursesConcludedDtoService],
Expand Down
8 changes: 8 additions & 0 deletions src/modules/user-score/services/user-score.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ import { UnprocessableDataException } from '../../../shared/domain/errors/Unproc
describe('UserScoreService', () => {
let userScoreService: UserScoreService;

beforeEach(() => {
jest.useFakeTimers({ doNotFake: ['nextTick'] })
})

afterAll(() => {
jest.useRealTimers()
})

beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
imports: [
Expand Down
10 changes: 10 additions & 0 deletions src/modules/user/services/user.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,20 @@ import { EmailAlreadyRegisteredException } from '../domain/errors/EmailAlreadyRe
import { UsernameAlreadyRegisteredException } from '../domain/errors/UsernameAlreadyRegistered.exception';
import { InvalidCredentialsException } from '../domain/errors/InvalidCredentials.exception';
import { UserNotFoundException } from '../domain/errors/UserNotFound.exception';
import { UserScoreRepository } from '../../user-score/repository/user-score-repository';

describe('UserService Test Suites', () => {
let userService: UserService;
let userClearingService: UserClearingService;

beforeEach(() => {
jest.useFakeTimers({ doNotFake: ['nextTick'] })
})

afterAll(() => {
jest.useRealTimers()
})

beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
imports: [
Expand All @@ -39,6 +48,7 @@ describe('UserService Test Suites', () => {
HashProvider,
UserRepository,
UserClearingService,
UserScoreRepository
],
exports: [JWTProvider, HashProvider, UserService, UserClearingService],
}).compile();
Expand Down
3 changes: 3 additions & 0 deletions test/jest-e2e.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,8 @@
"testRegex": ".e2e-spec.ts$",
"transform": {
"^.+\\.(t|j)s$": "ts-jest"
},
"moduleNameMapper": {
"^src/(.*)": "<rootDir>/../src/$1"
}
}

0 comments on commit 6a6d120

Please sign in to comment.