Skip to content

Fix RxDB COL20 when barcode scanning fields are undefined#134

Merged
kilbot merged 1 commit intomainfrom
codex/issue-133-barcode-settings-electron
Mar 2, 2026
Merged

Fix RxDB COL20 when barcode scanning fields are undefined#134
kilbot merged 1 commit intomainfrom
codex/issue-133-barcode-settings-electron

Conversation

@kilbot
Copy link
Copy Markdown
Contributor

@kilbot kilbot commented Mar 2, 2026

Summary

  • prevent useLocalMutation from writing undefined values into RxDB documents
  • filter patch entries before incrementalModify, while still updating date_modified_gmt
  • add a regression test for undefined patch data to ensure barcode scanner prefix/suffix are not overwritten with undefined
  • fixes Barcode Scanning settings modal throws RxDB COL20 in Electron #133

Test plan

  • Run pnpm --filter @wcpos/core lint and confirm there are no lint errors.
  • Run pnpm --filter @wcpos/core test and confirm the core suite passes.
  • In Electron desktop app, open Settings → Barcode Scanning for a store that has unset prefix/suffix values.
  • Confirm the console no longer logs RxDB COL20 validation errors for barcode_scanning_prefix / barcode_scanning_suffix.
  • Change prefix/suffix values and verify they still save correctly.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes

    • Improved local data mutation handling to properly filter out undefined field values.
  • Tests

    • Added comprehensive test coverage for local mutation behavior with undefined data fields.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 2, 2026

📝 Walkthrough

Walkthrough

This pull request modifies the useLocalMutation hook to filter out undefined patch data fields before applying database modifications. A new test file validates this behavior by ensuring undefined fields are not persisted, preventing RxDB schema validation errors when optional fields contain undefined values.

Changes

Cohort / File(s) Summary
Test Coverage
packages/core/src/screens/main/hooks/mutations/use-local-mutation.test.ts
New test file verifying that undefined patch data fields are ignored during local patch operations, with mocks for translations and date conversion functions.
Hook Implementation
packages/core/src/screens/main/hooks/mutations/use-local-mutation.ts
Modified to clone patch data, filter out undefined values before applying modifications, and add early return for no-op patches when no fields have changed.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 Undefined values, now cast away,
No schema errors will have their day,
A filter applied, so clean and neat,
Patches refined make logic complete!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title clearly identifies the main change: fixing an RxDB COL20 error caused by undefined barcode scanning fields, which matches the core objective of preventing undefined values from being written to the database.
Linked Issues check ✅ Passed The changes directly address issue #133 by preventing undefined barcode_scanning_prefix/suffix fields from being written to RxDB, filtering patch entries while maintaining date_modified_gmt updates, and adding a regression test to verify the fix.
Out of Scope Changes check ✅ Passed All changes are scoped to fixing the useLocalMutation hook's handling of undefined patch data and preventing RxDB validation errors, with no extraneous modifications detected.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch codex/issue-133-barcode-settings-electron

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

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
packages/core/src/screens/main/hooks/mutations/use-local-mutation.test.ts (1)

60-68: Expand this regression to include barcode_scanning_suffix undefined as well.

The issue scope calls out both fields; asserting both in one test better protects against partial regressions.

Suggested test update
 		const patchResult = await act(async () => {
 			return result.current.localPatch({
 				document: document as never,
 				data: {
 					barcode_scanning_prefix: undefined,
+					barcode_scanning_suffix: undefined,
 				} as never,
 			});
 		});

 		expect(persistedDoc.barcode_scanning_prefix).toBe('');
+		expect(persistedDoc.barcode_scanning_suffix).toBe('');
 		expect(patchResult?.changes).not.toHaveProperty('barcode_scanning_prefix');
+		expect(patchResult?.changes).not.toHaveProperty('barcode_scanning_suffix');
 		expect(mockConvertLocalDateToUTCString).toHaveBeenCalledTimes(1);
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/core/src/screens/main/hooks/mutations/use-local-mutation.test.ts`
around lines 60 - 68, Update the test in use-local-mutation.test.ts to also
simulate and assert the handling of barcode_scanning_suffix being undefined:
when applying the mutation that currently sets data: { barcode_scanning_prefix:
undefined } also include barcode_scanning_suffix: undefined (or add a separate
mutation call for it), then assert persistedDoc.barcode_scanning_suffix.toBe('')
and expect(patchResult?.changes).not.toHaveProperty('barcode_scanning_suffix');
keep the existing assertion for barcode_scanning_prefix and the
mockConvertLocalDateToUTCString call count unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@packages/core/src/screens/main/hooks/mutations/use-local-mutation.test.ts`:
- Around line 60-68: Update the test in use-local-mutation.test.ts to also
simulate and assert the handling of barcode_scanning_suffix being undefined:
when applying the mutation that currently sets data: { barcode_scanning_prefix:
undefined } also include barcode_scanning_suffix: undefined (or add a separate
mutation call for it), then assert persistedDoc.barcode_scanning_suffix.toBe('')
and expect(patchResult?.changes).not.toHaveProperty('barcode_scanning_suffix');
keep the existing assertion for barcode_scanning_prefix and the
mockConvertLocalDateToUTCString call count unchanged.

ℹ️ Review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2676820 and ac1d807.

📒 Files selected for processing (2)
  • packages/core/src/screens/main/hooks/mutations/use-local-mutation.test.ts
  • packages/core/src/screens/main/hooks/mutations/use-local-mutation.ts

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 2, 2026

📊 Test Coverage Report

Package Statements Branches Functions Lines
@wcpos/core 🔴 22.8% 🔴 25.6% 🔴 28.8% 🔴 22.1%
@wcpos/components 🔴 56.4% 🟡 73.6% 🔴 34.4% 🔴 58.9%
@wcpos/database 🔴 40.2% 🔴 46.4% 🔴 47.1% 🔴 39.2%
@wcpos/hooks 🔴 59.0% 🔴 55.4% 🔴 53.1% 🔴 58.9%
@wcpos/utils 🔴 55.9% 🟡 61.5% 🟡 71.4% 🔴 53.8%
@wcpos/query 🟡 79.6% 🟡 70.5% 🟡 74.4% 🟡 79.7%
Average 🔴 52.3% 🔴 55.5% 🔴 51.5% 🔴 52.1%
Coverage Legend
  • 🟢 Good (≥80%)
  • 🟡 Moderate (60-79%)
  • 🔴 Needs improvement (<60%)
  • ⚪ No coverage data
--- 🤖 Updated by GitHub Actions • [View full report](https://github.com/wcpos/monorepo/actions/runs/22586206288)

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 2, 2026

🚀 Deployment Summary

Item Status
Preview URL https://wcpos--5rkku0amcn.expo.app
E2E Tests ✅ Passed
Commit 70d53d3

🔗 Quick Links


🤖 Updated by GitHub Actions

@kilbot kilbot merged commit 655d3d7 into main Mar 2, 2026
18 checks passed
@kilbot kilbot deleted the codex/issue-133-barcode-settings-electron branch March 2, 2026 17:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Barcode Scanning settings modal throws RxDB COL20 in Electron

1 participant