diff --git a/x-pack/plugins/spaces/server/lib/space_schema.ts b/x-pack/plugins/spaces/server/lib/space_schema.ts index 0ffaf9ce51cf85..c2dcd3b2b9ac06 100644 --- a/x-pack/plugins/spaces/server/lib/space_schema.ts +++ b/x-pack/plugins/spaces/server/lib/space_schema.ts @@ -13,6 +13,8 @@ export const spaceSchema = Joi.object({ description: Joi.string().allow(''), initials: Joi.string().max(MAX_SPACE_INITIALS), color: Joi.string().regex(/^#[a-z0-9]{6}$/, `6 digit hex color, starting with a #`), - disabledFeatures: Joi.array().items(Joi.string()), + disabledFeatures: Joi.array() + .items(Joi.string()) + .default([]), _reserved: Joi.boolean(), }).default(); diff --git a/x-pack/plugins/spaces/server/routes/api/public/post.test.ts b/x-pack/plugins/spaces/server/routes/api/public/post.test.ts index cf69882f9857d6..c53aaf29636a4b 100644 --- a/x-pack/plugins/spaces/server/routes/api/public/post.test.ts +++ b/x-pack/plugins/spaces/server/routes/api/public/post.test.ts @@ -46,6 +46,7 @@ describe('Spaces Public API', () => { id: 'my-space-id', name: 'my new space', description: 'with a description', + disabledFeatures: ['foo'], }; const { mockSavedObjectsRepository, response } = await request('POST', '/api/spaces/space', { @@ -58,7 +59,7 @@ describe('Spaces Public API', () => { expect(mockSavedObjectsRepository.create).toHaveBeenCalledTimes(1); expect(mockSavedObjectsRepository.create).toHaveBeenCalledWith( 'space', - { name: 'my new space', description: 'with a description' }, + { name: 'my new space', description: 'with a description', disabledFeatures: ['foo'] }, { id: 'my-space-id' } ); }); @@ -102,4 +103,26 @@ describe('Spaces Public API', () => { statusCode: 409, }); }); + + test('POST /space should not require disabledFeatures to be specified', async () => { + const payload = { + id: 'my-space-id', + name: 'my new space', + description: 'with a description', + }; + + const { mockSavedObjectsRepository, response } = await request('POST', '/api/spaces/space', { + payload, + }); + + const { statusCode } = response; + + expect(statusCode).toEqual(200); + expect(mockSavedObjectsRepository.create).toHaveBeenCalledTimes(1); + expect(mockSavedObjectsRepository.create).toHaveBeenCalledWith( + 'space', + { name: 'my new space', description: 'with a description', disabledFeatures: [] }, + { id: 'my-space-id' } + ); + }); }); diff --git a/x-pack/plugins/spaces/server/routes/api/public/put.test.ts b/x-pack/plugins/spaces/server/routes/api/public/put.test.ts index 35c5779a236ae1..d2ac1f89e1df99 100644 --- a/x-pack/plugins/spaces/server/routes/api/public/put.test.ts +++ b/x-pack/plugins/spaces/server/routes/api/public/put.test.ts @@ -44,6 +44,7 @@ describe('Spaces Public API', () => { id: 'a-space', name: 'my updated space', description: 'with a description', + disabledFeatures: [], }; const { mockSavedObjectsRepository, response } = await request( @@ -61,6 +62,7 @@ describe('Spaces Public API', () => { expect(mockSavedObjectsRepository.update).toHaveBeenCalledWith('space', 'a-space', { name: 'my updated space', description: 'with a description', + disabledFeatures: [], }); }); @@ -69,6 +71,7 @@ describe('Spaces Public API', () => { id: 'a-space', name: 'my updated space', description: '', + disabledFeatures: ['foo'], }; const { mockSavedObjectsRepository, response } = await request( @@ -86,6 +89,33 @@ describe('Spaces Public API', () => { expect(mockSavedObjectsRepository.update).toHaveBeenCalledWith('space', 'a-space', { name: 'my updated space', description: '', + disabledFeatures: ['foo'], + }); + }); + + test('PUT /space should not require disabledFeatures', async () => { + const payload = { + id: 'a-space', + name: 'my updated space', + description: '', + }; + + const { mockSavedObjectsRepository, response } = await request( + 'PUT', + '/api/spaces/space/a-space', + { + payload, + } + ); + + const { statusCode } = response; + + expect(statusCode).toEqual(200); + expect(mockSavedObjectsRepository.update).toHaveBeenCalledTimes(1); + expect(mockSavedObjectsRepository.update).toHaveBeenCalledWith('space', 'a-space', { + name: 'my updated space', + description: '', + disabledFeatures: [], }); });