"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 workbench_core_base_1 = require("@aws/workbench-core-base");
const paabHelper_1 = require("../../../support/complex/paabHelper");
const HttpError_1 = __importDefault(require("../../../support/utils/HttpError"));
const utilities_1 = require("../../../support/utils/utilities");
describe('List Project negative tests', () => {
    const paabHelper = new paabHelper_1.PaabHelper();
    let adminSession;
    let paSession;
    let researcherSession;
    let anonymousSession;
    beforeEach(async () => {
        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();
    });
    describe('with filter', () => {
        describe('with name that is empty', () => {
            beforeEach(async () => { });
            test('it throws 400 error', async () => {
                try {
                    await adminSession.resources.projects.get({
                        filter: { name: { eq: '' } }
                    });
                }
                catch (e) {
                    (0, utilities_1.checkHttpError)(e, new HttpError_1.default(400, {
                        error: 'Bad Request',
                        message: `filter.name.eq: ${workbench_core_base_1.nonEmptyMessage}`
                    }));
                }
            });
        });
        describe('with createdAt', () => {
            beforeEach(async () => { });
            describe('with value1 > value2', () => {
                test('it throws 400 error', async () => {
                    try {
                        await adminSession.resources.projects.get({
                            filter: {
                                createdAt: {
                                    between: {
                                        value1: '2023-05-14T07:23:39.311Z',
                                        value2: '2023-05-11T07:23:39.311Z'
                                    }
                                }
                            }
                        });
                    }
                    catch (e) {
                        (0, utilities_1.checkHttpError)(e, new HttpError_1.default(400, {
                            error: 'Bad Request',
                            message: `filter.createdAt.between: ${workbench_core_base_1.betweenFilterMessage}`
                        }));
                    }
                });
            });
        });
    });
    describe('with invalid paginationToken', () => {
        const pagToken = '1';
        const queryParams = { paginationToken: pagToken };
        describe('as IT Admin', () => {
            test('it throws 400 error', async () => {
                try {
                    await adminSession.resources.projects.get(queryParams);
                }
                catch (e) {
                    (0, utilities_1.checkHttpError)(e, new HttpError_1.default(400, {
                        error: 'Bad Request',
                        message: `Invalid Pagination Token: ${queryParams.paginationToken}`
                    }));
                }
            });
        });
        const testBundle = [
            {
                username: 'projectAdmin',
                session: () => paSession
            },
            {
                username: 'researcher',
                session: () => researcherSession
            }
        ];
        describe.each(testBundle)('for each user', (testCase) => {
            const { username, session: sessionFunc } = testCase;
            let session;
            beforeEach(async () => {
                session = sessionFunc();
            });
            test(`it throws 400 error as ${username}`, async () => {
                try {
                    await session.resources.projects.get(queryParams);
                }
                catch (e) {
                    (0, utilities_1.checkHttpError)(e, new HttpError_1.default(400, {
                        error: 'Bad Request',
                        message: `Invalid Pagination Token: ${queryParams.paginationToken}`
                    }));
                }
            });
        });
        test('Unauthenticated user gets 401', async () => {
            try {
                await anonymousSession.resources.projects.get();
            }
            catch (e) {
                (0, utilities_1.checkHttpError)(e, new HttpError_1.default(401, {}));
            }
        });
    });
});
//# sourceMappingURL=list.test.js.map