"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
/*
 *  Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
 *  SPDX-License-Identifier: Apache-2.0
 */
const workbench_core_base_1 = require("@aws/workbench-core-base");
const paabHelper_1 = require("../../../support/complex/paabHelper");
const HttpError_1 = __importDefault(require("../../../support/utils/HttpError"));
const utilities_1 = require("../../../support/utils/utilities");
describe('remove user from project negative tests', () => {
    const paabHelper = new paabHelper_1.PaabHelper(2);
    let adminSession;
    let pa1Session;
    let rs1Session;
    let anonymousSession;
    let project1Id;
    let project2Id;
    const forbiddenHttpError = new HttpError_1.default(403, { error: 'User is not authorized' });
    beforeEach(() => {
        expect.hasAssertions();
    });
    beforeAll(async () => {
        ({ adminSession, pa1Session, rs1Session, anonymousSession, project1Id, project2Id } =
            await paabHelper.createResources(__filename));
    });
    afterAll(async () => {
        await paabHelper.cleanup();
    });
    test('user does not exist', async () => {
        const fakeUserId = '00000000-0000-0000-0000-000000000000';
        try {
            await adminSession.resources.projects.project(project1Id).removeUserFromProject(fakeUserId);
        }
        catch (e) {
            (0, utilities_1.checkHttpError)(e, new HttpError_1.default(404, {
                error: 'Not Found',
                message: `Could not find user ${fakeUserId}`
            }));
        }
    });
    test('project does not exist', async () => {
        let adminUserId = '';
        const projectId = `${workbench_core_base_1.resourceTypeToKey.project.toLowerCase()}-00000000-0000-0000-0000-000000000000`;
        try {
            adminUserId = adminSession.getUserId();
            await adminSession.resources.projects.project(projectId).removeUserFromProject(adminUserId !== null && adminUserId !== void 0 ? adminUserId : '');
        }
        catch (e) {
            (0, utilities_1.checkHttpError)(e, new HttpError_1.default(404, {
                error: 'Not Found',
                message: `Could not find project ${projectId}`
            }));
        }
    });
    test('Project Admin passing in project it does not belong to gets 403', async () => {
        var _a;
        try {
            await pa1Session.resources.projects
                .project(project2Id)
                .removeUserFromProject((_a = rs1Session.getUserId()) !== null && _a !== void 0 ? _a : '');
        }
        catch (e) {
            (0, utilities_1.checkHttpError)(e, forbiddenHttpError);
        }
    });
    test('Researcher gets 403', async () => {
        var _a;
        try {
            await rs1Session.resources.projects
                .project(project1Id)
                .removeUserFromProject((_a = adminSession.getUserId()) !== null && _a !== void 0 ? _a : '');
        }
        catch (e) {
            (0, utilities_1.checkHttpError)(e, forbiddenHttpError);
        }
    });
    test('unauthenticated user gets 403', async () => {
        var _a;
        try {
            await anonymousSession.resources.projects
                .project(project1Id)
                .removeUserFromProject((_a = rs1Session.getUserId()) !== null && _a !== void 0 ? _a : '');
        }
        catch (e) {
            (0, utilities_1.checkHttpError)(e, new HttpError_1.default(403, {}));
        }
    });
});
//# sourceMappingURL=removeUserFromProject.test.js.map