From b034d2c54c34cfbe0ec46dfc8ce7ce9052d9aa8e Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 24 Sep 2025 12:06:51 +0000 Subject: [PATCH 1/2] Initial plan From 23f66d9ea649a992de90a617619aeeb3e1cbe87e Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 24 Sep 2025 12:13:08 +0000 Subject: [PATCH 2/2] Fix missing overwritePassword import in users.js - Add overwritePassword to import statement in users.js - Add test to verify import works correctly - Resolves ReferenceError when overwriting user passwords --- phpmyfaq/admin/assets/src/user/users.js | 2 +- phpmyfaq/admin/assets/src/user/users.test.js | 76 ++++++++++++++++++++ 2 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 phpmyfaq/admin/assets/src/user/users.test.js diff --git a/phpmyfaq/admin/assets/src/user/users.js b/phpmyfaq/admin/assets/src/user/users.js index d788ac6fc8..7a46739105 100644 --- a/phpmyfaq/admin/assets/src/user/users.js +++ b/phpmyfaq/admin/assets/src/user/users.js @@ -16,7 +16,7 @@ */ import { Modal } from 'bootstrap'; -import { fetchAllUsers, fetchUserData, fetchUserRights, deleteUser, postUserData } from '../api'; +import { fetchAllUsers, fetchUserData, fetchUserRights, deleteUser, postUserData, overwritePassword } from '../api'; import { addElement, capitalize } from '../../../../assets/src/utils'; import { pushErrorNotification, pushNotification } from '../utils'; diff --git a/phpmyfaq/admin/assets/src/user/users.test.js b/phpmyfaq/admin/assets/src/user/users.test.js new file mode 100644 index 0000000000..cca61d4abf --- /dev/null +++ b/phpmyfaq/admin/assets/src/user/users.test.js @@ -0,0 +1,76 @@ +/** + * Test for user management functions + * + * This Source Code Form is subject to the terms of the Mozilla Public License, + * v. 2.0. If a copy of the MPL was not distributed with this file, You can + * obtain one at https://mozilla.org/MPL/2.0/. + * + * @package phpMyFAQ + * @author Thorsten Rinne + * @copyright 2010-2024 phpMyFAQ Team + * @license http://www.mozilla.org/MPL/2.0/ Mozilla Public License Version 2.0 + * @link https://www.phpmyfaq.de + * @since 2010-05-02 + */ + +// Mock the required modules +jest.mock('bootstrap', () => ({ + Modal: jest.fn(() => ({ + show: jest.fn(), + hide: jest.fn(), + })), +})); + +jest.mock('../api', () => ({ + fetchAllUsers: jest.fn(), + fetchUserData: jest.fn(), + fetchUserRights: jest.fn(), + deleteUser: jest.fn(), + postUserData: jest.fn(), + overwritePassword: jest.fn(), +})); + +jest.mock('../../../../assets/src/utils', () => ({ + addElement: jest.fn(), + capitalize: jest.fn(), +})); + +jest.mock('../utils', () => ({ + pushErrorNotification: jest.fn(), + pushNotification: jest.fn(), +})); + +describe('User Management Functions', () => { + beforeEach(() => { + // Setup DOM elements that are expected by the functions + document.body.innerHTML = ` + +
+ + + + + `; + }); + + afterEach(() => { + jest.clearAllMocks(); + document.body.innerHTML = ''; + }); + + test('overwritePassword function should be available for import', async () => { + // Import the overwritePassword function from the API + const { overwritePassword } = await import('../api'); + + // Verify the function is available and can be called + expect(overwritePassword).toBeDefined(); + expect(typeof overwritePassword).toBe('function'); + }); + + test('users.js should be able to import overwritePassword without errors', async () => { + // This test verifies that the import statement works without errors + expect(async () => { + await import('./users'); + }).not.toThrow(); + }); +}); \ No newline at end of file