Skip to content
This repository has been archived by the owner on Dec 6, 2024. It is now read-only.

Commit

Permalink
test: Integration tests for workspace-types-configuration (#340)
Browse files Browse the repository at this point in the history
* 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
3 people authored Feb 23, 2021
1 parent 03d6104 commit f5e2c3a
Show file tree
Hide file tree
Showing 12 changed files with 879 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ describe('Approve workspace-type scenarios', () => {
});
});

it('should fail if input schema is not valid', async () => {
it('should fail if input is not valid', async () => {
const workspaceTypeId = setup.gen.string({ prefix: 'workspace-test' });

await adminSession.resources.workspaceTypes.create({
Expand Down
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);
});
});
});
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);
});
});
Loading

0 comments on commit f5e2c3a

Please sign in to comment.