Skip to content

Commit

Permalink
adapt the FTR tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pgayvallet committed Jan 25, 2023
1 parent 63cafed commit f9f1e1f
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 82 deletions.
18 changes: 7 additions & 11 deletions x-pack/test/ftr_apis/security_and_spaces/apis/bulk_delete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { createTestSpaces, deleteTestSpaces, createData, deleteData } from './te
export default function (ftrContext: FtrProviderContext) {
const supertest = ftrContext.getService('supertestWithoutAuth');

describe('POST /internal/saved_objects_tagging/tags/_bulk_delete', () => {
describe('POST /internal/ftr/kbn_client_so/_bulk_delete', () => {
before(async () => {
await createTestSpaces(ftrContext);
});
Expand All @@ -35,7 +35,7 @@ export default function (ftrContext: FtrProviderContext) {
authorized: {
httpCode: 200,
expectResponse: ({ body }) => {
expect(body).to.eql({});
expect(body.statuses.length).to.eql(1);
},
},
unauthorized: {
Expand All @@ -44,19 +44,17 @@ export default function (ftrContext: FtrProviderContext) {
expect(body).to.eql({
statusCode: 403,
error: 'Forbidden',
message: 'Unable to delete tag',
message: 'Forbidden',
});
},
},
};

const expectedResults: Record<string, User[]> = {
authorized: [
USERS.SUPERUSER,
authorized: [USERS.SUPERUSER],
unauthorized: [
USERS.DEFAULT_SPACE_SO_MANAGEMENT_WRITE_USER,
USERS.DEFAULT_SPACE_SO_TAGGING_WRITE_USER,
],
unauthorized: [
USERS.DEFAULT_SPACE_READ_USER,
USERS.DEFAULT_SPACE_SO_TAGGING_READ_USER,
USERS.DEFAULT_SPACE_DASHBOARD_READ_USER,
Expand All @@ -72,10 +70,8 @@ export default function (ftrContext: FtrProviderContext) {
) => {
it(`returns expected ${httpCode} response for ${description ?? username}`, async () => {
await supertest
.post(`/internal/saved_objects_tagging/tags/_bulk_delete`)
.send({
ids: ['default-space-tag-1', 'default-space-tag-2'],
})
.post(`/internal/ftr/kbn_client_so/_bulk_delete`)
.send([{ type: 'tag', id: 'tag-1' }])
.auth(username, password)
.expect(httpCode)
.then(expectResponse);
Expand Down
31 changes: 14 additions & 17 deletions x-pack/test/ftr_apis/security_and_spaces/apis/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { createTestSpaces, deleteTestSpaces, createData, deleteData } from './te
export default function (ftrContext: FtrProviderContext) {
const supertest = ftrContext.getService('supertestWithoutAuth');

describe('POST /api/saved_objects_tagging/tags/create', () => {
describe('POST /internal/ftr/kbn_client_so/{type}', () => {
before(async () => {
await createTestSpaces(ftrContext);
});
Expand All @@ -35,13 +35,10 @@ export default function (ftrContext: FtrProviderContext) {
authorized: {
httpCode: 200,
expectResponse: ({ body }) => {
expect(body).to.eql({
tag: {
id: body.tag.id,
name: 'My new tag',
description: 'I just created that',
color: '#009000',
},
expect(body.attributes).to.eql({
name: 'My new tag',
description: 'I just created that',
color: '#009000',
});
},
},
Expand All @@ -51,19 +48,17 @@ export default function (ftrContext: FtrProviderContext) {
expect(body).to.eql({
statusCode: 403,
error: 'Forbidden',
message: 'Unable to create tag',
message: 'Forbidden',
});
},
},
};

const expectedResults: Record<string, User[]> = {
authorized: [
USERS.SUPERUSER,
authorized: [USERS.SUPERUSER],
unauthorized: [
USERS.DEFAULT_SPACE_SO_MANAGEMENT_WRITE_USER,
USERS.DEFAULT_SPACE_SO_TAGGING_WRITE_USER,
],
unauthorized: [
USERS.DEFAULT_SPACE_READ_USER,
USERS.DEFAULT_SPACE_SO_TAGGING_READ_USER,
USERS.DEFAULT_SPACE_DASHBOARD_READ_USER,
Expand All @@ -80,11 +75,13 @@ export default function (ftrContext: FtrProviderContext) {
) => {
it(`returns expected ${httpCode} response for ${description ?? username}`, async () => {
await supertest
.post(`/api/saved_objects_tagging/tags/create`)
.post(`/internal/ftr/kbn_client_so/tag`)
.send({
name: 'My new tag',
description: 'I just created that',
color: '#009000',
attributes: {
name: 'My new tag',
description: 'I just created that',
color: '#009000',
},
})
.auth(username, password)
.expect(httpCode)
Expand Down
12 changes: 5 additions & 7 deletions x-pack/test/ftr_apis/security_and_spaces/apis/delete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { createTestSpaces, deleteTestSpaces, createData, deleteData } from './te
export default function (ftrContext: FtrProviderContext) {
const supertest = ftrContext.getService('supertestWithoutAuth');

describe('DELETE /api/saved_objects_tagging/tags/{id}', () => {
describe('DELETE /internal/ftr/kbn_client_so/{type}/{id}', () => {
before(async () => {
await createTestSpaces(ftrContext);
});
Expand Down Expand Up @@ -44,19 +44,17 @@ export default function (ftrContext: FtrProviderContext) {
expect(body).to.eql({
statusCode: 403,
error: 'Forbidden',
message: 'Unable to delete tag',
message: 'Forbidden',
});
},
},
};

const expectedResults: Record<string, User[]> = {
authorized: [
USERS.SUPERUSER,
authorized: [USERS.SUPERUSER],
unauthorized: [
USERS.DEFAULT_SPACE_SO_MANAGEMENT_WRITE_USER,
USERS.DEFAULT_SPACE_SO_TAGGING_WRITE_USER,
],
unauthorized: [
USERS.DEFAULT_SPACE_READ_USER,
USERS.DEFAULT_SPACE_SO_TAGGING_READ_USER,
USERS.DEFAULT_SPACE_DASHBOARD_READ_USER,
Expand All @@ -73,7 +71,7 @@ export default function (ftrContext: FtrProviderContext) {
) => {
it(`returns expected ${httpCode} response for ${description ?? username}`, async () => {
await supertest
.delete(`/api/saved_objects_tagging/tags/default-space-tag-1`)
.delete(`/internal/ftr/kbn_client_so/visualization/vis-area-1`)
.auth(username, password)
.expect(httpCode)
.then(expectResponse);
Expand Down
38 changes: 9 additions & 29 deletions x-pack/test/ftr_apis/security_and_spaces/apis/find.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { createData, createTestSpaces, deleteData, deleteTestSpaces } from './te
export default function (ftrContext: FtrProviderContext) {
const supertest = ftrContext.getService('supertestWithoutAuth');

describe('GET /internal/saved_objects_tagging/tags/_find', () => {
describe('GET /internal/ftr/kbn_client_so/_find', () => {
before(async () => {
await createTestSpaces(ftrContext);
});
Expand All @@ -35,53 +35,33 @@ export default function (ftrContext: FtrProviderContext) {
authorized: {
httpCode: 200,
expectResponse: ({ body }) => {
expect(body).to.eql({
tags: [
{
id: 'default-space-tag-2',
name: 'tag-2',
description: 'Tag 2 in default space',
color: '#77CC11',
relationCount: 0,
},
],
total: 1,
});
},
},
noResults: {
httpCode: 200,
expectResponse: ({ body }) => {
expect(body).to.eql({
tags: [],
total: 0,
});
expect(body.saved_objects.length).to.be.greaterThan(0);
},
},
unauthorized: {
httpCode: 403,
expectResponse: ({ body }) => {
expect(body).to.eql({
error: 'Forbidden',
message: 'unauthorized',
message: 'Forbidden',
statusCode: 403,
});
},
},
};
const expectedResults: Record<string, User[]> = {
authorized: [
USERS.SUPERUSER,
authorized: [USERS.SUPERUSER],
unauthorized: [
USERS.DEFAULT_SPACE_READ_USER,
USERS.DEFAULT_SPACE_SO_MANAGEMENT_WRITE_USER,
USERS.DEFAULT_SPACE_SO_TAGGING_READ_USER,
USERS.DEFAULT_SPACE_SO_TAGGING_WRITE_USER,
USERS.DEFAULT_SPACE_DASHBOARD_READ_USER,
USERS.DEFAULT_SPACE_VISUALIZE_READ_USER,
USERS.DEFAULT_SPACE_MAPS_READ_USER,
USERS.DEFAULT_SPACE_ADVANCED_SETTINGS_READ_USER,
USERS.NOT_A_KIBANA_USER,
],
noResults: [USERS.DEFAULT_SPACE_ADVANCED_SETTINGS_READ_USER],
unauthorized: [USERS.NOT_A_KIBANA_USER],
};

const createUserTest = (
Expand All @@ -90,9 +70,9 @@ export default function (ftrContext: FtrProviderContext) {
) => {
it(`returns expected ${httpCode} response for ${description ?? username}`, async () => {
await supertest
.get(`/internal/saved_objects_tagging/tags/_find`)
.get(`/internal/ftr/kbn_client_so/_find`)
.query({
search: '2',
type: 'tag',
})
.auth(username, password)
.expect(httpCode)
Expand Down
25 changes: 7 additions & 18 deletions x-pack/test/ftr_apis/security_and_spaces/apis/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { createTestSpaces, deleteTestSpaces, createData, deleteData } from './te
export default function (ftrContext: FtrProviderContext) {
const supertest = ftrContext.getService('supertestWithoutAuth');

describe('POST /api/saved_objects_tagging/tags/{id}', () => {
describe('PUT /internal/ftr/kbn_client_so/{type}/{id}', () => {
before(async () => {
await createTestSpaces(ftrContext);
});
Expand All @@ -35,14 +35,7 @@ export default function (ftrContext: FtrProviderContext) {
authorized: {
httpCode: 200,
expectResponse: ({ body }) => {
expect(body).to.eql({
tag: {
id: body.tag.id,
name: 'Updated title',
description: 'I just updated that',
color: '#009000',
},
});
expect(body.attributes.name).to.eql('Updated title');
},
},
unauthorized: {
Expand All @@ -51,19 +44,17 @@ export default function (ftrContext: FtrProviderContext) {
expect(body).to.eql({
statusCode: 403,
error: 'Forbidden',
message: 'Unable to update tag',
message: 'Forbidden',
});
},
},
};

const expectedResults: Record<string, User[]> = {
authorized: [
USERS.SUPERUSER,
authorized: [USERS.SUPERUSER],
unauthorized: [
USERS.DEFAULT_SPACE_SO_MANAGEMENT_WRITE_USER,
USERS.DEFAULT_SPACE_SO_TAGGING_WRITE_USER,
],
unauthorized: [
USERS.DEFAULT_SPACE_READ_USER,
USERS.DEFAULT_SPACE_SO_TAGGING_READ_USER,
USERS.DEFAULT_SPACE_DASHBOARD_READ_USER,
Expand All @@ -80,11 +71,9 @@ export default function (ftrContext: FtrProviderContext) {
) => {
it(`returns expected ${httpCode} response for ${description ?? username}`, async () => {
await supertest
.post(`/api/saved_objects_tagging/tags/default-space-tag-1`)
.put(`/internal/ftr/kbn_client_so/tag/tag-1`)
.send({
name: 'Updated title',
description: 'I just updated that',
color: '#009000',
attributes: { name: 'Updated title' },
})
.auth(username, password)
.expect(httpCode)
Expand Down

0 comments on commit f9f1e1f

Please sign in to comment.