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

DSFAAP-510: create task list page and add model for tasks #39

Draft
wants to merge 13 commits into
base: main
Choose a base branch
from

Conversation

joseluisgraa
Copy link
Contributor

No description provided.

@hughfdjackson
Copy link
Contributor

@joseluisgraa - I think there's something off with the structure here.

The models (e.g. Address) represent datatypes that could appear in multiple sections. For instance, we collect an Address in both the "Movement Origin" section & the "Receiving the Licence" section.

We want the user experience (in terms of validation, error messages, etc) to be consistent across those sections - which the Address model allows for, if it's reused.

A better layout would be (IMO):

~/src/server/common/answer/ (containing the existing models)

and

~/src/server/common/section/ (containing the new section models)

Then the origin & licensed sections can make reference to the Address answer model.

@joseluisgraa
Copy link
Contributor Author

You are right, I created the one for the task and then started moving the existing ones into origin without realising they would be reused by different sections. I'll follow your proposed structure.

src/server/common/model/destination/destination.js Outdated Show resolved Hide resolved
src/server/common/model/origin/cph-number.js Outdated Show resolved Hide resolved
src/server/task-list-incomplete/controller.js Outdated Show resolved Hide resolved
* @param {boolean} isValid
* @param {boolean} isEnabled
*/
function buildGdsTaskItem(title, initialLink, summaryLink, isValid, isEnabled) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I find a this bit hard to read because we've got positional booleans, at the call site it's not clear what they mean.

normally I go for a 'options object' pattern here, so:

function buildGdsTaskItem({ title, initialLink, summaryLink, isValid, isEnabled }) {...}

Then the callsite looks like:

    const destinationGdsTask = buildGdsTaskItem({
      title: 'Movement destination',
      initialLink: '#',
      summaryLink: '#',
      isValid: destination.validate().isValid,
      isEnabled: isOriginValid
    })

let validationSchema

beforeEach(() => {
validationSchema = Joi.object({
Copy link
Contributor

Choose a reason for hiding this comment

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

schemas don't get mutated by being validated (may even be immutable?), so you can do:

const validationSchema = Joi.object({
  addressLine1: Joi.string().required(),
  postcode: Joi.string().required()
})

and drop the beforeEach block

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