From 5da23219bb93a419b54cd6ff54b9d31acf59516b Mon Sep 17 00:00:00 2001 From: Kat Date: Fri, 12 Jul 2024 11:19:25 +0100 Subject: [PATCH] Add original setup doc --- docs/testing.md | 60 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/docs/testing.md b/docs/testing.md index 57e40f747..708656b6a 100644 --- a/docs/testing.md +++ b/docs/testing.md @@ -31,3 +31,63 @@ bundle exec rake parallel:setup ```sh RAILS_ENV=test bundle exec rake parallel:spec ``` + +## Factories for Lettings Log, Sales Log, Organisation, and User +Each of these factories has nested relationships and callbacks that ensure associated objects are created and linked properly. For instance, creating a `lettings_log` involves creating or associating with a `user`, which in turn is linked to an `organisation`, potentially leading to creating `organisation_rent_periods` and a `data_protection_confirmation`. + +This documentation outlines the objects that are created and/or persisted to the database when using FactoryBot to create or build models for LettingsLog, SalesLog, Organisation, and User. There are other factories, but they are simpler, less frequently used and don't have as much resource hierarchy. + +### Lettings Log +Objects Created/Persisted: +- **User**: The `assigned_to` user is created. + - **LegacyUser**: A `LegacyUser` is created and associated with the newly created `assigned_to` user by `User` factory. + - **Organisation**: The `assigned_to` user’s organisation created by `User` factory. + - **DataProtectionConfirmation**: If `with_dsa` is `true` (default), a `DataProtectionConfirmation` is created with a `data_protection_officer` + - **User**: Data protection officer that signs the data protection confirmation + - **LegacyUser**: A `LegacyUser` is created and associated with the newly created `data_protection_officer` user by `User` factory. + +- **OrganisationRentPeriod**: If `log.period` is present and the `managing_organisation` does not have an `OrganisationRentPeriod` for that period, a new `OrganisationRentPeriod` is created and associated with `managing_organisation`. + +Example Usage: +``` +let(:lettings_log) { create(:lettings_log) } +``` + +### Sales Log +Objects Created/Persisted: +- **User**: The `assigned_to` user is created. + - **LegacyUser**: A `LegacyUser` is created and associated with the newly created `assigned_to` user by `User` factory. + - **Organisation**: The `assigned_to` user’s organisation created by `User` factory. + - **DataProtectionConfirmation**: If `with_dsa` is `true` (default), a `DataProtectionConfirmation` is created with a `data_protection_officer` + - **User**: Data protection officer that signs the data protection confirmation + - **LegacyUser**: A `LegacyUser` is created and associated with the newly created `data_protection_officer` user by `User` factory. + +Example Usage: +``` +let(:sales_log) { create(:sales_log) } +``` + +### Organisation +Objects Created/Persisted: +- **OrganisationRentPeriod**: For each rent period in transient attribute `rent_periods`, an `OrganisationRentPeriod` is created. +- **DataProtectionConfirmation**: If `with_dsa` is `true` (default), a `DataProtectionConfirmation` is created with a `data_protection_officer` +- **User**: Data protection officer that signs the data protection confirmation + - **LegacyUser**: A `LegacyUser` is created and associated with the newly created `data_protection_officer` user by `User` factory. + +Example Usage: +``` +let(:organisation) { create(:organisation, rent_periods: [1, 2])} +``` + +### User +Objects Created/Persisted: +- **LegacyUser**: A `LegacyUser` is created and associated with the newly created user. +- **Organisation**: User’s organisation. + - **DataProtectionConfirmation**: If `with_dsa` is `true` (default), a `DataProtectionConfirmation` is created with a `data_protection_officer` + - **User**: Data protection officer that signs the data protection confirmation + - **LegacyUser**: A `LegacyUser` is created and associated with the newly created `data_protection_officer` user by `User` factory. + +Example Usage: +``` +let(:user) { create(:user) } +``` \ No newline at end of file