You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
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.
Register those functions in src/functions/content-types/index.ts. This will handle the the CMS routes.
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:
Write unit tests in src/functions/content-types/needs-assessment/survey.test.ts
Manually test that this functionality behaves as expected when adding / updating NeedsAssessment.Survey entries in the Strapi CMS.
Write end-to-end tests in src/tests/ to call the NeedsAssessment.Survey api routes and confirm the API behaves as expected.
The text was updated successfully, but these errors were encountered:
@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.
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
@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
Create a new field that automatically populates with the
year
andquarter
fields from theNeedsAssessment.Survey
collection. Then use this new field as the one displayed in relations.Issue Goals:
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:src/functions/content-types/needs-assessment/survey.ts
file and write functions to create the calculated field. Seesrc/functions/content-types/product/item.ts
for an example.src/functions/content-types/index.ts
. This will handle the the CMS routes.src/api/needs-assessment/controllers/survey.ts
. Seesrc/api/product/controllers/item.ts
for an example.Testing:
src/functions/content-types/needs-assessment/survey.test.ts
NeedsAssessment.Survey
entries in the Strapi CMS.src/tests/
to call theNeedsAssessment.Survey
api routes and confirm the API behaves as expected.The text was updated successfully, but these errors were encountered: