Skip to content

Commit

Permalink
Merge branch 'master' into feat-add-leave_requests_on-faircalendar
Browse files Browse the repository at this point in the history
  • Loading branch information
florimondmanca authored Jun 21, 2024
2 parents 8e4b595 + 93cb6fd commit b48cac5
Show file tree
Hide file tree
Showing 51 changed files with 591 additions and 366 deletions.
2 changes: 1 addition & 1 deletion e2e/nav.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ test('nav links', async ({ page }) => {
['Clients', '/app/customers'],
['Projets', '/app/projects'],
['Missions', '/app/tasks'],
['Congés', '/app/people/leaves'],
['Congés', '/app/people/leave_requests'],
['Éléments de paie', '/app/people/payroll_elements'],
['Tickets resto', '/app/people/meal_tickets'],
['Coopérateur·ices et salarié·es', '/app/people/users']
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { MigrationInterface, QueryRunner } from 'typeorm';

export class AddPostponedWorkedFreeDayLeaveRequestType1718114720685
implements MigrationInterface {
name = 'AddPostponedWorkedFreeDayLeaveRequestType1718114720685';

public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TYPE "public"."leave_request_type_enum" RENAME TO "leave_request_type_enum_old"`
);
await queryRunner.query(
`CREATE TYPE "public"."leave_request_type_enum" AS ENUM('paid', 'unpaid', 'special', 'medical', 'illimited', 'postponedWorkedFreeDay')`
);
await queryRunner.query(
`ALTER TABLE "leave_request" ALTER COLUMN "type" TYPE "public"."leave_request_type_enum" USING "type"::"text"::"public"."leave_request_type_enum"`
);
await queryRunner.query(`DROP TYPE "public"."leave_request_type_enum_old"`);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`CREATE TYPE "public"."leave_request_type_enum_old" AS ENUM('paid', 'unpaid', 'special', 'medical', 'illimited')`
);
await queryRunner.query(
`ALTER TABLE "leave_request" ALTER COLUMN "type" TYPE "public"."leave_request_type_enum_old" USING "type"::"text"::"public"."leave_request_type_enum_old"`
);
await queryRunner.query(`DROP TYPE "public"."leave_request_type_enum"`);
await queryRunner.query(
`ALTER TYPE "public"."leave_request_type_enum_old" RENAME TO "leave_request_type_enum"`
);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { IQuery } from 'src/Application/IQuery';
import { User } from 'src/Domain/HumanResource/User/User.entity';

export class GetLeaveRequestByIdQuery implements IQuery {
constructor(public readonly id: string) {}
constructor(public readonly id: string, public readonly currentUser: User) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,22 @@ import { UserSummaryView } from '../../User/View/UserSummaryView';
import { LeaveRequestDetailView } from '../View/LeaveRequestDetailView';
import { GetLeaveRequestByIdQuery } from './GetLeaveRequestByIdQuery';
import { GetLeaveRequestByIdQueryHandler } from './GetLeaveRequestByIdQueryHandler';
import { CanLeaveRequestBeCancelled } from 'src/Domain/HumanResource/Leave/Specification/CanLeaveRequestBeCancelled';

describe('GetLeaveRequestByIdQueryHandler', () => {
let leaveRequestRepository: LeaveRequestRepository;
let dateUtils: DateUtilsAdapter;
let canLeaveRequestBeCancelled: CanLeaveRequestBeCancelled;
let queryHandler: GetLeaveRequestByIdQueryHandler;

beforeEach(() => {
leaveRequestRepository = mock(LeaveRequestRepository);
dateUtils = mock(DateUtilsAdapter);
canLeaveRequestBeCancelled = mock(CanLeaveRequestBeCancelled);
queryHandler = new GetLeaveRequestByIdQueryHandler(
instance(leaveRequestRepository),
instance(dateUtils)
instance(dateUtils),
instance(canLeaveRequestBeCancelled)
);
});

Expand All @@ -37,6 +41,7 @@ describe('GetLeaveRequestByIdQueryHandler', () => {
'2020-05-15',
true,
7.5,
false,
'Country vacation',
new UserSummaryView(
'54bb15ad-56da-45f8-b594-3ca43f13d4c0',
Expand All @@ -48,6 +53,7 @@ describe('GetLeaveRequestByIdQueryHandler', () => {
'Ada',
'LOVELACE'
),
'2020-05-01',
'Go go go'
);

Expand All @@ -72,8 +78,13 @@ describe('GetLeaveRequestByIdQueryHandler', () => {
when(leave.getComment()).thenReturn('Country vacation');
when(leave.getUser()).thenReturn(instance(user));
when(leave.getModerator()).thenReturn(instance(moderator));
when(leave.getModerateAt()).thenReturn('2020-05-01');
when(leave.getModerationComment()).thenReturn('Go go go');

when(
canLeaveRequestBeCancelled.isSatisfiedBy(instance(user), instance(leave))
).thenReturn(false);

when(
leaveRequestRepository.findOneById('204522d3-f077-4d21-b3ee-6e0d742fca44')
).thenResolve(instance(leave));
Expand All @@ -84,7 +95,10 @@ describe('GetLeaveRequestByIdQueryHandler', () => {

expect(
await queryHandler.execute(
new GetLeaveRequestByIdQuery('204522d3-f077-4d21-b3ee-6e0d742fca44')
new GetLeaveRequestByIdQuery(
'204522d3-f077-4d21-b3ee-6e0d742fca44',
instance(user)
)
)
).toMatchObject(expectedResult);

Expand All @@ -101,9 +115,14 @@ describe('GetLeaveRequestByIdQueryHandler', () => {
leaveRequestRepository.findOneById('204522d3-f077-4d21-b3ee-6e0d742fca44')
).thenResolve(null);

const user = mock(User);

try {
await queryHandler.execute(
new GetLeaveRequestByIdQuery('204522d3-f077-4d21-b3ee-6e0d742fca44')
new GetLeaveRequestByIdQuery(
'204522d3-f077-4d21-b3ee-6e0d742fca44',
user
)
);
} catch (e) {
expect(e).toBeInstanceOf(LeaveRequestNotFoundException);
Expand All @@ -126,13 +145,15 @@ describe('GetLeaveRequestByIdQueryHandler', () => {
'2020-05-15',
true,
7.5,
false,
'Country vacation',
new UserSummaryView(
'2402455a-4dc1-47c9-89a4-f9b859f02f5c',
'John',
'DOE'
),
null,
null,
null
);

Expand All @@ -154,6 +175,10 @@ describe('GetLeaveRequestByIdQueryHandler', () => {
when(leave.getModerator()).thenReturn(null);
when(leave.getModerationComment()).thenReturn(null);

when(
canLeaveRequestBeCancelled.isSatisfiedBy(instance(user), instance(leave))
).thenReturn(false);

when(
leaveRequestRepository.findOneById('a3753b9c-b711-4e0e-a535-e473161bd612')
).thenResolve(instance(leave));
Expand All @@ -164,7 +189,10 @@ describe('GetLeaveRequestByIdQueryHandler', () => {

expect(
await queryHandler.execute(
new GetLeaveRequestByIdQuery('a3753b9c-b711-4e0e-a535-e473161bd612')
new GetLeaveRequestByIdQuery(
'a3753b9c-b711-4e0e-a535-e473161bd612',
instance(user)
)
)
).toMatchObject(expectedResult);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@ import { LeaveRequestRepository } from 'src/Infrastructure/HumanResource/Leave/R
import { UserSummaryView } from '../../User/View/UserSummaryView';
import { LeaveRequestDetailView } from '../View/LeaveRequestDetailView';
import { GetLeaveRequestByIdQuery } from './GetLeaveRequestByIdQuery';
import { CanLeaveRequestBeCancelled } from 'src/Domain/HumanResource/Leave/Specification/CanLeaveRequestBeCancelled';

@QueryHandler(GetLeaveRequestByIdQuery)
export class GetLeaveRequestByIdQueryHandler {
constructor(
@Inject('ILeaveRequestRepository')
private readonly leaveRequestRepository: LeaveRequestRepository,
@Inject('IDateUtils')
private readonly dateUtils: IDateUtils
private readonly dateUtils: IDateUtils,
private readonly canLeaveRequestBeCancelled: CanLeaveRequestBeCancelled
) {}

public async execute(
Expand Down Expand Up @@ -53,13 +55,18 @@ export class GetLeaveRequestByIdQueryHandler {
leaveRequest.getEndDate(),
leaveRequest.isEndsAllDay()
),
this.canLeaveRequestBeCancelled.isSatisfiedBy(
query.currentUser,
leaveRequest
),
leaveRequest.getComment(),
new UserSummaryView(
user.getId(),
user.getFirstName(),
user.getLastName()
),
moderatorView,
leaveRequest.getModerateAt(),
leaveRequest.getModerationComment()
);
}
Expand Down
Loading

0 comments on commit b48cac5

Please sign in to comment.