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

Commit

Permalink
test: step template integration tests (#338)
Browse files Browse the repository at this point in the history
* feat: add support for project id when a researcher session si created

* fix: typo in the default value

* feat: framework update - implement default clean up logic

* Trigger notification

* fix: typo

* fix: use this.childType instead of this.type when inserting a cleanup task

* feat: aws apis foundational classes

* chore: Trigger notification

* chore: address the PR comments

* chore: add - to the check of runId

* chore: address PR comment and add '-' to the runId check

* fix: typo

* test: step-template integration tests

Co-authored-by: Hatim Khan <hatimk@amazon.com>
  • Loading branch information
hatimkhan and Hatim Khan authored Feb 23, 2021
1 parent ae4d4e1 commit aee44fb
Show file tree
Hide file tree
Showing 9 changed files with 609 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
/*
* 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 a step templates version scenarios', () => {
let setup;
let adminSession;
let templateId;

beforeAll(async () => {
setup = await runSetup();
adminSession = await setup.defaultAdminSession();
templateId = setup.gen.defaultStepTemplateId();
});

afterAll(async () => {
await setup.cleanup();
});

describe('Getting a step template version data', () => {
it('should fail for anonymous user', async () => {
const anonymousSession = await setup.createAnonymousSession();
await expect(
anonymousSession.resources.stepTemplates
.versions(templateId)
.version(1)
.get(),
).rejects.toMatchObject({
code: errorCode.http.code.badImplementation,
});
});

it('should fail for inactive user', async () => {
const researcherSession = await setup.createResearcherSession();
await adminSession.resources.users.deactivateUser(researcherSession.user);

await expect(
researcherSession.resources.stepTemplates
.versions(templateId)
.version(1)
.get(),
).rejects.toMatchObject({
code: errorCode.http.code.unauthorized,
});
});

it('should fail for internal guest', async () => {
const guestSession = await setup.createUserSession({ userRole: 'internal-guest', projectId: [] });
await expect(
guestSession.resources.stepTemplates
.versions(templateId)
.version(1)
.get(),
).rejects.toMatchObject({
code: errorCode.http.code.forbidden,
});
});

it('should fail if external guest', async () => {
const guestSession = await setup.createUserSession({ userRole: 'guest', projectId: [] });
await expect(
guestSession.resources.stepTemplates
.versions(templateId)
.version(1)
.get(),
).rejects.toMatchObject({
code: errorCode.http.code.forbidden,
});
});

it('should fail if researcher', async () => {
const researcherSession = await setup.createResearcherSession();
await expect(
researcherSession.resources.stepTemplates
.versions(templateId)
.version(1)
.get(),
).rejects.toMatchObject({
code: errorCode.http.code.forbidden,
});
});

it('should return the step template if admin', async () => {
await expect(
adminSession.resources.stepTemplates
.versions(templateId)
.version(1)
.get(),
).resolves.toHaveProperty('v', 1);
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
/*
* 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 step templates versions scenarios', () => {
let setup;
let adminSession;
let templateId;

beforeAll(async () => {
setup = await runSetup();
adminSession = await setup.defaultAdminSession();
templateId = setup.gen.defaultStepTemplateId();
});

afterAll(async () => {
await setup.cleanup();
});

describe('Getting step template versions', () => {
it('should fail for anonymous user', async () => {
const anonymousSession = await setup.createAnonymousSession();
await expect(anonymousSession.resources.stepTemplates.versions(templateId).get()).rejects.toMatchObject({
code: errorCode.http.code.badImplementation,
});
});

it('should fail for inactive user', async () => {
const researcherSession = await setup.createResearcherSession();
await adminSession.resources.users.deactivateUser(researcherSession.user);

await expect(researcherSession.resources.stepTemplates.versions(templateId).get()).rejects.toMatchObject({
code: errorCode.http.code.unauthorized,
});
});

it('should fail for internal guest', async () => {
const guestSession = await setup.createUserSession({ userRole: 'internal-guest', projectId: [] });
await expect(guestSession.resources.stepTemplates.versions(templateId).get()).rejects.toMatchObject({
code: errorCode.http.code.forbidden,
});
});

it('should fail if external guest', async () => {
const guestSession = await setup.createUserSession({ userRole: 'guest', projectId: [] });
await expect(guestSession.resources.stepTemplates.versions(templateId).get()).rejects.toMatchObject({
code: errorCode.http.code.forbidden,
});
});

it('should fail if researcher', async () => {
const researcherSession = await setup.createResearcherSession();
await expect(researcherSession.resources.stepTemplates.versions(templateId).get()).rejects.toMatchObject({
code: errorCode.http.code.forbidden,
});
});

it('should return step templates if admin', async () => {
await expect(adminSession.resources.stepTemplates.versions(templateId).get()).resolves.not.toHaveLength(0);
});
});

describe('Getting latest step template version', () => {
it('should fail for anonymous user', async () => {
const anonymousSession = await setup.createAnonymousSession();
await expect(anonymousSession.resources.stepTemplates.versions(templateId).latest()).rejects.toMatchObject({
code: errorCode.http.code.badImplementation,
});
});

it('should fail for inactive user', async () => {
const researcherSession = await setup.createResearcherSession();
await adminSession.resources.users.deactivateUser(researcherSession.user);

await expect(researcherSession.resources.stepTemplates.versions(templateId).latest()).rejects.toMatchObject({
code: errorCode.http.code.unauthorized,
});
});

it('should fail for internal guest', async () => {
const guestSession = await setup.createUserSession({ userRole: 'internal-guest', projectId: [] });
await expect(guestSession.resources.stepTemplates.versions(templateId).latest()).rejects.toMatchObject({
code: errorCode.http.code.forbidden,
});
});

it('should fail if external guest', async () => {
const guestSession = await setup.createUserSession({ userRole: 'guest', projectId: [] });
await expect(guestSession.resources.stepTemplates.versions(templateId).latest()).rejects.toMatchObject({
code: errorCode.http.code.forbidden,
});
});

it('should fail if researcher', async () => {
const researcherSession = await setup.createResearcherSession();
await expect(researcherSession.resources.stepTemplates.versions(templateId).latest()).rejects.toMatchObject({
code: errorCode.http.code.forbidden,
});
});

it('should return step templates if admin', async () => {
await expect(adminSession.resources.stepTemplates.versions(templateId).latest()).resolves.toHaveProperty(
'id',
templateId,
);
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
/*
* 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 step templates scenarios', () => {
let setup;
let adminSession;

beforeAll(async () => {
setup = await runSetup();
adminSession = await setup.defaultAdminSession();
});

afterAll(async () => {
await setup.cleanup();
});

describe('Getting step templates', () => {
it('should fail for anonymous user', async () => {
const anonymousSession = await setup.createAnonymousSession();
await expect(anonymousSession.resources.stepTemplates.get()).rejects.toMatchObject({
code: errorCode.http.code.badImplementation,
});
});

it('should fail for inactive user', async () => {
const researcherSession = await setup.createResearcherSession();
await adminSession.resources.users.deactivateUser(researcherSession.user);

await expect(researcherSession.resources.stepTemplates.get()).rejects.toMatchObject({
code: errorCode.http.code.unauthorized,
});
});

it('should fail for internal guest', async () => {
const guestSession = await setup.createUserSession({ userRole: 'internal-guest', projectId: [] });
await expect(guestSession.resources.stepTemplates.get()).rejects.toMatchObject({
code: errorCode.http.code.forbidden,
});
});

it('should fail if external guest', async () => {
const guestSession = await setup.createUserSession({ userRole: 'guest', projectId: [] });
await expect(guestSession.resources.stepTemplates.get()).rejects.toMatchObject({
code: errorCode.http.code.forbidden,
});
});

it('should fail if researcher', async () => {
const researcherSession = await setup.createResearcherSession();
await expect(researcherSession.resources.stepTemplates.get()).rejects.toMatchObject({
code: errorCode.http.code.forbidden,
});
});

it('should return step templates if admin', async () => {
await expect(adminSession.resources.stepTemplates.get()).resolves.not.toHaveLength(0);
});
});

describe('Getting latest step templates', () => {
it('should fail for anonymous user', async () => {
const anonymousSession = await setup.createAnonymousSession();
await expect(anonymousSession.resources.stepTemplates.latest()).rejects.toMatchObject({
code: errorCode.http.code.badImplementation,
});
});

it('should fail for inactive user', async () => {
const researcherSession = await setup.createResearcherSession();
await adminSession.resources.users.deactivateUser(researcherSession.user);

await expect(researcherSession.resources.stepTemplates.latest()).rejects.toMatchObject({
code: errorCode.http.code.unauthorized,
});
});

it('should fail for internal guest', async () => {
const guestSession = await setup.createUserSession({ userRole: 'internal-guest', projectId: [] });
await expect(guestSession.resources.stepTemplates.latest()).rejects.toMatchObject({
code: errorCode.http.code.forbidden,
});
});

it('should fail if external guest', async () => {
const guestSession = await setup.createUserSession({ userRole: 'guest', projectId: [] });
await expect(guestSession.resources.stepTemplates.latest()).rejects.toMatchObject({
code: errorCode.http.code.forbidden,
});
});

it('should fail if researcher', async () => {
const researcherSession = await setup.createResearcherSession();
await expect(researcherSession.resources.stepTemplates.latest()).rejects.toMatchObject({
code: errorCode.http.code.forbidden,
});
});

it('should return step templates if admin', async () => {
await expect(adminSession.resources.stepTemplates.latest()).resolves.not.toHaveLength(0);
});
});
});
Loading

0 comments on commit aee44fb

Please sign in to comment.