add attachment count attribute to template factory

pull/440/head
Alex Turchyn 9 months ago committed by Pete Matsyburka
parent fc4b4de6ed
commit 8d953f210f

@ -9,6 +9,7 @@ FactoryBot.define do
transient do
submitter_count { 1 }
attachment_count { 1 }
only_field_types do
%w[text date checkbox radio signature number multiple select initials image file stamp cells phone payment]
end
@ -16,6 +17,19 @@ FactoryBot.define do
end
after(:create) do |template, ev|
number_words = %w[first second third fourth fifth sixth seventh eighth ninth tenth]
template.submitters = Array.new(ev.submitter_count) do |i|
{
'name' => "#{number_words[i]&.capitalize} Party",
'uuid' => SecureRandom.uuid
}
end
ev.attachment_count.times do |i|
attachment_index = i + 1 if i > 0
field_index = "(#{attachment_index})" if attachment_index
blob = ActiveStorage::Blob.create_and_upload!(
io: Rails.root.join('spec/fixtures/sample-document.pdf').open,
filename: 'sample-document.pdf',
@ -29,22 +43,17 @@ FactoryBot.define do
Templates::ProcessDocument.call(attachment, attachment.download)
template.schema = [{ attachment_uuid: attachment.uuid, name: 'sample-document' }]
number_words = %w[first second third fourth fifth sixth seventh eighth ninth tenth]
template.submitters = Array.new(ev.submitter_count) do |i|
{
'name' => "#{number_words[i]&.capitalize} Party",
'uuid' => SecureRandom.uuid
template.schema << {
attachment_uuid: attachment.uuid,
name: ['sample-document', attachment_index].compact.join('-')
}
end
template.fields = template.submitters.reduce([]) do |fields, submitter|
template.fields += template.submitters.reduce([]) do |fields, submitter|
fields += [
{
'uuid' => SecureRandom.uuid,
'submitter_uuid' => submitter['uuid'],
'name' => 'First Name',
'name' => ['First Name', field_index].compact.join(' '),
'type' => 'text',
'required' => true,
'preferences' => {},
@ -62,7 +71,7 @@ FactoryBot.define do
{
'uuid' => SecureRandom.uuid,
'submitter_uuid' => submitter['uuid'],
'name' => 'Birthday',
'name' => ['Birthday', field_index].compact.join(' '),
'type' => 'date',
'required' => true,
'preferences' => { 'format' => 'DD/MM/YYYY' },
@ -80,7 +89,7 @@ FactoryBot.define do
{
'uuid' => SecureRandom.uuid,
'submitter_uuid' => submitter['uuid'],
'name' => 'Do you agree?',
'name' => ['Do you agree?', field_index].compact.join(' '),
'type' => 'checkbox',
'required' => true,
'preferences' => {},
@ -98,7 +107,7 @@ FactoryBot.define do
{
'uuid' => SecureRandom.uuid,
'submitter_uuid' => submitter['uuid'],
'name' => 'First child',
'name' => ['First child', field_index].compact.join(' '),
'type' => 'radio',
'required' => true,
'preferences' => {},
@ -120,7 +129,7 @@ FactoryBot.define do
{
'uuid' => SecureRandom.uuid,
'submitter_uuid' => submitter['uuid'],
'name' => 'Signature',
'name' => ['Signature', field_index].compact.join(' '),
'type' => 'signature',
'required' => true,
'preferences' => {},
@ -138,7 +147,7 @@ FactoryBot.define do
{
'uuid' => SecureRandom.uuid,
'submitter_uuid' => submitter['uuid'],
'name' => 'House number',
'name' => ['House number', field_index].compact.join(' '),
'type' => 'number',
'required' => true,
'preferences' => {},
@ -156,7 +165,7 @@ FactoryBot.define do
{
'uuid' => SecureRandom.uuid,
'submitter_uuid' => submitter['uuid'],
'name' => 'Colors',
'name' => ['Colors', field_index].compact.join(' '),
'type' => 'multiple',
'required' => true,
'preferences' => {},
@ -179,7 +188,7 @@ FactoryBot.define do
{
'uuid' => SecureRandom.uuid,
'submitter_uuid' => submitter['uuid'],
'name' => 'Gender',
'name' => ['Gender', field_index].compact.join(' '),
'type' => 'select',
'required' => true,
'preferences' => {},
@ -201,7 +210,7 @@ FactoryBot.define do
{
'uuid' => SecureRandom.uuid,
'submitter_uuid' => submitter['uuid'],
'name' => 'Initials',
'name' => ['Initials', field_index].compact.join(' '),
'type' => 'initials',
'required' => true,
'preferences' => {},
@ -219,7 +228,7 @@ FactoryBot.define do
{
'uuid' => SecureRandom.uuid,
'submitter_uuid' => submitter['uuid'],
'name' => 'Avatar',
'name' => ['Avatar', field_index].compact.join(' '),
'type' => 'image',
'required' => true,
'preferences' => {},
@ -237,7 +246,7 @@ FactoryBot.define do
{
'uuid' => SecureRandom.uuid,
'submitter_uuid' => submitter['uuid'],
'name' => 'Attachment',
'name' => ['Attachment', field_index].compact.join(' '),
'type' => 'file',
'required' => true,
'preferences' => {},
@ -255,7 +264,7 @@ FactoryBot.define do
{
'uuid' => SecureRandom.uuid,
'submitter_uuid' => submitter['uuid'],
'name' => 'Stamp',
'name' => ['Stamp', field_index].compact.join(' '),
'type' => 'stamp',
'required' => true,
'readonly' => true,
@ -274,7 +283,7 @@ FactoryBot.define do
{
'uuid' => SecureRandom.uuid,
'submitter_uuid' => submitter['uuid'],
'name' => 'Cell code',
'name' => ['Cell code', field_index].compact.join(' '),
'type' => 'cells',
'required' => true,
'preferences' => {},
@ -293,7 +302,7 @@ FactoryBot.define do
{
'uuid' => SecureRandom.uuid,
'submitter_uuid' => submitter['uuid'],
'name' => 'Payment',
'name' => ['Payment', field_index].compact.join(' '),
'type' => 'payment',
'required' => true,
'preferences' => { 'currency' => 'EUR', 'price' => 1000 },
@ -311,7 +320,7 @@ FactoryBot.define do
{
'uuid' => SecureRandom.uuid,
'submitter_uuid' => submitter['uuid'],
'name' => 'Mobile Phone',
'name' => ['Mobile Phone', field_index].compact.join(' '),
'type' => 'phone',
'required' => true,
'preferences' => {},
@ -330,6 +339,7 @@ FactoryBot.define do
fields
end
end
template.save!
end

Loading…
Cancel
Save