@@ -538,6 +538,52 @@ defmodule Core.Services.PaymentsTest do
538538 end
539539 end
540540
541+ describe "#has_feature?/2" do
542+ test "if a user's plan has a feature, then it returns true" do
543+ account = insert ( :account )
544+ insert ( :platform_subscription , account: account , plan: build ( :platform_plan , features: % { user_management: true } ) )
545+ user = insert ( :user , account: account )
546+ assert Payments . has_feature? ( user , :user_management )
547+ end
548+
549+ test "if a user's account is grandfathered, then it returns true" do
550+ account = insert ( :account , grandfathered_until: Timex . now ( ) |> Timex . shift ( days: 1 ) )
551+ insert ( :platform_subscription , account: account , plan: build ( :platform_plan , features: % { user_management: false } ) )
552+ user = insert ( :user , account: account )
553+ assert Payments . has_feature? ( user , :user_management )
554+
555+ account = insert ( :account , grandfathered_until: Timex . now ( ) |> Timex . shift ( days: - 1 ) )
556+ insert ( :platform_subscription , account: account , plan: build ( :platform_plan , features: % { user_management: false } ) )
557+ user = insert ( :user , account: account )
558+ refute Payments . has_feature? ( user , :user_management )
559+ end
560+
561+ test "if a user's account is delinquent then it returns false" do
562+ account = insert ( :account , delinquent_at: Timex . now ( ) |> Timex . shift ( days: - 100 ) )
563+ insert ( :platform_subscription , account: account , plan: build ( :platform_plan , features: % { user_management: true } ) )
564+ user = insert ( :user , account: account )
565+ refute Payments . has_feature? ( user , :user_management )
566+
567+ account = insert ( :account , delinquent_at: Timex . now ( ) )
568+ insert ( :platform_subscription , account: account , plan: build ( :platform_plan , features: % { user_management: true } ) )
569+ user = insert ( :user , account: account )
570+ assert Payments . has_feature? ( user , :user_management )
571+ end
572+
573+ test "if a user's account has no plan it returns false" do
574+ account = insert ( :account )
575+ user = insert ( :user , account: account )
576+ refute Payments . has_feature? ( user , :user_management )
577+ end
578+
579+ test "if a user's account is doesn't have the feature, then it returns false" do
580+ account = insert ( :account )
581+ insert ( :platform_subscription , account: account , plan: build ( :platform_plan , features: % { user_management: false } ) )
582+ user = insert ( :user , account: account )
583+ refute Payments . has_feature? ( user , :user_management )
584+ end
585+ end
586+
541587 describe "#update_plan/3" do
542588 test "Users can change plans" do
543589 expect ( Stripe.Subscription , :update , fn
0 commit comments