Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion phpmyfaq/admin/assets/src/user/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down
76 changes: 76 additions & 0 deletions phpmyfaq/admin/assets/src/user/users.test.js
Original file line number Diff line number Diff line change
@@ -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 <thorsten@phpmyfaq.de>
* @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 = `
<input id="pmf-user-password-overwrite-action" />
<div id="pmf-modal-user-password-overwrite"></div>
<input id="modal_csrf" value="test-csrf" />
<input id="modal_user_id" value="123" />
<input id="npass" value="newpass" />
<input id="bpass" value="newpass" />
`;
});

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();
});
});