"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('awsAccounts update negative tests', () => {
    const paabHelper = new paabHelper_1.PaabHelper(1);
    let adminSession;
    let paSession;
    let researcherSession;
    let anonymousSession;
    let account;
    const accountId = `${workbench_core_base_1.resourceTypeToKey.account.toLowerCase()}-00000000-0000-0000-0000-000000000000`;
    beforeEach(() => {
        expect.hasAssertions();
        account = adminSession.resources.accounts.account(accountId);
    });
    beforeAll(async () => {
        const paabResources = await paabHelper.createResources(__filename);
        adminSession = paabResources.adminSession;
        paSession = paabResources.pa1Session;
        researcherSession = paabResources.rs1Session;
        anonymousSession = paabResources.anonymousSession;
    });
    afterAll(async () => {
        await paabHelper.cleanup();
    });
    describe('when updating an account', () => {
        describe('and the update params are invalid', () => {
            test('it throws a validation error', async () => {
                try {
                    const surpriseIntValue = 1;
                    await account.update({
                        name: surpriseIntValue
                    }, true);
                }
                catch (e) {
                    (0, utilities_1.checkHttpError)(e, new HttpError_1.default(400, {
                        error: 'Bad Request',
                        message: 'name: Expected string, received number'
                    }));
                }
            });
        });
    });
    describe('Project admin or researcher can not update aws Account', () => {
        describe('As project admin', () => {
            test('it throws 403 error', async () => {
                try {
                    await paSession.resources.accounts.account(accountId).update({ name: 'testName' }, true);
                }
                catch (e) {
                    (0, utilities_1.checkHttpError)(e, new HttpError_1.default(403, {
                        error: 'User is not authorized'
                    }));
                }
            });
        });
        describe('As researcher', () => {
            test('it throws 403 error', async () => {
                try {
                    await researcherSession.resources.accounts.account(accountId).update({ name: 'testName' }, true);
                }
                catch (e) {
                    (0, utilities_1.checkHttpError)(e, new HttpError_1.default(403, {
                        error: 'User is not authorized'
                    }));
                }
            });
        });
        describe('As unauthenticated user', () => {
            test('it throws 403 error', async () => {
                try {
                    await anonymousSession.resources.accounts.account(accountId).update({ name: 'testName' }, true);
                }
                catch (e) {
                    (0, utilities_1.checkHttpError)(e, new HttpError_1.default(403, {}));
                }
            });
        });
    });
});
//# sourceMappingURL=update.test.js.map