"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 lodash_1 = __importDefault(require("lodash"));
const paabHelper_1 = require("../../../support/complex/paabHelper");
const HttpError_1 = __importDefault(require("../../../support/utils/HttpError"));
const utilities_1 = require("../../../support/utils/utilities");
describe('awsAccountTemplateUrls tests', () => {
    const mockExternalId = 'workbench-integration-test';
    const paabHelper = new paabHelper_1.PaabHelper(1);
    let adminSession;
    let paSession;
    let researcherSession;
    let anonymousSession;
    beforeEach(() => {
        expect.hasAssertions();
    });
    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();
    });
    it('returns all six expected URLs when called.', async () => {
        const response = await adminSession.resources.accounts.getHostingAccountTemplate(mockExternalId);
        const urls = response.data;
        expect(urls).toBeDefined();
        const onboardUrls = lodash_1.default.get(urls, 'onboard-account');
        expect(onboardUrls.createUrl).toBeTruthy();
        expect(onboardUrls.updateUrl).toBeTruthy();
        const byonUrls = lodash_1.default.get(urls, 'onboard-account-byon');
        expect(byonUrls.createUrl).toBeTruthy();
        expect(byonUrls.updateUrl).toBeTruthy();
    });
    describe('As project admin', () => {
        test('it throws 403 error', async () => {
            try {
                await paSession.resources.accounts.getHostingAccountTemplate(mockExternalId);
            }
            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.getHostingAccountTemplate(mockExternalId);
                }
                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.getHostingAccountTemplate(mockExternalId);
            }
            catch (e) {
                (0, utilities_1.checkHttpError)(e, new HttpError_1.default(403, {}));
            }
        });
    });
});
//# sourceMappingURL=awsAccountTemplateUrls.test.js.map