"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('Delete Cost Center negative tests', () => {
    const setup = setup_1.default.getSetup();
    const paabHelper = new paabHelper_1.PaabHelper(1);
    let itAdminSession;
    let pa1Session;
    let researcherSession;
    let anonymousSession;
    const unauthorizedHttpError = new HttpError_1.default(403, { error: 'User is not authorized' });
    beforeEach(() => {
        expect.hasAssertions();
    });
    beforeAll(async () => {
        const paabResources = await paabHelper.createResources(__filename);
        itAdminSession = paabResources.adminSession;
        pa1Session = paabResources.pa1Session;
        researcherSession = paabResources.rs1Session;
        anonymousSession = paabResources.anonymousSession;
    });
    afterAll(async () => {
        await paabHelper.cleanup();
        await setup.cleanup();
    });
    describe('authorization test:', () => {
        let costCenterId;
        beforeEach(async () => {
            const accountId = setup.getSettings().get('defaultHostingAccountId');
            const { data: createdCostCenterA } = await itAdminSession.resources.costCenters.create({
                accountId,
                name: 'costCenterIntegTest'
            });
            costCenterId = createdCostCenterA.id;
        });
        afterEach(async () => {
            await itAdminSession.resources.costCenters.costCenter(costCenterId).delete();
        });
        test('ITAdmin can soft delete a Cost Center', async () => {
            const response = await itAdminSession.resources.costCenters.costCenter(costCenterId).delete();
            expect(response.status).toEqual(204);
        });
        test('ProjectAdmin cannot soft delete a CostCenter', async () => {
            await expect(pa1Session.resources.costCenters.costCenter(costCenterId).delete()).rejects.toThrow(unauthorizedHttpError);
        });
        test('Researcher cannot soft delete a CostCenter', async () => {
            await expect(researcherSession.resources.costCenters.costCenter(costCenterId).delete()).rejects.toThrow(unauthorizedHttpError);
        });
        test('Unauthenticated user cannot soft delete a CostCenter', async () => {
            await expect(anonymousSession.resources.costCenters.costCenter(costCenterId).delete()).rejects.toThrow(new HttpError_1.default(403, {}));
        });
    });
    describe('with Cost Center that does not exist', () => {
        test('it throw 404 error', async () => {
            const invalidId = 'cc-abcdabcd-2199-46be-ac89-751a90f1999e';
            try {
                await itAdminSession.resources.costCenters.costCenter(invalidId).delete();
            }
            catch (e) {
                (0, utilities_1.checkHttpError)(e, new HttpError_1.default(404, {
                    error: 'Not Found',
                    message: `Could not find cost center ${invalidId}`
                }));
            }
        });
    });
});
//# sourceMappingURL=softDelete.test.js.map