Files
docuseal/spec/factories/templates.rb
T

74 lines
1.9 KiB
Ruby
Raw Normal View History

2023-08-20 12:42:47 +03:00
# frozen_string_literal: true
FactoryBot.define do
factory :template do
account
author factory: %i[user]
name { Faker::Book.title }
2024-10-15 21:44:15 +03:00
transient do
submitter_count { 1 }
end
after(:create) do |template, evaluator|
2023-08-20 12:42:47 +03:00
blob = ActiveStorage::Blob.create_and_upload!(
io: Rails.root.join('spec/fixtures/sample-document.pdf').open,
filename: 'sample-document.pdf',
content_type: 'application/pdf'
)
attachment = ActiveStorage::Attachment.create!(
blob:,
name: :documents,
record: template
)
2023-09-01 01:27:13 +03:00
Templates::ProcessDocument.call(attachment, attachment.download)
2023-08-20 12:42:47 +03:00
template.schema = [{ attachment_uuid: attachment.uuid, name: 'sample-document' }]
2024-10-15 21:44:15 +03:00
number_words = %w[first second third fourth fifth sixth seventh eighth ninth tenth]
template.submitters = Array.new(evaluator.submitter_count) do |i|
2023-08-20 12:42:47 +03:00
{
2024-10-15 21:44:15 +03:00
'name' => "#{number_words[i]&.capitalize} Party",
'uuid' => SecureRandom.uuid
2023-08-20 12:42:47 +03:00
}
2024-10-15 21:44:15 +03:00
end
template.fields = template.submitters.reduce([]) do |fields, submitter|
fields += [
{
'uuid' => SecureRandom.uuid,
'submitter_uuid' => submitter['uuid'],
'name' => 'First Name',
'type' => 'text',
'required' => true,
'areas' => [
{
'x' => 0.09027777777777778,
'y' => 0.1197252208047105,
'w' => 0.3069444444444444,
'h' => 0.03336604514229637,
'attachment_uuid' => attachment.uuid,
'page' => 0
}
]
},
{
'uuid' => SecureRandom.uuid,
'submitter_uuid' => submitter['uuid'],
'name' => '',
'type' => 'signature',
'required' => true,
'areas' => []
}
]
fields
end
2023-08-20 12:42:47 +03:00
template.save!
end
end
end