"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const paabHelper_1 = require("../../../support/complex/paabHelper");
const setup_1 = __importDefault(require("../../../support/setup"));
const HttpError_1 = __importDefault(require("../../../support/utils/HttpError"));
const utilities_1 = require("../../../support/utils/utilities");
describe('get hosting account', () => {
    const setup = setup_1.default.getSetup();
    const paabHelper = new paabHelper_1.PaabHelper(1);
    let adminSession;
    let paSession;
    let researcherSession;
    let anonymousSession;
    let accountId;
    beforeEach(() => {
        expect.hasAssertions();
    });
    beforeAll(async () => {
        const paabResources = await paabHelper.createResources(__filename);
        adminSession = paabResources.adminSession;
        paSession = paabResources.pa1Session;
        researcherSession = paabResources.rs1Session;
        anonymousSession = paabResources.anonymousSession;
        accountId = setup.getSettings().get('defaultHostingAccountId');
    });
    afterAll(async () => {
        await paabHelper.cleanup();
        await setup.cleanup();
    });
    describe('with valid accountId', () => {
        describe('as IT Admin', () => {
            test('it returns account information', async () => {
                await expect(adminSession.resources.accounts.account(accountId).get()).resolves.not.toThrow();
            });
        });
    });
    describe('Project admin or researcher can not get aws Account', () => {
        describe('As project admin', () => {
            test('it throws 403 error', async () => {
                try {
                    await paSession.resources.accounts.account(accountId).get();
                }
                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).get();
                }
                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).get();
                }
                catch (e) {
                    (0, utilities_1.checkHttpError)(e, new HttpError_1.default(401, {}));
                }
            });
        });
    });
});
//# sourceMappingURL=get.test.js.map