This repository has been archived by the owner on Dec 6, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: Integration tests for workspace-types-configuration (#340)
* Integration test for update api of workspace-types * test: Integration test for update api of workspace-types * Remove erroneously added update method Instead of adding an update in WorkspaceTypes collection the correct way of doing the update is to invoke the update in the singular WorkspaceType * test: implemented additional workspace-types apis Only remaining API is delete, which is pending on work that needs to be done at the parent resource level. * Applied code review feedback Ensured for the positive test cases we have workspaces in the databases. * test: Int tests for workspace-types-configuration Also includes test for delete-workspace , and typo fixes. * Applied code review feedback Co-authored-by: Eyor Alemayehu <eyor@amazon.com> Co-authored-by: Yanyu Zheng <yz2690@columbia.edu>
- Loading branch information
1 parent
03d6104
commit f5e2c3a
Showing
12 changed files
with
879 additions
and
4 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
142 changes: 142 additions & 0 deletions
142
...tion-tests/__test__/api-tests/workspace-types/configurations/create-configuration.test.js
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,142 @@ | ||
/* | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this file except in compliance with the License. | ||
* A copy of the License is located at | ||
* | ||
* http://aws.amazon.com/apache2.0 | ||
* | ||
* or in the "license" file accompanying this file. This file is distributed | ||
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
* express or implied. See the License for the specific language governing | ||
* permissions and limitations under the License. | ||
*/ | ||
|
||
const { runSetup } = require('../../../../support/setup'); | ||
const errorCode = require('../../../../support/utils/error-code'); | ||
|
||
describe('Create configuration scenarios', () => { | ||
let setup; | ||
let adminSession; | ||
|
||
beforeAll(async () => { | ||
setup = await runSetup(); | ||
adminSession = await setup.defaultAdminSession(); | ||
}); | ||
|
||
afterAll(async () => { | ||
await setup.cleanup(); | ||
}); | ||
|
||
describe('Create configuration', () => { | ||
it('should fail if user is inactive', async () => { | ||
const adminSession2 = await setup.createAdminSession(); | ||
const workspaceTypeId = setup.gen.string({ prefix: 'workspace-test' }); | ||
|
||
await adminSession.resources.workspaceTypes.create({ | ||
id: workspaceTypeId, | ||
}); | ||
|
||
await adminSession.resources.users.deactivateUser(adminSession2.user); | ||
|
||
const configurationId = setup.gen.string({ prefix: 'configuration-test' }); | ||
|
||
await expect( | ||
adminSession2.resources.workspaceTypes | ||
.workspaceType(workspaceTypeId) | ||
.configurations() | ||
.create({ | ||
id: configurationId, | ||
}), | ||
).rejects.toMatchObject({ | ||
code: errorCode.http.code.unauthorized, | ||
}); | ||
}); | ||
|
||
it('should fail if user is not admin', async () => { | ||
const researcherSession = await setup.createResearcherSession(); | ||
const workspaceTypeId = setup.gen.string({ prefix: 'workspace-test' }); | ||
|
||
await adminSession.resources.workspaceTypes.create({ | ||
id: workspaceTypeId, | ||
}); | ||
|
||
const configurationId = setup.gen.string({ prefix: 'configuration-test' }); | ||
|
||
await expect( | ||
researcherSession.resources.workspaceTypes | ||
.workspaceType(workspaceTypeId) | ||
.configurations() | ||
.create({ | ||
id: configurationId, | ||
}), | ||
).rejects.toMatchObject({ | ||
code: errorCode.http.code.forbidden, | ||
}); | ||
}); | ||
|
||
it('should fail if user is anonymous', async () => { | ||
const anonymousSession = await setup.createAnonymousSession(); | ||
const workspaceTypeId = setup.gen.string({ prefix: 'workspace-test' }); | ||
|
||
await adminSession.resources.workspaceTypes.create({ | ||
id: workspaceTypeId, | ||
}); | ||
|
||
const configurationId = setup.gen.string({ prefix: 'configuration-test' }); | ||
|
||
await expect( | ||
anonymousSession.resources.workspaceTypes | ||
.workspaceType(workspaceTypeId) | ||
.configurations() | ||
.create({ | ||
id: configurationId, | ||
}), | ||
).rejects.toMatchObject({ | ||
code: errorCode.http.code.badImplementation, | ||
}); | ||
}); | ||
|
||
it('should fail if input is not valid', async () => { | ||
const workspaceTypeId = setup.gen.string({ prefix: 'workspace-test' }); | ||
|
||
await adminSession.resources.workspaceTypes.create({ | ||
id: workspaceTypeId, | ||
}); | ||
|
||
const configurationId = setup.gen.string({ prefix: 'configuration-test' }); | ||
|
||
await expect( | ||
adminSession.resources.workspaceTypes | ||
.workspaceType(workspaceTypeId) | ||
.configurations() | ||
.create({ | ||
id: configurationId, | ||
invalid: 'data', | ||
}), | ||
).rejects.toMatchObject({ | ||
code: errorCode.http.code.badRequest, | ||
}); | ||
}); | ||
|
||
it('should create if user is admin', async () => { | ||
const workspaceTypeId = setup.gen.string({ prefix: 'workspace-test' }); | ||
|
||
await adminSession.resources.workspaceTypes.create({ | ||
id: workspaceTypeId, | ||
}); | ||
|
||
const configurationId = setup.gen.string({ prefix: 'configuration-test' }); | ||
|
||
await expect( | ||
adminSession.resources.workspaceTypes | ||
.workspaceType(workspaceTypeId) | ||
.configurations() | ||
.create({ | ||
id: configurationId, | ||
}), | ||
).resolves.toHaveProperty('id', configurationId); | ||
}); | ||
}); | ||
}); |
151 changes: 151 additions & 0 deletions
151
...gration-tests/__test__/api-tests/workspace-types/configurations/get-configuration.test.js
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,151 @@ | ||
/* | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this file except in compliance with the License. | ||
* A copy of the License is located at | ||
* | ||
* http://aws.amazon.com/apache2.0 | ||
* | ||
* or in the "license" file accompanying this file. This file is distributed | ||
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
* express or implied. See the License for the specific language governing | ||
* permissions and limitations under the License. | ||
*/ | ||
|
||
const { runSetup } = require('../../../../support/setup'); | ||
const errorCode = require('../../../../support/utils/error-code'); | ||
|
||
describe('Get configuration scenarios', () => { | ||
let setup; | ||
let adminSession; | ||
|
||
beforeAll(async () => { | ||
setup = await runSetup(); | ||
adminSession = await setup.defaultAdminSession(); | ||
}); | ||
|
||
afterAll(async () => { | ||
await setup.cleanup(); | ||
}); | ||
|
||
describe('Get configuration', () => { | ||
it('should fail to get a configuration if user is inactive', async () => { | ||
const adminSession2 = await setup.createAdminSession(); | ||
const workspaceTypeId = setup.gen.string({ prefix: 'workspace-test' }); | ||
|
||
await adminSession.resources.workspaceTypes.create({ | ||
id: workspaceTypeId, | ||
}); | ||
|
||
const configurationId = setup.gen.string({ prefix: 'configuration-test' }); | ||
|
||
await adminSession.resources.workspaceTypes | ||
.workspaceType(workspaceTypeId) | ||
.configurations() | ||
.create({ | ||
id: configurationId, | ||
}); | ||
|
||
await adminSession.resources.users.deactivateUser(adminSession2.user); | ||
|
||
await expect( | ||
adminSession2.resources.workspaceTypes | ||
.workspaceType(workspaceTypeId) | ||
.configurations() | ||
.configuration(configurationId) | ||
.get(), | ||
).rejects.toMatchObject({ | ||
code: errorCode.http.code.unauthorized, | ||
}); | ||
}); | ||
}); | ||
|
||
it('should fail to get a configuration if user is anonymous', async () => { | ||
const anonymousSession = await setup.createAnonymousSession(); | ||
const workspaceTypeId = setup.gen.string({ prefix: 'workspace-test' }); | ||
|
||
await adminSession.resources.workspaceTypes.create({ | ||
id: workspaceTypeId, | ||
}); | ||
|
||
const configurationId = setup.gen.string({ prefix: 'configuration-test' }); | ||
|
||
await adminSession.resources.workspaceTypes | ||
.workspaceType(workspaceTypeId) | ||
.configurations() | ||
.create({ | ||
id: configurationId, | ||
}); | ||
|
||
await expect( | ||
anonymousSession.resources.workspaceTypes | ||
.workspaceType(workspaceTypeId) | ||
.configurations() | ||
.configuration(configurationId) | ||
.get(), | ||
).rejects.toMatchObject({ | ||
code: errorCode.http.code.badImplementation, | ||
}); | ||
}); | ||
|
||
it("should fail if user's role does not have access", async () => { | ||
const workspaceTypeId = setup.gen.string({ prefix: 'workspace-test' }); | ||
|
||
await adminSession.resources.workspaceTypes.create({ | ||
id: workspaceTypeId, | ||
status: 'approved', | ||
}); | ||
|
||
const configurationId = setup.gen.string({ prefix: 'configuration-test' }); | ||
|
||
await adminSession.resources.workspaceTypes | ||
.workspaceType(workspaceTypeId) | ||
.configurations() | ||
.create({ | ||
id: configurationId, | ||
denyRoleIds: ['researcher'], | ||
}); | ||
|
||
const researcherSession = await setup.createResearcherSession(); | ||
|
||
await expect( | ||
researcherSession.resources.workspaceTypes | ||
.workspaceType(workspaceTypeId) | ||
.configurations() | ||
.configuration(configurationId) | ||
.get(), | ||
).rejects.toMatchObject({ | ||
code: errorCode.http.code.notFound, | ||
}); | ||
}); | ||
|
||
it("should get a configuration if user's role has access", async () => { | ||
const workspaceTypeId = setup.gen.string({ prefix: 'workspace-test' }); | ||
|
||
await adminSession.resources.workspaceTypes.create({ | ||
id: workspaceTypeId, | ||
status: 'approved', | ||
}); | ||
|
||
const configurationId = setup.gen.string({ prefix: 'configuration-test' }); | ||
|
||
await adminSession.resources.workspaceTypes | ||
.workspaceType(workspaceTypeId) | ||
.configurations() | ||
.create({ | ||
id: configurationId, | ||
allowRoleIds: ['researcher'], | ||
}); | ||
|
||
const researcherSession = await setup.createResearcherSession(); | ||
|
||
await expect( | ||
researcherSession.resources.workspaceTypes | ||
.workspaceType(workspaceTypeId) | ||
.configurations() | ||
.configuration(configurationId) | ||
.get(), | ||
).resolves.toHaveProperty('id', configurationId); | ||
}); | ||
}); |
Oops, something went wrong.