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

CA Task Id 37 - Validate Response from Persistence Layer #282

Merged
merged 14 commits into from
Dec 10, 2018

Conversation

codyseibert
Copy link

@codyseibert codyseibert commented Dec 9, 2018

  • adding a joiValidationDecorator function which we can pass constructor functions to in order to decorate the prototype with joi specific validation code
  • added a new method called 'validateRawCollection' which allows you to pass an array and each entity inside the array will be valided.
  • adding tests over all the use cases to verify these entities are validated before they are returned.

Copy link

@dknesek dknesek left a comment

Choose a reason for hiding this comment

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

This is great work. Thanks for the work Cody.

The general point I make below is that we sometimes return things from a use case that don't really make sense. For example, if an IRS attorney files an answer, why are we returning the case rather than a success or failure code with some metadata about the filing (like who and when).

I've raised this question with Will, and he addressed it to some degree in the "Send to IRS" use case.

As a general point, we want to avoid premature optimization and returning something base on speculation about what the user will want to see next. I left a few related comments below.

shared/src/business/entities/Case.js Show resolved Hide resolved
userId,
applicationContext,
});

return new Case(updatedCase).validate().toJSON();
Copy link

Choose a reason for hiding this comment

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

Why does file answer return an entire case? I would expect this to return the result of the filing plus a little metadata about the answer (when it was filed and who filed it).

Copy link
Author

Choose a reason for hiding this comment

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

Changing it to return the document metadata associated with the created document

applicationContext,
});

return new Case(caseAfterUpdate).validate().toJSON();
Copy link

Choose a reason for hiding this comment

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

Why does updateCase return a case?

Copy link

Choose a reason for hiding this comment

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

I don't know of any standard that says you shouldn't return the updated object. It's usually done because the backend has made some alteration to the data that the client needs to get back. Is there some standard we are violating here?

Copy link
Author

Choose a reason for hiding this comment

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

Yeah, I'm not to sure about this. I've always seen update methods return the update objects.

Copy link

Choose a reason for hiding this comment

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

@sadlerw Can you share a "standard" that says you should? I can see that before the age of SPAs, a web/application server would do this because of the way web forms worked or as an optimization. But there is nothing about the use case interactor's semantic that suggests that this is what it should return.

For example, when I submit an order to Amazon, I just want to see that it was successfully placed. I don't need (or want) to see the order actually refreshed, especially since I just looked at it and it's still showing on the page.

Copy link

@kkoskelin kkoskelin left a comment

Choose a reason for hiding this comment

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

Pretty awesome. Note you'll have some leading-zeroes alterations to do after merging from dev. Aside from that, nice work.

efcms-service/src/cases/getCases.test.js Show resolved Hide resolved
@@ -3,6 +3,7 @@ const assert = require('assert');
const Case = require('./Case');

const A_VALID_CASE = {
docketNumber: '00101-18',

Choose a reason for hiding this comment

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

We've updated the docket number pattern to remove leading zeroes. Although these tests will probably pass, you may want to adjust based on the very-recently-merged code.

@@ -0,0 +1,41 @@
const joi = require('joi-browser');

exports.joiValidationDecorator = function(entityConstructor, schema) {

Choose a reason for hiding this comment

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

👊

caseRecord: new Case({
userId: userId,
docketNumber: docketNumber,
documents: documents,

Choose a reason for hiding this comment

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

These could be shortened to {userId, docketNumber, documents}

@@ -25,7 +25,11 @@ describe('Create case', () => {
getPersistenceGateway: () => {
return {
createCase: () =>
Promise.resolve({ caseId: 'c54ba5a9-b37b-479d-9201-067ec6e335bb' }),
Promise.resolve({
docketNumber: '00101-18',

Choose a reason for hiding this comment

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

see previous mention of leading zeroes.

@codyseibert codyseibert merged commit 7e77411 into develop Dec 10, 2018
@codyseibert codyseibert deleted the task/CA_37_verify_response_objects branch December 10, 2018 23:28
@codyseibert codyseibert restored the task/CA_37_verify_response_objects branch December 12, 2018 01:00
@codyseibert codyseibert deleted the task/CA_37_verify_response_objects branch December 19, 2018 16:11
@codyseibert codyseibert restored the task/CA_37_verify_response_objects branch December 21, 2018 18:52
@codyseibert codyseibert deleted the task/CA_37_verify_response_objects branch January 8, 2019 20:12
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.

4 participants