"use strict";
/*
 *  Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
 *  SPDX-License-Identifier: Apache-2.0
 */
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const accountHelper_1 = require("../../support/complex/accountHelper");
const setup_1 = __importDefault(require("../../support/setup"));
const randomTextGenerator_1 = __importDefault(require("../../support/utils/randomTextGenerator"));
describe('multiStep awsAccount integration test', () => {
    const setup = setup_1.default.getSetup();
    const settings = setup.getSettings();
    let adminSession;
    beforeAll(async () => {
        adminSession = await setup.getDefaultAdminSession();
    });
    afterAll(async () => {
        await setup.cleanup();
    });
    test('it works', async () => {
        if (settings.optional('awsAccountId', undefined) !== undefined) {
            const stackName = setup.getStackName();
            const randomTextGenerator = new randomTextGenerator_1.default(setup.getSettings().get('runId'));
            const awsAccountIdToUse = settings.get('awsAccountId');
            const createAccountParams = {
                hostingAccountHandlerRoleArn: `arn:aws:iam::${awsAccountIdToUse}:role/${stackName}-hosting-account-role`,
                awsAccountId: awsAccountIdToUse,
                envMgmtRoleArn: `arn:aws:iam::${awsAccountIdToUse}:role/${stackName}-env-mgmt`,
                name: randomTextGenerator.getFakeText('fakeName'),
                externalId: 'workbench'
            };
            const createResponse = await adminSession.resources.accounts.create(createAccountParams, false);
            expect(createResponse.status).toEqual(201);
            const accountId = createResponse.data.id;
            expect(accountId).toBeTruthy();
            const accountHelper = new accountHelper_1.AccountHelper();
            const doesBusAllowAccount = await accountHelper.verifyBusAllowsAccount(createAccountParams.awsAccountId);
            expect(doesBusAllowAccount).toBe(true);
            const hostingAccountTemplateResponse = await adminSession.resources.accounts.getHostingAccountTemplate(accountId);
            expect(hostingAccountTemplateResponse.status).toEqual(200);
            expect(Object.keys(hostingAccountTemplateResponse.data).length).toEqual(3); // Should get three sets of template URLs
            const listResponse = await adminSession.resources.accounts.get({ pageSize: `100` });
            expect(listResponse.status).toEqual(200);
            expect(listResponse.data.data.some((item) => item.id === accountId)).toBe(true);
            const getResponse = await adminSession.resources.accounts.account(accountId).get();
            expect(getResponse.status).toEqual(200);
            expect(getResponse.data.id).toEqual(accountId);
            const dateString = new Date().toISOString().replace(/:/g, '');
            const name = `integrationTest${dateString}`;
            const updateResponse = await adminSession.resources.accounts.account(accountId).update({ name }, true);
            expect(updateResponse.status).toEqual(200);
            expect(updateResponse.data.name).toEqual(name);
        }
    });
});
//# sourceMappingURL=awsAccount.test.js.map