Skip to content

Conversation

gabrieltmonkai
Copy link
Contributor

@gabrieltmonkai gabrieltmonkai commented Oct 8, 2025

Overview

Jira Ticket Reference : MN-780

Added a new deleteImage function to handle image deletion of an inspection.

Checklist before requesting a review

  • I have updated the unit tests based on the changes I made
  • I have updated the docs (TSDoc / README / global doc) to reflect my changes
  • I have updated the local app configs if needed
  • I have performed self-QA of my feature by testing the apps and packages and made sure that :
    • No regression or new bug has occurred
    • The acceptance criteria listed in the ticket are met
    • Self-QA was made on both desktop and mobile

@gabrieltmonkai gabrieltmonkai force-pushed the feat/MN-780/create-deleteImage-api branch from 3ab10ff to 4121c7f Compare October 9, 2025 14:14
@gabrieltmonkai gabrieltmonkai force-pushed the feat/MN-780/create-deleteImage-api branch 7 times, most recently from 0788148 to cf49a7c Compare October 16, 2025 10:42
@gabrieltmonkai gabrieltmonkai force-pushed the feat/MN-780/create-deleteImage-api branch from cf49a7c to e8c1f0d Compare October 20, 2025 08:59
Comment on lines 621 to 633
const formData = JSON.stringify({
authorized_tasks_statuses: [ProgressStatus.NOT_STARTED],
});
const kyOptions = getDefaultOptions(config);
kyOptions.headers = {
...kyOptions.headers,
'Content-Type': 'application/json',
};
try {
const response = await ky.delete(`inspections/${options.id}/images/${options.imageId}`, {
...kyOptions,
body: formData,
});
Copy link
Contributor

@dlymonkai dlymonkai Oct 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that you need this 'content-type', you can skip using it.
And use json property of ky function passing
{ authorized_tasks_statuses: [ProgressStatus.NOT_STARTED]}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using the json property instead of body allowed me to get rid of content-type, otherwise the API would respond with 415 Code, saying "Did not attempt to load JSON data because the request Content-Type was not 'application/json'.".

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you still have this error?

@gabrieltmonkai gabrieltmonkai force-pushed the feat/MN-780/create-deleteImage-api branch 3 times, most recently from 4af7b00 to b6d4572 Compare October 21, 2025 08:59
Comment on lines 81 to 82
Delete an image from an inspection. The resulting action of this request will contain the details of the image that has
been created in the API.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change created text to deleted

Comment on lines 586 to 597
await deleteImage(options, apiConfig, dispatch);

expect(getDefaultOptions).toHaveBeenCalledWith(apiConfig);
expect(ky.delete).toHaveBeenCalledWith(
`inspections/${options.id}/images/${options.imageId}`,
expect.objectContaining(getDefaultOptions(apiConfig)),
);
expect(dispatch).toHaveBeenCalledWith({
type: MonkActionType.DELETED_ONE_IMAGE,
payload: {
inspectionId: options.id,
imageId: undefined,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mock the response of deleteImage and get the body.
Don't forget to change the expected imageId of dispatch function

@gabrieltmonkai gabrieltmonkai force-pushed the feat/MN-780/create-deleteImage-api branch 2 times, most recently from d864b1c to 6e0b9b2 Compare October 21, 2025 15:19
},
});
expect(result).toEqual({
id: 'delete-test-fake-id',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here it shouldn't be a hardcoded string, but body.id

type: MonkActionType.DELETED_ONE_IMAGE,
payload: {
inspectionId: options.id,
imageId: result.id,
Copy link
Contributor

@dlymonkai dlymonkai Oct 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually you want to get the real response of ky.delete, so instead of result.id. It should be body.id

});

it('should display an error if deletion fails', async () => {
const err = new Error('test delete error');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you change it to kebab-case convention please

Reset state objects containing the deleted image

Updated objects to be deleted in State

Updated API export and added more tests

Added docs

Updated Tests
@gabrieltmonkai gabrieltmonkai force-pushed the feat/MN-780/create-deleteImage-api branch from 6e0b9b2 to aaec99e Compare October 22, 2025 15:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants