forked from opensearch-project/OpenSearch-Dashboards
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Backport workspace]Patch/first pr (opensearch-project#194) (opensear…
…ch-project#196) * Patch/first pr (opensearch-project#194) * temp: add unit test Signed-off-by: SuZhou-Joe <[email protected]> * feat: add function test for workspace CRUD routes Signed-off-by: SuZhou-Joe <[email protected]> * feat: use saved objects client instead of internal repository Signed-off-by: SuZhou-Joe <[email protected]> * feat: update CHANGELOG Signed-off-by: SuZhou-Joe <[email protected]> * feat: exclude permission check wrapper Signed-off-by: SuZhou-Joe <[email protected]> * feat: add integration test Signed-off-by: SuZhou-Joe <[email protected]> * feat: add configuration Signed-off-by: SuZhou-Joe <[email protected]> * feat: enable workspace flag when run workspace related test Signed-off-by: SuZhou-Joe <[email protected]> --------- Signed-off-by: SuZhou-Joe <[email protected]> * feat: update test Signed-off-by: SuZhou-Joe <[email protected]> * feat: change to equal 3 Signed-off-by: SuZhou-Joe <[email protected]> * feat: test Signed-off-by: SuZhou-Joe <[email protected]> * feat: make permissions field optional Signed-off-by: SuZhou-Joe <[email protected]> * fix: make permissions as optional params Signed-off-by: SuZhou-Joe <[email protected]> * fix: make permissions params optional Signed-off-by: SuZhou-Joe <[email protected]> --------- Signed-off-by: SuZhou-Joe <[email protected]>
- Loading branch information
1 parent
8132e14
commit cef4ce7
Showing
6 changed files
with
310 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
150 changes: 150 additions & 0 deletions
150
src/plugins/workspace/server/integration_tests/routes.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { WorkspaceAttribute } from 'src/core/types'; | ||
import { omit } from 'lodash'; | ||
import * as osdTestServer from '../../../../core/test_helpers/osd_server'; | ||
import { WorkspaceRoutePermissionItem } from '../types'; | ||
import { WorkspacePermissionMode } from '../../../../core/server'; | ||
|
||
const testWorkspace: WorkspaceAttribute & { | ||
permissions: WorkspaceRoutePermissionItem; | ||
} = { | ||
id: 'fake_id', | ||
name: 'test_workspace', | ||
description: 'test_workspace_description', | ||
}; | ||
|
||
describe('workspace service', () => { | ||
let root: ReturnType<typeof osdTestServer.createRoot>; | ||
let opensearchServer: osdTestServer.TestOpenSearchUtils; | ||
beforeAll(async () => { | ||
const { startOpenSearch, startOpenSearchDashboards } = osdTestServer.createTestServers({ | ||
adjustTimeout: (t: number) => jest.setTimeout(t), | ||
settings: { | ||
osd: { | ||
workspace: { | ||
enabled: true, | ||
}, | ||
}, | ||
}, | ||
}); | ||
opensearchServer = await startOpenSearch(); | ||
const startOSDResp = await startOpenSearchDashboards(); | ||
root = startOSDResp.root; | ||
}, 30000); | ||
afterAll(async () => { | ||
await root.shutdown(); | ||
await opensearchServer.stop(); | ||
}); | ||
describe('Workspace CRUD apis', () => { | ||
afterEach(async () => { | ||
const listResult = await osdTestServer.request | ||
.post(root, `/api/workspaces/_list`) | ||
.send({ | ||
page: 1, | ||
}) | ||
.expect(200); | ||
await Promise.all( | ||
listResult.body.result.workspaces.map((item: WorkspaceAttribute) => | ||
osdTestServer.request.delete(root, `/api/workspaces/${item.id}`).expect(200) | ||
) | ||
); | ||
}); | ||
it('create', async () => { | ||
await osdTestServer.request | ||
.post(root, `/api/workspaces`) | ||
.send({ | ||
attributes: testWorkspace, | ||
}) | ||
.expect(400); | ||
|
||
const result: any = await osdTestServer.request | ||
.post(root, `/api/workspaces`) | ||
.send({ | ||
attributes: omit(testWorkspace, 'id'), | ||
}) | ||
.expect(200); | ||
|
||
expect(result.body.success).toEqual(true); | ||
expect(typeof result.body.result.id).toBe('string'); | ||
}); | ||
it('get', async () => { | ||
const result = await osdTestServer.request | ||
.post(root, `/api/workspaces`) | ||
.send({ | ||
attributes: omit(testWorkspace, 'id'), | ||
}) | ||
.expect(200); | ||
|
||
const getResult = await osdTestServer.request.get( | ||
root, | ||
`/api/workspaces/${result.body.result.id}` | ||
); | ||
expect(getResult.body.result.name).toEqual(testWorkspace.name); | ||
}); | ||
it('update', async () => { | ||
const result: any = await osdTestServer.request | ||
.post(root, `/api/workspaces`) | ||
.send({ | ||
attributes: omit(testWorkspace, 'id'), | ||
}) | ||
.expect(200); | ||
|
||
await osdTestServer.request | ||
.put(root, `/api/workspaces/${result.body.result.id}`) | ||
.send({ | ||
attributes: { | ||
...omit(testWorkspace, 'id'), | ||
name: 'updated', | ||
}, | ||
}) | ||
.expect(200); | ||
|
||
const getResult = await osdTestServer.request.get( | ||
root, | ||
`/api/workspaces/${result.body.result.id}` | ||
); | ||
|
||
expect(getResult.body.success).toEqual(true); | ||
expect(getResult.body.result.name).toEqual('updated'); | ||
}); | ||
it('delete', async () => { | ||
const result: any = await osdTestServer.request | ||
.post(root, `/api/workspaces`) | ||
.send({ | ||
attributes: omit(testWorkspace, 'id'), | ||
}) | ||
.expect(200); | ||
|
||
await osdTestServer.request | ||
.delete(root, `/api/workspaces/${result.body.result.id}`) | ||
.expect(200); | ||
|
||
const getResult = await osdTestServer.request.get( | ||
root, | ||
`/api/workspaces/${result.body.result.id}` | ||
); | ||
|
||
expect(getResult.body.success).toEqual(false); | ||
}); | ||
it('list', async () => { | ||
await osdTestServer.request | ||
.post(root, `/api/workspaces`) | ||
.send({ | ||
attributes: omit(testWorkspace, 'id'), | ||
}) | ||
.expect(200); | ||
|
||
const listResult = await osdTestServer.request | ||
.post(root, `/api/workspaces/_list`) | ||
.send({ | ||
page: 1, | ||
}) | ||
.expect(200); | ||
expect(listResult.body.result.total).toEqual(3); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import expect from '@osd/expect'; | ||
import { WorkspaceAttribute } from 'opensearch-dashboards/server'; | ||
import { omit } from 'lodash'; | ||
import { FtrProviderContext } from '../../ftr_provider_context'; | ||
|
||
const testWorkspace: WorkspaceAttribute = { | ||
id: 'fake_id', | ||
name: 'test_workspace', | ||
description: 'test_workspace_description', | ||
}; | ||
|
||
export default function ({ getService }: FtrProviderContext) { | ||
const supertest = getService('supertest'); | ||
|
||
describe('Workspace CRUD apis', () => { | ||
afterEach(async () => { | ||
const listResult = await supertest | ||
.post(`/api/workspaces/_list`) | ||
.send({ | ||
page: 1, | ||
}) | ||
.set('osd-xsrf', 'opensearch-dashboards') | ||
.expect(200); | ||
await Promise.all( | ||
listResult.body.result.workspaces.map((item: WorkspaceAttribute) => | ||
supertest | ||
.delete(`/api/workspaces/${item.id}`) | ||
.set('osd-xsrf', 'opensearch-dashboards') | ||
.expect(200) | ||
) | ||
); | ||
}); | ||
it('create', async () => { | ||
await supertest | ||
.post(`/api/workspaces`) | ||
.send({ | ||
attributes: testWorkspace, | ||
}) | ||
.set('osd-xsrf', 'opensearch-dashboards') | ||
.expect(400); | ||
|
||
const result: any = await supertest | ||
.post(`/api/workspaces`) | ||
.send({ | ||
attributes: omit(testWorkspace, 'id'), | ||
}) | ||
.set('osd-xsrf', 'opensearch-dashboards') | ||
.expect(200); | ||
|
||
expect(result.body.success).equal(true); | ||
expect(result.body.result.id).to.be.a('string'); | ||
}); | ||
it('get', async () => { | ||
const result = await supertest | ||
.post(`/api/workspaces`) | ||
.send({ | ||
attributes: omit(testWorkspace, 'id'), | ||
}) | ||
.set('osd-xsrf', 'opensearch-dashboards') | ||
.expect(200); | ||
|
||
const getResult = await supertest.get(`/api/workspaces/${result.body.result.id}`); | ||
expect(getResult.body.result.name).equal(testWorkspace.name); | ||
}); | ||
it('update', async () => { | ||
const result: any = await supertest | ||
.post(`/api/workspaces`) | ||
.send({ | ||
attributes: omit(testWorkspace, 'id'), | ||
}) | ||
.set('osd-xsrf', 'opensearch-dashboards') | ||
.expect(200); | ||
|
||
await supertest | ||
.put(`/api/workspaces/${result.body.result.id}`) | ||
.send({ | ||
attributes: { | ||
...omit(testWorkspace, 'id'), | ||
name: 'updated', | ||
}, | ||
}) | ||
.set('osd-xsrf', 'opensearch-dashboards') | ||
.expect(200); | ||
|
||
const getResult = await supertest.get(`/api/workspaces/${result.body.result.id}`); | ||
|
||
expect(getResult.body.success).equal(true); | ||
expect(getResult.body.result.name).equal('updated'); | ||
}); | ||
it('delete', async () => { | ||
const result: any = await supertest | ||
.post(`/api/workspaces`) | ||
.send({ | ||
attributes: omit(testWorkspace, 'id'), | ||
}) | ||
.set('osd-xsrf', 'opensearch-dashboards') | ||
.expect(200); | ||
|
||
await supertest | ||
.delete(`/api/workspaces/${result.body.result.id}`) | ||
.set('osd-xsrf', 'opensearch-dashboards') | ||
.expect(200); | ||
|
||
const getResult = await supertest.get(`/api/workspaces/${result.body.result.id}`); | ||
|
||
expect(getResult.body.success).equal(false); | ||
}); | ||
it('list', async () => { | ||
await supertest | ||
.post(`/api/workspaces`) | ||
.send({ | ||
attributes: omit(testWorkspace, 'id'), | ||
}) | ||
.set('osd-xsrf', 'opensearch-dashboards') | ||
.expect(200); | ||
|
||
const listResult = await supertest | ||
.post(`/api/workspaces/_list`) | ||
.send({ | ||
page: 1, | ||
}) | ||
.set('osd-xsrf', 'opensearch-dashboards') | ||
.expect(200); | ||
expect(listResult.body.result.total).equal(1); | ||
}); | ||
}).tags('is:workspace'); | ||
} |