Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Business subscriptions #168

Merged
merged 22 commits into from Dec 21, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
e422d51
Add Stripe secret keys to credentials
joemasilotti Dec 17, 2021
a253cb8
Add and configure Pay gem
joemasilotti Dec 18, 2021
24dce1b
Prioritize developer sign up over business
joemasilotti Dec 18, 2021
5c88279
Move platform-specific gem to bottom
joemasilotti Dec 19, 2021
cb2d2e6
Rename file to match Rails conventions
joemasilotti Dec 19, 2021
2cee520
Destroy business/developer if user is destroyed
joemasilotti Dec 19, 2021
c3a65b0
Redirect back to intent after adding biz profile
joemasilotti Dec 19, 2021
ff0ce68
Space out two groups on details
joemasilotti Dec 19, 2021
7d3352e
First pass at business subscriptions, TODOs noted
joemasilotti Dec 19, 2021
9f22506
Remove duplicate configuration
joemasilotti Dec 19, 2021
15cfc5c
Comment out test scaffolds so CI can pass
joemasilotti Dec 19, 2021
b43e5d3
Document Stripe for dev and start with bin/dev
joemasilotti Dec 19, 2021
06fd7c4
Don't check in development credentials
joemasilotti Dec 19, 2021
4b2694f
Move platform-specific gem to bottom
joemasilotti Dec 19, 2021
f438c13
Update Stripe credentials in production
joemasilotti Dec 19, 2021
6072e69
Don't check in development credentials
joemasilotti Dec 19, 2021
5da9e45
Merge branch 'pay-gem' into business-subscription
joemasilotti Dec 19, 2021
5cd0458
Merge branch 'main' into business-subscription
joemasilotti Dec 19, 2021
9e35cd2
Document signing secret
joemasilotti Dec 19, 2021
283345e
Mock Pay under test, not part of the system
joemasilotti Dec 20, 2021
b7d8c9a
Merge branch 'main' into business-subscription
joemasilotti Dec 20, 2021
f116068
Clean up README
joemasilotti Dec 21, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Mock Pay under test, not part of the system
  • Loading branch information
joemasilotti committed Dec 20, 2021
commit 283345e1431c71139cacd0ff778721e7c482871a
@@ -1,6 +1,8 @@
require "test_helper"

class ColdMessagesTest < ActionDispatch::IntegrationTest
include PayHelper

setup do
@developer = developers(:available)
@business = businesses(:with_conversation)
@@ -22,14 +24,8 @@ class ColdMessagesTest < ActionDispatch::IntegrationTest
end

test "must have an active business subscription" do
# TODO: Mock Stripe or Pay, not part of the system.
mock = Minitest::Mock.new
def mock.url
"checkout.stripe.com"
end

sign_in businesses(:one).user
BusinessSubscriptionCheckout.stub :new, mock do
stub_pay(businesses(:one).user, expected_success_url: new_developer_message_url(@developer)) do
get new_developer_message_path(@developer)
assert_redirected_to "checkout.stripe.com"
end
@@ -1,6 +1,8 @@
require "test_helper"

class MessagesTest < ActionDispatch::IntegrationTest
include PayHelper

setup do
@developer = developers(:with_conversation)
@business = businesses(:with_conversation)
@@ -55,13 +57,7 @@ class MessagesTest < ActionDispatch::IntegrationTest
pay_subscriptions(:business).update!(status: :incomplete)
sign_in @business.user

# TODO: Mock Stripe or Pay, not part of the system.
mock = Minitest::Mock.new
def mock.url
"checkout.stripe.com"
end

BusinessSubscriptionCheckout.stub :new, mock do
stub_pay(@business.user, expected_success_url: new_developer_message_url(@developer)) do
assert_no_difference "Message.count" do
post conversation_messages_path(@conversation), params: message_params
end
@@ -1,11 +1,48 @@
require "test_helper"

class BusinessSubscriptionCheckoutTest < ActiveSupport::TestCase
# TODO: Implement these tests.
# test "sets Stripe as the payment processor"
# test "builds a subscription Stripe Checkout"
# test "redirects to sending a developer message if a developer is given"
# test "redirects to conversations if the user has a business profile"
# test "redirects to adding a business profile if the user doesn't have one"
# test "returns a Stripe Checkout URL"
include PayHelper
include Rails.application.routes.url_helpers

test "creates a Pay::Customer for Stripe for the user" do
user = users(:with_business)
stub_pay(user) do
assert_changes "Pay::Customer.count", 1 do
BusinessSubscriptionCheckout.new(user).url
end
end
assert_equal Pay::Customer.last.owner, user
assert Pay::Customer.last.stripe?
end

test "redirects to sending a developer message if a developer is given" do
user = users(:with_business)
developer = developers(:available)

stub_pay(user, expected_success_url: new_developer_message_url(developer)) do
BusinessSubscriptionCheckout.new(user, developer: developer).url
end
end

test "redirects to conversations if the user has a business profile" do
user = users(:with_business)
stub_pay(user, expected_success_url: conversations_url) do
BusinessSubscriptionCheckout.new(user).url
end
end

test "redirects to adding a business profile if the user doesn't have one" do
user = users(:empty)
stub_pay(user, expected_success_url: new_business_url) do
BusinessSubscriptionCheckout.new(user).url
end
end

test "returns a Stripe Checkout URL" do
user = users(:with_business)
stub_pay(user) do
url = BusinessSubscriptionCheckout.new(user).url
assert_equal url, "checkout.stripe.com"
end
end
end
@@ -0,0 +1,24 @@
module PayHelper
extend ActiveSupport::Concern

included do
def stub_pay(user, expected_success_url: conversations_url)
checkout = Minitest::Mock.new
checkout.expect(:url, "checkout.stripe.com")

payment_processor = Minitest::Mock.new
payment_processor.expect(:checkout, checkout, [{
mode: "subscription",
line_items: "price_FAKE_PRICE_ID_FOR_TESTS",
success_url: expected_success_url
}])

user.stub(:payment_processor, payment_processor) do
yield
end

checkout.verify
payment_processor.verify
end
end
end