Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature lp 71 user specific course #57

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*
Warnings:

- Added the required column `Assignee` to the `UserCourse` table without a default value. This is not possible if the table is not empty.

*/
-- AlterTable
ALTER TABLE "UserCourse" ADD COLUMN "Assignee" TEXT NOT NULL;
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "UserCourse" ALTER COLUMN "Assignee" SET DEFAULT 'self';
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-- AlterTable
ALTER TABLE "User" ADD COLUMN "firstName" TEXT,
ADD COLUMN "lastName" TEXT;
3 changes: 3 additions & 0 deletions backend/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ enum Role {
model User {
id String @id @default(uuid())
eId String? @unique
firstName String?
lastName String?
role String?
clientTeam String?
projectTeam String?
Expand Down Expand Up @@ -68,6 +70,7 @@ model UserCourse {
courseId String
course Course @relation(fields: [courseId], references: [id], onDelete: Cascade)
isCompleted Boolean
Assignee String @default("self")
}

enum userRoles {
Expand Down
2 changes: 2 additions & 0 deletions backend/src/auth/auth.controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ describe('AuthController', () => {
clientTeam: 'abc',
roles: Role.Employee,
projectTeam: 'abc',
firstName:"ABC",
lastName:"XYZ",
});
const result = await controller.signup(user);
expect(service.signup).toBeCalledTimes(1);
Expand Down
14 changes: 14 additions & 0 deletions backend/src/auth/auth.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ describe('AuthService', () => {
role: 'BQA',
clientTeam: 'abc',
roles: Role.Employee,
firstName:"ABC",
lastName:"XYZ",
});
const result = await service.signup(userDTO);
expect(prismaService.user.create).toBeCalledTimes(1);
Expand Down Expand Up @@ -136,6 +138,8 @@ describe('AuthService', () => {
clientTeam: 'abc',
roles: Role.Employee,
projectTeam: 'abc',
firstName:"ABC",
lastName:"XYZ",
};

jest
Expand Down Expand Up @@ -167,6 +171,8 @@ describe('AuthService', () => {
role: 'BQA',
clientTeam: 'abc',
roles: Role.Employee,
firstName:"ABC",
lastName:"XYZ",
});

jest
Expand Down Expand Up @@ -196,6 +202,8 @@ describe('AuthService', () => {
role: 'BQA',
clientTeam: 'abc',
roles: Role.Employee,
firstName:"ABC",
lastName:"XYZ",
});

jest
Expand Down Expand Up @@ -231,6 +239,8 @@ describe('AuthService', () => {
clientTeam: 'abc',
roles: Role.Employee,
projectTeam: 'abc',
firstName:"ABC",
lastName:"XYZ",
});

const mockResponse = {
Expand Down Expand Up @@ -263,6 +273,8 @@ describe('AuthService', () => {
role: 'BQA',
clientTeam: 'abc',
roles: Role.Employee,
firstName:"ABC",
lastName:"XYZ",
});

const mockResponse = {
Expand Down Expand Up @@ -304,6 +316,8 @@ describe('AuthService', () => {
role: 'BQA',
clientTeam: 'abc',
roles: Role.Employee,
firstName:"ABC",
lastName:"XYZ",
};

jest.spyOn(prismaService.user, 'update').mockResolvedValueOnce(mockUser);
Expand Down
18 changes: 18 additions & 0 deletions backend/src/user/user.controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ describe('UserController', () => {
clientTeam: 'abc',
projectTeam: 'abc',
roles: Role.Employee,
firstName:"ABC",
lastName:"XYZ",
};

jest.spyOn(service, 'getUserById').mockResolvedValue(mockResponse);
Expand All @@ -81,6 +83,8 @@ describe('UserController', () => {
clientTeam: 'abc',
projectTeam: 'abc',
roles: Role.Employee,
firstName:"ABC",
lastName:"XYZ",
};

jest.spyOn(service, 'getUserById').mockResolvedValue(mockResponse);
Expand Down Expand Up @@ -165,6 +169,8 @@ describe('UserController', () => {
role: 'BQAE',
clientTeam: 'abcd',
roles: Role.Employee,
firstName:"ABC",
lastName:"XYZ",
};

jest.spyOn(service, 'updateProfile').mockResolvedValue(mockResponse);
Expand Down Expand Up @@ -195,6 +201,8 @@ describe('UserController', () => {
createdAt: Date.prototype,
updatedAt: Date.prototype,
roles: Role.Employee,
firstName:"ABC",
lastName:"XYZ",
},
CompletedCourseCount: 4,
},
Expand All @@ -213,6 +221,8 @@ describe('UserController', () => {
createdAt: Date.prototype,
updatedAt: Date.prototype,
roles: Role.Employee,
firstName:"ABC",
lastName:"XYZ",
},
CompletedCourseCount: 2,
},
Expand All @@ -239,6 +249,7 @@ describe('UserController', () => {
userId: '1',
courseId: 'course1',
isCompleted: false,
Assignee:'self'
};

jest.spyOn(service, 'enrollCourse').mockResolvedValue(mockResponse);
Expand All @@ -261,6 +272,7 @@ describe('UserController', () => {
userId: '1',
courseId: 'course1',
isCompleted: true,
Assignee:'self'
};
jest.spyOn(service, 'completeCourse').mockResolvedValue(mockResponse);
const result = await controller.completeCourse(userDecorator, courseBody);
Expand Down Expand Up @@ -330,6 +342,8 @@ describe('UserController', () => {
clientTeam: 'abcd',
projectTeam: 'abc',
roles: Role.Employee,
firstName:"ABC",
lastName:"XYZ",
};

jest.spyOn(service, 'updateUser').mockResolvedValueOnce(mockResponse);
Expand All @@ -351,6 +365,8 @@ describe('UserController', () => {
role: 'BQAE',
clientTeam: 'abcd',
roles: Role.Employee,
firstName:"ABC",
lastName:"XYZ",
};
jest.spyOn(service, 'deleteUser').mockResolvedValueOnce(mockResponse);
const result = await controller.deleteUser('1');
Expand All @@ -373,6 +389,8 @@ describe('UserController', () => {
clientTeam: 'abc',
projectTeam: 'abc',
roles: Role.Employee,
firstName:"ABC",
lastName:"XYZ",
},
];

Expand Down
31 changes: 31 additions & 0 deletions backend/src/user/user.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ describe('UserService', () => {
const mockResponse = {
email: userDTO.email,
password: userDTO.password,
firstName:"ABC",
lastName:"XYZ",
id: '1',
createdAt: Date.prototype,
profilePhoto: 'https://profilephoto.com',
Expand Down Expand Up @@ -143,18 +145,21 @@ describe('UserService', () => {
userId: '0cecbf92-d381-40b7-b8f8-49ccae3f8263',
courseId: '57baa1dd-5bed-4ef6-af67-e588962e3a55',
isCompleted: true,
Assignee : 'self'
},
{
id: 2,
userId: '0cecbf92-d381-40b7-b8f8-49ccae3f8263',
courseId: '7be805c9-906e-485f-86a5-0fc11cfe0e2d',
isCompleted: true,
Assignee : 'self'
},
{
id: 3,
userId: '0cecbf92-d381-40b7-b8f8-49ccae3f8263',
courseId: '1d47941f-d10f-411d-821c-32c3f27ec060',
isCompleted: true,
Assignee : 'self'
},
];
const mockCourse = [prismaCourse1, prismaCourse2, prismaCourse3];
Expand Down Expand Up @@ -224,12 +229,14 @@ describe('UserService', () => {
userId: '0cecbf92-d381-40b7-b8f8-49ccae3f8263',
courseId: '57baa1dd-5bed-4ef6-af67-e588962e3a55',
isCompleted: true,
Assignee : 'self'
},
{
id: 2,
userId: '0cecbf92-d381-40b7-b8f8-49ccae3f8263',
courseId: '7be805c9-906e-485f-86a5-0fc11cfe0e2d',
isCompleted: true,
Assignee : 'self'
},
];
const mockCourse = [prismaCourse1, prismaCourse2];
Expand Down Expand Up @@ -279,6 +286,8 @@ describe('UserService', () => {
password: userDTO.password,
id: '1',
createdAt: Date.prototype,
firstName:"ABC",
lastName:"XYZ",
profilePhoto: 'https://profilephoto.com',
updatedAt: Date.prototype,
eId: 'E0001',
Expand Down Expand Up @@ -311,6 +320,8 @@ describe('UserService', () => {
createdAt: Date.prototype,
updatedAt: Date.prototype,
roles: Role.Employee,
firstName:"ABC",
lastName:"XYZ",
},
CompletedCourseCount: 4,
},
Expand All @@ -329,6 +340,8 @@ describe('UserService', () => {
createdAt: Date.prototype,
updatedAt: Date.prototype,
roles: Role.Employee,
firstName:"ABC",
lastName:"XYZ",
},
CompletedCourseCount: 2,
},
Expand All @@ -348,6 +361,8 @@ describe('UserService', () => {
createdAt: Date.prototype,
updatedAt: Date.prototype,
roles: Role.Employee,
firstName:"ABC",
lastName:"XYZ",
};

const mockUser2 = {
Expand All @@ -363,6 +378,8 @@ describe('UserService', () => {
createdAt: Date.prototype,
updatedAt: Date.prototype,
roles: Role.Employee,
firstName:"ABC",
lastName:"XYZ",
};
const mockUsers = [mockUser2, mockUser1];
const mockUserCourse1 = {
Expand Down Expand Up @@ -422,6 +439,7 @@ describe('UserService', () => {
userId: '1',
courseId: 'course1',
isCompleted: false,
Assignee : 'self'
};

jest
Expand Down Expand Up @@ -450,6 +468,7 @@ describe('UserService', () => {
userId: '1',
courseId: 'course1',
isCompleted: false,
Assignee : 'self'
};
jest
.spyOn(prismaService.userCourse, 'findFirst')
Expand All @@ -467,6 +486,7 @@ describe('UserService', () => {
userId: '1',
courseId: 'course1',
isCompleted: false,
Assignee : 'self'
};
expect(service.isUserEnrolledInCourse(userCourse)).toBe(true);
});
Expand All @@ -482,12 +502,14 @@ describe('UserService', () => {
userId: '1',
courseId: 'course1',
isCompleted: false,
Assignee : 'self'
};
const updatedMockUser: UserCourse = {
id: 1,
userId: '1',
courseId: 'course1',
isCompleted: true,
Assignee : 'self'
};
jest
.spyOn(prismaService.userCourse, 'findFirst')
Expand Down Expand Up @@ -536,6 +558,7 @@ describe('UserService', () => {
userId: '1',
courseId: 'course1',
isCompleted: true,
Assignee : 'self'
};
jest
.spyOn(prismaService.userCourse, 'findFirst')
Expand Down Expand Up @@ -601,6 +624,7 @@ describe('UserService', () => {
userId: '1',
courseId: 'course1',
isCompleted: false,
Assignee : 'self'
};
jest
.spyOn(prismaService.userCourse, 'findFirst')
Expand Down Expand Up @@ -636,6 +660,7 @@ describe('UserService', () => {
userId: '1',
courseId: 'course1',
isCompleted: true,
Assignee : 'self'
};
jest
.spyOn(prismaService.userCourse, 'findFirst')
Expand Down Expand Up @@ -697,6 +722,8 @@ describe('UserService', () => {
role: 'BQAE',
clientTeam: 'abcd',
roles: Role.Employee,
firstName:"ABC",
lastName:"XYZ",
};
jest
.spyOn(prismaService.user, 'findFirst')
Expand All @@ -723,6 +750,8 @@ describe('UserService', () => {
role: 'BQAE',
clientTeam: 'abcd',
roles: Role.Employee,
firstName:"ABC",
lastName:"XYZ",
};
jest
.spyOn(prismaService.user, 'findFirst')
Expand Down Expand Up @@ -751,6 +780,8 @@ describe('UserService', () => {
role: 'BQA',
clientTeam: 'abc',
roles: Role.Employee,
firstName:"ABC",
lastName:"XYZ",
},
];

Expand Down