Skip to content

Commit

Permalink
Fix formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
dexter-sim committed Oct 18, 2024
1 parent a8796c1 commit 6d2f12e
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 16 deletions.
38 changes: 28 additions & 10 deletions backend/test/controllers/courseController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1064,10 +1064,15 @@ describe('courseController', () => {

describe('addRepositories', () => {
it('should add repositories to a course', async () => {
const req = mockRequest({ gitHubRepoLink: ['repo1', 'repo2'] }, { id: 'courseId' });
const req = mockRequest(
{ gitHubRepoLink: ['repo1', 'repo2'] },
{ id: 'courseId' }
);
const res = mockResponse();

jest.spyOn(courseService, 'addRepositoriesToCourse').mockResolvedValue(undefined);
jest
.spyOn(courseService, 'addRepositoriesToCourse')
.mockResolvedValue(undefined);

await addRepositories(req, res);

Expand All @@ -1078,7 +1083,10 @@ describe('courseController', () => {
});

it('should handle NotFoundError and send a 404 status', async () => {
const req = mockRequest({ gitHubRepoLink: ['repo1', 'repo2'] }, { id: 'courseId' });
const req = mockRequest(
{ gitHubRepoLink: ['repo1', 'repo2'] },
{ id: 'courseId' }
);
const res = mockResponse();

jest
Expand All @@ -1092,7 +1100,10 @@ describe('courseController', () => {
});

it('should handle errors when adding repositories', async () => {
const req = mockRequest({ gitHubRepoLink: ['repo1', 'repo2'] }, { id: 'courseId' });
const req = mockRequest(
{ gitHubRepoLink: ['repo1', 'repo2'] },
{ id: 'courseId' }
);
const res = mockResponse();

jest
Expand All @@ -1110,12 +1121,13 @@ describe('courseController', () => {

describe('updateRepository', () => {
it('should update repository in a course', async () => {
const req = mockRequest({ repoLink: 'repo3' }, { id: 'courseId', repositoryIndex: 1 });
const req = mockRequest(
{ repoLink: 'repo3' },
{ id: 'courseId', repositoryIndex: 1 }
);
const res = mockResponse();

jest
.spyOn(courseService, 'editRepository')
.mockResolvedValue(undefined);
jest.spyOn(courseService, 'editRepository').mockResolvedValue(undefined);

await updateRepository(req, res);

Expand All @@ -1126,7 +1138,10 @@ describe('courseController', () => {
});

it('should handle NotFoundError and send a 404 status', async () => {
const req = mockRequest({ repoLink: 'repo3' }, { id: 'courseId', repositoryIndex: 1 });
const req = mockRequest(
{ repoLink: 'repo3' },
{ id: 'courseId', repositoryIndex: 1 }
);
const res = mockResponse();

jest
Expand All @@ -1140,7 +1155,10 @@ describe('courseController', () => {
});

it('should handle errors when updating repository', async () => {
const req = mockRequest({ repoLink: 'repo3' }, { id: 'courseId', repositoryIndex: 1 });
const req = mockRequest(
{ repoLink: 'repo3' },
{ id: 'courseId', repositoryIndex: 1 }
);
const res = mockResponse();

jest
Expand Down
16 changes: 10 additions & 6 deletions backend/test/services/courseService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -928,24 +928,26 @@ describe('courseService', () => {

describe('getRepositoriesFromCourse', () => {
it('should get repositories from a course', async () => {
// Mock course data
const course = await CourseModel.findOne({ _id: courseId });
if (!course) {
throw new Error('Course not found');
}

const repo1 = 'https://github.com/org/repo1';
const repo2 = 'https://github.com/org/repo2';

// Add repository links to the course
course.gitHubRepoLinks.push('https://github.com/org/repo1');
course.gitHubRepoLinks.push('https://github.com/org/repo2');
course.gitHubRepoLinks.push(repo1);
course.gitHubRepoLinks.push(repo2);
await course.save();

const repositories = await getRepositoriesFromCourse(courseId);

// Ensure repositories are returned correctly
expect(repositories).toBeDefined();
expect(repositories.repositories.length).toBe(2);
expect(repositories.repositories).toContain('https://github.com/org/repo1');
expect(repositories.repositories).toContain('https://github.com/org/repo2');
expect(repositories.repositories).toContain(repo1);
expect(repositories.repositories).toContain(repo2);
});

it('should throw NotFoundError for invalid courseId', async () => {
Expand Down Expand Up @@ -1012,7 +1014,9 @@ describe('courseService', () => {
await editRepository(courseId, repositoryIndex, updateData);

const updatedCourse = await CourseModel.findById(courseId);
expect(updatedCourse?.gitHubRepoLinks[repositoryIndex]).toBe(updatedRepoLink);
expect(updatedCourse?.gitHubRepoLinks[repositoryIndex]).toBe(
updatedRepoLink
);
});

it('should throw NotFoundError for invalid courseId', async () => {
Expand Down

0 comments on commit 6d2f12e

Please sign in to comment.