Skip to content

Commit bae8f0b

Browse files
committed
tests: Added e2e testing for checklist item endpoints
1 parent aac3a23 commit bae8f0b

File tree

7 files changed

+424
-12
lines changed

7 files changed

+424
-12
lines changed

api/src/application/services/checklist-item.service.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,17 @@ class ChecklistItemService {
4343
checklistItemData.assignedProjectMemberIds,
4444
requesterAsProjectMember.projectId,
4545
);
46-
}
4746

48-
if (projectMembers.length === 0)
49-
throw boom.badData(
50-
'The provided project member ids do not belong to the project',
47+
if (projectMembers?.length === 0)
48+
throw boom.badData(
49+
'The provided project member ids do not belong to the project',
50+
);
51+
52+
checklistItemData.assignedProjectMemberIds = projectMembers.map(
53+
(member) => member.id,
5154
);
55+
}
5256

53-
checklistItemData.assignedProjectMemberIds = projectMembers.map(
54-
(member) => member.id,
55-
);
5657
return this.createChecklistItemUseCase.execute(checklistItemData);
5758
}
5859

api/src/application/use-cases/checklist-item/UpdateTheCheckOfItemUseCase.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable no-param-reassign */
12
const boom = require('@hapi/boom');
23
const ChecklistItemDto = require('../../dtos/checklist-item.dto');
34

@@ -9,9 +10,14 @@ class UpdateTheCheckOfItemUseCase {
910
async execute(checklistItemId, isChecked) {
1011
if (!checklistItemId) throw new Error('checklistItemId was not provided');
1112
if (typeof isChecked !== 'boolean') {
12-
throw new Error('checklistItemId was not provided');
13+
if (isChecked !== 'false' && isChecked !== 'true') {
14+
throw new Error('isChecked was not provided');
15+
}
1316
}
1417

18+
if (isChecked === 'false') isChecked = false;
19+
if (isChecked === 'true') isChecked = true;
20+
1521
const [affectedRows, [updateChecklistItem]] =
1622
await this.checklistItemRepository.update(checklistItemId, { isChecked });
1723

api/src/infrastructure/repositories/db/checklist-item.repository.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,25 @@ class ChecklistItemRepository extends IChecklistItemRepository {
2828
}
2929

3030
async findOneByIdAndProject(checklistItemId, projectId) {
31+
console.log(checklistItemId, projectId);
32+
3133
return this.db.models.ChecklistItem.findOne({
3234
where: { id: checklistItemId },
3335
include: [
3436
{
3537
model: this.db.models.Checklist,
3638
as: 'checklist',
39+
required: true,
3740
include: [
3841
{
3942
model: this.db.models.Card,
4043
as: 'card',
44+
required: true,
4145
include: [
4246
{
4347
model: this.db.models.List,
4448
as: 'list',
49+
required: true,
4550
where: { projectId },
4651
},
4752
],

api/src/interfaces/controllers/checklist-item.controller.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,14 +87,14 @@ const deleteChecklistItem = async (req, res, next) => {
8787
const { checklistItemId } = req.params;
8888
const requesterAsProjectMember = req.projectMember;
8989

90-
const deletedCard = await checklistItemService.deleteChecklistItem(
90+
const deletedItem = await checklistItemService.deleteChecklistItem(
9191
requesterAsProjectMember,
9292
checklistItemId,
9393
);
9494

9595
res.status(200).json({
9696
message: 'The checklist item was successfully removed',
97-
deletedCard,
97+
deletedItem,
9898
});
9999
} catch (error) {
100100
next(error);

api/src/interfaces/schemas/checklist-item.schema.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
11
const Joi = require('joi');
22

33
const id = Joi.string().uuid();
4-
const name = Joi.string().trim().min(1).max(50);
4+
const name = Joi.string()
5+
.trim()
6+
.min(1)
7+
.max(50)
8+
.pattern(/^(?!.*\.\.)(?![. ])([A-Za-z0-9 _.-]{3,80})(?<![. ])$/)
9+
.messages({
10+
'string.pattern.base':
11+
'The name can only contain letters, numbers and spaces.',
12+
});
513
const dueDate = Joi.date().iso().greater('now').messages({
614
'date.format': 'Due date must be a valid ISO date string',
715
'date.greater': 'Due date must be in the future',

0 commit comments

Comments
 (0)