Add unit tests for spaces

This commit is contained in:
Mike Cote 2019-05-01 08:58:35 -04:00
parent 9618c2cc3a
commit 2674a9d78f
2 changed files with 131 additions and 0 deletions

View file

@ -8,6 +8,12 @@ exports[`default space #bulkGet throws error if objects type is space 1`] = `"Sp
exports[`default space #bulkGet throws error if options.namespace is specified 1`] = `"Spaces currently determines the namespaces"`;
exports[`default space #canBulkCreate throws error if types contains space 1`] = `"Spaces can not be accessed using the SavedObjectsClient"`;
exports[`default space #canBulkGet throws error if objects type is space 1`] = `"Spaces can not be accessed using the SavedObjectsClient"`;
exports[`default space #canFind throws error if types contains space 1`] = `"Spaces can not be accessed using the SavedObjectsClient"`;
exports[`default space #create throws error if options.namespace is specified 1`] = `"Spaces currently determines the namespaces"`;
exports[`default space #create throws error if type is space 1`] = `"Spaces can not be accessed using the SavedObjectsClient"`;
@ -40,6 +46,12 @@ exports[`space_1 space #bulkGet throws error if objects type is space 1`] = `"Sp
exports[`space_1 space #bulkGet throws error if options.namespace is specified 1`] = `"Spaces currently determines the namespaces"`;
exports[`space_1 space #canBulkCreate throws error if types contains space 1`] = `"Spaces can not be accessed using the SavedObjectsClient"`;
exports[`space_1 space #canBulkGet throws error if objects type is space 1`] = `"Spaces can not be accessed using the SavedObjectsClient"`;
exports[`space_1 space #canFind throws error if types contains space 1`] = `"Spaces can not be accessed using the SavedObjectsClient"`;
exports[`space_1 space #create throws error if options.namespace is specified 1`] = `"Spaces currently determines the namespaces"`;
exports[`space_1 space #create throws error if type is space 1`] = `"Spaces can not be accessed using the SavedObjectsClient"`;

View file

@ -172,6 +172,45 @@ const createMockClient = () => {
});
});
describe('#canBulkGet', () => {
test('throws error if objects type is space', async () => {
const request = createMockRequest({ id: currentSpace.id });
const baseClient = createMockClient();
const spacesService = createSpacesService(server);
const client = new SpacesSavedObjectsClient({
request,
baseClient,
spacesService,
types,
});
await expect(client.canBulkGet(['foo', 'space'])).rejects.toThrowErrorMatchingSnapshot();
});
test('supplements options', async () => {
const request = createMockRequest({ id: currentSpace.id });
const baseClient = createMockClient();
const expectedReturnValue = Symbol();
baseClient.canBulkGet.mockReturnValue(expectedReturnValue);
const spacesService = createSpacesService(server);
const client = new SpacesSavedObjectsClient({
request,
baseClient,
spacesService,
types,
});
const reqTypes = Object.freeze(['foo']);
// @ts-ignore
const actualReturnValue = await client.canBulkGet(reqTypes);
expect(actualReturnValue).toBe(expectedReturnValue);
expect(baseClient.canBulkGet).toHaveBeenCalledWith(reqTypes);
});
});
describe('#find', () => {
test(`throws error if options.namespace is specified`, async () => {
const request = createMockRequest({ id: currentSpace.id });
@ -292,6 +331,47 @@ const createMockClient = () => {
});
});
describe('#canFind', () => {
test('throws error if types contains space', async () => {
const request = createMockRequest({ id: currentSpace.id });
const baseClient = createMockClient();
const expectedReturnValue = Symbol();
baseClient.canFind.mockReturnValue(expectedReturnValue);
const spacesService = createSpacesService(server);
const client = new SpacesSavedObjectsClient({
request,
baseClient,
spacesService,
types,
});
await expect(client.canFind(['space'])).rejects.toThrowErrorMatchingSnapshot();
});
test('supplements types', async () => {
const request = createMockRequest({ id: currentSpace.id });
const baseClient = createMockClient();
const expectedReturnValue = Symbol();
baseClient.canFind.mockReturnValue(expectedReturnValue);
const spacesService = createSpacesService(server);
const client = new SpacesSavedObjectsClient({
request,
baseClient,
spacesService,
types,
});
const reqTypes = Object.freeze(['foo', 'bar']);
// @ts-ignore
const actualReturnValue = await client.canFind(reqTypes);
expect(actualReturnValue).toBe(expectedReturnValue);
expect(baseClient.canFind).toHaveBeenCalledWith(reqTypes);
});
});
describe('#create', () => {
test(`throws error if options.namespace is specified`, async () => {
const request = createMockRequest({ id: currentSpace.id });
@ -418,6 +498,45 @@ const createMockClient = () => {
});
});
describe('#canBulkCreate', () => {
test('throws error if types contains space', async () => {
const request = createMockRequest({ id: currentSpace.id });
const baseClient = createMockClient();
const spacesService = createSpacesService(server);
const client = new SpacesSavedObjectsClient({
request,
baseClient,
spacesService,
types,
});
await expect(client.canBulkCreate(['foo', 'space'])).rejects.toThrowErrorMatchingSnapshot();
});
test('supplements options', async () => {
const request = createMockRequest({ id: currentSpace.id });
const baseClient = createMockClient();
const expectedReturnValue = Symbol();
baseClient.canBulkCreate.mockReturnValue(expectedReturnValue);
const spacesService = createSpacesService(server);
const client = new SpacesSavedObjectsClient({
request,
baseClient,
spacesService,
types,
});
const reqTypes = Object.freeze(['foo']);
// @ts-ignore
const actualReturnValue = await client.canBulkCreate(reqTypes);
expect(actualReturnValue).toBe(expectedReturnValue);
expect(baseClient.canBulkCreate).toHaveBeenCalledWith(reqTypes);
});
});
describe('#update', () => {
test(`throws error if options.namespace is specified`, async () => {
const request = createMockRequest({ id: currentSpace.id });