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

Feat(data-modeling): Add a new field type in the NeedsAssessment.Survey collection that combines other fields #191

Open
ll-zerr opened this issue Nov 14, 2024 · 3 comments · May be fixed by #202
Assignees
Labels
enhancement New feature or request

Comments

@ll-zerr
Copy link
Contributor

ll-zerr commented Nov 14, 2024

Create a new field that automatically populates with the year and quarter fields from the NeedsAssessment.Survey collection. Then use this new field as the one displayed in relations.

Issue Goals:

  • Add a new field that automatically populates with "year - quarter"
  • Modify settings to display this new field type in relations for entries in other collections

Code:

You'll want to override the Create & Update routes for the NeedsAssessment.Survey collection. This needs to be done for both the API and the CMS, each of which use two different routes:

  1. Create an src/functions/content-types/needs-assessment/survey.ts file and write functions to create the calculated field. See src/functions/content-types/product/item.ts for an example.
  2. Register those functions in src/functions/content-types/index.ts. This will handle the the CMS routes.
  3. Override the default Create and Update routes in src/api/needs-assessment/controllers/survey.ts. See src/api/product/controllers/item.ts for an example.

Testing:

  1. Write unit tests in src/functions/content-types/needs-assessment/survey.test.ts
  2. Manually test that this functionality behaves as expected when adding / updating NeedsAssessment.Survey entries in the Strapi CMS.
  3. Write end-to-end tests in src/tests/ to call the NeedsAssessment.Survey api routes and confirm the API behaves as expected.
@ll-zerr ll-zerr added the enhancement New feature or request label Nov 14, 2024
@github-project-automation github-project-automation bot moved this to Triage in DA Tech Nov 18, 2024
@jtfairbank jtfairbank moved this from Triage to Ready for Work in DA Tech Nov 18, 2024
@jtfairbank
Copy link
Collaborator

@madcalf can you double check me on the testing instructions here, especially point #3? I know we had just gotten testing going and I wasn't super involved in that, so I don't want to point folks in the wrong direction.

@madcalf
Copy link
Contributor

madcalf commented Nov 19, 2024

Yes spot on on the testing items 1 & 2.

We haven't done any of the API tests yet. Strapi docs don't go into much detail on this, but I've been looking at the supertest docs and was planning to take a crack at this on product.item. Or maybe I could start with this one if it's more of a priority?

Does it sense to match the same file structure as the API? e.g.
src/tests/api/needs-assessment/content-types/survey/survey.test.ts
or if that is overkill with the nesting, maybe
src/tests/api/needs-assessment/survey.test.ts

@jtfairbank
Copy link
Collaborator

@madcalf I think the latter should be fine for now! We can always refactor to make it more specific if the folders or files get crowded.

Would it be possible to have tests live near the code tho, or will that mess Strapi up? Like ideally the test for this computed Survey property lives in src/api/needs-assessment/controllers/survey.test.ts right next to the controller it's testing.

Obviously we'll still need the tests/ directory for more overarching end-to-end or tests that involve multiple API calls to assess the interactions between them

@swizzard swizzard linked a pull request Nov 21, 2024 that will close this issue
3 tasks
@swizzard swizzard self-assigned this Nov 21, 2024
@jtfairbank jtfairbank linked a pull request Nov 27, 2024 that will close this issue
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: In Progress
Development

Successfully merging a pull request may close this issue.

4 participants