"use strict";
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
Object.defineProperty(exports, "__esModule", { value: true });
const testHelper_1 = require("../testHelper");
const internal_1 = require("../../internal");
describe('Utilities.TraitToPropertyMapTests', () => {
    const testsSubpath = 'Utilities/TraitToPropertyMap';
    /**
     * Test update and fetch list lookup default value without attributeValue and displayOrder.
     */
    it('TestUpdateAndFetchListLookup', () => {
        const corpus = new internal_1.CdmCorpusDefinition();
        const cdmAttribute = new internal_1.CdmTypeAttributeDefinition(corpus.ctx, 'SomeAttribute');
        const t2pm = new internal_1.traitToPropertyMap(cdmAttribute);
        const constantValues = [
            {
                'languageTag': 'en',
                'displayText': 'Fax'
            }
        ];
        t2pm.updatePropertyValue('defaultValue', constantValues);
        const result = t2pm.fetchPropertyValue('defaultValue');
        expect(result.length).toBe(1);
        expect(result[0]['languageTag']).toBe('en');
        expect(result[0]['displayText']).toBe('Fax');
        expect(result[0]['attributeValue']).toBeNull();
        expect(result[0]['displayOrder']).toBeNull();
    });
    /**
     * Test setting and getting of data format
     */
    it('TestDataFormat', () => {
        const corpus = new internal_1.CdmCorpusDefinition();
        const att = corpus.MakeObject(internal_1.cdmObjectType.typeAttributeDef, 'att');
        // Object.keys give 2x the number that is in the enum
        const l = Object.keys(internal_1.cdmDataFormat).length / 2;
        for (let i = 0; i < l; i++) {
            att.dataFormat = i;
            expect(att.dataFormat)
                .toBe(i);
        }
    });
    /**
     * Test getting primary key.
     */
    it('TestFetchPrimaryKey', () => __awaiter(void 0, void 0, void 0, function* () {
        const corpus = testHelper_1.testHelper.getLocalCorpus(testsSubpath, "TestFetchPrimaryKey");
        const doc = yield corpus.fetchObjectAsync("Account.cdm.json");
        if (doc == undefined) {
            fail("Unable to load manifest account.cdm.json. Please inspect error log for additional details.");
        }
        const entity = doc.definitions.allItems[0];
        try {
            const pk = entity.primaryKey;
        }
        catch (e) {
            fail("Exception occur while reading primary key for entity account." + e);
        }
    }));
});
//# sourceMappingURL=TraitToPropertyMap.test.js.map