diff --git a/test/models/mailbox_test.rb b/test/models/mailbox_test.rb index a9e572883..3abe64cba 100755 --- a/test/models/mailbox_test.rb +++ b/test/models/mailbox_test.rb @@ -1,7 +1,15 @@ require "test_helper" class MailboxTest < ActiveSupport::TestCase - # test "the truth" do - # assert true - # end + def setup + @mailbox = Mailbox.new + end + + test "should be valid" do + assert @mailbox.valid? + end + + test "should inherit from ApplicationRecord" do + assert_kind_of ApplicationRecord, @mailbox + end end diff --git a/test/models/message_test.rb b/test/models/message_test.rb index 0e0d35bbe..875bdcd43 100755 --- a/test/models/message_test.rb +++ b/test/models/message_test.rb @@ -1,7 +1,59 @@ require "test_helper" class MessageTest < ActiveSupport::TestCase - # test "the truth" do - # assert true - # end + def setup + @message_thread = message_threads(:one) + @message = Message.new( + content: "Test message content", + message_thread: @message_thread + ) + end + + test "should be valid with content and message_thread" do + assert @message.valid? + end + + test "should validate presence of content" do + @message.content = nil + assert_not @message.valid? + assert_includes @message.errors[:content], "can't be blank" + end + + test "should belong to message_thread" do + assert_respond_to @message, :message_thread + assert_equal @message_thread, @message.message_thread + end + + test "should have rich text content" do + assert_respond_to @message, :content + assert_respond_to @message, :rich_text_content + end + + test "should have attachments" do + assert_respond_to @message, :attachments + end + + test "should generate email_message_id before save" do + @message.save! + assert_not_nil @message.email_message_id + assert_match /.+@.+/, @message.email_message_id + end + + test "should update message_thread current_email_message_id after create" do + original_message_id = @message_thread.current_email_message_id + @message.save! + @message_thread.reload + assert_equal @message.email_message_id, @message_thread.current_email_message_id + assert_not_equal original_message_id, @message_thread.current_email_message_id + end + + test "should default order by created_at DESC" do + @message.save! + older_message = Message.create!(content: "Older message", message_thread: @message_thread) + newer_message = Message.create!(content: "Newer message", message_thread: @message_thread) + + messages = Message.all + assert_equal newer_message, messages.first + assert_equal older_message, messages.second + end end diff --git a/test/models/message_thread_test.rb b/test/models/message_thread_test.rb index ed4e57de1..4dcfe5591 100755 --- a/test/models/message_thread_test.rb +++ b/test/models/message_thread_test.rb @@ -1,7 +1,48 @@ require "test_helper" class MessageThreadTest < ActiveSupport::TestCase - # test "the truth" do - # assert true - # end + def setup + @message_thread = MessageThread.new( + recipients: ["test@example.com"], + subject: "Test Subject" + ) + end + + test "should be valid with recipients" do + assert @message_thread.valid? + end + + test "should validate presence of recipients" do + @message_thread.recipients = nil + assert_not @message_thread.valid? + assert_includes @message_thread.errors[:recipients], "can't be blank" + end + + test "should validate recipients length minimum" do + @message_thread.recipients = [] + assert_not @message_thread.valid? + assert_includes @message_thread.errors[:recipients], "is too short (minimum is 1 character)" + end + + test "should have many messages" do + assert_respond_to @message_thread, :messages + assert_respond_to @message_thread, :messages= + end + + test "should accept nested attributes for messages" do + assert_respond_to @message_thread, :messages_attributes= + end + + test "should include comfy cms with categories" do + assert_includes MessageThread.included_modules, Comfy::Cms::WithCategories + end + + test "should have search scope" do + assert_respond_to MessageThread, :search_messages_content_body_or_subject_or_messages_from_or_recipients_contains + end + + test "should have ransackable scopes" do + ransackable_scopes = MessageThread.ransackable_scopes + assert_includes ransackable_scopes, :search_messages_content_body_or_subject_or_messages_from_or_recipients_contains + end end diff --git a/test/models/non_primitive_property_test.rb b/test/models/non_primitive_property_test.rb index 385e982c2..d55043fb1 100644 --- a/test/models/non_primitive_property_test.rb +++ b/test/models/non_primitive_property_test.rb @@ -1,7 +1,64 @@ require "test_helper" class NonPrimitivePropertyTest < ActiveSupport::TestCase - # test "the truth" do - # assert true - # end + def setup + @api_namespace = api_namespaces(:one) + @non_primitive_property = NonPrimitiveProperty.new( + label: "Test Property", + field_type: :richtext, + content: "Test content", + api_namespace: @api_namespace + ) + end + + test "should be valid with all attributes" do + assert @non_primitive_property.valid? + end + + test "should validate presence of label" do + @non_primitive_property.label = nil + assert_not @non_primitive_property.valid? + assert_includes @non_primitive_property.errors[:label], "can't be blank" + end + + test "should belong to api_resource optionally" do + assert_respond_to @non_primitive_property, :api_resource + assert_respond_to @non_primitive_property, :api_resource= + end + + test "should belong to api_namespace optionally" do + assert_respond_to @non_primitive_property, :api_namespace + assert_equal @api_namespace, @non_primitive_property.api_namespace + end + + test "should have field_type enum" do + assert_respond_to @non_primitive_property, :field_type + assert_equal 0, NonPrimitiveProperty.field_types[:file] + assert_equal 1, NonPrimitiveProperty.field_types[:richtext] + end + + test "should have rich text content" do + assert_respond_to @non_primitive_property, :content + assert_respond_to @non_primitive_property, :rich_text_content + end + + test "should have attachment" do + assert_respond_to @non_primitive_property, :attachment + end + + test "should respond to file_url method" do + assert_respond_to @non_primitive_property, :file_url + end + + test "should identify file type correctly" do + @non_primitive_property.field_type = :file + assert @non_primitive_property.file? + assert_not @non_primitive_property.richtext? + end + + test "should identify richtext type correctly" do + @non_primitive_property.field_type = :richtext + assert @non_primitive_property.richtext? + assert_not @non_primitive_property.file? + end end diff --git a/test/models/sales_asset_test.rb b/test/models/sales_asset_test.rb index 9952c4e39..5b249ccd9 100644 --- a/test/models/sales_asset_test.rb +++ b/test/models/sales_asset_test.rb @@ -1,7 +1,49 @@ require "test_helper" class SalesAssetTest < ActiveSupport::TestCase - # test "the truth" do - # assert true - # end + def setup + @sales_asset = SalesAsset.new( + name: "Test Sales Asset", + width: 800, + height: 600, + html: "