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

add cd feature to pro plans #1255

Merged
merged 2 commits into from
Sep 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/core/lib/core/schema/platform_plan.ex
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ defmodule Core.Schema.PlatformPlan do
field :external_id, :string

embeds_one :features, Features, on_replace: :update do
boolean_fields [:vpn, :user_management, :audit, :multi_cluster, :database_management]
boolean_fields [:vpn, :user_management, :audit, :multi_cluster, :database_management, :cd]
end

embeds_many :line_items, LineItem, on_replace: :delete
Expand Down
9 changes: 9 additions & 0 deletions apps/core/lib/core/services/payments.ex
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,15 @@ defmodule Core.Services.Payments do
|> execute(extract: :finalized)
end

def backfill_plan_features() do
Enum.each(~w(monthly yearly), fn period ->
with %PlatformPlan{} = p <- Core.Repo.get_by(PlatformPlan, name: "Pro", visible: true, period: period) do
PlatformPlan.changeset(p, %{features: Enum.into(PlatformPlan.features(), %{}, & {&1, true})})
|> Core.Repo.update()
end
end)
end

def setup_plans() do
{:ok, _} = create_default_plan(:monthly)
{:ok, _} = create_default_plan(:yearly)
Expand Down
5 changes: 5 additions & 0 deletions apps/core/priv/repo/seeds/015_backfill_plans.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import Botanist

seed do
Core.Services.Payments.backfill_plan_features()
end
12 changes: 12 additions & 0 deletions apps/core/test/services/payments_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,18 @@ defmodule Core.Services.PaymentsTest do
end
end

describe "#backfill_plan_features/0" do
test "it will backfill features for pro plans" do
plan = insert(:platform_plan, name: "Pro", visible: true, features: %{audits: true})

Payments.backfill_plan_features()

plan = refetch(plan)
for f <- Core.Schema.PlatformPlan.features(),
do: assert Map.get(plan.features, f)
end
end

describe "#update_plan_attributes" do
test "publishers can update SLAs for a plan" do
%{publisher: pub} = repository = insert(:repository, publisher: build(:publisher, billing_account_id: "account_id"))
Expand Down
1 change: 1 addition & 0 deletions apps/graphql/lib/graphql/schema/payments.ex
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ defmodule GraphQl.Schema.Payments do
field :user_management, :boolean
field :audit, :boolean
field :database_management, :boolean
field :cd, :boolean
end

object :service_level do
Expand Down
1 change: 1 addition & 0 deletions schema/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,7 @@ type PlanFeatures {
userManagement: Boolean
audit: Boolean
databaseManagement: Boolean
cd: Boolean
}

type PlatformSubscriptionLineItems {
Expand Down
1 change: 1 addition & 0 deletions www/src/generated/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2030,6 +2030,7 @@ export type PlanFeatureAttributes = {
export type PlanFeatures = {
__typename?: 'PlanFeatures';
audit?: Maybe<Scalars['Boolean']['output']>;
cd?: Maybe<Scalars['Boolean']['output']>;
databaseManagement?: Maybe<Scalars['Boolean']['output']>;
userManagement?: Maybe<Scalars['Boolean']['output']>;
vpn?: Maybe<Scalars['Boolean']['output']>;
Expand Down