"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 Persistence_1 = require("../../../Persistence");
const testHelper_1 = require("../../testHelper");
describe('Persistence.ModelJson.ModelJson', () => {
    /**
     * Test path between TestDataPath and TestName.
     */
    const testsSubpath = 'Persistence/ModelJson/DataPartition';
    it('TestModelJsonDataPartitionLocationConsistency', () => __awaiter(void 0, void 0, void 0, function* () {
        const cdmCorpus = testHelper_1.testHelper.getLocalCorpus(testsSubpath, 'TestModelJsonDataPartitionLocationConsistency');
        const manifestRead = yield cdmCorpus.fetchObjectAsync('default.manifest.cdm.json', cdmCorpus.storage.fetchRootFolder('local'));
        expect(manifestRead.entities.allItems[0].dataPartitions.allItems[0].location)
            .toEqual('EpisodeOfCare/partition-data.csv');
        const convertedToModelJson = yield Persistence_1.ModelJson.ManifestPersistence.toData(manifestRead, undefined, undefined);
        const location = convertedToModelJson.entities[0]['partitions'][0].location;
        expect(location.indexOf('\\Persistence\\ModelJson\\DataPartition\\TestModelJsonDataPartitionLocationConsistency\\Input\\EpisodeOfCare\\partition-data.csv'))
            .toBeGreaterThan(-1);
        const cdmCorpus2 = testHelper_1.testHelper.getLocalCorpus(testsSubpath, 'TestModelJsonDataPartitionLocationConsistency');
        const manifestAfterConvertion = yield Persistence_1.ModelJson.ManifestPersistence.fromObject(cdmCorpus2.ctx, convertedToModelJson, cdmCorpus2.storage.fetchRootFolder('local'));
        expect(manifestAfterConvertion.entities.allItems[0].dataPartitions.allItems[0].location)
            .toEqual('EpisodeOfCare/partition-data.csv');
        const cdmCorpus3 = testHelper_1.testHelper.getLocalCorpus(testsSubpath, 'TestModelJsonDataPartitionLocationConsistency');
        const readFile = testHelper_1.testHelper.getInputFileContent(testsSubpath, 'TestModelJsonDataPartitionLocationConsistency', 'model.json');
        const namespaceFolder = cdmCorpus3.storage.fetchRootFolder('local');
        let modelJsonAsString = readFile;
        modelJsonAsString = modelJsonAsString.replace(/\r\n/g, '\n');
        modelJsonAsString = modelJsonAsString.replace(/\s/g, '');
        modelJsonAsString = modelJsonAsString.replace('C:\\\\cdm\\\\testData\\\\Persistence\\\\ModelJson\\\\DataPartition\\\\TestModelJsonDataPartitionLocationConsistency\\\\Input\\\\EpisodeOfCare\\\\partition-data.csv', location.replace(new RegExp('\\\\', 'g'), '\\\\'));
        modelJsonAsString = modelJsonAsString.replace(new RegExp('/', 'g'), '\\\\');
        const manifestReadFromModelJson = yield Persistence_1.ModelJson.ManifestPersistence.fromObject(cdmCorpus3.ctx, JSON.parse(modelJsonAsString), namespaceFolder);
        expect(manifestReadFromModelJson.entities.allItems[0].dataPartitions.allItems[0].location)
            .toEqual('EpisodeOfCare/partition-data.csv');
    }));
});
//# sourceMappingURL=dataPartition.test.js.map