Files
sofarr/server/utils/ombiHelpers.js
T
gronod 4aa3590017
Build and Push Docker Image / build (push) Successful in 53s
Docs Check / Markdown lint (push) Successful in 1m36s
Licence Check / Licence compatibility and copyright header verification (push) Failing after 2m31s
CI / Security audit (push) Successful in 2m55s
Docs Check / Mermaid diagram parse check (push) Successful in 3m24s
CI / Swagger Validation & Coverage (push) Successful in 3m30s
CI / Tests & coverage (push) Successful in 3m50s
test: remediate test suite, enable skipped frontend/SSE tests, and add comprehensive unit tests
- Deleted redundant unit test file tests/unit/dashboard.test.js
- Enabled skipped frontend DOM state and API tests in tests/frontend/state.test.js
- Fixed Supertest client socket abort exception in SSE stream integration tests using new graceful testClose parameter
- Consolidated duplicate helpers in server/routes/history.js and server/utils/arrRetrievers.js to unified services TagMatcher and DownloadAssembler
- Added comprehensive unit tests for loadSecrets.js, PollingSonarrRetriever.js, PollingRadarrRetriever.js, and ombiHelpers.js
- Achieved a 100% Vitest pass rate (834/834 tests) with robust code coverage
2026-05-22 13:33:21 +01:00

44 lines
1.5 KiB
JavaScript

/**
* Helper functions for extracting user information from Ombi API responses.
* The Ombi API returns requestedUser as an OmbiStore.Entities.OmbiUser object,
* not a string, so we need to extract the username from the object.
*/
/**
* Extracts the username from an Ombi request object.
* Handles both the OmbiUser object format and legacy string format.
*
* @param {Object} request - The Ombi request object
* @returns {string} The extracted username, or empty string if not found
*/
function extractRequestedUser(request) {
if (!request) return '';
// Handle object format: OmbiStore.Entities.OmbiUser
if (request.requestedUser && typeof request.requestedUser === 'object') {
// Priority: alias > userAlias > userName > normalizedUserName > requestedByAlias
return request.requestedUser.alias ||
request.requestedUser.userAlias ||
request.requestedUser.userName ||
request.requestedUser.normalizedUserName ||
request.requestedByAlias || '';
}
// Handle string format (fallback for compatibility)
return request.requestedUser || request.requestedByAlias || '';
}
function filterRequestsByUser(requests, username, showAll) {
if (!Array.isArray(requests)) return [];
if (showAll || !username) return requests;
const usernameLower = username.toLowerCase();
return requests.filter(req => {
const requestedUser = extractRequestedUser(req);
return requestedUser.toLowerCase() === usernameLower;
});
}
module.exports = {
extractRequestedUser,
filterRequestsByUser
};