Skip to content
Open
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: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,8 @@ group :test do
# HTML testing (invoice rendering)
gem "rspec-snapshot", "~> 2.0"
gem "htmlbeautifier", "~> 1.4"

gem "test-prof", "~> 1.0"
end

group :development do
Expand Down
3 changes: 3 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1004,6 +1004,8 @@ GEM
temple (0.10.4)
terminal-table (4.0.0)
unicode-display_width (>= 1.1.1, < 4)
test-prof (1.6.3)
logger
thor (1.5.0)
throttling (0.4.1)
logger
Expand Down Expand Up @@ -1181,6 +1183,7 @@ DEPENDENCIES
stripe
strong_migrations
super_diff (~> 0.19.0)
test-prof (~> 1.0)
throttling
timecop
tzinfo-data
Expand Down
19 changes: 11 additions & 8 deletions spec/services/lifetime_usages/calculate_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,6 @@
subject(:service) { described_class.new(lifetime_usage: lifetime_usage) }

let(:lifetime_usage) { create(:lifetime_usage, organization:, subscription:, recalculate_current_usage:, recalculate_invoiced_usage:) }
let(:recalculate_current_usage) { false }
let(:recalculate_invoiced_usage) { false }
let(:subscription) { create(:subscription, customer:, subscription_at:) }
let(:organization) { customer.organization }
let(:customer) { create(:customer) }

let(:billable_metric) { create(:billable_metric, organization:, aggregation_type: "count_agg") }
let(:charge) { create(:standard_charge, plan: subscription.plan, billable_metric:, properties: {amount: "10"}) }
let(:timestamp) { Time.current }
let(:subscription_at) { timestamp - 6.months }
Expand All @@ -28,7 +21,6 @@
precise_coupons_amount_cents: 50
)
end

let(:events) do
create_list(
:event,
Expand All @@ -40,6 +32,17 @@
timestamp:
)
end
let(:recalculate_current_usage) { false }
let(:recalculate_invoiced_usage) { false }
let(:subscription) { create(:subscription, customer:, subscription_at:) }

let_it_be(:organization) { create_default(:organization) }
let_it_be(:billable_metric) { create(:billable_metric, organization:, aggregation_type: "count_agg") }
let_it_be(:customer) { create_default(:customer) }

before_all do
create_default(:plan)
end

describe "#recalculate_invoiced_usage" do
let(:recalculate_invoiced_usage) { true }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
let(:lifetime_usage) { create(:lifetime_usage, subscription:, recalculate_current_usage: true, recalculate_invoiced_usage: true, current_usage_amount_cents:) }
let(:current_usage_amount_cents) { 0 }
let(:subscription) { create(:subscription, customer_id: customer.id) }
let(:organization) { subscription.organization }
let(:customer) { create(:customer) }
let(:organization) { create_default(:organization) }
let(:customer) { create_default(:customer) }
let(:billable_metric) { create_default(:billable_metric, aggregation_type: "count_agg") }

let(:billable_metric) { create(:billable_metric, aggregation_type: "count_agg") }
let(:charge) { create(:standard_charge, plan: subscription.plan, billable_metric:, properties: {amount: "10"}) }
let(:timestamp) { Time.current }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@
subject(:lifetime_usage_result) { described_class.call(lifetime_usage:) }

let(:lifetime_usage) { create(:lifetime_usage, subscription:, organization:, current_usage_amount_cents:) }
let(:current_usage_amount_cents) { 0 }

let(:plan) { create(:plan) }
let(:organization) { plan.organization }

let(:customer) { create(:customer, organization:) }
let(:subscription) { create(:subscription, plan:, customer:) }
let(:current_usage_amount_cents) { 0 }

let_it_be(:organization) { create_default(:organization) }

it "computes the amounts" do
expect(lifetime_usage_result.last_threshold_amount_cents).to be_nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@
subject(:flag_service) { described_class.new(invoice:) }

let(:invoice) { create(:invoice, :subscription, subscriptions:, organization: customer.organization) }
let(:subscriptions) { create_list(:subscription, 1, plan:) }
let(:usage_threshold) { create(:usage_threshold, plan:) }
let(:lifetime_usage) { create(:lifetime_usage, subscription: invoice.subscriptions.first) }

let(:customer) { create(:customer) }
let(:plan) { create(:plan, organization: customer.organization) }
let(:subscriptions) { create_list(:subscription, 1, plan:) }
before_all do
create_default(:organization)
end

let(:usage_threshold) { create(:usage_threshold, plan:) }
let_it_be(:customer) { create_default(:customer) }
let_it_be(:plan) { create_default(:plan, organization: customer.organization) }

before do
usage_threshold
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
RSpec.describe LifetimeUsages::FlagRefreshFromPlanUpdateService do
subject { described_class.call(plan:) }

let(:plan) { create(:plan) }
before_all do
create_default(:organization)
end

let_it_be(:plan) { create(:plan) }
let(:result) { subject }

describe "#call" do
Expand Down
6 changes: 6 additions & 0 deletions spec/services/lifetime_usages/update_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
RSpec.describe LifetimeUsages::UpdateService do
subject(:update_service) { described_class.new(lifetime_usage:, params:) }

before_all do
create_default(:organization)
create_default(:customer)
create_default(:plan)
end

let(:lifetime_usage) { create(:lifetime_usage) }
let(:params) do
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,18 @@
subject(:service) { described_class.new(lifetime_usage:, progressive_billed_amount:) }

let(:lifetime_usage) { create(:lifetime_usage, subscription:, historical_usage_amount_cents:, recalculate_current_usage:, recalculate_invoiced_usage:) }
let(:historical_usage_amount_cents) { 0 }
let(:progressive_billed_amount) { 0 }
let(:recalculate_current_usage) { true }
let(:recalculate_invoiced_usage) { true }
let(:subscription) { create(:subscription, customer_id: customer.id) }
let(:organization) { subscription.organization }
let(:customer) { create(:customer) }
let(:historical_usage_amount_cents) { 0 }

let_it_be(:organization) { create_default(:organization) }
let_it_be(:customer) { create_default(:customer) }

before_all do
create_default(:plan)
end

def create_thresholds(subscription, amounts:, attach_to:, recurring: nil)
model = if attach_to == :subscription
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@
subject(:result) { described_class.call(lifetime_usage:) }

let(:lifetime_usage) { create(:lifetime_usage, subscription:, organization:, current_usage_amount_cents:) }
let(:current_usage_amount_cents) { 0 }

let(:plan) { create(:plan) }
let(:organization) { plan.organization }

let(:customer) { create(:customer, organization:) }
let(:subscription) { create(:subscription, plan:, customer:) }
let(:current_usage_amount_cents) { 0 }

let_it_be(:organization) { create_default(:organization) }

def create_threshold(attached_to:, **factory_args)
if attached_to == :subscription
Expand Down
3 changes: 2 additions & 1 deletion spec/services/memberships/create_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
subject(:create_service) { described_class.new(user:, organization:) }

let(:user) { create(:user) }
let(:organization) { create(:organization) }

let_it_be(:organization) { create(:organization) }

describe "#call" do
it "creates a membership" do
Expand Down
8 changes: 4 additions & 4 deletions spec/services/memberships/revoke_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@

include_context "with mocked security logger"

let(:organization) { create(:organization) }
let_it_be(:organization) { create(:organization) }
let(:admin_role) { create(:role, :admin) }
let(:other_membership) { create(:membership, user:, organization:) }
let(:finance_role) { create(:role, :finance) }

let(:user) { create(:user) }
let(:membership) { create(:membership, organization:) }
let(:other_membership) { create(:membership, user:, organization:) }
let_it_be(:user) { create(:user) }
let_it_be(:membership) { create(:membership, organization:) }

describe "#call" do
context "when revoking my own membership" do
Expand Down
8 changes: 4 additions & 4 deletions spec/services/memberships/update_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
RSpec.describe Memberships::UpdateService do
include_context "with mocked security logger"

let(:membership) { create(:membership) }
let(:organization) { membership.organization }
let(:acting_user) { create(:membership, organization:).user }
let_it_be(:organization) { create_default(:organization) }
let_it_be(:membership) { create(:membership) }
let_it_be(:acting_user) { create(:membership, organization:).user }
let(:admin_role) { create(:role, :admin) }
let!(:manager_role) { create(:role, :manager) }
let(:params) { {roles: %w[manager]} }
Expand All @@ -33,7 +33,7 @@
end

context "when admin grants admin role to another member" do
let(:acting_membership) { create(:membership, organization:) }
let_it_be(:acting_membership) { create(:membership, organization:) }
let(:acting_user) { acting_membership.user }
let(:params) { {roles: %w[admin]} }

Expand Down
7 changes: 6 additions & 1 deletion spec/services/metadata/delete_item_key_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@
RSpec.describe Metadata::DeleteItemKeyService do
subject(:service) { described_class.new(item:, key:) }

let(:organization) { create(:organization) }
let_it_be(:organization) { create_default(:organization) }

before_all do
create_default(:customer)
end

let(:owner) { create(:credit_note, organization:) }
let(:item) { create(:item_metadata, owner:, organization:, value:) }
let(:value) { {"foo" => "bar", "baz" => "qux"} }
Expand Down
7 changes: 6 additions & 1 deletion spec/services/metadata/update_item_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@
RSpec.describe Metadata::UpdateItemService do
subject(:service) { described_class.new(owner:, value:, partial:) }

let(:organization) { create(:organization) }
let_it_be(:organization) { create_default(:organization) }

before_all do
create_default(:customer)
end

let(:owner) { create(:credit_note, organization:) }
let(:value) { nil }
let(:partial) { false }
Expand Down
7 changes: 6 additions & 1 deletion spec/services/middlewares/activity_log_middleware_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,15 @@ def call
attr_reader :subscription
end
end

let(:subscription) { create(:subscription, name: "My Subscription") }
let(:activity_loggable_after_commit) { false }

before_all do
create_default(:organization)
create_default(:customer)
create_default(:plan)
end

def test_service_with_activity_loggable(after_commit:, action_match_updated: false)
expect(service_class).to use_middleware(described_class)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
RSpec.describe MultiCustomerConnections::BackfillConnectionsService do
subject(:result) { described_class.call(organization:, dry_run:, batch_size: 1000) }

let(:organization) { create(:organization) }
let(:customer) { create(:customer, organization:) }
let_it_be(:organization) { create(:organization) }
let_it_be(:customer) { create(:customer, organization:) }
let(:dry_run) { false }

describe "#call" do
Expand Down
8 changes: 7 additions & 1 deletion spec/services/order_forms/create_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,13 @@
RSpec.describe OrderForms::CreateService do
subject(:create_service) { described_class.new(quote_version:) }

let(:organization) { create(:organization, feature_flags: ["order_forms"]) }
let_it_be(:organization) { create_default(:organization, feature_flags: ["order_forms"]) }

before_all do
create_default(:customer)
create_default(:plan)
end

let(:quote) { create(:quote, organization:) }
let(:quote_version) { create(:quote_version, :approved, quote:, organization:) }

Expand Down
5 changes: 3 additions & 2 deletions spec/services/order_forms/expire_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
RSpec.describe OrderForms::ExpireService do
subject(:service) { described_class.new(order_form:) }

let(:organization) { create(:organization, feature_flags: ["order_forms"]) }
let(:customer) { create(:customer, organization:) }
let_it_be(:organization) { create(:organization, feature_flags: ["order_forms"]) }
let_it_be(:customer) { create(:customer, organization:) }
let(:quote) { create(:quote, organization:, customer:) }
let(:quote_version) { create(:quote_version, :approved, organization:, quote:) }
let(:order_form) { create(:order_form, :expired_yesterday, customer:, organization:, quote_version:) }
Expand All @@ -23,6 +23,7 @@
end

context "when the order_forms feature flag is disabled", :premium do
let(:customer) { create(:customer, organization:) }
let(:organization) { create(:organization) }

it "returns a forbidden failure" do
Expand Down
5 changes: 3 additions & 2 deletions spec/services/order_forms/mark_as_signed_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
RSpec.describe OrderForms::MarkAsSignedService do
subject(:service) { described_class.new(order_form:, signed_document:, execution_mode:, execute_at:) }

let(:organization) { create(:organization, feature_flags: ["order_forms"]) }
let(:customer) { create(:customer, organization:) }
let_it_be(:organization) { create(:organization, feature_flags: ["order_forms"]) }
let_it_be(:customer) { create(:customer, organization:) }
let(:quote) { create(:quote, customer:, organization:, order_type: :subscription_creation) }
let(:order_form) { create(:order_form, customer:, organization:, quote:) }
let(:signed_document) { nil }
Expand Down Expand Up @@ -38,6 +38,7 @@
end

context "when the order_forms feature flag is disabled" do
let(:customer) { create(:customer, organization:) }
let(:organization) { create(:organization) }

it "returns a forbidden failure" do
Expand Down
4 changes: 2 additions & 2 deletions spec/services/order_forms/void_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
RSpec.describe OrderForms::VoidService do
subject(:service) { described_class.new(order_form:) }

let(:organization) { create(:organization, feature_flags: ["order_forms"]) }
let(:customer) { create(:customer, organization:) }
let_it_be(:organization) { create(:organization, feature_flags: ["order_forms"]) }
let_it_be(:customer) { create(:customer, organization:) }
let(:quote) { create(:quote, organization:, customer:) }
let(:quote_version) { create(:quote_version, :approved, organization:, quote:) }
let(:order_form) { create(:order_form, customer:, organization:, quote_version:) }
Expand Down
10 changes: 8 additions & 2 deletions spec/services/orders/execute_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,13 @@
RSpec.describe Orders::ExecuteService do
subject(:execute_service) { described_class.new(order:) }

let(:organization) { create(:organization, feature_flags: ["order_forms"]) }
let(:customer) { create(:customer, organization:) }
let_it_be(:organization) { create_default(:organization, feature_flags: ["order_forms"]) }
let_it_be(:customer) { create(:customer, organization:) }

before_all do
create_default(:plan)
end

let(:quote) { create(:quote, organization:, customer:, order_type:) }
let(:quote_version) { create(:quote_version, :approved, quote:, organization:) }
let(:order_form) { create(:order_form, :signed, organization:, customer:, quote_version:) }
Expand Down Expand Up @@ -38,6 +43,7 @@
end

context "when the order_forms feature flag is disabled" do
let(:customer) { create(:customer, organization:) }
let(:organization) { create(:organization) }

it "returns a forbidden failure" do
Expand Down
8 changes: 4 additions & 4 deletions spec/services/orders/one_off/execute_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
RSpec.describe Orders::OneOff::ExecuteService do
subject(:execute_service) { described_class.new(order:) }

let(:organization) { create(:organization) }
let(:billing_entity) { create(:billing_entity, organization:) }
let(:customer) { create(:customer, organization:, billing_entity:, currency: "EUR") }
let(:add_on) { create(:add_on, organization:, amount_cents: 10_000) }
let_it_be(:organization) { create(:organization) }
let_it_be(:billing_entity) { create(:billing_entity, organization:) }
let_it_be(:customer) { create(:customer, organization:, billing_entity:, currency: "EUR") }
let_it_be(:add_on) { create(:add_on, organization:, amount_cents: 10_000) }
let(:add_on_item) do
{
"id" => add_on.id,
Expand Down
Loading
Loading