Browse Source

Test use of factory bot in seeds

pull/2806/head
Rachael Booth 7 months ago
parent
commit
60f3206611
  1. 74
      db/seeds.rb
  2. 11
      spec/factories/sales_log.rb

74
db/seeds.rb

@ -100,6 +100,24 @@ unless Rails.env.test?
provider_type: "LA",
)
OrganisationRelationship.find_or_create_by!(
parent_organisation: stock_owner1,
child_organisation: org,
)
OrganisationRelationship.find_or_create_by!(
parent_organisation: stock_owner2,
child_organisation: org,
)
OrganisationRelationship.find_or_create_by!(
parent_organisation: org,
child_organisation: managing_agent1,
)
OrganisationRelationship.find_or_create_by!(
parent_organisation: org,
child_organisation: managing_agent2,
)
if Rails.env.development? || Rails.env.review?
User.find_or_create_by!(
name: "Provider Owns Stock",
email: "provider.owner1@example.com",
@ -194,24 +212,6 @@ unless Rails.env.test?
create_data_protection_confirmation(user)
end
OrganisationRelationship.find_or_create_by!(
parent_organisation: stock_owner1,
child_organisation: org,
)
OrganisationRelationship.find_or_create_by!(
parent_organisation: stock_owner2,
child_organisation: org,
)
OrganisationRelationship.find_or_create_by!(
parent_organisation: org,
child_organisation: managing_agent1,
)
OrganisationRelationship.find_or_create_by!(
parent_organisation: org,
child_organisation: managing_agent2,
)
if Rails.env.development? || Rails.env.review?
User.find_or_create_by!(
name: "Provider",
email: "provider@example.com",
@ -251,42 +251,10 @@ unless Rails.env.test?
end
if (Rails.env.development? || Rails.env.review?) && SalesLog.count.zero?
SalesLog.find_or_create_by!(
assigned_to: support_user,
owning_organisation: org,
managing_organisation: org,
saledate: Time.zone.today,
purchid: "1",
ownershipsch: 1,
type: 2,
jointpur: 1,
jointmore: 1,
)
SalesLog.find_or_create_by!(
assigned_to: support_user,
owning_organisation: org,
managing_organisation: org,
saledate: Time.zone.today,
purchid: "1",
ownershipsch: 2,
type: 9,
jointpur: 1,
jointmore: 1,
)
SalesLog.find_or_create_by!(
assigned_to: support_user,
owning_organisation: org,
managing_organisation: org,
saledate: Time.zone.today,
purchid: "1",
ownershipsch: 3,
type: 10,
companybuy: 1,
)
FactoryBot.create(:sales_log, :shared_ownership_setup_complete, assigned_to: support_user)
FactoryBot.create(:sales_log, :discounted_ownership_setup_complete, assigned_to: support_user)
FactoryBot.create(:sales_log, :outright_sale_setup_complete, assigned_to: support_user)
pp "Seeded a sales log of each type"
end
if Rails.env.development? || Rails.env.review?

11
spec/factories/sales_log.rb

@ -32,6 +32,17 @@ FactoryBot.define do
jointpur { 2 }
noint { 2 }
privacynotice { 1 }
purchid { rand(999_999_999).to_s }
end
trait :discounted_ownership_setup_complete do
saledate_today
ownershipsch { 2 }
type { 9 }
jointpur { 1 }
jointmor { 1 }
noint { 2 }
privacynotice { 1 }
purchid { rand(999_999_999).to_s }
end
trait :outright_sale_setup_complete do
saledate_today

Loading…
Cancel
Save