Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions backend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@
"**/*.(t|j)s"
],
"coverageDirectory": "../coverage",
"testEnvironment": "node"
"testEnvironment": "node",
"moduleNameMapper": {
"^src/(.*)$": "<rootDir>/$1"
}
}
}
4 changes: 3 additions & 1 deletion backend/src/auth/auth.controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ describe('AuthController', () => {
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
controllers: [AuthController],
providers: [AuthService],
providers: [
{ provide: AuthService, useValue: { register: jest.fn(), login: jest.fn(), forgotPassword: jest.fn(), resetPassword: jest.fn() } },
],
}).compile();

controller = module.get<AuthController>(AuthController);
Expand Down
8 changes: 7 additions & 1 deletion backend/src/auth/auth.service.spec.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
import { Test, TestingModule } from '@nestjs/testing';
import { JwtService } from '@nestjs/jwt';
import { AuthService } from './auth.service';
import { UserService } from 'src/users/users.service';

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

beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
providers: [AuthService],
providers: [
AuthService,
{ provide: UserService, useValue: { create: jest.fn(), findByEmail: jest.fn() } },
{ provide: JwtService, useValue: { sign: jest.fn(), verify: jest.fn() } },
],
}).compile();

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

@Injectable()
export class JwtStrategy extends PassportStrategy(Strategy) {
Expand Down
16 changes: 9 additions & 7 deletions backend/src/certificates/certificates.controller.spec.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
import { Test, TestingModule } from '@nestjs/testing';
import { CertificatesController } from './certificates.controller';
import { CertificatesService } from './certificates.service';
import { CertificateController } from './certificates.controller';
import { CertificateService } from './certificates.service';

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

beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
controllers: [CertificatesController],
providers: [CertificatesService],
controllers: [CertificateController],
providers: [
{ provide: CertificateService, useValue: { verifyCertificate: jest.fn(), getAllCertificates: jest.fn(), revokeCertificate: jest.fn() } },
],
}).compile();

controller = module.get<CertificatesController>(CertificatesController);
controller = module.get<CertificateController>(CertificateController);
});

it('should be defined', () => {
Expand Down
5 changes: 3 additions & 2 deletions backend/src/certificates/certificates.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { JwtAuthGuard } from '../common/guards/jwt-auth.guard';
import { RolesGuard } from '../common/guards/roles.guard';
import { CertificateService } from './certificates.service';
import { Roles } from 'src/common/decorators/roles.decorator';
import { UserRole } from 'src/users/entities/user.entity';
import { CertificateVerificationResultDto } from './dto/certificate-response.dto';
import { VerifyCertificateDto } from './dto/verify-certificate.dto';

Expand Down Expand Up @@ -49,7 +50,7 @@ export class CertificateController {
* GET /certificates/all
*/
@UseGuards(JwtAuthGuard, RolesGuard)
@Roles('admin')
@Roles(UserRole.ADMIN)
@Get('all')
async getAllCertificates() {
return this.certificateService.getAllCertificates();
Expand All @@ -60,7 +61,7 @@ export class CertificateController {
* POST /certificates/revoke/:id
*/
@UseGuards(JwtAuthGuard, RolesGuard)
@Roles('admin')
@Roles(UserRole.ADMIN)
@Post('revoke/:id')
async revokeCertificate(@Param('id') id: string) {
return this.certificateService.revokeCertificate(id);
Expand Down
21 changes: 16 additions & 5 deletions backend/src/certificates/certificates.service.spec.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,26 @@
import { Test, TestingModule } from '@nestjs/testing';
import { CertificatesService } from './certificates.service';
import { getRepositoryToken } from '@nestjs/typeorm';
import { CertificateService } from './certificates.service';
import { Certificate } from './entities/certificate.entity';
import { User } from 'src/users/entities/user.entity';
import { Course } from 'src/courses/entities/course.entity';

describe('CertificatesService', () => {
let service: CertificatesService;
const mockRepo = () => ({ findOne: jest.fn(), find: jest.fn(), create: jest.fn(), save: jest.fn() });

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

beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
providers: [CertificatesService],
providers: [
CertificateService,
{ provide: getRepositoryToken(Certificate), useValue: mockRepo() },
{ provide: getRepositoryToken(User), useValue: mockRepo() },
{ provide: getRepositoryToken(Course), useValue: mockRepo() },
],
}).compile();

service = module.get<CertificatesService>(CertificatesService);
service = module.get<CertificateService>(CertificateService);
});

it('should be defined', () => {
Expand Down
2 changes: 1 addition & 1 deletion backend/src/common/decorators/roles.decorator.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { SetMetadata } from '@nestjs/common';
import { UserRole } from '../entities/user.entity';
import { UserRole } from 'src/users/entities/user.entity';

export const ROLES_KEY = 'roles';

Expand Down
2 changes: 1 addition & 1 deletion backend/src/common/guards/roles.guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
} from '@nestjs/common';
import { Reflector } from '@nestjs/core';
import { ROLES_KEY } from '../decorators/roles.decorator';
import { UserRole } from '../../entities/user.entity';
import { UserRole } from 'src/users/entities/user.entity';

@Injectable()
export class RolesGuard implements CanActivate {
Expand Down
6 changes: 5 additions & 1 deletion backend/src/courses/courses.controller.spec.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
import { Test, TestingModule } from '@nestjs/testing';
import { CoursesController } from './courses.controller';
import { CoursesService } from './courses.service';
import { PaginationService } from 'src/common/services/pagination.service';

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

beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
controllers: [CoursesController],
providers: [CoursesService],
providers: [
{ provide: CoursesService, useValue: { create: jest.fn(), findAll: jest.fn(), findOne: jest.fn(), update: jest.fn() } },
{ provide: PaginationService, useValue: {} },
],
}).compile();

controller = module.get<CoursesController>(CoursesController);
Expand Down
11 changes: 10 additions & 1 deletion backend/src/courses/courses.service.spec.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
import { Test, TestingModule } from '@nestjs/testing';
import { getRepositoryToken } from '@nestjs/typeorm';
import { CoursesService } from './courses.service';
import { Course } from './entities/course.entity';
import { CourseRegistration } from './entities/course-registration.entity';

const mockRepo = () => ({ findOne: jest.fn(), find: jest.fn(), create: jest.fn(), save: jest.fn() });

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

beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
providers: [CoursesService],
providers: [
CoursesService,
{ provide: getRepositoryToken(Course), useValue: mockRepo() },
{ provide: getRepositoryToken(CourseRegistration), useValue: mockRepo() },
],
}).compile();

service = module.get<CoursesService>(CoursesService);
Expand Down
2 changes: 1 addition & 1 deletion backend/src/courses/entities/course-registration.entity.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Entity, PrimaryGeneratedColumn, Column, ManyToOne, CreateDateColumn, JoinColumn } from 'typeorm';
import { User } from './user.entity';
import { User } from 'src/users/entities/user.entity';
import { Course } from './course.entity';

@Entity('course_registrations')
Expand Down
2 changes: 1 addition & 1 deletion backend/src/courses/entities/course.entity.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Lesson } from 'src/entities/lesson.entity';
import { Lesson } from 'src/lessons/entities/lesson.entity';
import {
Entity,
PrimaryGeneratedColumn,
Expand Down
4 changes: 3 additions & 1 deletion backend/src/lessons/lessons.controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ describe('LessonsController', () => {
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
controllers: [LessonsController],
providers: [LessonsService],
providers: [
{ provide: LessonsService, useValue: { create: jest.fn(), findAllByCourse: jest.fn(), findOne: jest.fn(), update: jest.fn(), remove: jest.fn() } },
],
}).compile();

controller = module.get<LessonsController>(LessonsController);
Expand Down
2 changes: 1 addition & 1 deletion backend/src/lessons/lessons.service.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Injectable, NotFoundException } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Course } from 'src/courses/entities/course.entity';
import { Lesson } from 'src/entities/lesson.entity';
import { Lesson } from './entities/lesson.entity';
import { Repository } from 'typeorm';
import { CreateLessonDto } from './dto/create-lesson.dto';
import { UpdateLessonDto } from './dto/update-lesson.dto';
Expand Down
11 changes: 11 additions & 0 deletions backend/src/progress/dto/complete-lesson.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { IsString, IsUUID } from 'class-validator';

export class CompleteLessonDto {
@IsString()
@IsUUID()
lessonId: string;

@IsString()
@IsUUID()
courseId: string;
}
50 changes: 49 additions & 1 deletion backend/src/progress/entities/progress.entity.ts
Original file line number Diff line number Diff line change
@@ -1 +1,49 @@
export class Progress {}
import {
Entity,
PrimaryGeneratedColumn,
Column,
CreateDateColumn,
UpdateDateColumn,
ManyToOne,
Unique,
} from 'typeorm';
import { User } from 'src/users/entities/user.entity';
import { Course } from 'src/courses/entities/course.entity';
import { Lesson } from 'src/lessons/entities/lesson.entity';

@Entity('progress')
@Unique(['user', 'lesson'])
export class Progress {
@PrimaryGeneratedColumn('uuid')
id: string;

@Column({ type: 'varchar' })
userId: string;

@Column({ type: 'varchar' })
courseId: string;

@Column({ type: 'varchar' })
lessonId: string;

@Column({ type: 'boolean', default: false })
completed: boolean;

@Column({ type: 'datetime', nullable: true })
completedAt: Date | null;

@CreateDateColumn()
createdAt: Date;

@UpdateDateColumn()
updatedAt: Date;

@ManyToOne(() => User, { onDelete: 'CASCADE' })
user: User;

@ManyToOne(() => Course, { onDelete: 'CASCADE' })
course: Course;

@ManyToOne(() => Lesson, { onDelete: 'CASCADE' })
lesson: Lesson;
}
Loading