mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-11 16:05:44 +01:00
fix errors with null values for array types
This commit is contained in:
@@ -117,12 +117,26 @@ export function modifyConfigReset() {
|
|||||||
|
|
||||||
//reducer
|
//reducer
|
||||||
|
|
||||||
|
function removeNullValues(config: Config) {
|
||||||
|
if (!config.adminGroups) {
|
||||||
|
config.adminGroups = [];
|
||||||
|
}
|
||||||
|
if (!config.adminUsers) {
|
||||||
|
config.adminUsers = [];
|
||||||
|
}
|
||||||
|
if (!config.proxyExcludes) {
|
||||||
|
config.proxyExcludes = [];
|
||||||
|
}
|
||||||
|
return config;
|
||||||
|
}
|
||||||
|
|
||||||
function reducer(state: any = {}, action: any = {}) {
|
function reducer(state: any = {}, action: any = {}) {
|
||||||
switch (action.type) {
|
switch (action.type) {
|
||||||
case FETCH_CONFIG_SUCCESS:
|
case FETCH_CONFIG_SUCCESS:
|
||||||
|
const config = removeNullValues(action.payload);
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
entries: action.payload,
|
entries: config,
|
||||||
configUpdatePermission: action.payload._links.update ? true : false
|
configUpdatePermission: action.payload._links.update ? true : false
|
||||||
};
|
};
|
||||||
default:
|
default:
|
||||||
|
|||||||
@@ -56,6 +56,35 @@ const config = {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const configWithNullValues = {
|
||||||
|
proxyPassword: null,
|
||||||
|
proxyPort: 8080,
|
||||||
|
proxyServer: "proxy.mydomain.com",
|
||||||
|
proxyUser: null,
|
||||||
|
enableProxy: false,
|
||||||
|
realmDescription: "SONIA :: SCM Manager",
|
||||||
|
enableRepositoryArchive: false,
|
||||||
|
disableGroupingGrid: false,
|
||||||
|
dateFormat: "YYYY-MM-DD HH:mm:ss",
|
||||||
|
anonymousAccessEnabled: false,
|
||||||
|
adminGroups: null,
|
||||||
|
adminUsers: null,
|
||||||
|
baseUrl: "http://localhost:8081/scm",
|
||||||
|
forceBaseUrl: false,
|
||||||
|
loginAttemptLimit: -1,
|
||||||
|
proxyExcludes: null,
|
||||||
|
skipFailedAuthenticators: false,
|
||||||
|
pluginUrl:
|
||||||
|
"http://plugins.scm-manager.org/scm-plugin-backend/api/{version}/plugins?os={os}&arch={arch}&snapshot=false",
|
||||||
|
loginAttemptLimitTimeout: 300,
|
||||||
|
enabledXsrfProtection: true,
|
||||||
|
defaultNamespaceStrategy: "sonia.scm.repository.DefaultNamespaceStrategy",
|
||||||
|
_links: {
|
||||||
|
self: { href: "http://localhost:8081/scm/api/rest/v2/config" },
|
||||||
|
update: { href: "http://localhost:8081/scm/api/rest/v2/config" }
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const responseBody = {
|
const responseBody = {
|
||||||
entries: config,
|
entries: config,
|
||||||
configUpdatePermission: false
|
configUpdatePermission: false
|
||||||
@@ -175,6 +204,14 @@ describe("config reducer", () => {
|
|||||||
const newState = reducer({}, fetchConfigSuccess(config));
|
const newState = reducer({}, fetchConfigSuccess(config));
|
||||||
expect(newState.entries).toBe(config);
|
expect(newState.entries).toBe(config);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("should return empty arrays for null values", () => {
|
||||||
|
const config = reducer({}, fetchConfigSuccess(configWithNullValues))
|
||||||
|
.entries;
|
||||||
|
expect(config.adminUsers).toEqual([]);
|
||||||
|
expect(config.adminGroups).toEqual([]);
|
||||||
|
expect(config.proxyExcludes).toEqual([]);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("selector tests", () => {
|
describe("selector tests", () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user