"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 testHelper_1 = require("../../testHelper");
describe('Persistence.CdmFolder.JsonSemanticVersionTest', () => {
    /**
     * The path between TestDataPath and TestName.
     */
    const testsSubpath = 'Persistence/CdmFolder/JsonSemanticVersionTest';
    /**
     * Test loading a document with a semantic version bigger than the one supported.
     */
    it('testLoadingUnsupportedVersion', (done) => __awaiter(void 0, void 0, void 0, function* () {
        const corpus = testHelper_1.testHelper.getLocalCorpus(testsSubpath, 'TestLoadingUnsupportedVersion');
        let errorCount = 0;
        // Test loading a resolved document.
        corpus.setEventCallback((level, message) => {
            if (message.includes('This ObjectModel version supports json semantic version') && level == internal_1.cdmStatusLevel.warning) {
                errorCount++;
            }
        }, internal_1.cdmStatusLevel.warning);
        yield corpus.fetchObjectAsync('local:/resolvedDoc.cdm.json');
        if (errorCount !== 1) {
            done.fail('Should have logged a warning.');
        }
        errorCount = 0;
        // Test loading a logical document.
        corpus.setEventCallback((level, message) => {
            if (message.includes('This ObjectModel version supports json semantic version') && level == internal_1.cdmStatusLevel.error) {
                errorCount++;
            }
        }, internal_1.cdmStatusLevel.error);
        yield corpus.fetchObjectAsync('local:/logicalDoc.cdm.json');
        if (errorCount !== 1) {
            done.fail('Should have logged an error.');
        }
        errorCount = 0;
        // Test loading a document missing the jsonSemanticVersion property.
        corpus.setEventCallback((level, message) => {
            if (message.includes('jsonSemanticVersion is a required property of a document.') && level == internal_1.cdmStatusLevel.warning) {
                errorCount++;
            }
        }, internal_1.cdmStatusLevel.warning);
        yield corpus.fetchObjectAsync('local:/missingDoc.cdm.json');
        if (errorCount !== 1) {
            done.fail('Should have logged a warning for missing property.');
        }
        done();
    }));
    /**
     * Test loading a document with a semantic version bigger than the one supported.
     */
    it('testLoadingInvalidVersion', (done) => __awaiter(void 0, void 0, void 0, function* () {
        const corpus = testHelper_1.testHelper.getLocalCorpus(testsSubpath, 'TestLoadingInvalidVersion');
        let errorCount = 0;
        corpus.setEventCallback((level, message) => {
            if (message.includes('jsonSemanticVersion must be set using the format <major>.<minor>.<patch>.') && level == internal_1.cdmStatusLevel.warning) {
                errorCount++;
            }
        }, internal_1.cdmStatusLevel.warning);
        // Test loading a version format "a.0.0".
        yield corpus.fetchObjectAsync('local:/invalidVersionDoc.cdm.json');
        if (errorCount !== 1) {
            done.fail('Should have logged a warning.');
        }
        errorCount = 0;
        // Test loading a version format "1.0".
        yield corpus.fetchObjectAsync('local:/invalidFormatDoc.cdm.json');
        if (errorCount !== 1) {
            done.fail('Should have logged a warning.');
        }
        done();
    }));
});
//# sourceMappingURL=JsonSemanticVersion.test.js.map