Skip to content

test: customer's billing profile id filter to cover the unpinned billing profiles#4506

Open
borosr wants to merge 1 commit into
mainfrom
test/testing-customer-filter-billing-profile-id
Open

test: customer's billing profile id filter to cover the unpinned billing profiles#4506
borosr wants to merge 1 commit into
mainfrom
test/testing-customer-filter-billing-profile-id

Conversation

@borosr

@borosr borosr commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

Summary by CodeRabbit

  • Tests
    • Added new test coverage for filtering customers by billing profile ID, verifying correct results across default profile behavior, non-default profile overrides, pinned overrides to other profiles, and unpinned cases (including null override billing profile IDs).

@borosr borosr requested review from solkimicreb and tothandras June 11, 2026 08:54
@borosr borosr requested a review from a team as a code owner June 11, 2026 08:54
@borosr borosr self-assigned this Jun 11, 2026
@borosr borosr added the release-note/misc Miscellaneous changes label Jun 11, 2026
@coderabbitai

coderabbitai Bot commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 6a70cae5-d56c-407a-9c38-8f1933b99f7b

📥 Commits

Reviewing files that changed from the base of the PR and between 3870828 and db0b09e.

📒 Files selected for processing (1)
  • openmeter/customer/adapter/customer_test.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • openmeter/customer/adapter/customer_test.go

📝 Walkthrough

Walkthrough

The PR adds a new test (TestListCustomersBillingProfileIDFilter) and supporting helpers to verify that the customer adapter's ListCustomers method correctly filters customers by billing profile ID across different override states: explicit default profile, explicit non-default profile, explicit NULL override, and no override.

Changes

Billing Profile Filter Test

Layer / File(s) Summary
BillingProfileID filter test and listing helper
openmeter/customer/adapter/customer_test.go
New test validates customer filtering by billing profile ID with equality predicates across four override resolution states. Helper function listCustomerIDsByBillingProfileID applies the BillingProfileID eq filter and extracts matched customer IDs for assertions. Import block expanded to include billing, datetime, filter, models, pagination, and utility packages.
Test data seeding helpers
openmeter/customer/adapter/customer_test.go
Helper functions seedApp, seedBillingProfile, seedCustomer, and seedBillingCustomerOverride construct billing infrastructure and customer override states. seedBillingProfile creates workflow configs and profiles (optionally marking as namespace default) wired to app IDs. seedBillingCustomerOverride uses nillable billing profile IDs to represent both pinned and unpinned overrides.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • openmeterio/openmeter#4369: This PR likely introduces the underlying billing profile filtering logic in customer.go that this test validates against different override resolution scenarios.

Suggested labels

area/billing

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main change: adding a test for customer billing profile ID filtering, specifically covering the unpinned billing profiles scenario.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch test/testing-customer-filter-billing-profile-id

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
openmeter/customer/adapter/customer_test.go (1)

392-419: ⚡ Quick win

Add one soft-deleted override case to lock in “live override only” behavior.

Nice coverage overall. One edge case still missing: a customer with a soft-deleted override row should behave like unpinned (fallback to namespace default). Adding that subtest would protect the deleted_at IS NULL contract from regressions.

As per coding guidelines, **/*_test.go changes should be comprehensive and cover the changed behavior surface.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@openmeter/customer/adapter/customer_test.go` around lines 392 - 419, Add a
subtest that creates a customer with a billing profile override row that is
soft-deleted (deleted_at set) and assert that when calling
env.listCustomerIDsByBillingProfileID(t, ns, defaultProfileID) that customer is
treated as unpinned (i.e., included with nullOverride/noOverride results) and
when calling with otherProfileID it is excluded; reference the existing test
helpers/vars (env.listCustomerIDsByBillingProfileID, ns, defaultProfileID,
otherProfileID, and the customer ID vars like
pinnedToDefault/pinnedToOther/nullOverride/noOverride) so the new case mirrors
the "soft-deleted override behaves like unpinned" contract.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@openmeter/customer/adapter/customer_test.go`:
- Around line 392-419: Add a subtest that creates a customer with a billing
profile override row that is soft-deleted (deleted_at set) and assert that when
calling env.listCustomerIDsByBillingProfileID(t, ns, defaultProfileID) that
customer is treated as unpinned (i.e., included with nullOverride/noOverride
results) and when calling with otherProfileID it is excluded; reference the
existing test helpers/vars (env.listCustomerIDsByBillingProfileID, ns,
defaultProfileID, otherProfileID, and the customer ID vars like
pinnedToDefault/pinnedToOther/nullOverride/noOverride) so the new case mirrors
the "soft-deleted override behaves like unpinned" contract.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: eb7d25fd-b1eb-442f-8328-8723e84cc7e9

📥 Commits

Reviewing files that changed from the base of the PR and between 0580df9 and 3870828.

📒 Files selected for processing (1)
  • openmeter/customer/adapter/customer_test.go

@borosr borosr force-pushed the test/testing-customer-filter-billing-profile-id branch from 3870828 to db0b09e Compare June 19, 2026 09:51
@greptile-apps

greptile-apps Bot commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR adds an integration test (TestListCustomersBillingProfileIDFilter) that verifies the BillingProfileID filter in ListCustomers correctly applies COALESCE semantics — returning unpinned customers (no override or NULL override) when filtering by the namespace default profile, and returning only explicitly pinned customers when filtering by a non-default profile.

  • Adds four new helper methods on testEnv (seedApp, seedBillingProfile, seedCustomer, seedBillingCustomerOverride) that directly write to the DB to set up all four customer override states.
  • Uses require.ElementsMatch in each sub-test to assert both presence and absence of results, providing comprehensive coverage of the effective-profile fallback logic.

Confidence Score: 5/5

Test-only change that adds no production code; safe to merge.

The change is purely additive test coverage with no modifications to production logic. The four seed helpers write directly to the DB and are self-contained. Both sub-tests use require.ElementsMatch for strict set equality, so the assertions catch both false negatives and unexpected extra results. No issues were found.

No files require special attention.

Important Files Changed

Filename Overview
openmeter/customer/adapter/customer_test.go Adds TestListCustomersBillingProfileIDFilter with four helper seed methods covering all customer override states; tests assert correct COALESCE-style effective-profile filtering for both the default and a non-default profile ID.

Sequence Diagram

%%{init: {'theme': 'neutral'}}%%
sequenceDiagram
    participant T as TestListCustomersBillingProfileIDFilter
    participant E as testEnv (DB)
    participant A as customer.Adapter

    T->>E: seedApp(ns) → appID
    T->>E: "seedBillingProfile(ns, appID, isDefault=true) → defaultProfileID"
    T->>E: "seedBillingProfile(ns, appID, isDefault=false) → otherProfileID"
    T->>E: seedCustomer(ns, "pinned-to-default") → cID1
    T->>E: "seedBillingCustomerOverride(ns, cID1, &defaultProfileID)"
    T->>E: seedCustomer(ns, "pinned-to-other") → cID2
    T->>E: "seedBillingCustomerOverride(ns, cID2, &otherProfileID)"
    T->>E: seedCustomer(ns, "null-override") → cID3
    T->>E: seedBillingCustomerOverride(ns, cID3, nil)
    T->>E: seedCustomer(ns, "no-override") → cID4

    Note over T,A: Sub-test: filter by defaultProfileID
    T->>A: "ListCustomers(BillingProfileID=eq(defaultProfileID))"
    A->>E: SELECT namespace default billing profile id
    A->>E: "WHERE override.billing_profile_id = defaultProfileID OR (no/null override AND EXISTS default profile row)"
    A-->>T: [cID1, cID3, cID4]
    T->>T: ElementsMatch([pinnedToDefault, nullOverride, noOverride])

    Note over T,A: Sub-test: filter by otherProfileID
    T->>A: "ListCustomers(BillingProfileID=eq(otherProfileID))"
    A->>E: SELECT namespace default billing profile id
    A->>E: "WHERE override.billing_profile_id = otherProfileID OR (no/null override AND EXISTS(default=otherProfileID)) false"
    A-->>T: [cID2]
    T->>T: ElementsMatch([pinnedToOther])
Loading
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
sequenceDiagram
    participant T as TestListCustomersBillingProfileIDFilter
    participant E as testEnv (DB)
    participant A as customer.Adapter

    T->>E: seedApp(ns) → appID
    T->>E: "seedBillingProfile(ns, appID, isDefault=true) → defaultProfileID"
    T->>E: "seedBillingProfile(ns, appID, isDefault=false) → otherProfileID"
    T->>E: seedCustomer(ns, "pinned-to-default") → cID1
    T->>E: "seedBillingCustomerOverride(ns, cID1, &defaultProfileID)"
    T->>E: seedCustomer(ns, "pinned-to-other") → cID2
    T->>E: "seedBillingCustomerOverride(ns, cID2, &otherProfileID)"
    T->>E: seedCustomer(ns, "null-override") → cID3
    T->>E: seedBillingCustomerOverride(ns, cID3, nil)
    T->>E: seedCustomer(ns, "no-override") → cID4

    Note over T,A: Sub-test: filter by defaultProfileID
    T->>A: "ListCustomers(BillingProfileID=eq(defaultProfileID))"
    A->>E: SELECT namespace default billing profile id
    A->>E: "WHERE override.billing_profile_id = defaultProfileID OR (no/null override AND EXISTS default profile row)"
    A-->>T: [cID1, cID3, cID4]
    T->>T: ElementsMatch([pinnedToDefault, nullOverride, noOverride])

    Note over T,A: Sub-test: filter by otherProfileID
    T->>A: "ListCustomers(BillingProfileID=eq(otherProfileID))"
    A->>E: SELECT namespace default billing profile id
    A->>E: "WHERE override.billing_profile_id = otherProfileID OR (no/null override AND EXISTS(default=otherProfileID)) false"
    A-->>T: [cID2]
    T->>T: ElementsMatch([pinnedToOther])
Loading

Reviews (1): Last reviewed commit: "test: customer's billing profile id filt..." | Re-trigger Greptile

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release-note/misc Miscellaneous changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant