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

add new workspace endpoint #78

Closed
wants to merge 1 commit into from
Closed
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
94 changes: 47 additions & 47 deletions src/server/workspace/src/schedule/schedule.controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,71 +39,71 @@ describe('ScheduleController', () => {
expect(controller).toBeDefined();
});

// describe('create', () => {
// it('should create a new schedule', async () => {
// const createDto: CreateScheduleDto = {
// date: '2024-06-24T10:00:00Z',
// workspace_id: 'workspace-id-1',
// lecturer_id: 'lecturer-id-1',
// description: 'Sample description',
// topic: 'Sample topic',
// };
// describe('create', () => {
// it('should create a new schedule', async () => {
// const createDto: CreateScheduleDto = {
// date: '2024-06-24T10:00:00Z',
// workspace_id: 'workspace-id-1',
// lecturer_id: 'lecturer-id-1',
// description: 'Sample description',
// topic: 'Sample topic',
// };

// const createdSchedule: Schedule = {
// _id: '6037bce2df95b73e28bc7227',
// ...createDto,
// };
// const createdSchedule: Schedule = {
// _id: '6037bce2df95b73e28bc7227',
// ...createDto,
// };

// jest.spyOn(scheduleService, 'create').mockResolvedValue(createdSchedule);
// jest.spyOn(scheduleService, 'create').mockResolvedValue(createdSchedule);

// const result = await controller.create(createDto);
// const result = await controller.create(createDto);

// expect(result).toEqual(createdSchedule);
// });
// });
// expect(result).toEqual(createdSchedule);
// });
// });

describe('findOne', () => {
it('should call the findOne method of the service', async () => {
const id = 'test-id';
describe('findOne', () => {
it('should call the findOne method of the service', async () => {
const id = 'test-id';

await controller.findOne(id);
await controller.findOne(id);

expect(service.findOne).toHaveBeenCalledWith(id);
expect(service.findOne).toHaveBeenCalledWith(id);
});
});
});

describe('findAllByWorkspaceId', () => {
it('should call the findAllByWorkspaceId method of the service', async () => {
const workspaceId = 'workspace-id-1';
describe('findAllByWorkspaceId', () => {
it('should call the findAllByWorkspaceId method of the service', async () => {
const workspaceId = 'workspace-id-1';

await controller.findAllByWorkspaceId(workspaceId);
await controller.findAllByWorkspaceId(workspaceId);

expect(service.findAllByWorkspaceId).toHaveBeenCalledWith(workspaceId);
expect(service.findAllByWorkspaceId).toHaveBeenCalledWith(workspaceId);
});
});
});

describe('update', () => {
it('should call the update method of the service', async () => {
const id = 'test-id';
const updateScheduleDto: UpdateScheduleDto = {
topic: 'Updated Material',
description: 'Updated Description',
date: '/path/to/updated-file.pdf',
};
describe('update', () => {
it('should call the update method of the service', async () => {
const id = 'test-id';
const updateScheduleDto: UpdateScheduleDto = {
topic: 'Updated Material',
description: 'Updated Description',
date: '/path/to/updated-file.pdf',
};

await controller.update(id, updateScheduleDto);
await controller.update(id, updateScheduleDto);

expect(service.update).toHaveBeenCalledWith(id, updateScheduleDto);
expect(service.update).toHaveBeenCalledWith(id, updateScheduleDto);
});
});
});

describe('delete', () => {
it('should call the delete method of the service', async () => {
const id = 'test-id';
describe('delete', () => {
it('should call the delete method of the service', async () => {
const id = 'test-id';

await controller.delete(id);
await controller.delete(id);

expect(service.delete).toHaveBeenCalledWith(id);
expect(service.delete).toHaveBeenCalledWith(id);
});
});
});
});
27 changes: 27 additions & 0 deletions src/server/workspace/src/workspace/workspace.controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ describe('WorkspaceController', () => {
useValue: {
create: jest.fn(),
findOne: jest.fn(),
findMany: jest.fn(),
update: jest.fn(),
delete: jest.fn(),
},
Expand Down Expand Up @@ -52,6 +53,32 @@ describe('WorkspaceController', () => {
});
});

describe('findMany', () => {
it('should call the findMany method of the service with empty query', async () => {
const query = {};
await controller.findMany(query);

expect(service.findMany).toHaveBeenCalledWith(query);
});

it('should call the findMany method of the service with specific name query', async () => {
const query = { name: 'Specific Workspace' };
await controller.findMany(query);

expect(service.findMany).toHaveBeenCalledWith(query);
});

it('should call the findMany method of the service with multiple query parameters', async () => {
const query = {
name: 'Specific Workspace',
createdBy: 'specific-user-id',
};
await controller.findMany(query);

expect(service.findMany).toHaveBeenCalledWith(query);
});
});

describe('update', () => {
it('should call the update method of the service', async () => {
const id = 'test-id';
Expand Down
6 changes: 6 additions & 0 deletions src/server/workspace/src/workspace/workspace.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
Put,
Body,
Post,
Query,
Param,
Delete,
Controller,
Expand All @@ -29,6 +30,11 @@ export class WorkspaceController {
return this.workspaceService.findAllByOrganisationId(organisationId);
}

@Get()
async findMany(@Query() query: Partial<CreateWorkspaceDto>) {
return await this.workspaceService.findMany({ ...query });
}

@Get(':id')
async findOne(@Param('id') id: string) {
return this.workspaceService.findOne(id);
Expand Down
24 changes: 24 additions & 0 deletions src/server/workspace/src/workspace/workspace.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,19 @@ describe('WorkspaceService', () => {
name: 'Updated Workspace',
};

const query = { name: 'Test Workspace' };

const workspacesMock = [
{
_id: 'test-id-1',
name: 'Test Workspace 1',
},
{
_id: 'test-id-2',
name: 'Test Workspace 2',
},
];

beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
providers: [
Expand All @@ -29,6 +42,7 @@ describe('WorkspaceService', () => {
new: jest.fn().mockResolvedValue(workspaceMock),
constructor: jest.fn().mockResolvedValue(workspaceMock),
findById: jest.fn(),
find: jest.fn(),
findByIdAndUpdate: jest.fn(),
findByIdAndDelete: jest.fn(),
},
Expand All @@ -52,6 +66,16 @@ describe('WorkspaceService', () => {
});
});

describe('findMany', () => {
it('should find many workspaces based on query', async () => {
jest.spyOn(model, 'find').mockReturnValueOnce({
exec: jest.fn().mockResolvedValueOnce(workspacesMock),
} as any);
const result = await service.findMany(query);
expect(result).toEqual(workspacesMock);
});
});

describe('update', () => {
it('should update a workspace', async () => {
jest.spyOn(model, 'findByIdAndUpdate').mockReturnValueOnce({
Expand Down
4 changes: 4 additions & 0 deletions src/server/workspace/src/workspace/workspace.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ export class WorkspaceService {
return this.workspaceModel.findById(id).exec();
}

async findMany(query: Partial<CreateWorkspaceDto>): Promise<Workspace[]> {
return this.workspaceModel.find(query).exec();
}

async findAllByOrganisationId(organisationId: string): Promise<Workspace[]> {
return this.workspaceModel.find({ organisation: organisationId }).exec();
}
Expand Down
Loading