"use strict";
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
Object.defineProperty(exports, "__esModule", { value: true });
const testHelper_1 = require("../../testHelper");
const projectionTestUtils_1 = require("../../Utilities/projectionTestUtils");
const TypeAttributeParam_1 = require("./TypeAttributeParam");
const ProjectionOMTestUtil_1 = require("./ProjectionOMTestUtil");
/**
 * A test class for testing the IncludeAttributes operation in a projection as well as SelectsSomeTakeNames in a resolution guidance
 */
describe('Cdm/Projection/ProjectionIncludeTest', () => {
    /**
     * All possible combinations of the different resolution directives
     */
    const resOptsCombinations = [
        [],
        ['referenceOnly'],
        ['normalized'],
        ['structured'],
        ['referenceOnly', 'normalized'],
        ['referenceOnly', 'structured'],
        ['normalized', 'structured'],
        ['referenceOnly', 'normalized', 'structured']
    ];
    /**
     * Path to foundations
     */
    const foundationJsonPath = 'cdm:/foundations.cdm.json';
    /**
     * The path between TestDataPath and TestName.
     */
    const testsSubpath = 'Cdm/Projection/ProjectionIncludeTest';
    /**
     * Test for entity extends with resolution guidance with a SelectsSomeTakeNames
     */
    it('TestExtends', () => __awaiter(void 0, void 0, void 0, function* () {
        const testName = 'TestExtends';
        const entityName = 'Color';
        const corpus = testHelper_1.testHelper.getLocalCorpus(testsSubpath, testName);
        for (const resOpt of resOptsCombinations) {
            yield projectionTestUtils_1.projectionTestUtils.loadEntityForResolutionOptionAndSave(corpus, testName, testsSubpath, entityName, resOpt);
        }
    }));
    /**
     * Test for entity extends with projection with an includeAttributes operation
     */
    it('TestExtendsProj', () => __awaiter(void 0, void 0, void 0, function* () {
        const testName = 'TestExtendsProj';
        const entityName = 'Color';
        const corpus = testHelper_1.testHelper.getLocalCorpus(testsSubpath, testName);
        for (const resOpt of resOptsCombinations) {
            yield projectionTestUtils_1.projectionTestUtils.loadEntityForResolutionOptionAndSave(corpus, testName, testsSubpath, entityName, resOpt);
        }
    }));
    /**
     * Test for entity attribute with resolution guidance with a SelectsSomeTakeNames
     */
    it('TestEA', () => __awaiter(void 0, void 0, void 0, function* () {
        const testName = 'TestEA';
        const entityName = 'Color';
        const corpus = testHelper_1.testHelper.getLocalCorpus(testsSubpath, testName);
        for (const resOpt of resOptsCombinations) {
            yield projectionTestUtils_1.projectionTestUtils.loadEntityForResolutionOptionAndSave(corpus, testName, testsSubpath, entityName, resOpt);
        }
    }));
    /**
     * Test for entity attribute with projection with an includeAttributes operation
     */
    it('TestEAProj', () => __awaiter(void 0, void 0, void 0, function* () {
        const testName = 'TestEAProj';
        const entityName = 'Color';
        const corpus = testHelper_1.testHelper.getLocalCorpus(testsSubpath, testName);
        for (const resOpt of resOptsCombinations) {
            yield projectionTestUtils_1.projectionTestUtils.loadEntityForResolutionOptionAndSave(corpus, testName, testsSubpath, entityName, resOpt);
        }
    }));
    /**
     * Test for object model
     */
    it('TestEAProjOM', () => __awaiter(void 0, void 0, void 0, function* () {
        const className = 'ProjectionIncludeTest';
        const testName = 'TestEAProjOM';
        const entityName_RGB = 'RGB';
        const attributeParams_RGB = [];
        attributeParams_RGB.push(new TypeAttributeParam_1.TypeAttributeParam('Red', 'string', 'hasA'));
        attributeParams_RGB.push(new TypeAttributeParam_1.TypeAttributeParam('Green', 'string', 'hasA'));
        attributeParams_RGB.push(new TypeAttributeParam_1.TypeAttributeParam('Blue', 'string', 'hasA'));
        attributeParams_RGB.push(new TypeAttributeParam_1.TypeAttributeParam('IsGrayscale', 'boolean', 'hasA'));
        const entityName_Color = 'Color';
        const attributeParams_Color = [];
        attributeParams_Color.push(new TypeAttributeParam_1.TypeAttributeParam('ColorName', 'string', 'identifiedBy'));
        const includeAttributeNames = [];
        includeAttributeNames.push('Red');
        includeAttributeNames.push('Green');
        includeAttributeNames.push('Blue');
        const util = new ProjectionOMTestUtil_1.ProjectionOMTestUtil(className, testName);
        const entity_RGB = util.CreateBasicEntity(entityName_RGB, attributeParams_RGB);
        util.validateBasicEntity(entity_RGB, entityName_RGB, attributeParams_RGB);
        const entity_Color = util.CreateBasicEntity(entityName_Color, attributeParams_Color);
        util.validateBasicEntity(entity_Color, entityName_Color, attributeParams_Color);
        const projection_RGBColor = util.createProjection(entity_RGB.entityName);
        const operation_IncludeAttributes = util.createOperationInputAttribute(projection_RGBColor, includeAttributeNames);
        const projectionEntityRef_RGBColor = util.createProjectionInlineEntityReference(projection_RGBColor);
        const entityAttribute_RGBColor = util.createEntityAttribute('RGBColor', projectionEntityRef_RGBColor);
        entity_Color.attributes.push(entityAttribute_RGBColor);
        for (const resOpts of resOptsCombinations) {
            yield util.getAndValidateResolvedEntity(entity_Color, resOpts);
        }
        util.defaultManifest.saveAsAsync(util.manifestDocName, true);
    }));
    /**
     * Test for leaf level projection
     */
    it('TestNested1of3Proj', () => __awaiter(void 0, void 0, void 0, function* () {
        const testName = 'TestNested1of3Proj';
        const entityName = 'Color';
        const corpus = testHelper_1.testHelper.getLocalCorpus(testsSubpath, testName);
        for (const resOpt of resOptsCombinations) {
            yield projectionTestUtils_1.projectionTestUtils.loadEntityForResolutionOptionAndSave(corpus, testName, testsSubpath, entityName, resOpt);
        }
    }));
    /**
     * Test for mid level projection
     */
    it('TestNested2of3Proj', () => __awaiter(void 0, void 0, void 0, function* () {
        const testName = 'TestNested2of3Proj';
        const entityName = 'Color';
        const corpus = testHelper_1.testHelper.getLocalCorpus(testsSubpath, testName);
        for (const resOpt of resOptsCombinations) {
            yield projectionTestUtils_1.projectionTestUtils.loadEntityForResolutionOptionAndSave(corpus, testName, testsSubpath, entityName, resOpt);
        }
    }));
    /**
     * Test for top level projection
     */
    it('TestNested3of3Proj', () => __awaiter(void 0, void 0, void 0, function* () {
        const testName = 'TestNested3of3Proj';
        const entityName = 'Color';
        const corpus = testHelper_1.testHelper.getLocalCorpus(testsSubpath, testName);
        for (const resOpt of resOptsCombinations) {
            yield projectionTestUtils_1.projectionTestUtils.loadEntityForResolutionOptionAndSave(corpus, testName, testsSubpath, entityName, resOpt);
        }
    }));
    /**
     * Test for Condition = 'false'
     */
    it('TestConditionProj', () => __awaiter(void 0, void 0, void 0, function* () {
        const testName = 'TestConditionProj';
        const entityName = 'Color';
        const corpus = testHelper_1.testHelper.getLocalCorpus(testsSubpath, testName);
        for (const resOpt of resOptsCombinations) {
            yield projectionTestUtils_1.projectionTestUtils.loadEntityForResolutionOptionAndSave(corpus, testName, testsSubpath, entityName, resOpt);
        }
    }));
    /**
     * Test for SelectsSomeTakeNames by Group Name
     */
    it('TestGroupName', () => __awaiter(void 0, void 0, void 0, function* () {
        const testName = 'TestGroupName';
        const entityName = 'Product';
        const corpus = testHelper_1.testHelper.getLocalCorpus(testsSubpath, testName);
        for (const resOpt of resOptsCombinations) {
            yield projectionTestUtils_1.projectionTestUtils.loadEntityForResolutionOptionAndSave(corpus, testName, testsSubpath, entityName, resOpt);
        }
    }));
    /**
     * Test for include attributes operation by Group Name
     */
    it('TestGroupNameProj', () => __awaiter(void 0, void 0, void 0, function* () {
        const testName = 'TestGroupNameProj';
        const entityName = 'Product';
        const corpus = testHelper_1.testHelper.getLocalCorpus(testsSubpath, testName);
        for (const resOpt of resOptsCombinations) {
            yield projectionTestUtils_1.projectionTestUtils.loadEntityForResolutionOptionAndSave(corpus, testName, testsSubpath, entityName, resOpt);
        }
    }));
    /**
     * Test for SelectsSomeTakeNames from an Array
     */
    it('TestArray', () => __awaiter(void 0, void 0, void 0, function* () {
        const testName = 'TestArray';
        const entityName = 'Sales';
        const corpus = testHelper_1.testHelper.getLocalCorpus(testsSubpath, testName);
        for (const resOpt of resOptsCombinations) {
            yield projectionTestUtils_1.projectionTestUtils.loadEntityForResolutionOptionAndSave(corpus, testName, testsSubpath, entityName, resOpt);
        }
    }));
    /**
     * Test for SelectsSomeTakeNames from a renamed Array
     */
    it('TestArrayRename', () => __awaiter(void 0, void 0, void 0, function* () {
        const testName = 'TestArrayRename';
        const entityName = 'Sales';
        const corpus = testHelper_1.testHelper.getLocalCorpus(testsSubpath, testName);
        for (const resOpt of resOptsCombinations) {
            yield projectionTestUtils_1.projectionTestUtils.loadEntityForResolutionOptionAndSave(corpus, testName, testsSubpath, entityName, resOpt);
        }
    }));
    /**
     * Test for Include Attributes from an Array
     */
    it('TestArrayProj', () => __awaiter(void 0, void 0, void 0, function* () {
        const testName = 'TestArrayProj';
        const entityName = 'Sales';
        const corpus = testHelper_1.testHelper.getLocalCorpus(testsSubpath, testName);
        for (const resOpt of resOptsCombinations) {
            yield projectionTestUtils_1.projectionTestUtils.loadEntityForResolutionOptionAndSave(corpus, testName, testsSubpath, entityName, resOpt);
        }
    }));
    /**
     * Test for SelectsSomeTakeNames from a Polymorphic Source
     */
    it('TestPolymorphic', () => __awaiter(void 0, void 0, void 0, function* () {
        const testName = 'TestPolymorphic';
        const entityName = 'Person';
        const corpus = testHelper_1.testHelper.getLocalCorpus(testsSubpath, testName);
        for (const resOpt of resOptsCombinations) {
            yield projectionTestUtils_1.projectionTestUtils.loadEntityForResolutionOptionAndSave(corpus, testName, testsSubpath, entityName, resOpt);
        }
    }));
    /**
     * Test for Include Attributes from a Polymorphic Source
     */
    it('TestPolymorphicProj', () => __awaiter(void 0, void 0, void 0, function* () {
        const testName = 'TestPolymorphicProj';
        const entityName = 'Person';
        const corpus = testHelper_1.testHelper.getLocalCorpus(testsSubpath, testName);
        for (const resOpt of resOptsCombinations) {
            yield projectionTestUtils_1.projectionTestUtils.loadEntityForResolutionOptionAndSave(corpus, testName, testsSubpath, entityName, resOpt);
        }
    }));
    /**
     * Test for Include Attributes from a Polymorphic Source
     */
    it('TestReorderProj', () => __awaiter(void 0, void 0, void 0, function* () {
        const testName = 'TestReorderProj';
        const entityName = 'NewPerson';
        const corpus = testHelper_1.testHelper.getLocalCorpus(testsSubpath, testName);
        for (const resOpt of resOptsCombinations) {
            yield projectionTestUtils_1.projectionTestUtils.loadEntityForResolutionOptionAndSave(corpus, testName, testsSubpath, entityName, resOpt);
        }
        const entity = yield corpus.fetchObjectAsync(`local:/${entityName}.cdm.json/${entityName}`);
        const resolvedEntity = yield projectionTestUtils_1.projectionTestUtils.getResolvedEntity(corpus, entity, []);
        // Original set of attributes: ['name', 'age', 'address', 'phoneNumber', 'email']
        // Renamed attribute 'age' with format 'yearsOld' and re-order all attributes removing email
        expect(resolvedEntity.attributes.allItems.length)
            .toEqual(4);
        expect(resolvedEntity.attributes.allItems[0].name)
            .toEqual('address');
        expect(resolvedEntity.attributes.allItems[1].name)
            .toEqual('phoneNumber');
        expect(resolvedEntity.attributes.allItems[2].name)
            .toEqual('yearsOld');
        expect(resolvedEntity.attributes.allItems[3].name)
            .toEqual('name');
    }));
    /**
     * Test for entity attribute with resolution guidance with an empty SelectsSomeTakeNames list
     */
    it('TestEmpty', () => __awaiter(void 0, void 0, void 0, function* () {
        const testName = 'TestEmpty';
        const entityName = 'Color';
        const corpus = testHelper_1.testHelper.getLocalCorpus(testsSubpath, testName);
        for (const resOpt of resOptsCombinations) {
            yield projectionTestUtils_1.projectionTestUtils.loadEntityForResolutionOptionAndSave(corpus, testName, testsSubpath, entityName, resOpt);
        }
    }));
    /**
     * Test for entity attribute with projection with an empty includeAttributes operation list
     */
    it('TestEmptyProj', () => __awaiter(void 0, void 0, void 0, function* () {
        const testName = 'TestEmptyProj';
        const entityName = 'Color';
        const corpus = testHelper_1.testHelper.getLocalCorpus(testsSubpath, testName);
        for (const resOpt of resOptsCombinations) {
            yield projectionTestUtils_1.projectionTestUtils.loadEntityForResolutionOptionAndSave(corpus, testName, testsSubpath, entityName, resOpt);
        }
    }));
    /**
     * Test for Nested Projections that include then exclude some attributes
     */
    it('TestNestedIncludeExcludeProj', () => __awaiter(void 0, void 0, void 0, function* () {
        const testName = 'TestNestedIncludeExcludeProj';
        const entityName = 'Color';
        const corpus = testHelper_1.testHelper.getLocalCorpus(testsSubpath, testName);
        for (const resOpt of resOptsCombinations) {
            yield projectionTestUtils_1.projectionTestUtils.loadEntityForResolutionOptionAndSave(corpus, testName, testsSubpath, entityName, resOpt);
        }
    }));
    /**
     * Test for Projections with include and exclude
     */
    it('TestIncludeExcludeProj', () => __awaiter(void 0, void 0, void 0, function* () {
        const testName = 'TestIncludeExcludeProj';
        const entityName = 'Color';
        const corpus = testHelper_1.testHelper.getLocalCorpus(testsSubpath, testName);
        for (const resOpt of resOptsCombinations) {
            yield projectionTestUtils_1.projectionTestUtils.loadEntityForResolutionOptionAndSave(corpus, testName, testsSubpath, entityName, resOpt);
        }
    }));
});
//# sourceMappingURL=ProjectionInclude.test.js.map