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

Refactor/homepage #331

Merged
merged 16 commits into from
Apr 5, 2022
Merged

Refactor/homepage #331

merged 16 commits into from
Apr 5, 2022

Conversation

alexanderleegs
Copy link
Contributor

Overview

This PR adds the refactored homepage router, in line with our recent refactoring efforts. It builds off the existing HomepagePageService that already exists for use by the SettingsRouter. It also adds the relevant tests for the homepage router component.

The media categories router contains the following endpoints:

GET /:siteName/homepage - Retrieve homepage information
POST /:siteName/homepage- Update homepage information

Notes

I have opted for a looser schema of the updateHomepage request (e.g. not checking all section details), as several sites have additional details in the front matter of their homepage due to legacy issues, though I am open to suggestions on what we could do if we want to enforce a stricter format.

@alexanderleegs alexanderleegs linked an issue Feb 8, 2022 that may be closed by this pull request
Copy link
Contributor

@seaerchin seaerchin left a comment

Choose a reason for hiding this comment

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

lgtm with some minor clarifications

newroutes/__tests__/Homepage.spec.js Outdated Show resolved Hide resolved
newroutes/__tests__/Homepage.spec.js Outdated Show resolved Hide resolved
newroutes/__tests__/Homepage.spec.js Outdated Show resolved Hide resolved
newroutes/homepage.js Outdated Show resolved Hide resolved
Comment on lines 40 to 44
const { error } = UpdateHomepageSchema.validate(req.body, {
allowUnknown: true,
})
Copy link
Contributor

Choose a reason for hiding this comment

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

i think this is a good pattern that we should be using going forward! we validate unknown data and ensure that it's of a valid shape before passing it onto our services!

newroutes/homepage.js Outdated Show resolved Hide resolved
validators/RequestSchema.js Outdated Show resolved Hide resolved
Base automatically changed from refactor/auth to develop March 14, 2022 03:56
Copy link
Contributor

@seaerchin seaerchin left a comment

Choose a reason for hiding this comment

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

minor comments but looking good overall!

newroutes/homepage.js Outdated Show resolved Hide resolved

router.get(
"/:siteName/homepage",
attachReadRouteHandlerWrapper(this.readHomepage)
Copy link
Contributor

Choose a reason for hiding this comment

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

i think once we shift to ts, we can try doing this with decorators to see if it eases the friction!

server.js Outdated Show resolved Hide resolved
validators/RequestSchema.js Outdated Show resolved Hide resolved
validators/RequestSchema.js Outdated Show resolved Hide resolved
Copy link
Contributor

@seaerchin seaerchin left a comment

Choose a reason for hiding this comment

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

lgtm once extra test case is added and behaviour of FE clarified

newroutes/authenticatedSites/__tests__/Homepage.spec.js Outdated Show resolved Hide resolved
validators/RequestSchema.js Show resolved Hide resolved
@alexanderleegs alexanderleegs requested a review from seaerchin April 5, 2022 06:04
Copy link
Contributor

@seaerchin seaerchin left a comment

Choose a reason for hiding this comment

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

lgtm

@alexanderleegs alexanderleegs merged commit 61b62aa into develop Apr 5, 2022
@alexanderleegs alexanderleegs deleted the refactor/homepage branch April 5, 2022 10:28
This was referenced Apr 14, 2022
harishv7 pushed a commit that referenced this pull request Feb 17, 2023
* Feat: add updateHomepageSchema

* Feat: add homepage router

* Fix: allow pageBody for updateHomepage

* Test: add tests for homepage router

* Nit: line spacing

* Chore: add comment for empty string in schema

* Nit: fix comment for error type importing

* Fix: throw only error.message from joi

* Rebase: inject auth middleware verify into router

* Nit: rename variable

* Fix: allow empty description and notification

* Fix: use subrouter for homepage

* Fix: test location

* Fix: retrieve accessToken from res.locals

* Fix: use fixtures and omit in homepage tests

* Feat: add read failure to homepage test suite
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.

[Backend] Homepage router refactor
2 participants