Skip to content

test(backend): add integration tests for access group promote/demote (ref #1142)#2292

Merged
wp99cp merged 2 commits into
devfrom
feat/1142-access-group-permissions-tests
Jun 25, 2026
Merged

test(backend): add integration tests for access group promote/demote (ref #1142)#2292
wp99cp merged 2 commits into
devfrom
feat/1142-access-group-permissions-tests

Conversation

@wp99cp

@wp99cp wp99cp commented Jun 25, 2026

Copy link
Copy Markdown
Member

This PR adds integration and functional tests for the access group promote and demote user endpoint, ensuring database updates, validation constraints, and audit log events are properly asserted. See #1142

@greptile-apps

greptile-apps Bot commented Jun 25, 2026

Copy link
Copy Markdown

Greptile Summary

This PR adds integration tests for the promote and demote user endpoints on access groups, covering happy-path DB updates, the "last editor" conflict guard, and authorization for non-editors. It also introduces a pollForAuditEvent helper that retries the audit-log query, addressing the async race condition flagged in earlier review threads.

  • Four new tests cover: editor promotes a member, editor demotes an editor, conflict when demoting the last editor, and a non-editor (both member and unrelated user) attempting promote or demote — all returning the expected status codes with DB and audit-log assertions.
  • pollForAuditEvent retries up to 10 times with 50 ms intervals to wait for the detached audit-log write to commit, replacing the previous direct query that was prone to timing failures.
  • Details key confirmed: the service logs { userUuid, userName, canEditGroup } in the PROMOTE_USER/DEMOTE_USER event, matching promoteEvent.details.userUuid and demoteEvent.details.userUuid used in the assertions.

Confidence Score: 5/5

Test-only change; no production code is modified and the new tests exercise the correct API surface with proper assertions.

All changes are confined to the integration test file. The pollForAuditEvent helper correctly resolves the async audit-log timing issue from earlier reviews, the details.userUuid key matches what the service actually stores, and the non-editor tests now cover both the promote and demote paths for both member and unrelated-user roles.

No files require special attention.

Important Files Changed

Filename Overview
backend/tests/auth/access-groups/access-groups.test.ts Adds four integration tests for promote/demote user permissions, pollForAuditEvent helper, and a demote-last-editor conflict guard test; assertions cover HTTP status, response body, DB state, and audit log events.

Reviews (2): Last reviewed commit: "test(backend): fix flaky audit log asser..." | Re-trigger Greptile

Comment thread backend/tests/auth/access-groups/access-groups.test.ts
Comment thread backend/tests/auth/access-groups/access-groups.test.ts
Comment thread backend/tests/auth/access-groups/access-groups.test.ts
@greptile-apps

greptile-apps Bot commented Jun 25, 2026

Copy link
Copy Markdown

Want your agent to iterate on Greptile's feedback? Try greploops.

@wp99cp
wp99cp merged commit 77b4596 into dev Jun 25, 2026
4 checks passed
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