diff --git a/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/components/agent_policy_advanced_fields/index.tsx b/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/components/agent_policy_advanced_fields/index.tsx index 0277184acabf2..305148584f545 100644 --- a/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/components/agent_policy_advanced_fields/index.tsx +++ b/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/components/agent_policy_advanced_fields/index.tsx @@ -375,8 +375,8 @@ export const AgentPolicyAdvancedOptionsContent: React.FunctionComponent = > { }); }); }); + +describe('getSpaceSettings', () => { + function createSavedsClientMock(settingsAttributes?: any) { + const client = savedObjectsClientMock.create(); + + if (settingsAttributes) { + client.get.mockResolvedValue({ + attributes: settingsAttributes, + } as any); + } else { + client.get.mockRejectedValue( + SavedObjectsErrorHelpers.createGenericNotFoundError('Not found') + ); + } + + jest.mocked(appContextService.getInternalUserSOClientForSpaceId).mockReturnValue(client); + + return client; + } + it('should work with managedBy:null', async () => { + createSavedsClientMock({ + allowed_namespace_prefixes: ['test'], + managed_by: null, + }); + const res = await getSpaceSettings(); + + expect(res).toEqual({ + allowed_namespace_prefixes: ['test'], + managed_by: undefined, + }); + }); +}); diff --git a/x-pack/plugins/fleet/server/services/spaces/space_settings.ts b/x-pack/plugins/fleet/server/services/spaces/space_settings.ts index ece0291ff4f7c..dff4df63b6a9d 100644 --- a/x-pack/plugins/fleet/server/services/spaces/space_settings.ts +++ b/x-pack/plugins/fleet/server/services/spaces/space_settings.ts @@ -36,7 +36,7 @@ export async function getSpaceSettings(spaceId?: string) { return { allowed_namespace_prefixes: settings?.attributes?.allowed_namespace_prefixes ?? [], - managed_by: settings?.attributes?.managed_by, + managed_by: settings?.attributes?.managed_by ?? undefined, }; }