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

CMDCT-4224: POC for update report validation using yup schemas #90

Merged
merged 10 commits into from
Jan 21, 2025

Conversation

angelaco11
Copy link
Contributor

Description

This is a working idea for update report validation. do not review unless your initials are B.M. or if you want to experience a world of Horrors

Related ticket(s)

CMDCT-4224


How to test

.required();

const measureTemplatesSchema = object().shape({
[MeasureTemplateName["LTSS-1"]]: measurePageTemplateSchema,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

im sure there's a way to do this in some sort of reduce function but i attempted to do this for way too long and typescript would cry and my tests would fail with every iteration of a reduce function i would write. so if anyone has any ideas on how to make a reduce function work here, hit me up

Copy link
Contributor

Choose a reason for hiding this comment

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

In fact we can go a step more declarative than reduce, with Object.fromEntries():

const measureTemplateNames = Object.values(MeasureTemplateName);
const measureTemplatesSchema2 = object().shape(
  Object.fromEntries(
    measureTemplateNames.map((meas) => [meas, measurePageTemplateSchema])
  )
);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

you told me not to get excited but too late because THIS WORKS!!!!!!! THANK YOU!!!!!!!!!!!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ugh. never mind, it was working and then all of a sudden tests started failing. idk, this stuff is really hard to debug so it's kind of killing my soul here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK great news. I got this working by fixing the enum!

Copy link
Contributor

@benmartin-coforma benmartin-coforma left a comment

Choose a reason for hiding this comment

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

Right now I'm not familiar enough with the report shape to confirm that this validation code is completely correct. But I like the way you've put it together, and if any details need to be adjusted we can do that as they come up.

Very nice!

Comment on lines 116 to 117
default:
return mixed().notRequired(); // Fallback, although it should never be hit
Copy link
Contributor

Choose a reason for hiding this comment

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

Will this cooperate with stripUnknown so that invalid element types will be removed from the object? If so, great!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's a great question and I will write some tests to see if I can confirm or deny this!

.required();

const measureTemplatesSchema = object().shape({
[MeasureTemplateName["LTSS-1"]]: measurePageTemplateSchema,
Copy link
Contributor

Choose a reason for hiding this comment

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

In fact we can go a step more declarative than reduce, with Object.fromEntries():

const measureTemplateNames = Object.values(MeasureTemplateName);
const measureTemplatesSchema2 = object().shape(
  Object.fromEntries(
    measureTemplateNames.map((meas) => [meas, measurePageTemplateSchema])
  )
);

@angelaco11 angelaco11 marked this pull request as ready for review January 14, 2025 17:47
@@ -0,0 +1,1154 @@
import { qmReportTemplate } from "../../forms/qm";
Copy link

Choose a reason for hiding this comment

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

File mockReport.ts has 1141 lines of code (exceeds 1000 allowed). Consider refactoring.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i am not going to not refactor because this is a mock data file and the mock reports are large and there's no getting around it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i lied, i cleaned this up quite a bit so that it's only like 200 lines now

Copy link

codeclimate bot commented Jan 17, 2025

Code Climate has analyzed commit 8354b5e and detected 0 issues on this pull request.

The test coverage on the diff in this pull request is 94.8% (90% is the threshold).

This pull request will bring the total coverage in the repository to 93.6% (0.0% change).

View more on Code Climate.

Copy link
Contributor

@rocio-desantiago rocio-desantiago left a comment

Choose a reason for hiding this comment

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

Small nitpick to update instances of qm to qms
i.e, qmReportTemplate to qmsReportTemplate

@rocio-desantiago rocio-desantiago self-requested a review January 21, 2025 19:21
Copy link
Contributor

@rocio-desantiago rocio-desantiago left a comment

Choose a reason for hiding this comment

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

May I request the qm to qms update 😬

@angelaco11
Copy link
Contributor Author

May I request the qm to qms update 😬

I did this update on Friday. could i get an approval?

@BearHanded BearHanded merged commit d8a59d6 into main Jan 21, 2025
19 checks passed
@BearHanded BearHanded deleted the cmdct-4224 branch January 21, 2025 20:09
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