Skip to content
This repository has been archived by the owner on Mar 31, 2024. It is now read-only.

Commit

Permalink
[7.2] Spaces API - default disabledFeatures to empty array (#4… (elas…
Browse files Browse the repository at this point in the history
…tic#40058)

* default disabledFeatures to empty array

* update PUT spaces tests
  • Loading branch information
legrego authored Jul 1, 2019
1 parent c371ada commit b430c52
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 2 deletions.
4 changes: 3 additions & 1 deletion x-pack/plugins/spaces/server/lib/space_schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
25 changes: 24 additions & 1 deletion x-pack/plugins/spaces/server/routes/api/public/post.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', {
Expand All @@ -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' }
);
});
Expand Down Expand Up @@ -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' }
);
});
});
30 changes: 30 additions & 0 deletions x-pack/plugins/spaces/server/routes/api/public/put.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -61,6 +62,7 @@ describe('Spaces Public API', () => {
expect(mockSavedObjectsRepository.update).toHaveBeenCalledWith('space', 'a-space', {
name: 'my updated space',
description: 'with a description',
disabledFeatures: [],
});
});

Expand All @@ -69,6 +71,7 @@ describe('Spaces Public API', () => {
id: 'a-space',
name: 'my updated space',
description: '',
disabledFeatures: ['foo'],
};

const { mockSavedObjectsRepository, response } = await request(
Expand All @@ -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: [],
});
});

Expand Down

0 comments on commit b430c52

Please sign in to comment.