From a7fed4567e5d45500419eff224d37dd8be9eeb66 Mon Sep 17 00:00:00 2001 From: Scott Clampet Date: Thu, 4 Apr 2024 14:01:57 -0500 Subject: [PATCH 1/3] testLoginSignup tests --- .../PostCampaignCheckoutViewModelTests.swift | 138 +++++++++++++++++- 1 file changed, 135 insertions(+), 3 deletions(-) diff --git a/Library/ViewModels/PostCampaignCheckoutViewModelTests.swift b/Library/ViewModels/PostCampaignCheckoutViewModelTests.swift index 45fd2845a3..09be9a1d34 100644 --- a/Library/ViewModels/PostCampaignCheckoutViewModelTests.swift +++ b/Library/ViewModels/PostCampaignCheckoutViewModelTests.swift @@ -11,13 +11,24 @@ final class PostCampaignCheckoutViewModelTests: TestCase { PostCampaignPaymentAuthorizationData, Never >() - fileprivate let checkoutComplete = TestObserver() - fileprivate let processingViewIsHidden = TestObserver() - fileprivate let validateCheckoutSuccess = TestObserver() + private let checkoutComplete = TestObserver() + private let paymentMethodsViewHidden = TestObserver() + private let processingViewIsHidden = TestObserver() + private let validateCheckoutSuccess = TestObserver() + + private let goToLoginSignup = TestObserver<(LoginIntent, Project, Reward?), Never>() + + private let configurePaymentMethodsViewControllerWithUser = TestObserver() + private let configurePaymentMethodsViewControllerWithProject = TestObserver() + private let configurePaymentMethodsViewControllerWithReward = TestObserver() + private let configurePaymentMethodsViewControllerWithContext = TestObserver() private let configurePledgeViewCTAContainerViewIsLoggedIn = TestObserver() private let configurePledgeViewCTAContainerViewIsEnabled = TestObserver() private let configurePledgeViewCTAContainerViewContext = TestObserver() + + private let configureStripeIntegrationMerchantId = TestObserver() + private let configureStripeIntegrationPublishableKey = TestObserver() override func setUp() { super.setUp() @@ -25,6 +36,19 @@ final class PostCampaignCheckoutViewModelTests: TestCase { self.vm.checkoutComplete.observe(self.checkoutComplete.observer) self.vm.processingViewIsHidden.observe(self.processingViewIsHidden.observer) self.vm.validateCheckoutSuccess.observe(self.validateCheckoutSuccess.observer) + + self.vm.outputs.goToLoginSignup.observe(self.goToLoginSignup.observer) + + self.vm.outputs.paymentMethodsViewHidden.observe(self.paymentMethodsViewHidden.observer) + + self.vm.outputs.configurePaymentMethodsViewControllerWithValue.map { $0.0 } + .observe(self.configurePaymentMethodsViewControllerWithUser.observer) + self.vm.outputs.configurePaymentMethodsViewControllerWithValue.map { $0.1 } + .observe(self.configurePaymentMethodsViewControllerWithProject.observer) + self.vm.outputs.configurePaymentMethodsViewControllerWithValue.map { $0.2 } + .observe(self.configurePaymentMethodsViewControllerWithReward.observer) + self.vm.outputs.configurePaymentMethodsViewControllerWithValue.map { $0.3 } + .observe(self.configurePaymentMethodsViewControllerWithContext.observer) self.vm.outputs.configurePledgeViewCTAContainerView.map { $0.0 } .observe(self.configurePledgeViewCTAContainerViewIsLoggedIn.observer) @@ -32,7 +56,115 @@ final class PostCampaignCheckoutViewModelTests: TestCase { .observe(self.configurePledgeViewCTAContainerViewIsEnabled.observer) self.vm.outputs.configurePledgeViewCTAContainerView.map { $0.2 } .observe(self.configurePledgeViewCTAContainerViewContext.observer) + + self.vm.outputs.configureStripeIntegration.map(first) + .observe(self.configureStripeIntegrationMerchantId.observer) + self.vm.outputs.configureStripeIntegration.map(second) + .observe(self.configureStripeIntegrationPublishableKey.observer) } + + func testLoginSignup_NoCardSelected_CTADisabled() { + let project = Project.template + let reward = Reward.template + let user = User.template + + withEnvironment(currentUser: nil) { + let data = PostCampaignCheckoutData( + project: project, + rewards: [reward], + selectedQuantities: [:], + bonusAmount: 0, + total: 5, + shipping: nil, + refTag: nil, + context: .latePledge, + checkoutId: "0" + ) + + self.vm.inputs.configure(with: data) + self.vm.inputs.viewDidLoad() + + self.configurePaymentMethodsViewControllerWithUser.assertDidNotEmitValue() + self.configurePaymentMethodsViewControllerWithProject.assertDidNotEmitValue() + self.configurePaymentMethodsViewControllerWithReward.assertDidNotEmitValue() + self.configurePaymentMethodsViewControllerWithContext.assertDidNotEmitValue() + + self.configurePledgeViewCTAContainerViewIsLoggedIn.assertValues([false]) + self.configurePledgeViewCTAContainerViewIsEnabled.assertValues([false]) + self.configurePledgeViewCTAContainerViewContext.assertValues([.latePledge]) + + self.paymentMethodsViewHidden.assertValues([true]) + + withEnvironment(currentUser: user) { + self.vm.inputs.userSessionStarted() + + self.configurePaymentMethodsViewControllerWithUser.assertValues([user]) + self.configurePaymentMethodsViewControllerWithProject.assertValues([project]) + self.configurePaymentMethodsViewControllerWithReward.assertValues([reward]) + self.configurePaymentMethodsViewControllerWithContext.assertValues([.latePledge]) + + self.configurePledgeViewCTAContainerViewIsLoggedIn.assertValues([false, true]) + self.configurePledgeViewCTAContainerViewIsEnabled.assertValues([false, false]) + self.configurePledgeViewCTAContainerViewContext.assertValues([.latePledge, .latePledge]) + + self.paymentMethodsViewHidden.assertValues([true, false]) + } + } + } + + func testLoginSignup_CardSelected_CTAEnabled() { + let project = Project.template + let reward = Reward.template + let user = User.template + + withEnvironment(currentUser: nil) { + let data = PostCampaignCheckoutData( + project: project, + rewards: [reward], + selectedQuantities: [:], + bonusAmount: 0, + total: 5, + shipping: nil, + refTag: nil, + context: .latePledge, + checkoutId: "0" + ) + + self.vm.inputs.configure(with: data) + self.vm.inputs.viewDidLoad() + + self.configurePaymentMethodsViewControllerWithUser.assertDidNotEmitValue() + self.configurePaymentMethodsViewControllerWithProject.assertDidNotEmitValue() + self.configurePaymentMethodsViewControllerWithReward.assertDidNotEmitValue() + self.configurePaymentMethodsViewControllerWithContext.assertDidNotEmitValue() + + self.configurePledgeViewCTAContainerViewIsLoggedIn.assertValues([false]) + self.configurePledgeViewCTAContainerViewIsEnabled.assertValues([false]) + self.configurePledgeViewCTAContainerViewContext.assertValues([.latePledge]) + + self.paymentMethodsViewHidden.assertValues([true]) + + withEnvironment(currentUser: user) { + self.vm.inputs.userSessionStarted() + + self.configurePaymentMethodsViewControllerWithUser.assertValues([user]) + self.configurePaymentMethodsViewControllerWithProject.assertValues([project]) + self.configurePaymentMethodsViewControllerWithReward.assertValues([reward]) + self.configurePaymentMethodsViewControllerWithContext.assertValues([.latePledge]) + + let paymentSource = PaymentSourceSelected.paymentIntentClientSecret("123") + self.vm.inputs + .creditCardSelected(source: paymentSource, paymentMethodId: "123", isNewPaymentMethod: true) + + self.configurePledgeViewCTAContainerViewIsLoggedIn.assertValues([false, true, true]) + self.configurePledgeViewCTAContainerViewIsEnabled.assertValues([false, false, true]) + self.configurePledgeViewCTAContainerViewContext.assertValues([.latePledge, .latePledge, .latePledge]) + + self.paymentMethodsViewHidden.assertValues([true, false]) + } + } + } + func testApplePayAuthorization_noReward_isCorrect() { let project = Project.cosmicSurgery From d5783aa2905df7a709d434327c69bfbabc999277 Mon Sep 17 00:00:00 2001 From: Scott Clampet Date: Thu, 4 Apr 2024 14:08:39 -0500 Subject: [PATCH 2/3] testStripeConfiguration tests --- .../PostCampaignCheckoutViewModelTests.swift | 88 ++++++++++++++++--- 1 file changed, 75 insertions(+), 13 deletions(-) diff --git a/Library/ViewModels/PostCampaignCheckoutViewModelTests.swift b/Library/ViewModels/PostCampaignCheckoutViewModelTests.swift index 09be9a1d34..bc77650e1d 100644 --- a/Library/ViewModels/PostCampaignCheckoutViewModelTests.swift +++ b/Library/ViewModels/PostCampaignCheckoutViewModelTests.swift @@ -15,9 +15,9 @@ final class PostCampaignCheckoutViewModelTests: TestCase { private let paymentMethodsViewHidden = TestObserver() private let processingViewIsHidden = TestObserver() private let validateCheckoutSuccess = TestObserver() - + private let goToLoginSignup = TestObserver<(LoginIntent, Project, Reward?), Never>() - + private let configurePaymentMethodsViewControllerWithUser = TestObserver() private let configurePaymentMethodsViewControllerWithProject = TestObserver() private let configurePaymentMethodsViewControllerWithReward = TestObserver() @@ -26,7 +26,7 @@ final class PostCampaignCheckoutViewModelTests: TestCase { private let configurePledgeViewCTAContainerViewIsLoggedIn = TestObserver() private let configurePledgeViewCTAContainerViewIsEnabled = TestObserver() private let configurePledgeViewCTAContainerViewContext = TestObserver() - + private let configureStripeIntegrationMerchantId = TestObserver() private let configureStripeIntegrationPublishableKey = TestObserver() @@ -36,11 +36,11 @@ final class PostCampaignCheckoutViewModelTests: TestCase { self.vm.checkoutComplete.observe(self.checkoutComplete.observer) self.vm.processingViewIsHidden.observe(self.processingViewIsHidden.observer) self.vm.validateCheckoutSuccess.observe(self.validateCheckoutSuccess.observer) - + self.vm.outputs.goToLoginSignup.observe(self.goToLoginSignup.observer) - + self.vm.outputs.paymentMethodsViewHidden.observe(self.paymentMethodsViewHidden.observer) - + self.vm.outputs.configurePaymentMethodsViewControllerWithValue.map { $0.0 } .observe(self.configurePaymentMethodsViewControllerWithUser.observer) self.vm.outputs.configurePaymentMethodsViewControllerWithValue.map { $0.1 } @@ -56,13 +56,13 @@ final class PostCampaignCheckoutViewModelTests: TestCase { .observe(self.configurePledgeViewCTAContainerViewIsEnabled.observer) self.vm.outputs.configurePledgeViewCTAContainerView.map { $0.2 } .observe(self.configurePledgeViewCTAContainerViewContext.observer) - + self.vm.outputs.configureStripeIntegration.map(first) .observe(self.configureStripeIntegrationMerchantId.observer) self.vm.outputs.configureStripeIntegration.map(second) .observe(self.configureStripeIntegrationPublishableKey.observer) } - + func testLoginSignup_NoCardSelected_CTADisabled() { let project = Project.template let reward = Reward.template @@ -70,8 +70,9 @@ final class PostCampaignCheckoutViewModelTests: TestCase { withEnvironment(currentUser: nil) { let data = PostCampaignCheckoutData( - project: project, - rewards: [reward], + project: .template, + baseReward: .template, + rewards: [.template], selectedQuantities: [:], bonusAmount: 0, total: 5, @@ -111,7 +112,7 @@ final class PostCampaignCheckoutViewModelTests: TestCase { } } } - + func testLoginSignup_CardSelected_CTAEnabled() { let project = Project.template let reward = Reward.template @@ -119,7 +120,8 @@ final class PostCampaignCheckoutViewModelTests: TestCase { withEnvironment(currentUser: nil) { let data = PostCampaignCheckoutData( - project: project, + project: .template, + baseReward: .template, rewards: [reward], selectedQuantities: [:], bonusAmount: 0, @@ -151,7 +153,7 @@ final class PostCampaignCheckoutViewModelTests: TestCase { self.configurePaymentMethodsViewControllerWithProject.assertValues([project]) self.configurePaymentMethodsViewControllerWithReward.assertValues([reward]) self.configurePaymentMethodsViewControllerWithContext.assertValues([.latePledge]) - + let paymentSource = PaymentSourceSelected.paymentIntentClientSecret("123") self.vm.inputs .creditCardSelected(source: paymentSource, paymentMethodId: "123", isNewPaymentMethod: true) @@ -165,6 +167,66 @@ final class PostCampaignCheckoutViewModelTests: TestCase { } } + func testStripeConfiguration_StagingEnvironment() { + let mockService = MockService(serverConfig: ServerConfig.staging) + + withEnvironment(apiService: mockService) { + self.configureStripeIntegrationMerchantId.assertDidNotEmitValue() + self.configureStripeIntegrationPublishableKey.assertDidNotEmitValue() + + let project = Project.template + let reward = Reward.template + + let data = PostCampaignCheckoutData( + project: project, + baseReward: reward, + rewards: [reward], + selectedQuantities: [:], + bonusAmount: 0, + total: 5, + shipping: nil, + refTag: nil, + context: .pledge, + checkoutId: "0" + ) + + self.vm.inputs.configure(with: data) + self.vm.inputs.viewDidLoad() + + self.configureStripeIntegrationMerchantId.assertValues([Secrets.ApplePay.merchantIdentifier]) + self.configureStripeIntegrationPublishableKey.assertValues([Secrets.StripePublishableKey.staging]) + } + } + + func testStripeConfiguration_ProductionEnvironment() { + let mockService = MockService(serverConfig: ServerConfig.production) + + withEnvironment(apiService: mockService) { + self.configureStripeIntegrationMerchantId.assertDidNotEmitValue() + + let project = Project.template + let reward = Reward.template + + let data = PostCampaignCheckoutData( + project: project, + baseReward: reward, + rewards: [reward], + selectedQuantities: [:], + bonusAmount: 0, + total: 5, + shipping: nil, + refTag: nil, + context: .pledge, + checkoutId: "0" + ) + + self.vm.inputs.configure(with: data) + self.vm.inputs.viewDidLoad() + + self.configureStripeIntegrationMerchantId.assertValues([Secrets.ApplePay.merchantIdentifier]) + self.configureStripeIntegrationPublishableKey.assertValues([Secrets.StripePublishableKey.production]) + } + } func testApplePayAuthorization_noReward_isCorrect() { let project = Project.cosmicSurgery From beeabfb06b4e6df805a759f468c5850681d39482 Mon Sep 17 00:00:00 2001 From: Scott Clampet Date: Thu, 4 Apr 2024 14:15:18 -0500 Subject: [PATCH 3/3] showWebHelp tests --- .../PostCampaignCheckoutViewModelTests.swift | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/Library/ViewModels/PostCampaignCheckoutViewModelTests.swift b/Library/ViewModels/PostCampaignCheckoutViewModelTests.swift index bc77650e1d..31a6617ebe 100644 --- a/Library/ViewModels/PostCampaignCheckoutViewModelTests.swift +++ b/Library/ViewModels/PostCampaignCheckoutViewModelTests.swift @@ -30,6 +30,8 @@ final class PostCampaignCheckoutViewModelTests: TestCase { private let configureStripeIntegrationMerchantId = TestObserver() private let configureStripeIntegrationPublishableKey = TestObserver() + private let showWebHelp = TestObserver() + override func setUp() { super.setUp() self.vm.goToApplePayPaymentAuthorization.observe(self.goToApplePayPaymentAuthorization.observer) @@ -61,8 +63,12 @@ final class PostCampaignCheckoutViewModelTests: TestCase { .observe(self.configureStripeIntegrationMerchantId.observer) self.vm.outputs.configureStripeIntegration.map(second) .observe(self.configureStripeIntegrationPublishableKey.observer) + + self.vm.outputs.showWebHelp.observe(self.showWebHelp.observer) } + // MARK: - Login/Signup + func testLoginSignup_NoCardSelected_CTADisabled() { let project = Project.template let reward = Reward.template @@ -167,6 +173,26 @@ final class PostCampaignCheckoutViewModelTests: TestCase { } } + // MARK: - Web Help + + func testShowWebHelp() { + self.vm.inputs.viewDidLoad() + + self.vm.inputs.termsOfUseTapped(with: .terms) + + self.showWebHelp.assertValues([HelpType.terms]) + } + + func testShowWebHelpLearnMore() { + self.vm.inputs.viewDidLoad() + + self.vm.inputs.pledgeDisclaimerViewDidTapLearnMore() + + self.showWebHelp.assertValues([HelpType.trust]) + } + + // MARK: - Stripe + func testStripeConfiguration_StagingEnvironment() { let mockService = MockService(serverConfig: ServerConfig.staging) @@ -228,6 +254,8 @@ final class PostCampaignCheckoutViewModelTests: TestCase { } } + // MARK: - Apple Pay + func testApplePayAuthorization_noReward_isCorrect() { let project = Project.cosmicSurgery let reward = Reward.noReward |> Reward.lens.minimum .~ 5