Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spaces API - default disabledFeatures to empty array #40017

Merged
merged 2 commits into from Jul 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion x-pack/legacy/plugins/spaces/server/lib/space_schema.ts
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();
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' }
);
});
});
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