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

Fix bug to prevent /ec when editing doctor #225

Merged
merged 3 commits into from
Nov 12, 2023

Conversation

tanveersingh10
Copy link

@tanveersingh10 tanveersingh10 commented Nov 12, 2023

fixes #221

Copy link

codecov bot commented Nov 12, 2023

Codecov Report

Merging #225 (334b671) into master (6ffae7b) will increase coverage by 0.03%.
The diff coverage is 45.00%.

@@             Coverage Diff              @@
##             master     #225      +/-   ##
============================================
+ Coverage     75.37%   75.41%   +0.03%     
- Complexity      756      758       +2     
============================================
  Files           112      112              
  Lines          2530     2538       +8     
  Branches        272      271       -1     
============================================
+ Hits           1907     1914       +7     
  Misses          530      530              
- Partials         93       94       +1     
Files Coverage Δ
...java/seedu/address/logic/commands/EditCommand.java 83.93% <45.00%> (+0.15%) ⬆️

📣 Codecov offers a browser extension for seamless coverage viewing on GitHub. Try it in Chrome or Firefox today!

Copy link

@cmHuang777 cmHuang777 left a comment

Choose a reason for hiding this comment

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

Looks great. May be you can also try to cover the test cases for the newly added code.

Copy link

@chonguschonguschongus chonguschonguschongus left a comment

Choose a reason for hiding this comment

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

LGTM. Good job on solving the issue, now just to ensure code coverage is good!

Comment on lines -138 to +161
throw new CommandException("Doctors cannot have Condition or BloodType fields.");
}
if (editPersonDescriptor.getTags().isPresent()
&& !editPersonDescriptor.isValidDoctorTagList(editPersonDescriptor.getTags().get())) {
logger.warning(editPersonDescriptor.getTags().toString());
throw new CommandException("Please enter valid Doctor tags.");
}
editedPerson = createEditedDoctor((Doctor) personToEdit, editPersonDescriptor);
Doctor doctorToEdit = (Doctor) personToEdit;
validateDoctor();
editedPerson = createEditedDoctor(doctorToEdit, editPersonDescriptor);
}
if (!personToEdit.isSamePerson(editedPerson) && model.hasPerson(editedPerson)) {
logger.warning("Edited Person and orignal person are the same");
throw new CommandException(MESSAGE_DUPLICATE_PERSON);
}
return editedPerson;
}
private void validatePatient() throws CommandException {
if (editPersonDescriptor.getTags().isPresent()
&& !editPersonDescriptor.isValidPatientTagList(editPersonDescriptor.getTags().get())) {
logger.warning("Invalid tag for patient");
throw new CommandException("Please enter a valid patient tag.");
}
}
private void validateDoctor() throws CommandException {
if (editPersonDescriptor.getCondition().isPresent() || editPersonDescriptor.getBloodType().isPresent()
|| editPersonDescriptor.getEmergencyContact().isPresent()) {
logger.warning("Error thrown - tried to edit condition/blood type/emergency contact of doctor");
throw new CommandException("Doctors cannot have Condition, BloodType or Emergency Contact fields.");
}
if (editPersonDescriptor.getTags().isPresent()
&& !editPersonDescriptor.isValidDoctorTagList(editPersonDescriptor.getTags().get())) {
logger.warning(editPersonDescriptor.getTags().toString());
throw new CommandException("Please enter valid Doctor tags.");
}
}

Choose a reason for hiding this comment

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

gotta write new test cases for all these!

@kohkaijie kohkaijie merged commit ec3d7ef into AY2324S1-CS2103T-T09-3:master Nov 12, 2023
4 of 5 checks passed
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.

Inconsistency bug in EditCommand
4 participants