"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 AddCountAttribute operation in a projection as well as CountAttribute in a resolution guidance
 */
describe('Cdm/Projection/ProjectionAddCountTest', () => {
    /**
     * 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/ProjectionAddCountTest';
    /**
     * Test for creating a projection with an AddCountAttribute 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 AddCountAttribute operation
        const addCountAttrOp = corpus.MakeObject(internal_1.cdmObjectType.operationAddCountAttributeDef);
        addCountAttrOp.countAttribute = corpus.MakeObject(internal_1.cdmObjectType.typeAttributeDef, 'testCount');
        addCountAttrOp.countAttribute.dataType = corpus.MakeRef(internal_1.cdmObjectType.dataTypeRef, 'integer', true);
        projection.operations.push(addCountAttrOp);
        // 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 AddCountAttribute operation
        // Original set of attributes: ["id", "name", "value", "date"]
        // Count attribute: "testCount"
        expect(resolvedEntity.attributes.length)
            .toEqual(5);
        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');
        expect(resolvedEntity.attributes.allItems[4].name)
            .toEqual('testCount');
        expect(resolvedEntity.attributes.allItems[4].appliedTraits.allItems[1].namedReference)
            .toEqual('is.linkedEntity.array.count');
    }));
    /**
     * Test for creating a projection with an AddCountAttribute 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 AddCountAttribute operation
        const addCountAttrOp = corpus.MakeObject(internal_1.cdmObjectType.operationAddCountAttributeDef);
        addCountAttrOp.countAttribute = corpus.MakeObject(internal_1.cdmObjectType.typeAttributeDef, 'testCount');
        addCountAttrOp.countAttribute.dataType = corpus.MakeRef(internal_1.cdmObjectType.dataTypeRef, 'integer', true);
        projection.operations.push(addCountAttrOp);
        // 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 AddCountAttribute operation
        // Original set of attributes: ["id", "name", "value", "date"]
        // Count attribute: "testCount"
        expect(resolvedEntity.attributes.length)
            .toEqual(5);
        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');
        expect(resolvedEntity.attributes.allItems[4].name)
            .toEqual('testCount');
        expect(resolvedEntity.attributes.allItems[4].appliedTraits.allItems[1].namedReference)
            .toEqual('is.linkedEntity.array.count');
    }));
    /**
     * Test for creating a projection with an AddCountAttribute 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 AddCountAttribute operation
        const addCountAttrOp = corpus.MakeObject(internal_1.cdmObjectType.operationAddCountAttributeDef);
        addCountAttrOp.countAttribute = corpus.MakeObject(internal_1.cdmObjectType.typeAttributeDef, 'testCount');
        addCountAttrOp.countAttribute.dataType = corpus.MakeRef(internal_1.cdmObjectType.dataTypeRef, 'integer', true);
        projection.operations.push(addCountAttrOp);
        // 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 AddCountAttribute operation
        // Original set of attributes: ["id", "name", "value", "date"]
        // Count attribute: "testCount"
        expect(resolvedEntityWithReferenceOnly.attributes.length)
            .toEqual(5);
        expect(resolvedEntityWithReferenceOnly.attributes.allItems[0].name)
            .toEqual('id');
        expect(resolvedEntityWithReferenceOnly.attributes.allItems[1].name)
            .toEqual('name');
        expect(resolvedEntityWithReferenceOnly.attributes.allItems[2].name)
            .toEqual('value');
        expect(resolvedEntityWithReferenceOnly.attributes.allItems[3].name)
            .toEqual('date');
        expect(resolvedEntityWithReferenceOnly.attributes.allItems[4].name)
            .toEqual('testCount');
        expect(resolvedEntityWithReferenceOnly.attributes.allItems[4].appliedTraits.allItems[1].namedReference)
            .toEqual('is.linkedEntity.array.count');
        // 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 AddCountAttribute operation
        // Original set of attributes: ["id", "name", "value", "date"]
        // No Count attribute added, 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');
    }));
    /**
     * AddCountAttribute on an entity attribute
     */
    it('TestAddCountAttribute', () => __awaiter(void 0, void 0, void 0, function* () {
        const testName = 'TestAddCountAttribute';
        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"]
        // Count attribute: "someCount"
        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('address');
        expect(resolvedEntity.attributes.allItems[3].name)
            .toEqual('phoneNumber');
        expect(resolvedEntity.attributes.allItems[4].name)
            .toEqual('email');
        expect(resolvedEntity.attributes.allItems[5].name)
            .toEqual('someCount');
        expect(resolvedEntity.attributes.allItems[5].appliedTraits.allItems[1].namedReference)
            .toEqual('is.linkedEntity.array.count');
    }));
    /**
     * CountAttribute on an entity attribute
     */
    it('TestCountAttribute', () => __awaiter(void 0, void 0, void 0, function* () {
        const testName = 'TestCountAttribute';
        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"]
        // Count attribute: "someCount"
        // For resolution guidance, CountAttribute has to be used with Expansion so we do an Expansion of 1...1 here
        expect(resolvedEntity.attributes.length)
            .toEqual(6);
        expect(resolvedEntity.attributes.allItems[0].name)
            .toEqual('someCount');
        expect(resolvedEntity.attributes.allItems[0].appliedTraits.allItems[1].namedReference)
            .toEqual('is.linkedEntity.array.count');
        expect(resolvedEntity.attributes.allItems[1].name)
            .toEqual('name1');
        expect(resolvedEntity.attributes.allItems[2].name)
            .toEqual('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');
    }));
    /**
     * AddCountAttribute on an entity definition
     */
    it('TestExtendsEntityProj', () => __awaiter(void 0, void 0, void 0, function* () {
        const testName = 'TestExtendsEntityProj';
        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"]
        // Count attribute: "someCount"
        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('address');
        expect(resolvedEntity.attributes.allItems[3].name)
            .toEqual('phoneNumber');
        expect(resolvedEntity.attributes.allItems[4].name)
            .toEqual('email');
        expect(resolvedEntity.attributes.allItems[5].name)
            .toEqual('someCount');
        expect(resolvedEntity.attributes.allItems[5].appliedTraits.allItems[1].namedReference)
            .toEqual('is.linkedEntity.array.count');
    }));
    /**
     * CountAttribute on an entity definition
     */
    it('TestExtendsEntity', () => __awaiter(void 0, void 0, void 0, function* () {
        const testName = 'TestExtendsEntity';
        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"]
        // Count attribute: "someCount"
        // For resolution guidance, CountAttribute has to be used with Expansion so we do an Expansion of 1...1 here
        // ExtendsEntityResolutionGuidance doesn't support doing expansions, so we only get the Count attribute
        expect(resolvedEntity.attributes.length)
            .toEqual(1);
        expect(resolvedEntity.attributes.allItems[0].name)
            .toEqual('someCount');
        expect(resolvedEntity.attributes.allItems[0].appliedTraits.allItems[1].namedReference)
            .toEqual('is.linkedEntity.array.count');
    }));
    /**
     * Nested projections with ArrayExpansion, then AddCountAttribute, and then RenameAttributes
     */
    it('TestWithNestedArrayExpansion', () => __awaiter(void 0, void 0, void 0, function* () {
        const testName = 'TestWithNestedArrayExpansion';
        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"]
        // Count attribute: "personCount", expand 1...2, renameFormat = {m}{o}
        expect(resolvedEntity.attributes.length)
            .toEqual(11);
        expect(resolvedEntity.attributes.allItems[0].name)
            .toEqual('name1');
        expect(resolvedEntity.attributes.allItems[1].name)
            .toEqual('age1');
        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('age2');
        expect(resolvedEntity.attributes.allItems[7].name)
            .toEqual('address2');
        expect(resolvedEntity.attributes.allItems[8].name)
            .toEqual('phoneNumber2');
        expect(resolvedEntity.attributes.allItems[9].name)
            .toEqual('email2');
        expect(resolvedEntity.attributes.allItems[10].name)
            .toEqual('personCount');
        expect(resolvedEntity.attributes.allItems[10].appliedTraits.allItems[1].namedReference)
            .toEqual('is.linkedEntity.array.count');
        expect(resolvedEntity.attributes.allItems[10].appliedTraits.allItems[2].namedReference)
            .toEqual('indicates.expansionInfo.count');
    }));
    /**
     * AddCountAttribute with other operations in the same projection
     */
    it('TestCombineOps', () => __awaiter(void 0, void 0, void 0, function* () {
        const testName = 'TestCombineOps';
        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"]
        // Count attribute: "someCount", count attribute: "anotherCount", rename "name" to "firstName"
        expect(resolvedEntity.attributes.length)
            .toEqual(8);
        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');
        expect(resolvedEntity.attributes.allItems[5].name)
            .toEqual('someCount');
        expect(resolvedEntity.attributes.allItems[5].appliedTraits.allItems[1].namedReference)
            .toEqual('is.linkedEntity.array.count');
        expect(resolvedEntity.attributes.allItems[6].name)
            .toEqual('anotherCount');
        expect(resolvedEntity.attributes.allItems[6].appliedTraits.allItems[1].namedReference)
            .toEqual('is.linkedEntity.array.count');
        expect(resolvedEntity.attributes.allItems[7].name)
            .toEqual('firstName');
    }));
    /**
     * Nested projections with AddCountAttribute and other operations
     */
    it('TestCombineOpsNestedProj', () => __awaiter(void 0, void 0, void 0, function* () {
        const testName = 'TestCombineOpsNestedProj';
        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"]
        // Count attribute: "someCount", renameFormat = new_{m}, include ["new_name", "age", "new_someCount"]
        expect(resolvedEntity.attributes.length)
            .toEqual(3);
        expect(resolvedEntity.attributes.allItems[0].name)
            .toEqual('new_name');
        expect(resolvedEntity.attributes.allItems[1].name)
            .toEqual('new_age');
        expect(resolvedEntity.attributes.allItems[2].name)
            .toEqual('new_someCount');
        expect(resolvedEntity.attributes.allItems[2].appliedTraits.allItems[1].namedReference)
            .toEqual('is.linkedEntity.array.count');
    }));
    /**
     * AddCountAttribute 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, []);
        // Original set of attributes: ["name", "age", "address", "phoneNumber", "email"]
        // Count attribute: "someCount"
        // Condition is false, so no Count attribute added
        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');
    }));
    /**
     * AddCountAttribute 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"]
        // Count attribute: "someCount"
        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('address');
        expect(resolvedEntity.attributes.allItems[3].name)
            .toEqual('phoneNumber');
        expect(resolvedEntity.attributes.allItems[4].name)
            .toEqual('email');
        expect(resolvedEntity.attributes.allItems[5].name)
            .toEqual('someCount');
        expect(resolvedEntity.attributes.allItems[5].appliedTraits.allItems[1].namedReference)
            .toEqual('is.linkedEntity.array.count');
    }));
    /**
     * CountAttribute 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: ["name", "age", "address", "phoneNumber", "email"]
        // Count attribute: "someCount"
        // For resolution guidance, CountAttribute has to be used with Expansion so we do an Expansion of 1...1 here
        expect(resolvedEntity.attributes.length)
            .toEqual(6);
        expect(resolvedEntity.attributes.allItems[0].name)
            .toEqual('someCount');
        expect(resolvedEntity.attributes.allItems[0].appliedTraits.allItems[1].namedReference)
            .toEqual('is.linkedEntity.array.count');
        expect(resolvedEntity.attributes.allItems[1].name)
            .toEqual('name1');
        expect(resolvedEntity.attributes.allItems[2].name)
            .toEqual('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');
    }));
    /**
     * Two AddCountAttribute operations in a single projection using the same Count attribute
     */
    it('TestDuplicate', () => __awaiter(void 0, void 0, void 0, function* () {
        const testName = 'TestDuplicate';
        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"]
        // Count attribute: "someCount", count attribute: "someCount"
        // "someCount" should get merged into one
        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('address');
        expect(resolvedEntity.attributes.allItems[3].name)
            .toEqual('phoneNumber');
        expect(resolvedEntity.attributes.allItems[4].name)
            .toEqual('email');
        expect(resolvedEntity.attributes.allItems[5].name)
            .toEqual('someCount');
        expect(resolvedEntity.attributes.allItems[5].appliedTraits.allItems[1].namedReference)
            .toEqual('is.linkedEntity.array.count');
    }));
});
//# sourceMappingURL=ProjectionAddCount.test.js.map