Skip to content

Seeder api #6304

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

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft

Seeder api #6304

wants to merge 3 commits into from

Conversation

FireLemons
Copy link
Collaborator

@FireLemons FireLemons commented Apr 2, 2025

What changed, and why?

API to more easily control test data

How is this tested? (please write rspec and jest tests!) 💖💪

One time testing log here. Not many people need this feature and the seeder is part of CI already.

@github-actions github-actions bot added the ruby Pull requests that update Ruby code label Apr 2, 2025
@FireLemons
Copy link
Collaborator Author

FireLemons commented Apr 9, 2025

Test for seed_additional_expense

casa(dev)> seed_additional_expense(case_contact_id: '1')
  TRANSACTION (0.2ms)  BEGIN
  CaseContact Load (26.0ms)  SELECT "case_contacts".* FROM "case_contacts" WHERE "case_contacts"."deleted_at" IS NULL AND "case_contacts"."id" = $1 LIMIT $2  [["id", 1], ["LIMIT", 1]]
  AdditionalExpense Create (47.8ms)  INSERT INTO "additional_expenses" ("case_contact_id", "other_expense_amount", "other_expenses_describe", "created_at", "updated_at") VALUES ($1, $2, $3, $4, $5) RETURNING "id"  [["case_contact_id", 1], ["other_expense_amount", "8.22"], ["other_expenses_describe", "Rustic Steel Knife"], ["created_at", "2025-04-09 00:24:43.229255"], ["updated_at", "2025-04-09 00:24:43.229255"]]
  TRANSACTION (20.7ms)  COMMIT
=> 
#<AdditionalExpense:0x000076309f8c0898
 id: 6,
 case_contact_id: 1,
 other_expense_amount: 0.822e1,
 other_expenses_describe: "Rustic Steel Knife",
 created_at: "2025-04-09 00:24:43.229255000 +0000",
 updated_at: "2025-04-09 00:24:43.229255000 +0000">

casa(dev)> seed_additional_expense(case_contact: CaseContact.first)
  CaseContact Load (0.6ms)  SELECT "case_contacts".* FROM "case_contacts" WHERE "case_contacts"."deleted_at" IS NULL ORDER BY "case_contacts"."id" ASC LIMIT $1  [["LIMIT", 1]]
  TRANSACTION (0.3ms)  BEGIN
  AdditionalExpense Create (1.5ms)  INSERT INTO "additional_expenses" ("case_contact_id", "other_expense_amount", "other_expenses_describe", "created_at", "updated_at") VALUES ($1, $2, $3, $4, $5) RETURNING "id"  [["case_contact_id", 1], ["other_expense_amount", "40.82"], ["other_expenses_describe", "Mediocre Concrete Chair"], ["created_at", "2025-04-09 00:26:57.280805"], ["updated_at", "2025-04-09 00:26:57.280805"]]
  TRANSACTION (7.1ms)  COMMIT
=> 
#<AdditionalExpense:0x000076309f39a148
 id: 7,
 case_contact_id: 1,
 other_expense_amount: 0.4082e2,
 other_expenses_describe: "Mediocre Concrete Chair",
 created_at: "2025-04-09 00:26:57.280805000 +0000",
 updated_at: "2025-04-09 00:26:57.280805000 +0000">

casa(dev)> seed_additional_expense(case_contact: CaseContact.first, case_contact_id: 1)
  CaseContact Load (1.1ms)  SELECT "case_contacts".* FROM "case_contacts" WHERE "case_contacts"."deleted_at" IS NULL ORDER BY "case_contacts"."id" ASC LIMIT $1  [["LIMIT", 1]]
(casa):4:in `<top (required)>': cannot use case_contact: and case_contact_id: (ArgumentError)

    raise ArgumentError.new("cannot use case_contact: and case_contact_id:")
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

casa(dev)> seed_additional_expense()
(casa):5:in `<top (required)>': case_contact: or case_contact_id: is required (ArgumentError)

    raise ArgumentError.new("case_contact: or case_contact_id: is required")
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

@FireLemons
Copy link
Collaborator Author

FireLemons commented Apr 10, 2025

Test for seed_additional_expenses

casa(dev)> seed_additional_expenses(case_contact_ids:[1, 2], count: 2)
  TRANSACTION (0.6ms)  BEGIN
  CaseContact Load (0.9ms)  SELECT "case_contacts".* FROM "case_contacts" WHERE "case_contacts"."deleted_at" IS NULL AND "case_contacts"."id" = $1 LIMIT $2  [["id", 1], ["LIMIT", 1]]
  AdditionalExpense Create (0.8ms)  INSERT INTO "additional_expenses" ("case_contact_id", "other_expense_amount", "other_expenses_describe", "created_at", "updated_at") VALUES ($1, $2, $3, $4, $5) RETURNING "id"  [["case_contact_id", 1], ["other_expense_amount", "19.49"], ["other_expenses_describe", "Mediocre Aluminum Chair"], ["created_at", "2025-04-10 21:16:00.210388"], ["updated_at", "2025-04-10 21:16:00.210388"]]
  TRANSACTION (68.3ms)  COMMIT
  TRANSACTION (0.3ms)  BEGIN
  CaseContact Load (0.6ms)  SELECT "case_contacts".* FROM "case_contacts" WHERE "case_contacts"."deleted_at" IS NULL AND "case_contacts"."id" = $1 LIMIT $2  [["id", 1], ["LIMIT", 1]]
  AdditionalExpense Create (1.1ms)  INSERT INTO "additional_expenses" ("case_contact_id", "other_expense_amount", "other_expenses_describe", "created_at", "updated_at") VALUES ($1, $2, $3, $4, $5) RETURNING "id"  [["case_contact_id", 1], ["other_expense_amount", "14.63"], ["other_expenses_describe", "Incredible Linen Shirt"], ["created_at", "2025-04-10 21:16:00.286122"], ["updated_at", "2025-04-10 21:16:00.286122"]]
  TRANSACTION (59.4ms)  COMMIT
=> [18, 19]

casa(dev)> seed_additional_expenses(case_contacts: CaseContact.all, case_contact_ids:[1, 2], count: 2)
(casa):6:in `<top (required)>': cannot use case_contacts: and case_contact_ids: (ArgumentError)

    raise ArgumentError.new("cannot use case_contacts: and case_contact_ids:")
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

casa(dev)> seed_additional_expenses(count: 2)
(casa):7:in `<top (required)>': case_contacts: or case_contact_ids: is required (ArgumentError)

    raise ArgumentError.new("case_contacts: or case_contact_ids: is required")
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

casa(dev)> seed_additional_expenses(case_contacts: 2, count: 2)
(casa):2:in `<top (required)>': param case_contacts must be an ActiveRecord::Relation (TypeError)

      raise TypeError.new("param case_contacts must be an ActiveRecord::Relation")
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

casa(dev)> seed_additional_expenses(case_contact_ids: 2, count: 2)
(casa):3:in `<top (required)>': param case_contact_ids: must be an array (TypeError)

      raise TypeError.new("param case_contact_ids: must be an array")
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ruby Pull requests that update Ruby code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant