"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 paabHelper_1 = require("../../../support/complex/paabHelper");
const HttpError_1 = __importDefault(require("../../../support/utils/HttpError"));
const utilities_1 = require("../../../support/utils/utilities");
describe('list users negative tests', () => {
    const paabHelper = new paabHelper_1.PaabHelper(1);
    let adminSession;
    let pa1Session;
    let rs1Session;
    let anonymousSession;
    beforeEach(() => {
        expect.hasAssertions();
    });
    beforeAll(async () => {
        ({ adminSession, pa1Session, rs1Session, anonymousSession } = await paabHelper.createResources(__filename));
    });
    afterAll(async () => {
        await paabHelper.cleanup();
    });
    describe('with invalid parameters', () => {
        describe('--non encoded pagination token', () => {
            const paginationToken = 'invalidPaginationToken123';
            const queryParams = { paginationToken };
            test('it throws 400 error', async () => {
                try {
                    await adminSession.resources.users.get(queryParams);
                }
                catch (e) {
                    (0, utilities_1.checkHttpError)(e, new HttpError_1.default(400, {
                        error: 'Bad Request',
                        message: 'Invalid parameter'
                    }));
                }
            });
        });
        describe('--non number page size', () => {
            const pageSize = 'one';
            const queryParams = { pageSize };
            test('it throws 400 error', async () => {
                try {
                    await adminSession.resources.users.get(queryParams);
                }
                catch (e) {
                    (0, utilities_1.checkHttpError)(e, new HttpError_1.default(400, {
                        error: 'Bad Request',
                        message: `pageSize: Must be a number`
                    }));
                }
            });
        });
        describe('--page size too small', () => {
            const pageSize = '0';
            const queryParams = { pageSize };
            test('it throws 400 error', async () => {
                try {
                    await adminSession.resources.users.get(queryParams);
                }
                catch (e) {
                    (0, utilities_1.checkHttpError)(e, new HttpError_1.default(400, {
                        error: 'Bad Request',
                        message: `pageSize: Must be Between 1 and 100`
                    }));
                }
            });
        });
        describe('--page size too large', () => {
            const pageSize = '110';
            const queryParams = { pageSize };
            test('it throws 400 error', async () => {
                try {
                    await adminSession.resources.users.get(queryParams);
                }
                catch (e) {
                    (0, utilities_1.checkHttpError)(e, new HttpError_1.default(400, {
                        error: 'Bad Request',
                        message: `pageSize: Must be Between 1 and 100`
                    }));
                }
            });
        });
    });
    describe('boundary tests', () => {
        test('cannot list users if user is a researcher', async () => {
            try {
                await rs1Session.resources.users.get();
            }
            catch (e) {
                (0, utilities_1.checkHttpError)(e, new HttpError_1.default(403, {
                    error: 'User is not authorized'
                }));
            }
        });
        test('cannot list users if user is unauthenticated', async () => {
            try {
                await anonymousSession.resources.users.get();
            }
            catch (e) {
                (0, utilities_1.checkHttpError)(e, new HttpError_1.default(401, {}));
            }
        });
        test('can list users if user is a ITAdmin', async () => {
            await expect(adminSession.resources.users.get()).resolves.not.toThrow();
        });
        test('can list users if user is a project admin', async () => {
            await expect(pa1Session.resources.users.get()).resolves.not.toThrow();
        });
    });
});
//# sourceMappingURL=listUsers.test.js.map