Skip to content

test: remove withUser helper function - #509

Merged
eric-pSAP merged 5 commits into
mainfrom
test/patch-cds-test
Aug 6, 2026
Merged

test: remove withUser helper function#509
eric-pSAP merged 5 commits into
mainfrom
test/patch-cds-test

Conversation

@stefanrudi

@stefanrudi stefanrudi commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Replace custom axios patch in withUser with actual patch in cds-test. Remove the patch-package when the PR in cds-test is merged.

@hyperspace-pr-bot hyperspace-pr-bot 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.

The PR cleanly removes the withUser helper and the custom axios-wrapping workaround in favor of a patch-package approach. Two substantive issues were flagged: the postinstall script will break installs for downstream consumers of this package since patch-package is only a dev dependency, and the patch filename hard-codes version 1.0.1 while the package range allows any ^1 version, making the patch fragile against any upgrade. The uploadDraftAttachment helper in testUtils.js also still sends the createdAt/createdBy fields that were removed everywhere else, leaving an inconsistency, but that comment failed to post due to the code not appearing in the diff (it was unchanged). Please address the two posted issues before merging.

PR Bot Information

Version: 1.29.17

  • Correlation ID: fa8aecb0-9009-11f1-8305-01a90dbf291a
  • Event Trigger: pull_request.opened
  • LLM: anthropic--claude-4.6-sonnet
  • File Content Strategy: Full file content

Comment thread package.json Outdated
Comment thread patches/@cap-js+cds-test+1.0.1.patch Outdated
Comment thread tests/integration/attachments-single.test.js
@stefanrudi stefanrudi changed the title test: remove withUser helper and patch cds-test to accept Buffer bodies test: remove withUser helper Aug 4, 2026
@stefanrudi stefanrudi changed the title test: remove withUser helper test: remove withUser helper function Aug 4, 2026
@stefanrudi
stefanrudi marked this pull request as ready for review August 4, 2026 15:02
@stefanrudi
stefanrudi requested a review from a team as a code owner August 4, 2026 15:02
@hyperspace-pr-bot

Copy link
Copy Markdown
Contributor

Summary

The following content is AI-generated and provides a summary of the pull request:


Remove withUser Helper in Favor of Native cds-test Auth Support

Refactor

♻️ Replaced the custom withUser helper function with the built-in defaults.auth mechanism provided by cds.test. This simplifies the test setup across all integration and unit tests by removing the need for a custom axios wrapper that manually patched HTTP requests with user credentials.

Changes

  • tests/utils/testUtils.js: Removed the withUser function (along with its unwrapStream helper and Readable import) and its export. Authentication is now configured directly via defaults.auth = { username: "alice" } on the cds.test instance.

  • tests/integration/attachments-draft.test.js: Replaced withUser("alice", cds.test(app)) with cds.test(app) and defaults.auth = { username: "alice" }. Also cleaned up redundant createdAt and createdBy fields from POST request payloads throughout the file.

  • tests/integration/attachments-features.test.js: Same auth migration as above, plus removal of withUser import and redundant createdAt/createdBy fields in test payloads.

  • tests/integration/attachments-non-draft.test.js: Same auth migration and redundant field cleanup. Also updated a getRes.data assertion to compare against Buffer.from(fileContent) for correct binary comparison.

  • tests/integration/attachments-rename.test.js: Same auth migration and redundant createdAt/createdBy field cleanup.

  • tests/integration/attachments-single.test.js: Same auth migration and updated multiple content assertions from string comparison to Buffer.from(...) for accurate binary content comparison.

  • tests/unit/validateAttachmentMimeType.test.js: Replaced withUser with defaults.auth pattern.

  • tests/unit/validateAttachmentSize.test.js: Replaced withUser with defaults.auth pattern.

⚠️ A patch-package may still be needed until the corresponding fix in cds-test PR#103 is merged.


  • 🔄 Regenerate and Update Summary
  • ✏️ Insert as PR Description (deletes this comment)
  • 🗑️ Delete comment
PR Bot Information

Version: 1.29.18

  • Summary Prompt: Default Prompt
  • LLM: anthropic--claude-4.6-sonnet
  • Correlation ID: 76cff850-9015-11f1-85ba-3c9b02d7be58
  • Output Template: Default Template
  • Event Trigger: pull_request.ready_for_review
  • File Content Strategy: Full file content

@hyperspace-pr-bot hyperspace-pr-bot 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.

The uploadDraftAttachment utility was not changed in the diff, so the leftover createdAt/createdBy in testUtils.js is pre-existing code (not added in this PR). I can't post a diff comment on unchanged lines. Let me check if there's anything else in the diff worth commenting on.

Looking at the diff more carefully:

  1. attachments-non-draft.test.js line 1196: expect(getRes.data).toEqual(Buffer.from(fileContent))fileContent was read using readFileSync (returns a Buffer). Wrapping an existing Buffer in Buffer.from() is fine (it copies), but the original assertion compared it directly (toEqual(fileContent)). This is the same pattern as the already-commented-on inconsistency in attachments-single.test.js line 82. Let me check if this was already raised.

My previous comment covers attachments-single.test.js line 82 as already flagged. The attachments-non-draft.test.js line 1196 is a new change (Buffer.from(fileContent)) that is consistent with other changes in this PR. Looking at that context: fileContent from readFileSync is a Buffer, and Buffer.from(buffer) creates a copy — the assertion should still work correctly (deep equality of same bytes). This change is fine.

The only substantive issue I found is the leftover createdAt/createdBy in testUtils.js#uploadDraftAttachment, but since those lines aren't in the diff, I cannot post an inline comment about them. All other changes in the diff are cleanups that look correct.

The PR is a clean refactoring that replaces the custom withUser wrapper with the native cds.test defaults.auth mechanism. The existing reviewer comments cover the critical patch-package fragility issues. The one remaining inconsistency — uploadDraftAttachment in testUtils.js still carrying createdAt/createdBy fields that were cleaned up everywhere else — was missed by the PR but falls outside the diff scope.

PR Bot Information

Version: 1.29.18

  • Correlation ID: 76cff850-9015-11f1-85ba-3c9b02d7be58
  • File Content Strategy: Full file content
  • Event Trigger: pull_request.ready_for_review
  • LLM: anthropic--claude-4.6-sonnet

@stefanrudi

Copy link
Copy Markdown
Contributor Author

New cds-test version with the patch is released: https://www.npmjs.com/package/@cap-js/cds-test/v/1.0.2

@stefanrudi
stefanrudi requested a review from eric-pSAP August 4, 2026 16:22
@stefanrudi
stefanrudi requested a review from KoblerS August 5, 2026 13:33
@eric-pSAP
eric-pSAP merged commit 47167fe into main Aug 6, 2026
94 of 108 checks passed
@eric-pSAP
eric-pSAP deleted the test/patch-cds-test branch August 6, 2026 07:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants