Skip to content

Revised testing - #50

Open
Henk3000 wants to merge 21 commits into
DaveMoudy:mainfrom
Henk3000:revisedTesting
Open

Revised testing#50
Henk3000 wants to merge 21 commits into
DaveMoudy:mainfrom
Henk3000:revisedTesting

Conversation

@Henk3000

Copy link
Copy Markdown
Contributor

Summary

This PR updates the DocGen unit tests to align with a User-first data model and standard Salesforce relationships. The primary goal is to make the tests more deterministic and packaging-friendly by reducing reliance on Account/Opportunity-style data setup and instead using relationships that reliably exist on standard objects.

Changes

Reworking test setups/configs to use User records plus User.CreatedBy / User.CreatedBy.* for parent/grandparent coverage.
Switching child relationship scenarios to the standard ManagedUsers relationship to exercise parent-on-child and nested traversal behavior.
Adjusting V2/V3 junction + stitching test coverage to use real standard junction rows (not “fake” relational objects), with ContentDocumentLink/ContentDocument used as the practical junction-backed target.
Updating DocGenSharingTests to share the template via a Group that includes the current user (instead of sharing to a newly inserted user).
Branch Comparison vs main
Compared to main, this branch changes 7 test files:

force-app/main/default/classes/DocGenBulkControllerTest.cls
force-app/main/default/classes/DocGenBulkFlowActionTest.cls
force-app/main/default/classes/DocGenBulkTests.cls
force-app/main/default/classes/DocGenControllerTests.cls
force-app/main/default/classes/DocGenMiscTests.cls
force-app/main/default/classes/DocGenSharingTests.cls
force-app/main/default/classes/DocGenTests.cls
Diff stats:

7 files changed, 1159 insertions(+), 1533 deletions(-)
Test Result Comparison (from scripts/testResultCompare.log)
Highlights from the comparison log (coverage-style per class):

apex code coverage:
BarcodeGenerator 100% => 100%
DocGenBatch 90% => 89%
DocGenBulkController 85% => 85%
DocGenBulkFlowAction 100% => 100%
DocGenController 58% => 58%
DocGenDataRetriever 85% => 85%
DocGenException 0% => 0%
DocGenFlowAction 63% => 63%
DocGenHtmlRenderer 80% => 80%
DocGenMergeJob 92% => 92%
DocGenService 79% => 78%
DocGenSetupController 100% => 100%
DocGenTemplateManager 96% => 96%

Why this improves unmanaged/package test reliability
Tests that rely on standard objects and relationships that always exist tend to be more robust in unmanaged packaging scenarios. Standard objects like User (and relationships like CreatedBy/ManagedUsers), plus platform junctions like ContentDocumentLink, are consistently available across subscriber orgs. That reduces:

brittleness caused by org-specific custom data expectations,
mismatches in test data shape/relationship behavior during upgrades or CI,
and excessive setup requirements that can make unmanaged test execution flaky.
Using these standard structures keeps the tests focused on DocGen behavior (query parsing, hierarchy stitching, junction handling) rather than fragile test-data manufacturing.

Testing

  • Ran E2E tests (sf apex run --target-org <org> -f scripts/e2e-test.apex) — all passing
  • Ran Apex unit tests (sf apex run test --synchronous --code-coverage) — all passing
  • Tested manually in a scratch org
  • Added/updated E2E test assertions for new behavior

Related Issues

None

Checklist

  • No hardcoded IDs, URLs, or credentials
  • No VersionData in PDF image queries (see CLAUDE.md)
  • SOQL uses WITH USER_MODE or Security.stripInaccessible() where appropriate
  • No new external dependencies introduced

Henk3000 and others added 21 commits March 26, 2026 17:03
…mageRenderSpec class for improved clarity and maintainability.

- Updated README to reflect new image size syntax options, including fixed and max constraints for image dimensions.
- Improved documentation for image tag specifications to aid user understanding.
…ding exception details in thrown messages for better debugging. This improves the clarity of error messages related to document generation, template saving, and deletion operations.
…test setups and assertions across multiple test classes to ensure compatibility with User-based templates and queries. This change enhances the relevance of tests to the current data model and improves overall test coverage.
…ds polish

- Headers and footers now render in PDF with merge tag replacement
- Tables in header/footer lose borders (renderer formatting gap)
- Footer positioned inline (Flying Saucer position:fixed crashes)
- Needs: border parsing for header/footer tables, proper page positioning

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…e tags

Fixes DaveMoudy#42. Based on approach from PR DaveMoudy#46 by @josephedwards-png.

- Headers render at top of page, footers pinned to bottom via absolute positioning
- Namespaced image relIds prevent collisions between header/footer/document parts
- Table style resolution: detect w:tblStyle references (TableGrid etc.) for borders
- styles.xml now saved as pre-decomposed CV for future style lookups
- Zero paragraph margins in header/footer tables for tight cell spacing
- combineXmlWithHeadersFooters() helper used in all 4 render paths
- Templates with headers/footers must be re-saved to pick up the fix

Known limitation: Cell-level formatting (padding, exact widths) from Word styles
renders slightly larger than the original template. Full styles.xml parsing for
cell-level properties is a future enhancement.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Fixes DaveMoudy#42. Based on approach from PR DaveMoudy#46 by @josephedwards-png.

- Header/footer rendering with full formatting, borders, merge tags
- Namespaced image relIds (header1_rId1) prevent part collisions
- Dynamic table style resolution from styles.xml
- Dynamic @page CSS from w:sectPr (page size, margins)
- Dynamic cell padding from TableNormal style
- styles.xml saved as pre-decomposed CV
- Content height calculated from page dimensions
- All 4 render paths use combineXmlWithHeadersFooters()
- PDF merger restored: generate+merge, merge-only, packets
- Client-side DOCX assembly with per-image Apex calls
- 507/507 Apex tests, 22/22 E2E, 0 Critical/High

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Integrates PR DaveMoudy#47 from @Henk3000 with enhancements:

- ImageRenderSpec: percentage sizing ({%Logo:100%x}), max constraints
  ({%Logo:m100%x}), intrinsic PNG/JPEG dimension detection, aspect
  ratio preservation
- Error diagnostics: malformed merge tags and unclosed loops now throw
  DocGenException with descriptive messages
- Multiline text: newlines in text fields render as proper <w:br/> with
  correct run element handling
- Smart container expansion: loops inside numbered/bulleted lists now
  repeat list formatting (previously only table rows)
- ahe() helper: consistent AuraHandledException creation with original
  exception logging across all 38 throw sites
- Universal file save: saveContentVersion() handles objects that don't
  support FirstPublishLocationId or ContentDocumentLink (e.g. Pricebook2)
- 0 Critical, 0 High on Code Analyzer. 507/507 tests, 22/22 E2E

Thanks to @Henk3000 for the excellent PR — the ImageRenderSpec and error
diagnostics are significant improvements to the template engine.

Co-Authored-By: Henk3000 <Henk3000@users.noreply.github.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Empty catch blocks now log warnings instead of silently swallowing.
Code Analyzer: 0 Critical, 0 High without any suppressions.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…e Text

Integrates PR DaveMoudy#47 from @Henk3000:

- ImageRenderSpec: percentage sizing, max constraints, intrinsic
  PNG/JPEG dimension detection, aspect ratio preservation
- Error diagnostics: malformed tags throw DocGenException with
  descriptive messages instead of silently producing broken output
- Multiline text: newlines render as proper <w:br/> with correct
  run element handling
- Smart container expansion: loops in numbered/bulleted lists
  now repeat list formatting
- ahe() helper: consistent AuraHandledException with debug logging
- Universal file save: handles objects without file linking support

0 Critical, 0 High (no suppressions). 507/507 tests. 22/22 E2E.

Co-Authored-By: Henk3000 <Henk3000@users.noreply.github.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Clickable hyperlinks from rich text fields now render as real <a> tags
in PDF output. Install links updated to 04tal000006PClhAAG.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Removed unused methods from DocGenService.
- Updated template fields in DocGenMiscTests to replace 'AccountSource' with 'Id' in various locations.
- Adjusted test cases to reflect changes in template fields and ensure proper functionality.
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.

1 participant