Skip to content

refactor(person-factory): align Person.create call with other factories - #1745

Merged
kaligrafy merged 1 commit into
chairemobilite:mainfrom
kaligrafy:refactor/person-factory-create-pattern
Jul 31, 2026
Merged

refactor(person-factory): align Person.create call with other factories#1745
kaligrafy merged 1 commit into
chairemobilite:mainfrom
kaligrafy:refactor/person-factory-create-pattern

Conversation

@kaligrafy

@kaligrafy kaligrafy commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Summary

PersonFactory was using an old create pattern, we need to update it to be consistent with other base objects factories.

  • Omit nested journeys before calling Person.create, since journeys are built separately by JourneyFactory
  • Cast person attributes to ExtendedPersonAttributes, matching the pattern used in JourneyFactory and TripFactory
  • Add a unit test verifying journeys are not passed to Person.create

Test plan

  • yarn test --testPathPatterns='PersonFactory.test.ts' passes (7 tests)

Summary by CodeRabbit

  • Bug Fixes

    • Improved survey object creation by populating each person’s journeys after successful creation.
    • Ensured work and school locations are configured after journey population.
    • Prevented follow-up setup when person creation fails, reducing incomplete survey data.
  • Tests

    • Expanded coverage for person creation, journey population, and work/school location setup.
    • Updated household creation tests to verify the revised processing flow.

@kaligrafy
kaligrafy requested a review from greenscientist July 23, 2026 14:25
@kaligrafy
kaligrafy force-pushed the refactor/person-factory-create-pattern branch from 3b3d76a to 5c2f67a Compare July 23, 2026 14:26
@chairemobilite chairemobilite deleted a comment from coderabbitai Bot Jul 23, 2026

@greenscientist greenscientist left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please explain why you need to omit nested journeys. (At least in the commit message, but it probably need a comment in the code also.

@kaligrafy
kaligrafy force-pushed the refactor/person-factory-create-pattern branch from 5c2f67a to 8d8ac14 Compare July 29, 2026 15:38
@coderabbitai

coderabbitai Bot commented Jul 29, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: d6b42576-0a3e-4b85-93d0-557ed01c823e

📥 Commits

Reviewing files that changed from the base of the PR and between 4b421f4 and ec4d61f.

📒 Files selected for processing (5)
  • packages/evolution-backend/src/services/audits/__tests__/SurveyObjectParsers.test.ts
  • packages/evolution-backend/src/services/surveyObjects/PersonFactory.ts
  • packages/evolution-backend/src/services/surveyObjects/SurveyObjectsFactory.ts
  • packages/evolution-backend/src/services/surveyObjects/__tests__/PersonFactory.test.ts
  • packages/evolution-backend/src/services/surveyObjects/__tests__/SurveyObjectsFactory.test.ts
📜 Recent review details
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2026-03-31T18:20:32.322Z
Learnt from: kaligrafy
Repo: chairemobilite/evolution PR: 1462
File: packages/evolution-common/src/services/baseObjects/Completable.ts:1-6
Timestamp: 2026-03-31T18:20:32.322Z
Learning: In this repository (chairemobilite/evolution), do not flag or require a copyright year in file headers. For new files, the header format `Copyright Polytechnique Montreal and contributors` (without a year) is acceptable. Only verify the header presence/consistency, not the presence of the year.

Applied to files:

  • packages/evolution-backend/src/services/audits/__tests__/SurveyObjectParsers.test.ts
  • packages/evolution-backend/src/services/surveyObjects/SurveyObjectsFactory.ts
  • packages/evolution-backend/src/services/surveyObjects/PersonFactory.ts
  • packages/evolution-backend/src/services/surveyObjects/__tests__/PersonFactory.test.ts
  • packages/evolution-backend/src/services/surveyObjects/__tests__/SurveyObjectsFactory.test.ts
🔇 Additional comments (5)
packages/evolution-backend/src/services/surveyObjects/PersonFactory.ts (1)

8-36: LGTM!

Also applies to: 67-90

packages/evolution-backend/src/services/surveyObjects/__tests__/PersonFactory.test.ts (1)

10-10: LGTM!

Also applies to: 24-28, 86-86, 95-110, 146-263, 289-293, 303-311, 338-342

packages/evolution-backend/src/services/audits/__tests__/SurveyObjectParsers.test.ts (1)

189-189: LGTM!

packages/evolution-backend/src/services/surveyObjects/SurveyObjectsFactory.ts (1)

178-186: LGTM!

packages/evolution-backend/src/services/surveyObjects/__tests__/SurveyObjectsFactory.test.ts (1)

113-113: LGTM!

Also applies to: 178-178, 267-317


Walkthrough

populatePersonsForHousehold now accepts home context, creates persons without journeys, and populates journeys and work/school places after successful creation. SurveyObjectsFactory delegates this processing instead of iterating over household members directly. Tests cover the updated signature, delegation, side effects, and failure behavior.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related PRs

Suggested reviewers: greenscientist, tahini

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main change: updating the Person.create call to match the pattern used by other factories.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@kaligrafy

Copy link
Copy Markdown
Contributor Author

Please explain why you need to omit nested journeys. (At least in the commit message, but it probably need a comment in the code also.

Ajouté au commit message

@kaligrafy
kaligrafy force-pushed the refactor/person-factory-create-pattern branch from 8d8ac14 to 40b5baa Compare July 29, 2026 15:57

// Verify person and journey factories were called
// Verify person factory was called (journeys/setupWorkAndSchoolPlaces are now
// triggered from within populatePersonsForHousehold, covered by PersonFactory.test.ts)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

On n'a pas besoin de savoir ça, "are now triggered", now par rapport à quoi? Ceci est un commentaire justifiant le changement (genre dans le commit message), ça ne va pas dans le code

// Journey.create in JourneyFactory: it is a nested child collection, not a Person
// attribute. Once the person itself is successfully created, populateJourneysForPerson
// builds each journey individually so that per-journey errors are tracked separately
// instead of failing the whole Person.create call.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Svp, revoir les commentaires écrits par Claude, souvent, ils ne sont pas pertinents dans le code et ne font qu'expliquer pouquoi le changement a été fait. Il faut lire ce commentaire du point du vue de la personne qui va lire le code et vouloir le modifier dans 6 mois. Ici, simplement // Omit journeys as they will be populated separately in the next step est suffisant, pas besoin de comparer avec le visitedPlaces/trips car ça veut dire que le commentaire ici dépend de l'implémentation là-bas, il ne faut pas.

@kaligrafy
kaligrafy force-pushed the refactor/person-factory-create-pattern branch from 40b5baa to 4b421f4 Compare July 29, 2026 20:17
@kaligrafy
kaligrafy requested a review from tahini July 29, 2026 20:18
@kaligrafy
kaligrafy force-pushed the refactor/person-factory-create-pattern branch 2 times, most recently from ebf9609 to 799fd89 Compare July 30, 2026 19:36
PersonFactory was using an old create pattern, we need to update it to
be consistent with other base objects factories.

Omit nested journeys before Person.create and cast to ExtendedPersonAttributes,
matching the JourneyFactory pattern for child objects built separately.

Why omit journeys: journeys are a nested child collection stored on the
person's attributes, not a Person constructor input. Just like
visitedPlaces/trips are omitted before Journey.create in JourneyFactory,
journeys must be created individually (via populateJourneysForPerson) once
the person itself exists, so that errors for each journey are tracked
separately instead of failing the whole Person.create call.

Also move the populateJourneysForPerson + setupWorkAndSchoolPlaces calls
from SurveyObjectsFactory into populatePersonsForHousehold, right after a
person is successfully created. This matches the pattern already used by
JourneyFactory, which calls populateVisitedPlacesForJourney and
populateTripsForJourney directly in its own isOk block instead of leaving
that orchestration to the caller.

Code written by Cursor Composer 2.5 and reviewed by @kaligrafy
@kaligrafy
kaligrafy force-pushed the refactor/person-factory-create-pattern branch from 799fd89 to ec4d61f Compare July 30, 2026 19:47
@coderabbitai coderabbitai Bot mentioned this pull request Jul 30, 2026
@github-actions

Copy link
Copy Markdown

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 31, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@greenscientist greenscientist left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I guess I'll accept.
I feel that the omitting should be handled by the create function directly, maybe we some flags passed to create to tell it to omit certain part.
Or maybe we should pass new journeys directly to that create function.
Just some thoughts for your considerations.

@kaligrafy

Copy link
Copy Markdown
Contributor Author

See #1774 1774

@kaligrafy
kaligrafy merged commit 7e87fc6 into chairemobilite:main Jul 31, 2026
7 checks passed
@kaligrafy
kaligrafy deleted the refactor/person-factory-create-pattern branch July 31, 2026 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.

3 participants