Skip to content

#259 patch remove section from issue map - #298

Open
Justin-4205 wants to merge 5 commits into
mainfrom
#259-PATCH-remove-section-from-issue-map
Open

#259 patch remove section from issue map#298
Justin-4205 wants to merge 5 commits into
mainfrom
#259-PATCH-remove-section-from-issue-map

Conversation

@Justin-4205

Copy link
Copy Markdown
Contributor

Pull Request

Brief Summary

  • Created the patchRemoveSections Route.
  • Created two db acessors addArticles and removeSection.
  • Reformatted issue map seed.

Questions / Considerations for the Future

  • Ensure the articles in the general and section fields are unique.

API Changes

  • patchRemoveSections endpoint.

Database Changes

-

New Tests

  • Created tests for patchRemoveSection route.
  • Modified patchRemoveArticle tests.

Closes #259

Added the addArticle and removeSection accessors. Added the preliminary structure for tests.
Added the necessary tests. Changed the accessor and controller to the properly deal with adding articles and removing sections.
Changed seeding data for specific tests. Made sure articles added to general article list is unique.
Further changed the reseed data such that the general and articles in sections are unique. Changed corresponding tests.
Comment thread app/controllers/issueMapController.js Outdated
* @param {Request} req
* @param {Response} res
*/
static async patchSection(req, res) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Given that this function only removes sections, I would rename the function to patchRemoveSection.

const sectionColor = req.body.sectionColor;

if (!sectionName || !sectionColor) {
throw new ErrorInvalidRequestBody();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Given the number of possibilities for an invalid request body, a specific message may help with specificity.

Comment thread app/controllers/issueMapController.js Outdated
const sectionName = req.body.sectionName;
const sectionColor = req.body.sectionColor;

if (!sectionName || !sectionColor) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Also check for the issue number being present? If you don't have an issue number, where are you deleting the section from?

await updated.save();

// remove section
const issues = await IssueMap.findOneAndUpdate(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nitpick: If you're only updating one issue, why is this const pluralized

{ issueNumber: issueNumber },
{
$pull: {
sections: {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You use $elemMatch below, why not here? Otherwise (as I understand it) you aren't ensuring that both portions match.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

$pull will delete elements that satisfy both requirements.

}

// extract articles
const toMove = article.sections[0].articles;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Related to my above issue - why does the index to 0 just work? How do you know that the section is going to be the first one in the array?

* @return issue map with added articles to general field
*/
static async addArticles(issueNumber, sectionName, sectionColor) {
const article = await IssueMap.findOne(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

So, this is not an article? It seems that the return of this function is an IssueMap.


if (!finalArticle) {
throw new ErrorIssueMapNotFound();
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I would move this check above, because you've already looked for this issueMap once. If you couldn't find it then, the error should have been thrown then.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is to ensure nothing weird happens when articles are added.

sectionName: "Project Discussion",
sectionColor: "#FF5733",
};

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This section doesn't have multiple articles

})
);

expect(response.body.articles).toStrictEqual(validSection.articles);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If you're only doing article array comparisons, you don't really need a full object, no?

Fixed testing data and PR comments.
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.

Endpoint - PATCH remove section from issue map

2 participants