]> gitweb.mndrdr.org Git - arelpe.git/commitdiff
Updated test suite, in its entirety
authorAidan Cornelius-Bell <[email protected]>
Tue, 31 Dec 2024 21:49:04 +0000 (08:19 +1030)
committerAidan Cornelius-Bell <[email protected]>
Tue, 31 Dec 2024 21:49:04 +0000 (08:19 +1030)
15 files changed:
test/controllers/job_runner_controller_test.rb
test/controllers/mailing_lists_controller_test.rb
test/controllers/pages_controller_test.rb
test/controllers/posts_controller_test.rb
test/controllers/pubview_controller_test.rb
test/controllers/subscriptions_controller_test.rb
test/controllers/two_factor_controller_test.rb
test/mailers/admin_mailer_test.rb
test/mailers/digest_mailer_test.rb
test/mailers/previews/admin_mailer_preview.rb
test/mailers/previews/digest_mailer_preview.rb
test/mailers/previews/subscription_mailer_preview.rb
test/mailers/previews/welcome_mailer_preview.rb
test/mailers/subscription_mailer_test.rb
test/mailers/welcome_mailer_test.rb

index c39d3d74a82df72c71dd2c69c86ca5d24ed31804..b89d2f8dc3813e56b1a0a7aa8a0a3e2f3d44d0a4 100644 (file)
@@ -1,13 +1,23 @@
 require "test_helper"
 
 class JobRunnerControllerTest < ActionDispatch::IntegrationTest
+  setup do
+    sign_in users(:admin)
+  end
+
   test "should get index" do
-    get job_runner_index_url
+    get job_runner_url
     assert_response :success
   end
 
-  test "should get run" do
-    get job_runner_run_url
-    assert_response :success
+  test "should run job" do
+    post run_job_runner_url, params: { job: 'weekly_bookmarks_digest' }
+    assert_redirected_to job_runner_url
+  end
+
+  test "should handle invalid job" do
+    post run_job_runner_url, params: { job: 'invalid_job' }
+    assert_redirected_to job_runner_url
+    assert_not_empty flash[:alert]
   end
 end
index 6b69c783d342417db10316e9517d3e7b2c0c85b2..08cf1078e05a15941618c9970c9402042f24cdfe 100644 (file)
@@ -1,18 +1,32 @@
 require "test_helper"
 
 class MailingListsControllerTest < ActionDispatch::IntegrationTest
+  setup do
+    sign_in users(:regular_user)
+  end
+
   test "should get index" do
-    get mailing_lists_index_url
+    get mailing_lists_url
     assert_response :success
   end
 
-  test "should get edit" do
-    get mailing_lists_edit_url
-    assert_response :success
+  test "should subscribe" do
+    post subscribe_mailing_lists_url
+    assert_redirected_to mailing_lists_url
   end
 
-  test "should get update" do
-    get mailing_lists_update_url
-    assert_response :success
+  test "should unsubscribe" do
+    delete unsubscribe_mailing_lists_url
+    assert_redirected_to mailing_lists_url
+  end
+
+  test "should sync status" do
+    post sync_status_mailing_lists_url
+    assert_redirected_to mailing_lists_url
+  end
+
+  test "should resync from buttondown" do
+    post resync_from_buttondown_mailing_lists_url
+    assert_redirected_to mailing_lists_url
   end
 end
index 2380d9befacc062b95bcaeb82dd7ee850c163d88..c087aeeb5977ef7cb6e12b84bd842c19bbe623e7 100644 (file)
@@ -2,7 +2,8 @@ require "test_helper"
 
 class PagesControllerTest < ActionDispatch::IntegrationTest
   setup do
-    @page = pages(:one)
+    @page = pages(:about)
+    sign_in users(:admin)
   end
 
   test "should get index" do
@@ -17,7 +18,14 @@ class PagesControllerTest < ActionDispatch::IntegrationTest
 
   test "should create page" do
     assert_difference("Page.count") do
-      post pages_url, params: { page: { content: @page.content, public: @page.public, slug: @page.slug, title: @page.title } }
+      post pages_url, params: {
+        page: {
+          content: @page.content,
+          slug: "#{@page.slug}-new",
+          title: "#{@page.title} New",
+          visibility: @page.visibility
+        }
+      }
     end
 
     assert_redirected_to page_url(Page.last)
@@ -34,7 +42,14 @@ class PagesControllerTest < ActionDispatch::IntegrationTest
   end
 
   test "should update page" do
-    patch page_url(@page), params: { page: { content: @page.content, public: @page.public, slug: @page.slug, title: @page.title } }
+    patch page_url(@page), params: {
+      page: {
+        content: @page.content,
+        slug: @page.slug,
+        title: @page.title,
+        visibility: @page.visibility
+      }
+    }
     assert_redirected_to page_url(@page)
   end
 
index 5ccdfbd519a4387ad9a69fa76c634c950f7236f0..2c5831617bbe98fa3791773fc45aa8595efe8656 100644 (file)
@@ -2,7 +2,8 @@ require "test_helper"
 
 class PostsControllerTest < ActionDispatch::IntegrationTest
   setup do
-    @post = posts(:one)
+    @post = posts(:tech_dispatch)
+    sign_in users(:admin)
   end
 
   test "should get index" do
@@ -17,7 +18,18 @@ class PostsControllerTest < ActionDispatch::IntegrationTest
 
   test "should create post" do
     assert_difference("Post.count") do
-      post posts_url, params: { post: { content: @post.content, excerpt: @post.excerpt, post_type: @post.post_type, published_at: @post.published_at, slug: @post.slug, tags: @post.tags, title: @post.title, url: @post.url } }
+      post posts_url, params: {
+        post: {
+          content: @post.content,
+          excerpt: @post.excerpt,
+          post_type: @post.post_type,
+          published_at: @post.published_at,
+          slug: "#{@post.slug}-new",
+          tags: @post.tags,
+          title: "#{@post.title} New",
+          url: @post.url
+        }
+      }
     end
 
     assert_redirected_to post_url(Post.last)
@@ -34,7 +46,18 @@ class PostsControllerTest < ActionDispatch::IntegrationTest
   end
 
   test "should update post" do
-    patch post_url(@post), params: { post: { content: @post.content, excerpt: @post.excerpt, post_type: @post.post_type, published_at: @post.published_at, slug: @post.slug, tags: @post.tags, title: @post.title, url: @post.url } }
+    patch post_url(@post), params: {
+      post: {
+        content: @post.content,
+        excerpt: @post.excerpt,
+        post_type: @post.post_type,
+        published_at: @post.published_at,
+        slug: @post.slug,
+        tags: @post.tags,
+        title: @post.title,
+        url: @post.url
+      }
+    }
     assert_redirected_to post_url(@post)
   end
 
index 0acbddf8336502527f52697619f424c4eaf6063e..d407ef016beac7bc63c8142851f8d8f475494c6a 100644 (file)
@@ -2,17 +2,35 @@ require "test_helper"
 
 class PubviewControllerTest < ActionDispatch::IntegrationTest
   test "should get index" do
-    get pubview_index_url
+    get root_url
     assert_response :success
   end
 
-  test "should get post" do
-    get pubview_post_url
+  test "should get dispatch post" do
+    post = posts(:tech_dispatch)
+    get public_post_url(year: post.published_at.year, slug: post.slug)
     assert_response :success
   end
 
-  test "should get rss" do
-    get pubview_rss_url
+  test "should get bookmark post" do
+    post = posts(:tech_bookmark)
+    get public_post_url(year: post.published_at.year, slug: post.slug)
+    assert_response :success
+  end
+
+  test "should get public page" do
+    page = pages(:about)
+    get public_page_url(slug: page.slug)
+    assert_response :success
+  end
+
+  test "should get rss feed" do
+    get rss_url(format: :rss)
+    assert_response :success
+  end
+
+  test "should get dispatches rss feed" do
+    get dispatches_rss_url(format: :rss)
     assert_response :success
   end
 end
index 3958a5a9b61355ff1f37b73d0bdf7cde3df580ed..d5117e7cdd0e8701723c6897c1b47ab3680e99a3 100644 (file)
@@ -1,18 +1,42 @@
 require "test_helper"
 
 class SubscriptionsControllerTest < ActionDispatch::IntegrationTest
-  test "should get new" do
-    get subscriptions_new_url
-    assert_response :success
+  setup do
+    sign_in users(:regular_user)
   end
 
-  test "should get create" do
-    get subscriptions_create_url
+  test "should get index" do
+    get subscriptions_url
     assert_response :success
   end
 
-  test "should get view" do
-    get subscriptions_view_url
+  test "should get new" do
+    get new_subscription_url
     assert_response :success
   end
+
+  test "should create subscription" do
+    post subscriptions_url, params: {
+      support_type: 'non_financial'
+    }
+    assert_redirected_to subscriptions_url
+  end
+
+  test "should handle one time payment" do
+    post subscriptions_url, params: {
+      support_type: 'one_time',
+      payment_amount: '10.00',
+      stripeToken: 'dummy_token'
+    }
+    assert_redirected_to subscriptions_url
+  end
+
+  test "should handle ongoing payment" do
+    post subscriptions_url, params: {
+      support_type: 'ongoing',
+      payment_amount: '10.00',
+      stripeToken: 'dummy_token'
+    }
+    assert_redirected_to subscriptions_url
+  end
 end
index 4ef2cf780008f43941f8f8fa8f3e561e0b987d0c..12b17a416011d01654f541febd30e041d90085c9 100644 (file)
@@ -1,18 +1,27 @@
 require "test_helper"
 
 class TwoFactorControllerTest < ActionDispatch::IntegrationTest
+  setup do
+    sign_in users(:regular_user)
+  end
+
   test "should get new" do
-    get two_factor_new_url
+    get new_two_factor_url
     assert_response :success
   end
 
-  test "should get create" do
-    get two_factor_create_url
-    assert_response :success
+  test "should create" do
+    post two_factor_url, params: { otp_attempt: "123456" }
+    assert_redirected_to backup_codes_two_factor_url
   end
 
-  test "should get destroy" do
-    get two_factor_destroy_url
+  test "should show backup codes" do
+    get backup_codes_two_factor_url
     assert_response :success
   end
+
+  test "should destroy" do
+    delete two_factor_url
+    assert_redirected_to root_url
+  end
 end
index 43f15c3748e11112f95661537a790caaa2155147..1291807031cb9219126ea83b18b856dd41246a81 100644 (file)
@@ -2,18 +2,20 @@ require "test_helper"
 
 class AdminMailerTest < ActionMailer::TestCase
   test "new_paid_member" do
-    mail = AdminMailer.new_paid_member
-    assert_equal "New paid member", mail.subject
-    assert_equal [ "[email protected]" ], mail.to
-    assert_equal [ "[email protected]" ], mail.from
-    assert_match "Hi", mail.body.encoded
+    user = users(:paid_user)
+    mail = AdminMailer.new_paid_member(user)
+    assert_equal "mind reader :: New Paid Member", mail.subject
+    assert_equal [ENV["ADMIN_EMAIL"]], mail.to
+    assert_equal ["[email protected]"], mail.from
+    assert_match user.email, mail.body.encoded
   end
 
   test "new_non_financial_member" do
-    mail = AdminMailer.new_non_financial_member
-    assert_equal "New non financial member", mail.subject
-    assert_equal [ "[email protected]" ], mail.to
-    assert_equal [ "[email protected]" ], mail.from
-    assert_match "Hi", mail.body.encoded
+    user = users(:regular_user)
+    mail = AdminMailer.new_non_financial_member(user)
+    assert_equal "mind reader :: New Non-Financial Member", mail.subject
+    assert_equal [ENV["ADMIN_EMAIL"]], mail.to
+    assert_equal ["[email protected]"], mail.from
+    assert_match user.email, mail.body.encoded
   end
 end
index b87ee996f420fc289cd800ffbbbf6e658f3afa75..ad12f37d0b1b785740cdbc5808f2b99f2f7d3fce 100644 (file)
@@ -2,10 +2,16 @@ require "test_helper"
 
 class DigestMailerTest < ActionMailer::TestCase
   test "weekly_bookmarks_digest" do
-    mail = DigestMailer.weekly_bookmarks_digest
-    assert_equal "Weekly bookmarks digest", mail.subject
-    assert_equal [ "[email protected]" ], mail.to
-    assert_equal [ "[email protected]" ], mail.from
-    assert_match "Hi", mail.body.encoded
+    user = users(:paid_user)
+    bookmarks = Post.bookmarks.limit(5)
+
+    mail = DigestMailer.weekly_bookmarks_digest(user, bookmarks)
+    assert_equal "mind reader :: weekly digest", mail.subject
+    assert_equal [user.email], mail.to
+    assert_equal ["[email protected]"], mail.from
+    assert_match "weekly digest", mail.body.encoded
+    bookmarks.each do |bookmark|
+      assert_match bookmark.title, mail.body.encoded
+    end
   end
 end
index a04596ff81b5c497a169412c4ca716cbb6c5d1ad..48505d177e9ff7fc47e5de7c9571a326f93c4f7a 100644 (file)
@@ -1,12 +1,9 @@
-# Preview all emails at http://localhost:3000/rails/mailers/admin_mailer
 class AdminMailerPreview < ActionMailer::Preview
-  # Preview this email at http://localhost:3000/rails/mailers/admin_mailer/new_paid_member
   def new_paid_member
-    AdminMailer.new_paid_member
+    AdminMailer.new_paid_member(User.first)
   end
 
-  # Preview this email at http://localhost:3000/rails/mailers/admin_mailer/new_non_financial_member
   def new_non_financial_member
-    AdminMailer.new_non_financial_member
+    AdminMailer.new_non_financial_member(User.first)
   end
 end
index 7c29e212c3822526ac30274c025f191f415cb10d..8d0dc9898b8b6892b3472dbea0d2bb4d92dac21e 100644 (file)
@@ -1,7 +1,5 @@
-# Preview all emails at http://localhost:3000/rails/mailers/digest_mailer
 class DigestMailerPreview < ActionMailer::Preview
-  # Preview this email at http://localhost:3000/rails/mailers/digest_mailer/weekly_bookmarks_digest
   def weekly_bookmarks_digest
-    DigestMailer.weekly_bookmarks_digest
+    DigestMailer.weekly_bookmarks_digest(User.first, Post.bookmarks.limit(5))
   end
 end
index 4bcb8aa722e466da0c438da4f7f6ef168be05654..72d91b9c6d3953b44f490a63a16ada12ad57d11b 100644 (file)
@@ -1,7 +1,5 @@
-# Preview all emails at http://localhost:3000/rails/mailers/subscription_mailer
 class SubscriptionMailerPreview < ActionMailer::Preview
-  # Preview this email at http://localhost:3000/rails/mailers/subscription_mailer/confirmation_email
   def confirmation_email
-    SubscriptionMailer.confirmation_email
+    SubscriptionMailer.confirmation_email(User.first, 10.00, "ongoing")
   end
 end
index 1b5a5a6fb53ebaeb9fbba301051adc5c8f2439eb..aa0f89e856e00bc2571bcae0bc8466226b7d4312 100644 (file)
@@ -1,7 +1,5 @@
-# Preview all emails at http://localhost:3000/rails/mailers/welcome_mailer
 class WelcomeMailerPreview < ActionMailer::Preview
-  # Preview this email at http://localhost:3000/rails/mailers/welcome_mailer/welcome_email
   def welcome_email
-    WelcomeMailer.welcome_email
+    WelcomeMailer.welcome_email(User.first)
   end
 end
index 83c53cffa047aa0b140d9e707926f858314cd114..76f0e56bde2d82a181c5645d6b887e3db41ac282 100644 (file)
@@ -2,10 +2,15 @@ require "test_helper"
 
 class SubscriptionMailerTest < ActionMailer::TestCase
   test "confirmation_email" do
-    mail = SubscriptionMailer.confirmation_email
-    assert_equal "Confirmation email", mail.subject
-    assert_equal [ "[email protected]" ], mail.to
-    assert_equal [ "[email protected]" ], mail.from
-    assert_match "Hi", mail.body.encoded
+    user = users(:paid_user)
+    amount = 10.00
+    support_type = "ongoing"
+
+    mail = SubscriptionMailer.confirmation_email(user, amount, support_type)
+    assert_equal "Thank you for supporting mind reader!", mail.subject
+    assert_equal [user.email], mail.to
+    assert_equal ["[email protected]"], mail.from
+    assert_match support_type, mail.body.encoded
+    assert_match amount.to_s, mail.body.encoded if amount
   end
 end
index 0c5ce680bfe4da189d165d60ff32161f07c4c5e7..58d2beecab356cec0171a514213b242fd71686cf 100644 (file)
@@ -2,10 +2,23 @@ require "test_helper"
 
 class WelcomeMailerTest < ActionMailer::TestCase
   test "welcome_email" do
-    mail = WelcomeMailer.welcome_email
-    assert_equal "Welcome email", mail.subject
-    assert_equal [ "[email protected]" ], mail.to
-    assert_equal [ "[email protected]" ], mail.from
-    assert_match "Hi", mail.body.encoded
+    user = users(:regular_user)
+    mail = WelcomeMailer.welcome_email(user)
+    assert_equal "Welcome to mind reader", mail.subject
+    assert_equal [user.email], mail.to
+    assert_equal ["[email protected]"], mail.from
+    assert_match "Welcome", mail.body.encoded
+    assert_match user.first_name, mail.body.encoded
+  end
+
+  test "welcome_email_for_paid_user" do
+    user = users(:paid_user)
+    mail = WelcomeMailer.welcome_email(user)
+    assert_equal "Welcome to mind reader", mail.subject
+    assert_equal [user.email], mail.to
+    assert_equal ["[email protected]"], mail.from
+    assert_match "Welcome", mail.body.encoded
+    assert_match user.first_name, mail.body.encoded
+    assert_match "Premium", mail.body.encoded
   end
 end