-
Notifications
You must be signed in to change notification settings - Fork 11.3k
fix(web): restore admin unbinding for built-in providers #6987
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
seefs001
merged 2 commits into
QuantumNous:main
from
zcxads666:codex/fix-admin-builtin-binding-types-6985
Aug 29, 2026
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
148 changes: 148 additions & 0 deletions
148
web/src/features/users/components/dialogs/__tests__/user-binding-dialog.test.tsx
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,148 @@ | ||
| /* | ||
| Copyright (C) 2023-2026 QuantumNous | ||
|
|
||
| This program is free software: you can redistribute it and/or modify | ||
| it under the terms of the GNU Affero General Public License as | ||
| published by the Free Software Foundation, either version 3 of the | ||
| License, or (at your option) any later version. | ||
|
|
||
| This program is distributed in the hope that it will be useful, | ||
| but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| GNU Affero General Public License for more details. | ||
|
|
||
| You should have received a copy of the GNU Affero General Public License | ||
| along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
|
|
||
| For commercial licensing, please contact support@quantumnous.com | ||
| */ | ||
| import { fireEvent, render, screen, waitFor } from '@testing-library/react' | ||
| import { afterAll, afterEach, beforeAll, describe, expect, test } from 'vitest' | ||
|
|
||
| import { api } from '@/lib/api' | ||
|
|
||
| import { UserBindingDialog } from '../user-binding-dialog' | ||
|
|
||
| type ApiMethod = (url: string) => Promise<{ data: unknown }> | ||
| type MockableApi = { | ||
| get: ApiMethod | ||
| delete: ApiMethod | ||
| } | ||
|
|
||
| const apiClient = api as unknown as MockableApi | ||
| const originalGet = apiClient.get | ||
| const originalDelete = apiClient.delete | ||
| const originalGetAnimations = Object.getOwnPropertyDescriptor( | ||
| HTMLElement.prototype, | ||
| 'getAnimations' | ||
| ) | ||
|
|
||
| const user = { | ||
| id: 7, | ||
| username: 'bound-user', | ||
| email: 'user@example.com', | ||
| github_id: 'github-user', | ||
| discord_id: 'discord-user', | ||
| wechat_id: 'wechat-user', | ||
| oidc_id: 'oidc-user', | ||
| telegram_id: 'telegram-user', | ||
| linux_do_id: 'linuxdo-user', | ||
| } | ||
|
|
||
| function findUnbindButton(provider: string): HTMLButtonElement { | ||
| let container = screen.getByText(provider).parentElement | ||
| while (container && !container.querySelector('button')) { | ||
| container = container.parentElement | ||
| } | ||
| const button = container?.querySelector<HTMLButtonElement>('button') | ||
| if (!button) { | ||
| throw new Error(`Expected unbind button for ${provider}`) | ||
| } | ||
| return button | ||
| } | ||
|
|
||
| beforeAll(() => { | ||
| Object.defineProperty(HTMLElement.prototype, 'getAnimations', { | ||
| configurable: true, | ||
| value: () => [], | ||
| }) | ||
| }) | ||
|
|
||
| afterAll(() => { | ||
| if (originalGetAnimations) { | ||
| Object.defineProperty( | ||
| HTMLElement.prototype, | ||
| 'getAnimations', | ||
| originalGetAnimations | ||
| ) | ||
| return | ||
| } | ||
| Reflect.deleteProperty(HTMLElement.prototype, 'getAnimations') | ||
| }) | ||
|
|
||
| afterEach(() => { | ||
| apiClient.get = originalGet | ||
| apiClient.delete = originalDelete | ||
| }) | ||
|
|
||
| describe('UserBindingDialog built-in bindings', () => { | ||
| test('submits every built-in provider type accepted by the backend', async () => { | ||
| const deletedUrls: string[] = [] | ||
| apiClient.get = async (url) => { | ||
| switch (url) { | ||
| case '/api/user/7': | ||
| return { data: { success: true, data: user } } | ||
| case '/api/user/7/oauth/bindings': | ||
| return { data: { success: true, data: [] } } | ||
| case '/api/status': | ||
| return { | ||
| data: { | ||
| success: true, | ||
| data: { | ||
| github_oauth: true, | ||
| discord_oauth: true, | ||
| wechat_login: true, | ||
| oidc_enabled: true, | ||
| telegram_oauth: true, | ||
| linuxdo_oauth: true, | ||
| }, | ||
| }, | ||
| } | ||
| default: | ||
| throw new Error(`Unexpected GET ${url}`) | ||
| } | ||
| } | ||
| apiClient.delete = async (url) => { | ||
| deletedUrls.push(url) | ||
| return { data: { success: true, message: 'success' } } | ||
| } | ||
|
|
||
| render(<UserBindingDialog open userId={7} onOpenChange={() => undefined} />) | ||
|
|
||
| const expectedBindings = [ | ||
| ['Email', 'email'], | ||
| ['GitHub', 'github'], | ||
| ['Discord', 'discord'], | ||
| ['WeChat', 'wechat'], | ||
| ['OIDC', 'oidc'], | ||
| ['Telegram', 'telegram'], | ||
| ['LinuxDO', 'linuxdo'], | ||
| ] as const | ||
|
|
||
| await screen.findByText('bound-user (ID: 7)') | ||
| for (const [provider, bindingType] of expectedBindings) { | ||
| fireEvent.click(findUnbindButton(provider)) | ||
| fireEvent.click(screen.getByRole('button', { name: 'Confirm Unbind' })) | ||
| await waitFor(() => { | ||
| expect(deletedUrls.at(-1)).toBe(`/api/user/7/bindings/${bindingType}`) | ||
| }) | ||
| await waitFor(() => { | ||
| expect( | ||
| screen.queryByRole('button', { name: 'Confirm Unbind' }) | ||
| ).not.toBeInTheDocument() | ||
| }) | ||
| } | ||
|
|
||
| expect(deletedUrls).toHaveLength(expectedBindings.length) | ||
| }) | ||
| }) | ||
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Verify the refreshed unbound state.
The GET mock always returns all provider IDs as bound. The test can pass when
fetchData()does not refresh the dialog because it only verifies confirmation-dialog dismissal. Update the mock after each DELETE to clear the affected field, then assert that the provider displays as unbound.🤖 Prompt for AI Agents
Source: Coding guidelines