"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 AttributeResolutionDirectiveSet_1 = require("../../../Utilities/AttributeResolutionDirectiveSet");
const resolveOptions_1 = require("../../../Utilities/resolveOptions");
const testHelper_1 = require("../../testHelper");
describe('Cdm/Resolution/CircularResolution', () => {
    /**
     * The path between TestDataPath and TestName.
     */
    const testsSubpath = 'Cdm/Resolution/CircularResolutionTest';
    /**
     * Test proper behavior for entities that contain circular references
     */
    it('TestCircularReference', () => __awaiter(void 0, void 0, void 0, function* () {
        const cdmCorpus = testHelper_1.testHelper.getLocalCorpus(testsSubpath, 'TestCircularReference');
        const customer = yield cdmCorpus.fetchObjectAsync('local:/Customer.cdm.json/Customer');
        const resCustomerStructured = yield customer.createResolvedEntityAsync('resCustomer', new resolveOptions_1.resolveOptions(customer.inDocument, new AttributeResolutionDirectiveSet_1.AttributeResolutionDirectiveSet(new Set(['normalized', 'structured', 'noMaxDepth']))));
        // check that the circular reference attribute has a single id attribute
        const storeGroupAtt = resCustomerStructured.attributes.allItems[1].explicitReference;
        const customerGroupAtt = storeGroupAtt.members.allItems[1].explicitReference;
        expect(customerGroupAtt.members.length)
            .toBe(1);
        expect(customerGroupAtt.members.allItems[0].name)
            .toBe('customerId');
    }));
    /**
     * Test that relationship is created when an entity contains a reference to itself
     */
    it('TestSelfReference', () => __awaiter(void 0, void 0, void 0, function* () {
        const cdmCorpus = testHelper_1.testHelper.getLocalCorpus(testsSubpath, 'TestSelfReference');
        const manifest = yield cdmCorpus.fetchObjectAsync('local:/SelfReference.manifest.cdm.json');
        yield cdmCorpus.calculateEntityGraphAsync(manifest);
        yield manifest.populateManifestRelationshipsAsync();
        expect(manifest.relationships.length)
            .toBe(1);
        const rel = manifest.relationships.allItems[0];
        expect(rel.fromEntity)
            .toBe('CustTable.cdm.json/CustTable');
        expect(rel.toEntity)
            .toBe('CustTable.cdm.json/CustTable');
        expect(rel.fromEntityAttribute)
            .toBe('FactoringAccountRelationship');
        expect(rel.toEntityAttribute)
            .toBe('PaymTermId');
    }));
});
//# sourceMappingURL=CircularResolution.test.js.map