"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 internal_1 = require("../../../internal");
const Storage_1 = require("../../../Storage");
const testHelper_1 = require("../../testHelper");
const projectionTestUtils_1 = require("../../Utilities/projectionTestUtils");
/**
 *  Class to handle RenameAttributes operations
 */
describe('Cdm/Projection/ProjectionRenameAttributesTest', () => {
    /**
     * The path between TestDataPath and TestName.
     */
    const testsSubpath = 'Cdm/Projection/ProjectionRenameTest';
    /**
     * All possible combinations of the different resolution directives
     */
    const resOptsCombinations = [
        [],
        ['referenceOnly'],
        ['normalized'],
        ['structured'],
        ['referenceOnly', 'normalized'],
        ['referenceOnly', 'structured'],
        ['normalized', 'structured'],
        ['referenceOnly', 'normalized', 'structured']
    ];
    /**
     * Test for creating a projection with an RenameAttributes operation on an entity attribute using the object model
     */
    it('TestEntityAttributeProjUsingObjectModel', () => __awaiter(void 0, void 0, void 0, function* () {
        const corpus = testHelper_1.testHelper.getLocalCorpus(testsSubpath, 'TestEntityAttributeProjUsingObjectModel');
        corpus.storage.mount('local', new Storage_1.LocalAdapter(testHelper_1.testHelper.getActualOutputFolderPath(testsSubpath, 'TestEntityAttributeProjUsingObjectModel')));
        const localRoot = corpus.storage.fetchRootFolder('local');
        // Create an entity
        const entity = projectionTestUtils_1.projectionTestUtils.createEntity(corpus, localRoot);
        // Create a projection
        const projection = projectionTestUtils_1.projectionTestUtils.createProjection(corpus, localRoot);
        // Create an RenameAttributes operation
        const renameAttrsOp = corpus.MakeObject(internal_1.cdmObjectType.operationRenameAttributesDef);
        renameAttrsOp.renameFormat = '{a}-{o}-{m}';
        projection.operations.push(renameAttrsOp);
        // Create an entity reference to hold this projection
        const projectionEntityRef = corpus.MakeObject(internal_1.cdmObjectType.entityRef, null);
        projectionEntityRef.explicitReference = projection;
        // Create an entity attribute that contains this projection and add this to the entity
        const entityAttribute = corpus.MakeObject(internal_1.cdmObjectType.entityAttributeDef, 'TestEntityAttribute');
        entityAttribute.entity = projectionEntityRef;
        entity.attributes.push(entityAttribute);
        // Resolve the entity.
        const resolvedEntity = yield entity.createResolvedEntityAsync(`Resolved_${entity.entityName}.cdm.json`, null, localRoot);
        // Verify correctness of the resolved attributes after running the RenameAttributes operation
        // Original set of attributes: ['id', 'name', 'value', 'date']
        // Rename all attributes with format '{a}-{o}-{m}'
        expect(resolvedEntity.attributes.length)
            .toEqual(4);
        expect(resolvedEntity.attributes.allItems[0].name)
            .toEqual('TestEntityAttribute--id');
        expect(resolvedEntity.attributes.allItems[1].name)
            .toEqual('TestEntityAttribute--name');
        expect(resolvedEntity.attributes.allItems[2].name)
            .toEqual('TestEntityAttribute--value');
        expect(resolvedEntity.attributes.allItems[3].name)
            .toEqual('TestEntityAttribute--date');
    }));
    /**
     * Test for creating a projection with an RenameAttributes operation on an entity definition using the object model.
     */
    it('TestEntityProjUsingObjectModel', () => __awaiter(void 0, void 0, void 0, function* () {
        const corpus = testHelper_1.testHelper.getLocalCorpus(testsSubpath, 'TestEntityProjUsingObjectModel');
        corpus.storage.mount('local', new Storage_1.LocalAdapter(testHelper_1.testHelper.getActualOutputFolderPath(testsSubpath, 'TestEntityProjUsingObjectModel')));
        const localRoot = corpus.storage.fetchRootFolder('local');
        // Create an entity
        const entity = projectionTestUtils_1.projectionTestUtils.createEntity(corpus, localRoot);
        // Create a projection
        const projection = projectionTestUtils_1.projectionTestUtils.createProjection(corpus, localRoot);
        // Create an RenameAttributes operation
        const renameAttrsOp = corpus.MakeObject(internal_1.cdmObjectType.operationRenameAttributesDef);
        renameAttrsOp.renameFormat = '{A}.{o}.{M}';
        projection.operations.push(renameAttrsOp);
        // Create an entity reference to hold this projection
        const projectionEntityRef = corpus.MakeObject(internal_1.cdmObjectType.entityRef, null);
        projectionEntityRef.explicitReference = projection;
        // Set the entity's ExtendEntity to be the projection
        entity.extendsEntity = projectionEntityRef;
        // Resolve the entity
        const resolvedEntity = yield entity.createResolvedEntityAsync(`Resolved_${entity.entityName}.cdm.json`, null, localRoot);
        // Verify correctness of the resolved attributes after running the RenameAttributes operation
        // Original set of attributes: ['id', 'name', 'value', 'date']
        // Rename all attributes with format {A}.{o}.{M}
        expect(resolvedEntity.attributes.length)
            .toEqual(4);
        expect(resolvedEntity.attributes.allItems[0].name)
            .toEqual('..Id');
        expect(resolvedEntity.attributes.allItems[1].name)
            .toEqual('..Name');
        expect(resolvedEntity.attributes.allItems[2].name)
            .toEqual('..Value');
        expect(resolvedEntity.attributes.allItems[3].name)
            .toEqual('..Date');
    }));
    /**
     * Test for creating nested projections with RenameAttributes operations using the object model
     */
    it('TestNestedProjUsingObjectModel', () => __awaiter(void 0, void 0, void 0, function* () {
        const corpus = testHelper_1.testHelper.getLocalCorpus(testsSubpath, 'TestNestedProjUsingObjectModel');
        corpus.storage.mount('local', new Storage_1.LocalAdapter(testHelper_1.testHelper.getActualOutputFolderPath(testsSubpath, 'TestNestedProjUsingObjectModel')));
        const localRoot = corpus.storage.fetchRootFolder('local');
        // Create an entity
        const entity = projectionTestUtils_1.projectionTestUtils.createEntity(corpus, localRoot);
        // Create a projection
        const projection = projectionTestUtils_1.projectionTestUtils.createProjection(corpus, localRoot);
        // Create an RenameAttributes operation
        const renameAttrsOp = corpus.MakeObject(internal_1.cdmObjectType.operationRenameAttributesDef);
        renameAttrsOp.renameFormat = '{A}.{o}.{M}';
        projection.operations.push(renameAttrsOp);
        // Create an entity reference to hold this projection
        const projectionEntityRef = corpus.MakeObject(internal_1.cdmObjectType.entityRef, null);
        projectionEntityRef.explicitReference = projection;
        // Create another projection that uses the previous projection as its source
        const projection2 = corpus.MakeObject(internal_1.cdmObjectType.projectionDef);
        projection2.source = projectionEntityRef;
        // Create an RenameAttributes operation
        const renameAttrsOp2 = corpus.MakeObject(internal_1.cdmObjectType.operationRenameAttributesDef);
        renameAttrsOp2.renameFormat = '{a}-{o}-{m}';
        renameAttrsOp2.applyTo = ['name'];
        projection2.operations.push(renameAttrsOp2);
        // Create an entity reference to hold this projection
        const projectionEntityRef2 = corpus.MakeObject(internal_1.cdmObjectType.entityRef, null);
        projectionEntityRef2.explicitReference = projection2;
        // Create an entity attribute that contains this projection and add this to the entity
        const entityAttribute = corpus.MakeObject(internal_1.cdmObjectType.entityAttributeDef, 'TestEntityAttribute');
        entityAttribute.entity = projectionEntityRef2;
        entity.attributes.push(entityAttribute);
        // Resolve the entity
        const resolvedEntity = yield entity.createResolvedEntityAsync(`Resolved_${entity.entityName}.cdm.json`, null, localRoot);
        // Verify correctness of the resolved attributes after running the RenameAttributes operations
        // Original set of attributes: ['id', 'name', 'value', 'date']
        // Rename all attributes attributes with format {A}.{o}.{M}, then rename 'name' with format '{a}-{o}-{m}'
        expect(resolvedEntity.attributes.length)
            .toEqual(4);
        expect(resolvedEntity.attributes.allItems[0].name)
            .toEqual('TestEntityAttribute..Id');
        expect(resolvedEntity.attributes.allItems[1].name)
            .toEqual('TestEntityAttribute--TestEntityAttribute..Name');
        expect(resolvedEntity.attributes.allItems[2].name)
            .toEqual('TestEntityAttribute..Value');
        expect(resolvedEntity.attributes.allItems[3].name)
            .toEqual('TestEntityAttribute..Date');
    }));
    /**
     * Test correctness when renameFormat has repeated pattern
     */
    it('TestRepeatedPatternProj', () => __awaiter(void 0, void 0, void 0, function* () {
        const corpus = testHelper_1.testHelper.getLocalCorpus(testsSubpath, 'TestEntityAttributeProjUsingObjectModel');
        corpus.storage.mount('local', new Storage_1.LocalAdapter(testHelper_1.testHelper.getActualOutputFolderPath(testsSubpath, 'TestEntityAttributeProjUsingObjectModel')));
        const localRoot = corpus.storage.fetchRootFolder('local');
        // Create an entity
        const entity = projectionTestUtils_1.projectionTestUtils.createEntity(corpus, localRoot);
        // Create a projection
        const projection = projectionTestUtils_1.projectionTestUtils.createProjection(corpus, localRoot);
        // Create an RenameAttributes operation
        const renameAttrsOp = corpus.MakeObject(internal_1.cdmObjectType.operationRenameAttributesDef);
        renameAttrsOp.renameFormat = '{a}-{M}-{o}-{A}-{m}-{O}';
        projection.operations.push(renameAttrsOp);
        // Create an entity reference to hold this projection
        const projectionEntityRef = corpus.MakeObject(internal_1.cdmObjectType.entityRef, null);
        projectionEntityRef.explicitReference = projection;
        // Create an entity attribute that contains this projection and add this to the entity
        const entityAttribute = corpus.MakeObject(internal_1.cdmObjectType.entityAttributeDef, 'TestEntityAttribute');
        entityAttribute.entity = projectionEntityRef;
        entity.attributes.push(entityAttribute);
        // Resolve the entity.
        const resolvedEntity = yield entity.createResolvedEntityAsync(`Resolved_${entity.entityName}.cdm.json`, null, localRoot);
        // Verify correctness of the resolved attributes after running the RenameAttributes operation
        // Original set of attributes: ['id', 'name', 'value', 'date']
        // Rename all attributes with format '{a}-{M}-{o}-{A}-{m}-{O}'
        expect(resolvedEntity.attributes.length)
            .toEqual(4);
        expect(resolvedEntity.attributes.allItems[0].name)
            .toEqual('TestEntityAttribute-Id--TestEntityAttribute-id-');
        expect(resolvedEntity.attributes.allItems[1].name)
            .toEqual('TestEntityAttribute-Name--TestEntityAttribute-name-');
        expect(resolvedEntity.attributes.allItems[2].name)
            .toEqual('TestEntityAttribute-Value--TestEntityAttribute-value-');
        expect(resolvedEntity.attributes.allItems[3].name)
            .toEqual('TestEntityAttribute-Date--TestEntityAttribute-date-');
    }));
    /**
     * Test for creating a projection with an RenameAttributes operation and a condition using the object model
     */
    it('TestConditionalProjUsingObjectModel', () => __awaiter(void 0, void 0, void 0, function* () {
        const corpus = testHelper_1.testHelper.getLocalCorpus(testsSubpath, 'TestConditionalProjUsingObjectModel');
        corpus.storage.mount('local', new Storage_1.LocalAdapter(testHelper_1.testHelper.getActualOutputFolderPath(testsSubpath, 'TestConditionalProjUsingObjectModel')));
        const localRoot = corpus.storage.fetchRootFolder('local');
        // Create an entity.
        const entity = projectionTestUtils_1.projectionTestUtils.createEntity(corpus, localRoot);
        // Create a projection with a condition that states the operation should only execute when the resolution directive is 'referenceOnly'.
        const projection = projectionTestUtils_1.projectionTestUtils.createProjection(corpus, localRoot);
        projection.condition = 'referenceOnly==true';
        // Create an RenameAttributes operation
        const renameAttrsOp = corpus.MakeObject(internal_1.cdmObjectType.operationRenameAttributesDef);
        renameAttrsOp.renameFormat = '{A}.{o}.{M}';
        projection.operations.push(renameAttrsOp);
        // Create an entity reference to hold this projection.
        const projectionEntityRef = corpus.MakeObject(internal_1.cdmObjectType.entityRef, null);
        projectionEntityRef.explicitReference = projection;
        // Create an entity attribute that contains this projection and add this to the entity.
        const entityAttribute = corpus.MakeObject(internal_1.cdmObjectType.entityAttributeDef, 'TestEntityAttribute');
        entityAttribute.entity = projectionEntityRef;
        entity.attributes.push(entityAttribute);
        // Create resolution options with the 'referenceOnly' directive.
        const resOpt = new internal_1.resolveOptions(entity.inDocument);
        resOpt.directives = new internal_1.AttributeResolutionDirectiveSet(new Set(['referenceOnly']));
        // Resolve the entity with 'referenceOnly'
        const resolvedEntityWithReferenceOnly = yield entity.createResolvedEntityAsync(`Resolved_${entity.entityName}.cdm.json`, resOpt, localRoot);
        // Verify correctness of the resolved attributes after running the RenameAttributes operation
        // Original set of attributes: ['id', 'name', 'value', 'date']
        // Rename all attributes with format '{A}.{o}.{M}'
        expect(resolvedEntityWithReferenceOnly.attributes.length)
            .toEqual(4);
        expect(resolvedEntityWithReferenceOnly.attributes.allItems[0].name)
            .toEqual('TestEntityAttribute..Id');
        expect(resolvedEntityWithReferenceOnly.attributes.allItems[1].name)
            .toEqual('TestEntityAttribute..Name');
        expect(resolvedEntityWithReferenceOnly.attributes.allItems[2].name)
            .toEqual('TestEntityAttribute..Value');
        expect(resolvedEntityWithReferenceOnly.attributes.allItems[3].name)
            .toEqual('TestEntityAttribute..Date');
        // Now resolve the entity with the 'structured' directive
        resOpt.directives = new internal_1.AttributeResolutionDirectiveSet(new Set(['structured']));
        const resolvedEntityWithStructured = yield entity.createResolvedEntityAsync(`Resolved_${entity.entityName}.cdm.json`, resOpt, localRoot);
        // Verify correctness of the resolved attributes after running the RenameAttributes operation
        // Original set of attributes: ['id', 'name', 'value', 'date']
        // Renamed attributes: none, condition was false
        expect(resolvedEntityWithStructured.attributes.length)
            .toEqual(4);
        expect(resolvedEntityWithStructured.attributes.allItems[0].name)
            .toEqual('id');
        expect(resolvedEntityWithStructured.attributes.allItems[1].name)
            .toEqual('name');
        expect(resolvedEntityWithStructured.attributes.allItems[2].name)
            .toEqual('value');
        expect(resolvedEntityWithStructured.attributes.allItems[3].name)
            .toEqual('date');
    }));
    /**
     * RenameAttributes with a plain string as rename format.
     */
    it('TestRenameFormatAsStringProj', () => __awaiter(void 0, void 0, void 0, function* () {
        const testName = 'TestRenameFormatAsStringProj';
        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 'address' with format 'whereYouLive'.
        expect(resolvedEntity.attributes.length)
            .toEqual(5);
        expect(resolvedEntity.attributes.allItems[0].name)
            .toEqual('name');
        expect(resolvedEntity.attributes.allItems[1].name)
            .toEqual('age');
        expect(resolvedEntity.attributes.allItems[2].name)
            .toEqual('whereYouLive');
        expect(resolvedEntity.attributes.allItems[3].name)
            .toEqual('phoneNumber');
        expect(resolvedEntity.attributes.allItems[4].name)
            .toEqual('email');
    }));
    /**
     * RenameFormat on an entity attribute.
     */
    it('TestRenameFormat', () => __awaiter(void 0, void 0, void 0, function* () {
        const testName = 'TestRenameFormat';
        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: ['PersonInfoName', 'PersonInfoAge', 'PersonInfoAddress', 'PersonInfoPhoneNumber', 'PersonInfoEmail'].
        // Renamed all attributes with format {a}.{o}.{M}
        expect(resolvedEntity.attributes.length)
            .toEqual(5);
        expect(resolvedEntity.attributes.allItems[0].name)
            .toEqual('PersonInfo..Name');
        expect(resolvedEntity.attributes.allItems[1].name)
            .toEqual('PersonInfo..Age');
        expect(resolvedEntity.attributes.allItems[2].name)
            .toEqual('PersonInfo..Address');
        expect(resolvedEntity.attributes.allItems[3].name)
            .toEqual('PersonInfo..PhoneNumber');
        expect(resolvedEntity.attributes.allItems[4].name)
            .toEqual('PersonInfo..Email');
    }));
    /**
     * RenameFormat on an entity attribute.
     */
    it('TestRenameFormatProj', () => __awaiter(void 0, void 0, void 0, function* () {
        const testName = 'TestRenameFormatProj';
        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: ['PersonInfoName', 'PersonInfoAge', 'PersonInfoAddress', 'PersonInfoPhoneNumber', 'PersonInfoEmail'].
        // Renamed all attributes with format {a}.{o}.{M}
        expect(resolvedEntity.attributes.length)
            .toEqual(5);
        expect(resolvedEntity.attributes.allItems[0].name)
            .toEqual('PersonInfo..Name');
        expect(resolvedEntity.attributes.allItems[1].name)
            .toEqual('PersonInfo..Age');
        expect(resolvedEntity.attributes.allItems[2].name)
            .toEqual('PersonInfo..Address');
        expect(resolvedEntity.attributes.allItems[3].name)
            .toEqual('PersonInfo..PhoneNumber');
        expect(resolvedEntity.attributes.allItems[4].name)
            .toEqual('PersonInfo..Email');
    }));
    /**
     * A nested RenameAttributes operation in a single projection.
     */
    it('TestSingleNestedProj', () => __awaiter(void 0, void 0, void 0, function* () {
        const testName = 'TestSingleNestedProj';
        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 all attributes with format 'New{M}'.
        expect(resolvedEntity.attributes.length)
            .toEqual(5);
        expect(resolvedEntity.attributes.allItems[0].name)
            .toEqual('NewName');
        expect(resolvedEntity.attributes.allItems[1].name)
            .toEqual('NewAge');
        expect(resolvedEntity.attributes.allItems[2].name)
            .toEqual('NewAddress');
        expect(resolvedEntity.attributes.allItems[3].name)
            .toEqual('NewPhoneNumber');
        expect(resolvedEntity.attributes.allItems[4].name)
            .toEqual('NewEmail');
    }));
    /**
     * Nested projections with RenameAttributes
     */
    it('TestNestedProj', () => __awaiter(void 0, void 0, void 0, function* () {
        const testName = 'TestNestedProj';
        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']
        // Rename all attributes attributes with format {A}.{o}.{M}, then rename 'age' with format '{a}-{o}-{m}', finally rename "email" with format '{a}-{o}-{mo}'
        expect(resolvedEntity.attributes.length)
            .toEqual(5);
        expect(resolvedEntity.attributes.allItems[0].name)
            .toEqual('PersonInfo..Name');
        expect(resolvedEntity.attributes.allItems[1].name)
            .toEqual('PersonInfo--PersonInfo..Age');
        expect(resolvedEntity.attributes.allItems[2].name)
            .toEqual('PersonInfo..Address');
        expect(resolvedEntity.attributes.allItems[3].name)
            .toEqual('PersonInfo..PhoneNumber');
        expect(resolvedEntity.attributes.allItems[4].name)
            .toEqual('PersonInfo--email');
    }));
    /**
     * Multiple RenameAttributes in a single projection.
     */
    it('TestMultipleRename', () => __awaiter(void 0, void 0, void 0, function* () {
        const testName = 'TestMultipleRename';
        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']
        // Rename attributes 'age' to 'yearsOld' then 'address' to 'homePlace'
        expect(resolvedEntity.attributes.length)
            .toEqual(7);
        expect(resolvedEntity.attributes.allItems[0].name)
            .toEqual('name');
        expect(resolvedEntity.attributes.allItems[1].name)
            .toEqual('yearsOld');
        expect(resolvedEntity.attributes.allItems[2].name)
            .toEqual('address');
        expect(resolvedEntity.attributes.allItems[3].name)
            .toEqual('phoneNumber');
        expect(resolvedEntity.attributes.allItems[4].name)
            .toEqual('email');
        expect(resolvedEntity.attributes.allItems[5].name)
            .toEqual('age');
        expect(resolvedEntity.attributes.allItems[6].name)
            .toEqual('homePlace');
    }));
    /**
     * RenameFormat on an entity definition.
     */
    it('TestExtendsEntityProj', () => __awaiter(void 0, void 0, void 0, function* () {
        const testName = 'TestExtendsEntityProj';
        const entityName = 'Child';
        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'].
        // All attributes renamed with format '{a}.{o}.{M}'.
        expect(resolvedEntity.attributes.length)
            .toEqual(5);
        expect(resolvedEntity.attributes.allItems[0].name)
            .toEqual('..name');
        expect(resolvedEntity.attributes.allItems[1].name)
            .toEqual('..age');
        expect(resolvedEntity.attributes.allItems[2].name)
            .toEqual('..address');
        expect(resolvedEntity.attributes.allItems[3].name)
            .toEqual('..phoneNumber');
        expect(resolvedEntity.attributes.allItems[4].name)
            .toEqual('..email');
    }));
    /**
     * RenameFormat on an entity definition.
     * NOTE: this is not supported with resolution guidance.
     */
    it('TestExtendsEntity', () => __awaiter(void 0, void 0, void 0, function* () {
        const testName = 'TestExtendsEntity';
        const entityName = 'Child';
        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 attributes: [] with format '{a}.{o}.{M}'.
        expect(resolvedEntity.attributes.length)
            .toEqual(5);
        expect(resolvedEntity.attributes.allItems[0].name)
            .toEqual('name');
        expect(resolvedEntity.attributes.allItems[1].name)
            .toEqual('age');
        expect(resolvedEntity.attributes.allItems[2].name)
            .toEqual('address');
        expect(resolvedEntity.attributes.allItems[3].name)
            .toEqual('phoneNumber');
        expect(resolvedEntity.attributes.allItems[4].name)
            .toEqual('email');
    }));
    /**
     * RenameAttributes on a polymorphic source
     */
    it('TestPolymorphicProj', () => __awaiter(void 0, void 0, void 0, function* () {
        const testName = 'TestPolymorphicProj';
        const entityName = 'BusinessPerson';
        const corpus = testHelper_1.testHelper.getLocalCorpus(testsSubpath, testName);
        for (const resOpt of resOptsCombinations) {
            if (resOpt.includes('structured')) {
                // Rename attributes is not supported on an attribute group yet.
                continue;
            }
            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: ['emailId', 'address', 'isPrimary', 'phoneId', 'number', 'socialId', 'account'].
        // Renamed all attributes with format {A}.{o}.{M}.
        expect(resolvedEntity.attributes.length)
            .toEqual(7);
        expect(resolvedEntity.attributes.allItems[0].name)
            .toEqual('ContactAt..EmailId');
        expect(resolvedEntity.attributes.allItems[1].name)
            .toEqual('ContactAt..Address');
        expect(resolvedEntity.attributes.allItems[2].name)
            .toEqual('ContactAt..IsPrimary');
        expect(resolvedEntity.attributes.allItems[3].name)
            .toEqual('ContactAt..PhoneId');
        expect(resolvedEntity.attributes.allItems[4].name)
            .toEqual('ContactAt..Number');
        expect(resolvedEntity.attributes.allItems[5].name)
            .toEqual('ContactAt..SocialId');
        expect(resolvedEntity.attributes.allItems[6].name)
            .toEqual('ContactAt..Account');
    }));
    /**
     * RenameAttributes on a polymorphic source
     */
    it('TestPolymorphicApplyToProj', () => __awaiter(void 0, void 0, void 0, function* () {
        const testName = 'TestPolymorphicApplyToProj';
        const entityName = 'BusinessPerson';
        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: ['emailId', 'address', 'isPrimary', 'phoneId', 'number', 'socialId', 'account']
        // Renamed attributes: [address, number] with format {A}.{o}.{M}
        expect(resolvedEntity.attributes.length)
            .toEqual(7);
        expect(resolvedEntity.attributes.allItems[0].name)
            .toEqual('emailId');
        expect(resolvedEntity.attributes.allItems[1].name)
            .toEqual('ContactAt..Address');
        expect(resolvedEntity.attributes.allItems[2].name)
            .toEqual('isPrimary');
        expect(resolvedEntity.attributes.allItems[3].name)
            .toEqual('phoneId');
        expect(resolvedEntity.attributes.allItems[4].name)
            .toEqual('ContactAt..Number');
        expect(resolvedEntity.attributes.allItems[5].name)
            .toEqual('socialId');
        expect(resolvedEntity.attributes.allItems[6].name)
            .toEqual('account');
    }));
    /**
     * SelectsSomeAvoidNames on a polymorphic source
     */
    it('TestPolymorphic', () => __awaiter(void 0, void 0, void 0, function* () {
        const testName = 'TestPolymorphic';
        const entityName = 'BusinessPerson';
        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: ['emailId', 'address', 'isPrimary', 'phoneId', 'number', 'socialId', 'account']
        // Renamed all attributes with format '{A}.{o}.{M}'
        expect(resolvedEntity.attributes.length)
            .toEqual(7);
        expect(resolvedEntity.attributes.allItems[0].name)
            .toEqual('ContactAt..EmailId');
        expect(resolvedEntity.attributes.allItems[1].name)
            .toEqual('ContactAt..Address');
        expect(resolvedEntity.attributes.allItems[2].name)
            .toEqual('ContactAt..IsPrimary');
        expect(resolvedEntity.attributes.allItems[3].name)
            .toEqual('ContactAt..PhoneId');
        expect(resolvedEntity.attributes.allItems[4].name)
            .toEqual('ContactAt..Number');
        expect(resolvedEntity.attributes.allItems[5].name)
            .toEqual('ContactAt..SocialId');
        expect(resolvedEntity.attributes.allItems[6].name)
            .toEqual('ContactAt..Account');
    }));
    /**
     * RenameAttributes on an array source
     */
    it('TestArraySourceProj', () => __awaiter(void 0, void 0, void 0, function* () {
        const testName = 'TestArraySourceProj';
        const entityName = 'FriendGroup';
        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: ['personCount', 'name1', 'age1', 'address1', 'phoneNumber1', 'email1', ..., 'email3'] (16 total)
        // Attributes renamed from format {a}{M} to {a}.{o}.{M}
        // NOTE: This behavior is different in the rename projection. The ordinal is this case is leaked by the resolution guidance
        expect(resolvedEntity.attributes.length)
            .toEqual(16);
        expect(resolvedEntity.attributes.allItems[0].name)
            .toEqual('GroupOfPeople..PersonCount');
        expect(resolvedEntity.attributes.allItems[1].name)
            .toEqual('GroupOfPeople..Name1');
        expect(resolvedEntity.attributes.allItems[2].name)
            .toEqual('GroupOfPeople..Age1');
        expect(resolvedEntity.attributes.allItems[3].name)
            .toEqual('GroupOfPeople..Address1');
        expect(resolvedEntity.attributes.allItems[4].name)
            .toEqual('GroupOfPeople..PhoneNumber1');
        expect(resolvedEntity.attributes.allItems[5].name)
            .toEqual('GroupOfPeople..Email1');
        expect(resolvedEntity.attributes.allItems[6].name)
            .toEqual('GroupOfPeople..Name2');
        expect(resolvedEntity.attributes.allItems[7].name)
            .toEqual('GroupOfPeople..Age2');
        expect(resolvedEntity.attributes.allItems[8].name)
            .toEqual('GroupOfPeople..Address2');
        expect(resolvedEntity.attributes.allItems[9].name)
            .toEqual('GroupOfPeople..PhoneNumber2');
        expect(resolvedEntity.attributes.allItems[10].name)
            .toEqual('GroupOfPeople..Email2');
        expect(resolvedEntity.attributes.allItems[11].name)
            .toEqual('GroupOfPeople..Name3');
        expect(resolvedEntity.attributes.allItems[12].name)
            .toEqual('GroupOfPeople..Age3');
        expect(resolvedEntity.attributes.allItems[13].name)
            .toEqual('GroupOfPeople..Address3');
        expect(resolvedEntity.attributes.allItems[14].name)
            .toEqual('GroupOfPeople..PhoneNumber3');
        expect(resolvedEntity.attributes.allItems[15].name)
            .toEqual('GroupOfPeople..Email3');
    }));
    /**
     * RenameFormat on an array source
     */
    it('TestArraySource', () => __awaiter(void 0, void 0, void 0, function* () {
        const testName = 'TestArraySource';
        const entityName = 'FriendGroup';
        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: ['GroupOfPeoplePersonCount', 'GroupOfPeopleName1', 'GroupOfPeopleAge1', 'GroupOfPeopleAddress1',
        //                              'GroupOfPeoplePhoneNumber1', 'GroupOfPeopleEmail1', ..., 'GroupOfPeopleEmail3'] (16 total)
        // Attributes renamed from format {a}{M} to {a}.{o}.{M}
        // NOTE: This behavior is different in the rename projection. The ordinal is this case is leaked by the resolution guidance
        expect(resolvedEntity.attributes.length)
            .toEqual(16);
        expect(resolvedEntity.attributes.allItems[0].name)
            .toEqual('GroupOfPeople..PersonCount');
        expect(resolvedEntity.attributes.allItems[1].name)
            .toEqual('GroupOfPeople.1.Name1');
        expect(resolvedEntity.attributes.allItems[2].name)
            .toEqual('GroupOfPeople.1.Age1');
        expect(resolvedEntity.attributes.allItems[3].name)
            .toEqual('GroupOfPeople.1.Address1');
        expect(resolvedEntity.attributes.allItems[4].name)
            .toEqual('GroupOfPeople.1.PhoneNumber1');
        expect(resolvedEntity.attributes.allItems[5].name)
            .toEqual('GroupOfPeople.1.Email1');
        expect(resolvedEntity.attributes.allItems[6].name)
            .toEqual('GroupOfPeople.2.Name2');
        expect(resolvedEntity.attributes.allItems[7].name)
            .toEqual('GroupOfPeople.2.Age2');
        expect(resolvedEntity.attributes.allItems[8].name)
            .toEqual('GroupOfPeople.2.Address2');
        expect(resolvedEntity.attributes.allItems[9].name)
            .toEqual('GroupOfPeople.2.PhoneNumber2');
        expect(resolvedEntity.attributes.allItems[10].name)
            .toEqual('GroupOfPeople.2.Email2');
        expect(resolvedEntity.attributes.allItems[11].name)
            .toEqual('GroupOfPeople.3.Name3');
        expect(resolvedEntity.attributes.allItems[12].name)
            .toEqual('GroupOfPeople.3.Age3');
        expect(resolvedEntity.attributes.allItems[13].name)
            .toEqual('GroupOfPeople.3.Address3');
        expect(resolvedEntity.attributes.allItems[14].name)
            .toEqual('GroupOfPeople.3.PhoneNumber3');
        expect(resolvedEntity.attributes.allItems[15].name)
            .toEqual('GroupOfPeople.3.Email3');
    }));
    /**
     * RenameFormat on an array source using apply to.
     */
    it('TestArraySourceRenameApplyToProj', () => __awaiter(void 0, void 0, void 0, function* () {
        const testName = 'TestArraySourceRenameApplyToProj';
        const entityName = 'FriendGroup';
        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: ['personCount', 'name1', 'age1', 'address1', 'phoneNumber1', 'email1', ..., 'email3'] (16 total).
        // Renamed attributes: ['age1', 'age2', 'age3'] with the format '{a}.{o}.{M}'.
        expect(resolvedEntity.attributes.length)
            .toEqual(16);
        expect(resolvedEntity.attributes.allItems[0].name)
            .toEqual('personCount');
        expect(resolvedEntity.attributes.allItems[1].name)
            .toEqual('name1');
        expect(resolvedEntity.attributes.allItems[2].name)
            .toEqual('GroupOfPeople..Age1');
        expect(resolvedEntity.attributes.allItems[3].name)
            .toEqual('address1');
        expect(resolvedEntity.attributes.allItems[4].name)
            .toEqual('phoneNumber1');
        expect(resolvedEntity.attributes.allItems[5].name)
            .toEqual('email1');
        expect(resolvedEntity.attributes.allItems[6].name)
            .toEqual('name2');
        expect(resolvedEntity.attributes.allItems[7].name)
            .toEqual('GroupOfPeople..Age2');
        expect(resolvedEntity.attributes.allItems[8].name)
            .toEqual('address2');
        expect(resolvedEntity.attributes.allItems[9].name)
            .toEqual('phoneNumber2');
        expect(resolvedEntity.attributes.allItems[10].name)
            .toEqual('email2');
        expect(resolvedEntity.attributes.allItems[11].name)
            .toEqual('name3');
        expect(resolvedEntity.attributes.allItems[12].name)
            .toEqual('GroupOfPeople..Age3');
        expect(resolvedEntity.attributes.allItems[13].name)
            .toEqual('address3');
        expect(resolvedEntity.attributes.allItems[14].name)
            .toEqual('phoneNumber3');
        expect(resolvedEntity.attributes.allItems[15].name)
            .toEqual('email3');
    }));
    /**
     * RenameAttributes with a condition.
     */
    it('TestConditionalProj', () => __awaiter(void 0, void 0, void 0, function* () {
        const testName = 'TestConditionalProj';
        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, ['referenceOnly']);
        // Original set of attributes: ['name', 'age', 'address', 'phoneNumber', 'email'].
        // Renamed attributes with format '{M}.{o}.{a}'
        expect(resolvedEntity.attributes.length)
            .toEqual(5);
        expect(resolvedEntity.attributes.allItems[0].name)
            .toEqual('Name..personInfo');
        expect(resolvedEntity.attributes.allItems[1].name)
            .toEqual('Age..personInfo');
        expect(resolvedEntity.attributes.allItems[2].name)
            .toEqual('Address..personInfo');
        expect(resolvedEntity.attributes.allItems[3].name)
            .toEqual('PhoneNumber..personInfo');
        expect(resolvedEntity.attributes.allItems[4].name)
            .toEqual('Email..personInfo');
        const resolvedEntity2 = yield projectionTestUtils_1.projectionTestUtils.getResolvedEntity(corpus, entity, []);
        // Original set of attributes: ['name', 'age', 'address', 'phoneNumber', 'email'].
        // Renamed attributes: none, condition was false.
        expect(resolvedEntity2.attributes.length)
            .toEqual(5);
        expect(resolvedEntity2.attributes.allItems[0].name)
            .toEqual('name');
        expect(resolvedEntity2.attributes.allItems[1].name)
            .toEqual('age');
        expect(resolvedEntity2.attributes.allItems[2].name)
            .toEqual('address');
        expect(resolvedEntity2.attributes.allItems[3].name)
            .toEqual('phoneNumber');
        expect(resolvedEntity2.attributes.allItems[4].name)
            .toEqual('email');
    }));
    /**
     * RenameAttributes with an empty apply to list
     */
    it('TestEmptyApplyTo', () => __awaiter(void 0, void 0, void 0, function* () {
        const testName = 'TestEmptyApplyTo';
        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 attributes: [].
        expect(resolvedEntity.attributes.length)
            .toEqual(5);
        expect(resolvedEntity.attributes.allItems[0].name)
            .toEqual('name');
        expect(resolvedEntity.attributes.allItems[1].name)
            .toEqual('age');
        expect(resolvedEntity.attributes.allItems[2].name)
            .toEqual('address');
        expect(resolvedEntity.attributes.allItems[3].name)
            .toEqual('phoneNumber');
        expect(resolvedEntity.attributes.allItems[4].name)
            .toEqual('email');
    }));
    /**
     * RenameFormat on an entity with an attribute group
     */
    it('TestGroupProj', () => __awaiter(void 0, void 0, void 0, function* () {
        const testName = 'TestGroupProj';
        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'].
        // Rename all attributes with format {a}-{o}-{M}
        expect(resolvedEntity.attributes.length)
            .toEqual(5);
        expect(resolvedEntity.attributes.allItems[0].name)
            .toEqual('PersonInfo--Name');
        expect(resolvedEntity.attributes.allItems[1].name)
            .toEqual('PersonInfo--Age');
        expect(resolvedEntity.attributes.allItems[2].name)
            .toEqual('PersonInfo--Address');
        expect(resolvedEntity.attributes.allItems[3].name)
            .toEqual('PersonInfo--PhoneNumber');
        expect(resolvedEntity.attributes.allItems[4].name)
            .toEqual('PersonInfo--Email');
    }));
    /**
     * RenameFormat on an entity with an attribute group.
     */
    it('TestGroupRename', () => __awaiter(void 0, void 0, void 0, function* () {
        const testName = 'TestGroupRename';
        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: ['PersonInfoName', 'PersonInfoAge', 'PersonInfoAddress', 'PersonInfoPhoneNumber', 'PersonInfoEmail'].
        // Rename all attributes with format {a}-{o}-{M}
        expect(resolvedEntity.attributes.length)
            .toEqual(5);
        expect(resolvedEntity.attributes.allItems[0].name)
            .toEqual('PersonInfo--Name');
        expect(resolvedEntity.attributes.allItems[1].name)
            .toEqual('PersonInfo--Age');
        expect(resolvedEntity.attributes.allItems[2].name)
            .toEqual('PersonInfo--Address');
        expect(resolvedEntity.attributes.allItems[3].name)
            .toEqual('PersonInfo--PhoneNumber');
        expect(resolvedEntity.attributes.allItems[4].name)
            .toEqual('PersonInfo--Email');
    }));
    /**
     * Test RenameFormat applying a rename nested in a exclude operation
     */
    it('testRenameAndExcludeProj', () => __awaiter(void 0, void 0, void 0, function* () {
        const testName = "TestRenameAndExcludeProj";
        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"]
        // Rename all attributes with format {a}-{o}-{M} and remove ["age", "PersonInfo--PhoneNumber"]
        expect(resolvedEntity.attributes.length)
            .toEqual(3);
        expect(resolvedEntity.attributes.allItems[0].name)
            .toEqual('PersonInfo--Name');
        expect(resolvedEntity.attributes.allItems[1].name)
            .toEqual('PersonInfo--Address');
        expect(resolvedEntity.attributes.allItems[2].name)
            .toEqual('PersonInfo--Email');
    }));
    /**
     * RenameAttributes with an entity attribute name on an inline entity reference that contains entity attributes.
     * This is testing that, for the case of the structured directive, we can filter using the name of an entity attribute.
     * in the inline entity reference to rename the entire entity attribute group.
     */
    test.skip('TestEANameProj', () => __awaiter(void 0, void 0, void 0, function* () {
        const testName = 'TestEANameProj';
        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, ['structured']);
        // Original set of attributes: ['name', 'age', 'address', 'phoneNumber', 'email', 'title', 'company', 'tenure'].
        // Rename with format '{a}-{o}-{M}' attributes ['PersonInfoAge', 'OccupationInfo']
        // 'OccupationInfo' is an entity attribute
        expect(resolvedEntity.attributes.length)
            .toEqual(2); // attribute group created because of structured directive.
        const attGroup = resolvedEntity.attributes.allItems[0].explicitReference;
        expect(attGroup.getName())
            .toEqual('PersonInfo');
        expect(attGroup.members.length)
            .toEqual(5);
        expect(attGroup.members[0].name)
            .toEqual('name');
        expect(attGroup.members[1].name)
            .toEqual('age');
        expect(attGroup.members[2].name)
            .toEqual('address');
        expect(attGroup.members[3].name)
            .toEqual('phoneNumber');
        expect(attGroup.members[4].name)
            .toEqual('email');
        const attGroup2 = resolvedEntity.attributes.allItems[1].explicitReference;
        expect(attGroup2.getName())
            .toEqual('PersonInfo--OccupationInfo');
        expect(attGroup2.members.length)
            .toEqual(5);
        expect(attGroup2.members[0].name)
            .toEqual('title');
        expect(attGroup2.members[1].name)
            .toEqual('company');
        expect(attGroup2.members[2].name)
            .toEqual('tenure');
    }));
    /**
     * Test resolving a type attribute with a rename attributes operation
     */
    it('TestTypeAttributeProj', () => __awaiter(void 0, void 0, void 0, function* () {
        const testName = 'TestTypeAttributeProj';
        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);
        }
        const entity = yield corpus.fetchObjectAsync(`local:/${entityName}.cdm.json/${entityName}`);
        const resolvedEntity = yield projectionTestUtils_1.projectionTestUtils.getResolvedEntity(corpus, entity, ['referenceOnly']);
        // Original set of attributes: ["name", "age", "address", "phoneNumber", "email"]
        // Rename with format "n{a}e{o}w{M}" attributes ["address"]
        // Add new attribute realNewAddress with rename format "n{a}e{o}w{M}"
        expect(resolvedEntity.attributes.length)
            .toEqual(6);
        expect(resolvedEntity.attributes.allItems[0].name)
            .toEqual('name');
        expect(resolvedEntity.attributes.allItems[1].name)
            .toEqual('age');
        expect(resolvedEntity.attributes.allItems[2].name)
            .toEqual('naddressewAddress');
        expect(resolvedEntity.attributes.allItems[3].name)
            .toEqual('naddressewRealNewAddress');
        expect(resolvedEntity.attributes.allItems[4].name)
            .toEqual('phoneNumber');
        expect(resolvedEntity.attributes.allItems[5].name)
            .toEqual('email');
    }));
});
//# sourceMappingURL=ProjectionRename.test.js.map