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
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
class PagesControllerTest < ActionDispatch::IntegrationTest
setup do
- @page = pages(:one)
+ @page = pages(:about)
+ sign_in users(:admin)
end
test "should get index" do
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)
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
class PostsControllerTest < ActionDispatch::IntegrationTest
setup do
- @post = posts(:one)
+ @post = posts(:tech_dispatch)
+ sign_in users(:admin)
end
test "should get index" do
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)
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
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
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
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
class AdminMailerTest < ActionMailer::TestCase
test "new_paid_member" do
- mail = AdminMailer.new_paid_member
- assert_equal "New paid member", mail.subject
- 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_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_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_match user.email, mail.body.encoded
end
end
class DigestMailerTest < ActionMailer::TestCase
test "weekly_bookmarks_digest" do
- mail = DigestMailer.weekly_bookmarks_digest
- assert_equal "Weekly bookmarks digest", mail.subject
- 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_match "weekly digest", mail.body.encoded
+ bookmarks.each do |bookmark|
+ assert_match bookmark.title, mail.body.encoded
+ end
end
end
-# 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
-# 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
-# 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
-# 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
class SubscriptionMailerTest < ActionMailer::TestCase
test "confirmation_email" do
- mail = SubscriptionMailer.confirmation_email
- assert_equal "Confirmation email", mail.subject
- 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_match support_type, mail.body.encoded
+ assert_match amount.to_s, mail.body.encoded if amount
end
end
class WelcomeMailerTest < ActionMailer::TestCase
test "welcome_email" do
- mail = WelcomeMailer.welcome_email
- assert_equal "Welcome email", mail.subject
- 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_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_match "Welcome", mail.body.encoded
+ assert_match user.first_name, mail.body.encoded
+ assert_match "Premium", mail.body.encoded
end
end