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

Include fields on GET /applicationForms/{id} optionally #157

Merged
merged 1 commit into from
Feb 13, 2023

Conversation

bickelj
Copy link
Contributor

@bickelj bickelj commented Dec 7, 2022

Use query parameter includeFields=true to include application form
fields in the response from GET /applicationForms/{id}, otherwise a
shallow response with only direct attributes on application form will
be returned.

The implementation is more akin to the one for /proposals in PR #210.

This commit combines four commits from 2022-12-06, 2022-12-12,
2022-12-12, 2022-12-16, 2023-02-09, respectively, and cleanup on
2023-02-13. Some history of changes should be available at
#157

Issue #132 Provide visibility of application form fields

@bickelj bickelj requested a review from slifty December 7, 2022 03:18
@codecov
Copy link

codecov bot commented Dec 7, 2022

Codecov Report

Base: 95.74% // Head: 95.63% // Decreases project coverage by -0.11% ⚠️

Coverage data is based on head (f7229b8) compared to base (c9bc6d9).
Patch coverage: 100.00% of modified lines in pull request are covered.

❗ Current head f7229b8 differs from pull request most recent head 01efd86. Consider uploading reports for the commit 01efd86 to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #157      +/-   ##
==========================================
- Coverage   95.74%   95.63%   -0.11%     
==========================================
  Files          48       48              
  Lines         775      825      +50     
  Branches      143      156      +13     
==========================================
+ Hits          742      789      +47     
- Misses         32       35       +3     
  Partials        1        1              
Impacted Files Coverage Δ
src/handlers/applicationFormsHandlers.ts 95.28% <100.00%> (-1.21%) ⬇️
src/routers/applicationFormsRouter.ts 100.00% <100.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@bickelj bickelj force-pushed the 132-visibility-of-application-form-fields branch from a3074e5 to e6c7877 Compare December 12, 2022 18:18
@bickelj
Copy link
Contributor Author

bickelj commented Dec 12, 2022

e6c7877 rebases, adds a test, updates doc, does a small refactor.

@bickelj bickelj force-pushed the 132-visibility-of-application-form-fields branch from e6c7877 to 6afbc57 Compare December 12, 2022 18:35
@bickelj
Copy link
Contributor Author

bickelj commented Dec 12, 2022

6afbc57 actually adds the test.

@bickelj
Copy link
Contributor Author

bickelj commented Dec 12, 2022

Code coverage? From https://github.com/PhilanthropyDataCommons/service/actions/runs/3678723239/jobs/6222324994#step:8:34

[2022-12-12T18:37:07.844Z] ['error'] There was an error running the uploader: Error uploading to https://codecov.io: Error: There was an error fetching the storage URL during POST: 404 - {'detail': ErrorDetail(string='Unable to locate build via Github Actions API. Please upload with the Codecov repository upload token to resolve issue.', code='not_found')}

Maybe another push is needed.

@bickelj bickelj force-pushed the 132-visibility-of-application-form-fields branch from 6afbc57 to b71998d Compare December 12, 2022 21:36
@bickelj
Copy link
Contributor Author

bickelj commented Dec 12, 2022

b71998d is a whitespace change in an attempt to get the code coverage report to run.

// add field to previousRow
if (currentApplicationForm.fields === undefined) {
currentApplicationForm.fields = [formField];
} else {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Suppose I remove the above unreachable code (because it is always defined, you can see it defined on lines 67 and 96 here) in both places, now the compiler gets confused because it thinks it could possibly be undefined (even though it is always defined):

src/handlers/applicationFormsHandlers.ts:79:15 - error TS2532: Object is possibly 'undefined'.

79 currentApplicationForm.fields.push(formField);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

src/handlers/applicationFormsHandlers.ts:98:15 - error TS2532: Object is possibly 'undefined'.

98 currentApplicationForm.fields.push(formField);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

opportunityId: formWithFieldRow.opportunityId,
version: formWithFieldRow.version,
createdAt: formWithFieldRow.createdAt,
fields: [],
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Suppose I remove this line 96 and 67 to force that possibility of undefined fields, well then a bigger issue arises: the response body might not have the fields key at all, which is going to be a problem if you want to consistently be able to parse the response using a schema. It makes the most sense to always have the empty list than to sometimes have it and other times not have it.

 FAIL  src/__tests__/applicationForm.int.test.ts (9.288 s)
  ● /applicationForms › GET / › returns all application forms present in the database

    expected [
      {
        createdAt: '2022-07-20T12:00:00.000Z',
        id: 1,
        opportunityId: 1,
        version: 1,
        fields: []
      },
      {
        createdAt: '2022-08-20T12:00:00.000Z',
        id: 2,
        opportunityId: 1,
        version: 2,
        fields: []
      },
      {
        createdAt: '2022-09-20T12:00:00.000Z',
        id: 3,
        opportunityId: 2,
        version: 1,
        fields: []
      }
    ] response body, got [
      {
        id: 1,
        opportunityId: 1,
        version: 1,
        createdAt: '2022-07-20T12:00:00.000Z'
      },
      {
        id: 2,
        opportunityId: 1,
        version: 2,
        createdAt: '2022-08-20T12:00:00.000Z'
      },
      {
        id: 3,
        opportunityId: 2,
        version: 1,
        createdAt: '2022-09-20T12:00:00.000Z'
      }
    ]

@@ -17,6 +17,18 @@ export interface ApplicationForm {
readonly createdAt: Date;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

One more thing might be to make fields mandatory here in the original type, then it really cannot be undefined under any circumstances.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Doing that causes validation failures that make me think an empty array does not pass validation unless there is something else I'm missing.

@bickelj
Copy link
Contributor Author

bickelj commented Dec 12, 2022

I'm not sure how much more time it's worth to get that additional 0.08% coverage. This might be as good as it gets. In any case I hope to hear @slifty's comments on this approach.

@bickelj
Copy link
Contributor Author

bickelj commented Dec 13, 2022

@slifty Suggested make this an option and via query parameter.

@bickelj
Copy link
Contributor Author

bickelj commented Dec 16, 2022

@slifty @reefdog better?

@bickelj
Copy link
Contributor Author

bickelj commented Feb 9, 2023

Feedback on #210 applies here too: rework it to use one query per table, have the code join the results, etc.

@bickelj bickelj force-pushed the 132-visibility-of-application-form-fields branch 2 times, most recently from e5f0d6a to 41589e8 Compare February 10, 2023 15:27
@bickelj
Copy link
Contributor Author

bickelj commented Feb 10, 2023

41589e8 rebases on main.

@bickelj bickelj force-pushed the 132-visibility-of-application-form-fields branch from 41589e8 to 3b0f4f7 Compare February 13, 2023 15:46
@bickelj
Copy link
Contributor Author

bickelj commented Feb 13, 2023

3b0f4f7 rebases on main, improves test coverage, removed a no-longer-used sql file, and reverted some unneeded whitespace or import order changes to make the diff easier to read.

@bickelj
Copy link
Contributor Author

bickelj commented Feb 13, 2023

It is unclear what makes codecov get an update vs not get an update. Perhaps a new commit? Suppose I squash all the commits, trying that because it needs to happen anyway.

bickelj added a commit that referenced this pull request Feb 13, 2023
Use query parameter `includeFields=true` to include application form
fields in the response from `GET /applicationForms/{id}`, otherwise a
shallow response with only direct attributes on application form will
be returned.

The implementation is more akin to the one for /proposals in PR #210.

This commit combines four commits from 2022-12-06, 2022-12-12,
2022-12-12, 2022-12-16, 2023-02-09, respectively, and cleanup on
2023-02-13. Some history of changes should be available at
#157

Issue #132 Provide visibility of application form fields
@bickelj bickelj force-pushed the 132-visibility-of-application-form-fields branch from 3b0f4f7 to cada08c Compare February 13, 2023 16:10
@bickelj bickelj changed the title Include fields on GET /applicationForms Include fields on GET /applicationForms/{id} optionally Feb 13, 2023
.contentType('application/json')
.send(applicationForm);
}).catch((error: unknown) => {
throw error;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This error does not get caught below in 135-144.

bickelj added a commit that referenced this pull request Feb 13, 2023
Use query parameter `includeFields=true` to include application form
fields in the response from `GET /applicationForms/{id}`, otherwise a
shallow response with only direct attributes on application form will
be returned.

The implementation is more akin to the one for /proposals in PR #210.

This commit combines four commits from 2022-12-06, 2022-12-12,
2022-12-12, 2022-12-16, 2023-02-09, respectively, and cleanup on
2023-02-13. Some history of changes should be available at
#157

Issue #132 Provide visibility of application form fields
@bickelj bickelj force-pushed the 132-visibility-of-application-form-fields branch from cada08c to 46828c9 Compare February 13, 2023 20:12
@bickelj
Copy link
Contributor Author

bickelj commented Feb 13, 2023

46828c9 has some additional test coverage, renames the integration tests for applicationForms (to be plural), and fixes an issue revealed by trying to get that last little bit of test coverage.

bickelj added a commit that referenced this pull request Feb 13, 2023
Use query parameter `includeFields=true` to include application form
fields in the response from `GET /applicationForms/{id}`, otherwise a
shallow response with only direct attributes on application form will
be returned.

The implementation is more akin to the one for /proposals in PR #210.

This commit combines four commits from 2022-12-06, 2022-12-12,
2022-12-12, 2022-12-16, 2023-02-09, respectively, and cleanup on
2023-02-13. Some history of changes should be available at
#157

Issue #132 Provide visibility of application form fields
@bickelj bickelj force-pushed the 132-visibility-of-application-form-fields branch from 46828c9 to f7229b8 Compare February 13, 2023 20:27
@bickelj
Copy link
Contributor Author

bickelj commented Feb 13, 2023

f7229b8 has one more test.

Use query parameter `includeFields=true` to include application form
fields in the response from `GET /applicationForms/{id}`, otherwise a
shallow response with only direct attributes on application form will
be returned.

The implementation is more akin to the one for /proposals in PR #210.

This commit combines four commits from 2022-12-06, 2022-12-12,
2022-12-12, 2022-12-16, 2023-02-09, respectively, and cleanup on
2023-02-13. Some history of changes should be available at
#157

Issue #132 Provide visibility of application form fields
@bickelj bickelj force-pushed the 132-visibility-of-application-form-fields branch from f7229b8 to 01efd86 Compare February 13, 2023 20:40
@bickelj
Copy link
Contributor Author

bickelj commented Feb 13, 2023

01efd86 has one (hopefully last?) test.

@bickelj bickelj merged commit 19167f6 into main Feb 13, 2023
@bickelj bickelj deleted the 132-visibility-of-application-form-fields branch February 13, 2023 20:56
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.

None yet

1 participant