lexicongovernance / pluraltools-backend

Backend implementation of the plural voting tool.
https://demo.lexicongovernance.org/
GNU General Public License v3.0
3 stars 1 forks source link

Add parameters to seed #335

Closed diegoalzate closed 4 months ago

diegoalzate commented 4 months ago

Improve Test Data Setup to Increase Test Resilience

Description:

Currently, the seed function in our codebase is responsible for generating and inserting seed data into the database for testing purposes. While this function serves its purpose, it can become problematic when we need to change the default seed data, as it might break existing tests or require modifications in multiple places.

The problem arises because the tests are tightly coupled to the default seed data generated by the seed function. If we modify the seed data generation logic, we risk breaking tests that rely on the previous seed data structure or values.

To make our tests more resistant to changes in the seed data and to allow for more flexibility in specifying the required data for each test case, we propose the following solution:

Proposed Solution:

  1. Extract Seed Data Generation into Separate Functions:

    • Create separate functions that generate the seed data for each entity (e.g., generateEventData, generateUserData, generateGroupData).
    • These functions should accept any necessary parameters or configurations to generate the desired seed data.
    • Move the logic for generating seed data from the seed function into these separate functions.
  2. Update the seed Function:

    • The seed function should no longer generate seed data directly.
    • Instead, it should accept the seed data for each entity as parameters.
    • The seed function will then insert the provided seed data into the database using the existing helper functions (createEvent, createCycle, etc.).
  3. Update Tests:

    • In the tests, call the seed data generation functions with the desired configurations or parameters.
    • Pass the generated seed data to the seed function.

Benefits:

Implementation Steps:

  1. Create a new file (e.g., seed-data-generators.ts) to host the seed data generator functions.
  2. Refactor the seed function to accept the seed data for each entity as parameters.
  3. Update the tests to call the appropriate seed data generator functions and pass the generated data to the seed function.

By adopting this solution, we can improve the resilience of our tests against changes in the seed data while maintaining a simple and maintainable codebase.

MartinBenediktBusch commented 4 months ago

@diegoalzate This PR needs more clarification. It is not clear to me how the exisiting seed should interact with each testing file or whether it is independent and each testing file has its own seed.

MartinBenediktBusch commented 4 months ago

This will be part of #340