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

Section API-controller actions #6955

Merged
merged 9 commits into from
Feb 18, 2024

Conversation

mimischly7
Copy link
Contributor

@mimischly7 mimischly7 commented Feb 12, 2024

Motivation and Context

Due to an instructor request, we are currently developing an API-controller for the Section's model. This pull request takes care of some of the actions of this controller, as well as extensive testing of these new actions.

Your Changes

Description:
Added index, show, and update actions to the API controller of the Section's model. I modified routes.rb (to actually establish the existence of these routes). Added thorough RSPEC tests for these actions.

Type of change (select all that apply):

  • New feature (non-breaking change which adds functionality)

Testing

I tested both authorized and unauthorized requests, and for the GET requests (show and index), where either a json or xml response is expected, I tested that all necessary keys (corresponding to model attributes) are present, although I did not check whether the values of these attributes match between the responses and the original object data (not sure whether I should go this far). Also, for the index request, some of my expectations perform an equality comparison between arrays; maybe it would be preferable to instead convert these to sets and make a comparison between sets.

Questions and Comments (if applicable)

I realized that because of the MainApiController (which all the API controllers inherit), the SessionHandler.check_record method already ensures that an incoming request trying to do something with a particular record is valid (e.g. the record actually exists), so it would be redundant to check this again in the controller; e.g. whether current_course.sections.find(params[:id]) returns a valid section.

Checklist

  • I have performed a self-review of my own code.
  • I have verified that the pre-commit.ci checks have passed.
  • I have verified that the CI tests have passed.
  • I have reviewed the test coverage changes reported on Coveralls.
  • I have added tests for my changes.
  • I have updated the Changelog.md file.
  • I have made changes to the documentation and linked to that pull request below.

Pull request to make documentation changes (if applicable)

MarkUsProject/Wiki#206

Added index, show, and update actions for the api controller of the sections model. I modified routes.rb (to actually establish the existence of these routes).

I realised that because of the MainApiController (which all the API controllers inherit), the SessionHandler.check_record method already ensures that an incoming request trying to do something with a particular record is valid (i.e. the record actually exists), so it would be redundant to check whether current_course.sections.find(params[:id]) for example returns a valid current_course.
Added rspec tests for the update, index, and show actions of the api controller of sections. I tested both authorised and unauthorised requests, and for the GET requests (show and index), where either a json or xml response is expected, I tested that all necessary keys (corresponding to model attributes) are present, although I did not check whether the values of these attributes match between the responses and the original object data (not sure whether I should go this far). Also, for the #index request, some of my expectations perform an equality comparison between arrays; maybe it would be preferable to instead convert these to sets and make a comparison between sets.
@coveralls
Copy link
Collaborator

coveralls commented Feb 12, 2024

Pull Request Test Coverage Report for Build 7939947237

Details

  • -1 of 93 (98.92%) changed or added relevant lines in 3 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.02%) to 91.748%

Changes Missing Coverage Covered Lines Changed/Added Lines %
app/controllers/api/sections_controller.rb 14 15 93.33%
Totals Coverage Status
Change from base Build 7938807998: 0.02%
Covered Lines: 39026
Relevant Lines: 41914

💛 - Coveralls

Turns out I had accidentally deleted my tests for #destroy. I also changed a put destroy to a put update (which is what it should be)
Updated changelog and utilized existing record method in the update method of api-controller for sections.
Copy link
Collaborator

@david-yz-liu david-yz-liu left a comment

Choose a reason for hiding this comment

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

@mimischly7 good work, the tests are good. I left two small comments

end

def show
section = current_course.sections.find(params[:id])
Copy link
Collaborator

Choose a reason for hiding this comment

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

You can use record here as well

old_name = section.name
put :update, params: { course_id: course.id, id: section.id, name: 'LEC999' }
expect(response).to have_http_status(403)
expect(section.name).to equal(old_name) # both equal and eq work here
Copy link
Collaborator

Choose a reason for hiding this comment

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

This comment is not necessary

Using record instead of manually finding object, and removing redundant comment
Changelog.md Outdated
@@ -8,6 +8,7 @@
- Fix bug where grader distribution graph displays graders multiple times (#6950)
- Fixed bug where TA Summary table failed to display members (#6949)
- Make display of group member information consistent across submissions and summary table (#6917)
- Add new routes for `update`, `show`, and `index` actions of the Sections API Controller (#6955)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please do a merge from master, and then make sure this changelog entry is under [unreleased]

@david-yz-liu david-yz-liu merged commit bb75e14 into MarkUsProject:master Feb 18, 2024
6 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.

3 participants