Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…into choose-interv
  • Loading branch information
whiitex committed Jun 1, 2024
2 parents bdb7af6 + 4eb7351 commit 7c49dbd
Show file tree
Hide file tree
Showing 22 changed files with 1,661 additions and 71 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/fullstack.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,4 @@ jobs:
uses: SonarSource/sonarcloud-github-action@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
2 changes: 0 additions & 2 deletions api/src/availability/availability.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
} from '../../../shared/src/availability';
import { User } from 'src/users/user.entity';
import { TimeSlot } from 'src/timeslots/timeslot.entity';
import { DbAwareColumn } from 'src/utils/db-aware-column';

@Entity()
export class Availability implements AvailabilityInterface {
Expand All @@ -24,7 +23,6 @@ export class Availability implements AvailabilityInterface {
@Column({ name: 'last_modified' })
lastModified: Date;

@DbAwareColumn(() => TimeSlot, { name: 'time_slot' })
@ManyToOne(() => TimeSlot, (timeSlot) => timeSlot.availabilities)
timeSlot: Relation<TimeSlot>;

Expand Down
29 changes: 29 additions & 0 deletions api/src/availability/availability.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,28 @@ describe('AvailabilityService', () => {
});
});

describe('updateAvailability', () => {
it('should update the availability with the specified id', async () => {
const mockUpdatedAvailability = {
...mockAvailability,
state: AvailabilityState.Interviewing,
};
jest
.spyOn(mockedRepository, 'save')
.mockResolvedValue(mockUpdatedAvailability);
const result = await service.updateAvailability(
mockAvailability.id,
mockUpdatedAvailability,
);
expect(result).toEqual(mockUpdatedAvailability);
expect(mockedRepository.save).toHaveBeenCalledTimes(1);
expect(mockedRepository.save).toHaveBeenCalledWith({
...mockUpdatedAvailability,
id: mockAvailability.id,
});
});
});

describe('deleteAvailability', () => {
it('should remove the specified availability from the database', async () => {
const mockAvailabilityRepository = {
Expand Down Expand Up @@ -142,6 +164,13 @@ describe('AvailabilityService', () => {
expect(result).toEqual(mockAvailability);
expect(mockedRepository.findBy).toHaveBeenCalledTimes(1);
});

it('should return null if no availability is found', async () => {
jest.spyOn(mockedRepository, 'findBy').mockResolvedValue([]);
const result = await service.findById(mockAvailability.id);
expect(result).toBeNull();
expect(mockedRepository.findBy).toHaveBeenCalledTimes(1);
});
});

describe('findByUserAndTimeSlot', () => {
Expand Down
35 changes: 33 additions & 2 deletions api/src/availability/availability.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,29 +16,54 @@ export class AvailabilityService {
private dataSource: DataSource,
) {}

/**
* List all availabilities
* @returns {Promise<Availability[]>} - List of availabilities
*/
async listAvailabilities(): Promise<Availability[]> {
return await this.availabilityRepository.find();
}

/**
* Find all availabilities for a given user
* @param user - User to find availabilities for
* @returns {Promise<Availability[]>} - List of availabilities for the user
*/
async findById(id: number): Promise<Availability> {
const matches = await this.availabilityRepository.findBy({
id: id,
});
return matches.length > 0 ? matches[0] : null;
}

/**
* Find all availabilities for a given user
* @param user - User to find availabilities for
* @returns {Promise<Availability[]>} - List of availabilities for the user
*/
async findByUserAndTimeSlot(user: User, timeSlot: TimeSlot) {
const matches = await this.availabilityRepository.findBy({
user: user,
timeSlot: timeSlot,
user: user as any,
timeSlot: timeSlot as any,
});
return matches.length > 0 ? matches[0] : null;
}

/**
* Create an availability
* @param availability - Availability to create
* @returns {Promise<Availability>} - Created availability
*/
async createAvailability(availability: Availability): Promise<Availability> {
return await this.availabilityRepository.save(availability);
}

/**
* Update an availability
* @param oldAvailabilityId - ID of the
* @param newAvailability - New availability
* @returns {Promise<Availability>} - Updated availability
*/
async updateAvailability(
oldAvailabilityId: number,
newAvailability: Availability,
Expand All @@ -49,6 +74,12 @@ export class AvailabilityService {
});
}

/**
* Delete an availability
* @param availabilityId - ID of the availability to delete
* @returns {Promise<Availability>} - Deleted availability
* @throws {ConflictException} - If availability is in use
*/
async deleteAvailability(availabilityId: number): Promise<Availability> {
return await transaction(
this.dataSource,
Expand Down
62 changes: 8 additions & 54 deletions api/src/mocks/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,6 @@ export const testDateTime1Hour = new Date(2023, 0, 1, 11, 30, 0);
export const testDateTime3Hours = new Date(2023, 0, 1, 13, 30, 0);
export const testDateTimeEnd = new Date(2023, 0, 1, 11, 30, 0);

export const mockTimeSlot = {
start: testDateTimeStart,
end: testDateTimeEnd,
id: 1,
availabilities: [],
} as TimeSlot & { availabilities: any[] };

export const testInterviewStart = '11:55' as unknown as Date;
export const testInterviewEnd = '20:35' as unknown as Date;
export const testDay1 = '2024-10-20' as unknown as Date;
Expand All @@ -57,6 +50,14 @@ export const mockRecruitmentSession = {
lastModified: testDateLastModified,
};

export const mockTimeSlot = {
recruitmentSession: mockRecruitmentSession,
start: testDateTimeStart,
end: testDateTimeEnd,
id: 1,
availabilities: [],
} as TimeSlot & { availabilities: any[] };

export const mockCreateRecruitmentSessionDto = {
slotDuration: 50,
interviewStart: testInterviewStart,
Expand Down Expand Up @@ -231,50 +232,3 @@ export const mockAvailability = {
export const mockCreateAvailabilityDto = {
timeSlotId: mockTimeSlot.id,
} as CreateAvailabilityDto;

export const mockInterview: Interview = {
id: 123,
notes: 'qwerty',
createdAt: new Date(2023, 0, 1),
timeslot: mockTimeSlot,
application: mockMscApplication,
interviewer1: {
oauthId: '123',
firstName: 'Jane',
lastName: 'Doe',
sex: 'F',
email: '[email protected]',
is_board: true,
is_expert: false,
role: Role.Member,
},
interviewer2: {
oauthId: '456',
firstName: 'John',
lastName: 'Doe',
sex: 'M',
email: '[email protected]',
is_board: false,
is_expert: true,
role: Role.Member,
},
optionalInterviewer: {
oauthId: '678',
firstName: 'Jack',
lastName: 'Dao',
sex: 'M',
email: '[email protected]',
is_board: false,
is_expert: false,
role: Role.Member,
},
};

export const MockCreateInterviewDTO: CreateInterviewDto = {
createdAt: new Date(2023, 0, 1),
timeslot_id: mockTimeSlot.id,
};

export const MockUpdateInterviewDTO = {
notes: 'Notes',
} as UpdateInterviewDto;
Loading

0 comments on commit 7c49dbd

Please sign in to comment.