"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");
/**
 * A test class for testing the ExcludeAttributes operation in a projection as well as SelectsSomeAvoidNames in a resolution guidance
 */
describe('Cdm/Projection/ProjectionExcludeTest', () => {
    /**
     * All possible combinations of the different resolution directives
     */
    const resOptsCombinations = [
        [],
        ['referenceOnly'],
        ['normalized'],
        ['structured'],
        ['referenceOnly', 'normalized'],
        ['referenceOnly', 'structured'],
        ['normalized', 'structured'],
        ['referenceOnly', 'normalized', 'structured']
    ];
    /**
     * The path between TestDataPath and TestName.
     */
    const testsSubpath = 'Cdm/Projection/ProjectionExcludeTest';
    /**
     * Test for creating a projection with an ExcludeAttributes 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 ExcludeAttributes operation
        const excludeAttrsOp = corpus.MakeObject(internal_1.cdmObjectType.operationExcludeAttributesDef);
        excludeAttrsOp.excludeAttributes = ['id', 'date'];
        projection.operations.push(excludeAttrsOp);
        // Create an entity reference to hold this projection
        const projectionEntityRef = corpus.MakeObject(internal_1.cdmObjectType.entityRef, undefined);
        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`, undefined, localRoot);
        // Verify correctness of the resolved attributes after running the ExcludeAttributes operation
        // Original set of attributes: ['id', 'name', 'value', 'date']
        // Excluded attributes: ['id', 'date']
        expect(resolvedEntity.attributes.length)
            .toEqual(2);
        expect(resolvedEntity.attributes.allItems[0].name)
            .toEqual('name');
        expect(resolvedEntity.attributes.allItems[1].name)
            .toEqual('value');
    }));
    /**
     * Test for creating a projection with an ExcludeAttributes 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 ExcludeAttributes operation
        const excludeAttrsOp = corpus.MakeObject(internal_1.cdmObjectType.operationExcludeAttributesDef);
        excludeAttrsOp.excludeAttributes = ['name', 'value'];
        projection.operations.push(excludeAttrsOp);
        // Create an entity reference to hold this projection
        const projectionEntityRef = corpus.MakeObject(internal_1.cdmObjectType.entityRef, undefined);
        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`, undefined, localRoot);
        // Verify correctness of the resolved attributes after running the ExcludeAttributes operation
        // Original set of attributes: ['id', 'name', 'value', 'date']
        // Excluded attributes: ['name', 'value']
        expect(resolvedEntity.attributes.length)
            .toEqual(2);
        expect(resolvedEntity.attributes.allItems[0].name)
            .toEqual('id');
        expect(resolvedEntity.attributes.allItems[1].name)
            .toEqual('date');
    }));
    /**
     * Test for creating nested projections with ExcludeAttributes 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 ExcludeAttributes operation
        const excludeAttrsOp = corpus.MakeObject(internal_1.cdmObjectType.operationExcludeAttributesDef);
        excludeAttrsOp.excludeAttributes = ['id', 'date'];
        projection.operations.push(excludeAttrsOp);
        // Create an entity reference to hold this projection
        const projectionEntityRef = corpus.MakeObject(internal_1.cdmObjectType.entityRef, undefined);
        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 ExcludeAttributes operation
        const excludeAttrsOp2 = corpus.MakeObject(internal_1.cdmObjectType.operationExcludeAttributesDef);
        excludeAttrsOp2.excludeAttributes = ['value'];
        projection2.operations.push(excludeAttrsOp2);
        // Create an entity reference to hold this projection
        const projectionEntityRef2 = corpus.MakeObject(internal_1.cdmObjectType.entityRef, undefined);
        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`, undefined, localRoot);
        // Verify correctness of the resolved attributes after running the ExcludeAttributes operations
        // Original set of attributes: ['id', 'name', 'value', 'date']
        // Excluded attributes: ['id', 'date'], ['value']
        expect(resolvedEntity.attributes.length)
            .toEqual(1);
        expect(resolvedEntity.attributes.allItems[0].name)
            .toEqual('name');
    }));
    /**
     * Test for creating a projection with an ExcludeAttributes 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 ExcludeAttributes operation
        const excludeAttrsOp = corpus.MakeObject(internal_1.cdmObjectType.operationExcludeAttributesDef);
        excludeAttrsOp.excludeAttributes = ['id', 'date'];
        projection.operations.push(excludeAttrsOp);
        // Create an entity reference to hold this projection
        const projectionEntityRef = corpus.MakeObject(internal_1.cdmObjectType.entityRef, undefined);
        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 ExcludeAttributes operation
        // Original set of attributes: ['id', 'name', 'value', 'date']
        // Excluded attributes: ['id', 'date']
        expect(resolvedEntityWithReferenceOnly.attributes.length)
            .toEqual(2);
        expect(resolvedEntityWithReferenceOnly.attributes.allItems[0].name)
            .toEqual('name');
        expect(resolvedEntityWithReferenceOnly.attributes.allItems[1].name)
            .toEqual('value');
        // 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 ExcludeAttributes operation
        // Original set of attributes: ['id', 'name', 'value', 'date']
        // Excluded 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');
    }));
    /**
     * ExcludeAttributes on an entity attribute
     */
    it('TestExcludeAttributes', () => __awaiter(void 0, void 0, void 0, function* () {
        const testName = 'TestExcludeAttributes';
        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']
        // Excluded attributes: ['address', 'phoneNumber', 'email']
        expect(resolvedEntity.attributes.length)
            .toEqual(2);
        expect(resolvedEntity.attributes.allItems[0].name)
            .toEqual('name');
        expect(resolvedEntity.attributes.allItems[1].name)
            .toEqual('age');
    }));
    /**
     * SelectsSomeAvoidNames on an entity attribute
     */
    it('TestSSAN', () => __awaiter(void 0, void 0, void 0, function* () {
        const testName = 'TestSSAN';
        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']
        // Excluded attributes: ['PersonInfoAddress', 'PersonInfoPhoneNumber', 'PersonInfoEmail']
        expect(resolvedEntity.attributes.length)
            .toEqual(2);
        expect(resolvedEntity.attributes.allItems[0].name)
            .toEqual('PersonInfoName');
        expect(resolvedEntity.attributes.allItems[1].name)
            .toEqual('PersonInfoAge');
    }));
    /**
     * SelectsSomeAvoidNames on an entity attribute that has renameFormat = "{m}"
     */
    it('TestSSANRename', () => __awaiter(void 0, void 0, void 0, function* () {
        const testName = 'TestSSANRename';
        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']
        // Excluded attributes: ['address', 'phoneNumber', 'email']
        expect(resolvedEntity.attributes.length)
            .toEqual(2);
        expect(resolvedEntity.attributes.allItems[0].name)
            .toEqual('name');
        expect(resolvedEntity.attributes.allItems[1].name)
            .toEqual('age');
    }));
    /**
     * A nested ExcludeAttributes 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']
        // Excluded attributes: ['address', 'phoneNumber', 'email']
        expect(resolvedEntity.attributes.length)
            .toEqual(2);
        expect(resolvedEntity.attributes.allItems[0].name)
            .toEqual('name');
        expect(resolvedEntity.attributes.allItems[1].name)
            .toEqual('age');
    }));
    /**
     * Nested projections with ExcludeAttributes
     */
    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']
        // Excluded attributes: ['address', 'phoneNumber', 'email'], ['age']
        expect(resolvedEntity.attributes.length)
            .toEqual(1);
        expect(resolvedEntity.attributes.allItems[0].name)
            .toEqual('name');
    }));
    /**
     * Multiple ExcludeAttributes in a single projection
     */
    it('TestMultipleExclude', () => __awaiter(void 0, void 0, void 0, function* () {
        const testName = 'TestMultipleExclude';
        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']
        // Excluded attributes: ['name', 'age', 'address'], ['address', 'email']
        expect(resolvedEntity.attributes.length)
            .toEqual(4);
        expect(resolvedEntity.attributes.allItems[0].name)
            .toEqual('name');
        expect(resolvedEntity.attributes.allItems[1].name)
            .toEqual('age');
        expect(resolvedEntity.attributes.allItems[2].name)
            .toEqual('phoneNumber');
        expect(resolvedEntity.attributes.allItems[3].name)
            .toEqual('email');
    }));
    /**
     * ExcludeAttributes 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']
        // Excluded attributes: ['phoneNumber', 'email']
        expect(resolvedEntity.attributes.length)
            .toEqual(3);
        expect(resolvedEntity.attributes.allItems[0].name)
            .toEqual('name');
        expect(resolvedEntity.attributes.allItems[1].name)
            .toEqual('age');
        expect(resolvedEntity.attributes.allItems[2].name)
            .toEqual('address');
    }));
    /**
     * SelectsSomeAvoidNames on an entity definition
     */
    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']
        // Excluded attributes: ['phoneNumber', 'email']
        expect(resolvedEntity.attributes.length)
            .toEqual(3);
        expect(resolvedEntity.attributes.allItems[0].name)
            .toEqual('name');
        expect(resolvedEntity.attributes.allItems[1].name)
            .toEqual('age');
        expect(resolvedEntity.attributes.allItems[2].name)
            .toEqual('address');
    }));
    /**
     * ExcludeAttributes 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) {
            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']
        // Excluded attributes: ['socialId', 'account']
        expect(resolvedEntity.attributes.length)
            .toEqual(5);
        expect(resolvedEntity.attributes.allItems[0].name)
            .toEqual('emailId');
        expect(resolvedEntity.attributes.allItems[1].name)
            .toEqual('address');
        expect(resolvedEntity.attributes.allItems[2].name)
            .toEqual('isPrimary');
        expect(resolvedEntity.attributes.allItems[3].name)
            .toEqual('phoneId');
        expect(resolvedEntity.attributes.allItems[4].name)
            .toEqual('number');
    }));
    /**
     * 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']
        // Excluded attributes: ['socialId', 'account']
        expect(resolvedEntity.attributes.length)
            .toEqual(5);
        expect(resolvedEntity.attributes.allItems[0].name)
            .toEqual('emailId');
        expect(resolvedEntity.attributes.allItems[1].name)
            .toEqual('address');
        expect(resolvedEntity.attributes.allItems[2].name)
            .toEqual('isPrimary');
        expect(resolvedEntity.attributes.allItems[3].name)
            .toEqual('phoneId');
        expect(resolvedEntity.attributes.allItems[4].name)
            .toEqual('number');
    }));
    /**
     * ExcludeAttributes 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)
        // Excluded attributes: ['age1', 'age2', 'age3']
        expect(resolvedEntity.attributes.length)
            .toEqual(13);
        expect(resolvedEntity.attributes.allItems[0].name)
            .toEqual('personCount');
        expect(resolvedEntity.attributes.allItems[1].name)
            .toEqual('name1');
        expect(resolvedEntity.attributes.allItems[2].name)
            .toEqual('address1');
        expect(resolvedEntity.attributes.allItems[3].name)
            .toEqual('phoneNumber1');
        expect(resolvedEntity.attributes.allItems[4].name)
            .toEqual('email1');
        expect(resolvedEntity.attributes.allItems[5].name)
            .toEqual('name2');
        expect(resolvedEntity.attributes.allItems[6].name)
            .toEqual('address2');
        expect(resolvedEntity.attributes.allItems[7].name)
            .toEqual('phoneNumber2');
        expect(resolvedEntity.attributes.allItems[8].name)
            .toEqual('email2');
        expect(resolvedEntity.attributes.allItems[9].name)
            .toEqual('name3');
        expect(resolvedEntity.attributes.allItems[10].name)
            .toEqual('address3');
        expect(resolvedEntity.attributes.allItems[11].name)
            .toEqual('phoneNumber3');
        expect(resolvedEntity.attributes.allItems[12].name)
            .toEqual('email3');
    }));
    /**
     * SelectsSomeAvoidNames 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)
        // Excluded attributes: ['GroupOfPeopleAge1', 'GroupOfPeopleAge2', 'GroupOfPeopleAge3']
        expect(resolvedEntity.attributes.length)
            .toEqual(13);
        expect(resolvedEntity.attributes.allItems[0].name)
            .toEqual('GroupOfPeoplePersonCount');
        expect(resolvedEntity.attributes.allItems[1].name)
            .toEqual('GroupOfPeopleName1');
        expect(resolvedEntity.attributes.allItems[2].name)
            .toEqual('GroupOfPeopleAddress1');
        expect(resolvedEntity.attributes.allItems[3].name)
            .toEqual('GroupOfPeoplePhoneNumber1');
        expect(resolvedEntity.attributes.allItems[4].name)
            .toEqual('GroupOfPeopleEmail1');
        expect(resolvedEntity.attributes.allItems[5].name)
            .toEqual('GroupOfPeopleName2');
        expect(resolvedEntity.attributes.allItems[6].name)
            .toEqual('GroupOfPeopleAddress2');
        expect(resolvedEntity.attributes.allItems[7].name)
            .toEqual('GroupOfPeoplePhoneNumber2');
        expect(resolvedEntity.attributes.allItems[8].name)
            .toEqual('GroupOfPeopleEmail2');
        expect(resolvedEntity.attributes.allItems[9].name)
            .toEqual('GroupOfPeopleName3');
        expect(resolvedEntity.attributes.allItems[10].name)
            .toEqual('GroupOfPeopleAddress3');
        expect(resolvedEntity.attributes.allItems[11].name)
            .toEqual('GroupOfPeoplePhoneNumber3');
        expect(resolvedEntity.attributes.allItems[12].name)
            .toEqual('GroupOfPeopleEmail3');
    }));
    /**
     * SelectsSomeAvoidNames on an array source that has renameFormat = '{m}'
     */
    it('TestArraySourceRename', () => __awaiter(void 0, void 0, void 0, function* () {
        const testName = 'TestArraySourceRename';
        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)
        // Excluded attributes: ['age1', 'age2', 'age3']
        expect(resolvedEntity.attributes.length)
            .toEqual(13);
        expect(resolvedEntity.attributes.allItems[0].name)
            .toEqual('personCount');
        expect(resolvedEntity.attributes.allItems[1].name)
            .toEqual('name1');
        expect(resolvedEntity.attributes.allItems[2].name)
            .toEqual('address1');
        expect(resolvedEntity.attributes.allItems[3].name)
            .toEqual('phoneNumber1');
        expect(resolvedEntity.attributes.allItems[4].name)
            .toEqual('email1');
        expect(resolvedEntity.attributes.allItems[5].name)
            .toEqual('name2');
        expect(resolvedEntity.attributes.allItems[6].name)
            .toEqual('address2');
        expect(resolvedEntity.attributes.allItems[7].name)
            .toEqual('phoneNumber2');
        expect(resolvedEntity.attributes.allItems[8].name)
            .toEqual('email2');
        expect(resolvedEntity.attributes.allItems[9].name)
            .toEqual('name3');
        expect(resolvedEntity.attributes.allItems[10].name)
            .toEqual('address3');
        expect(resolvedEntity.attributes.allItems[11].name)
            .toEqual('phoneNumber3');
        expect(resolvedEntity.attributes.allItems[12].name)
            .toEqual('email3');
    }));
    /**
     * ExcludeAttributes 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']
        // Excluded attributes: ['address', 'phoneNumber', 'email']
        expect(resolvedEntity.attributes.length)
            .toEqual(2);
        expect(resolvedEntity.attributes.allItems[0].name)
            .toEqual('name');
        expect(resolvedEntity.attributes.allItems[1].name)
            .toEqual('age');
        const resolvedEntity2 = yield projectionTestUtils_1.projectionTestUtils.getResolvedEntity(corpus, entity, []);
        // Original set of attributes: ['name', 'age', 'address', 'phoneNumber', 'email']
        // Excluded 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');
    }));
    /**
     * ExcludeAttributes with an empty exclude attributes list
     */
    it('TestEmptyExclude', () => __awaiter(void 0, void 0, void 0, function* () {
        const testName = 'TestEmptyExclude';
        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']
        // Excluded 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');
    }));
    /**
     * ExcludeAttributes 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']
        // Excluded attributes: ['address', 'phoneNumber', 'email']
        expect(resolvedEntity.attributes.length)
            .toEqual(2);
        expect(resolvedEntity.attributes.allItems[0].name)
            .toEqual('name');
        expect(resolvedEntity.attributes.allItems[1].name)
            .toEqual('age');
    }));
    /**
     * SelectsSomeAvoidNames on an entity with an attribute group
     */
    it('TestGroup', () => __awaiter(void 0, void 0, void 0, function* () {
        const testName = 'TestGroup';
        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']
        // Excluded attributes: ['PersonInfoAddress', 'PersonInfoPhoneNumber', 'PersonInfoEmail']
        expect(resolvedEntity.attributes.length)
            .toEqual(2);
        expect(resolvedEntity.attributes.allItems[0].name)
            .toEqual('PersonInfoName');
        expect(resolvedEntity.attributes.allItems[1].name)
            .toEqual('PersonInfoAge');
    }));
    /**
     * SelectsSomeAvoidNames on an entity with an attribute group that has renameFormat = '{m}'
     */
    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: ['name', 'age', 'address', 'phoneNumber', 'email']
        // Excluded attributes: ['address', 'phoneNumber', 'email']
        expect(resolvedEntity.attributes.length)
            .toEqual(2);
        expect(resolvedEntity.attributes.allItems[0].name)
            .toEqual('name');
        expect(resolvedEntity.attributes.allItems[1].name)
            .toEqual('age');
    }));
    /**
     * ExcludeAttributes 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 exclude the entire entity attribute group
     */
    it('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']
        // Excluded attributes: ['OccupationInfo'] (name of entity attribute that contains 'title', 'company', 'tenure')
        expect(resolvedEntity.attributes.length)
            .toEqual(1); // attribute group created because of structured directive
        const attGroup = resolvedEntity.attributes.allItems[0].explicitReference;
        expect(attGroup.members.length)
            .toEqual(5);
        expect(attGroup.members.allItems[0].name)
            .toEqual('name');
        expect(attGroup.members.allItems[1].name)
            .toEqual('age');
        expect(attGroup.members.allItems[2].name)
            .toEqual('address');
        expect(attGroup.members.allItems[3].name)
            .toEqual('phoneNumber');
        expect(attGroup.members.allItems[4].name)
            .toEqual('email');
    }));
    /**
     * Test resolving a type attribute with a exclude 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"]
        // Exclude attributes ["address"]
        expect(resolvedEntity.attributes.length)
            .toEqual(4);
        expect(resolvedEntity.attributes.allItems[0].name)
            .toEqual('name');
        expect(resolvedEntity.attributes.allItems[1].name)
            .toEqual('age');
        expect(resolvedEntity.attributes.allItems[2].name)
            .toEqual('phoneNumber');
        expect(resolvedEntity.attributes.allItems[3].name)
            .toEqual('email');
    }));
});
//# sourceMappingURL=ProjectionExclude.test.js.map