-
Notifications
You must be signed in to change notification settings - Fork 516
Fix null-unsafe payments config validation for partial overrides #1363
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
Merged
+101
−5
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
4df268d
Make payments schema validator handle partial overrides
mantrakp04 2a95ebc
fix: guard null payments config entries
mantrakp04 03347ac
refactor: simplify product and product line access in branchPaymentsS…
mantrakp04 2782654
refactor: remove old schema tests and integrate them into schema defi…
mantrakp04 2bb0d32
Merge branch 'dev' into fix/sentry-config-validation-issue
mantrakp04 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| import { describe, expect, it } from "vitest"; | ||
| import { branchPaymentsSchema } from "./schema"; | ||
|
|
||
| describe("branchPaymentsSchema", () => { | ||
| it("accepts partial payments config without products", async () => { | ||
| await expect(branchPaymentsSchema.validate({ | ||
| blockNewPurchases: true, | ||
| })).resolves.toMatchObject({ | ||
| blockNewPurchases: true, | ||
| }); | ||
| }); | ||
|
|
||
| it("accepts product lines without products", async () => { | ||
| await expect(branchPaymentsSchema.validate({ | ||
| productLines: { | ||
| pro: { | ||
| displayName: "Pro", | ||
| customerType: "user", | ||
| }, | ||
| }, | ||
| })).resolves.toMatchObject({ | ||
| productLines: { | ||
| pro: { | ||
| displayName: "Pro", | ||
| customerType: "user", | ||
| }, | ||
| }, | ||
| }); | ||
| }); | ||
|
|
||
| it("rejects a product that references a missing product line", async () => { | ||
| await expect(branchPaymentsSchema.validate({ | ||
| products: { | ||
| pro: { | ||
| customerType: "user", | ||
| productLineId: "missing-line", | ||
| }, | ||
| }, | ||
| })).rejects.toThrow('Product "pro" specifies product line ID "missing-line", but that product line does not exist'); | ||
| }); | ||
|
|
||
| it("rejects a product whose customer type differs from its product line", async () => { | ||
| await expect(branchPaymentsSchema.validate({ | ||
| productLines: { | ||
| teamLine: { | ||
| customerType: "team", | ||
| }, | ||
| }, | ||
| products: { | ||
| pro: { | ||
| customerType: "user", | ||
| productLineId: "teamLine", | ||
| }, | ||
| }, | ||
| })).rejects.toThrow('Product "pro" has customer type "user" but its product line "teamLine" has customer type "team"'); | ||
| }); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -181,9 +181,13 @@ export const branchPaymentsSchema = yupObject({ | |
| 'Product customer type must match its product line customer type', | ||
| function(this: yup.TestContext<yup.AnyObject>, value) { | ||
| if (!value) return true; | ||
| for (const [productId, product] of Object.entries(value.products)) { | ||
| if (!product.productLineId) continue; | ||
| const productLine = getOrUndefined(value.productLines, product.productLineId); | ||
| const products = Reflect.get(value, "products"); | ||
| if (!isObjectLike(products)) return true; | ||
|
|
||
| const productLines = Reflect.get(value, "productLines"); | ||
|
mantrakp04 marked this conversation as resolved.
Outdated
|
||
| for (const [productId, product] of Object.entries(products)) { | ||
| if (product.productLineId == null) continue; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Discussion: this is a stricter check than what we had before. Is there a reason you switched it? This change would mean empty product line ids are not skipped. |
||
| const productLine = isObjectLike(productLines) ? getOrUndefined(productLines, product.productLineId) : undefined; | ||
|
coderabbitai[bot] marked this conversation as resolved.
Outdated
mantrakp04 marked this conversation as resolved.
Outdated
|
||
| if (productLine === undefined) { | ||
| return this.createError({ | ||
| message: `Product "${productId}" specifies product line ID "${product.productLineId}", but that product line does not exist`, | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.