"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 path = require("path");
const Storage_1 = require("../../Storage");
const cdmstandards = require("cdm.objectmodel.cdmstandards");
/**
 * Tests if the CdmStandardsAdapter functions correctly.
 */
describe('Storage.CdmStandardsAdapter', () => {
    const EXTENSION_FILE_PATH = '/extensions/pbi.extension.cdm.json';
    const FOUNDATIONS_FILE_PATH = '/cdmfoundation/foundations.cdm.json';
    const INVALID_FILE_PATH = 'invalidFile.cdm.json';
    /**
     * Tests if the corpus path is created correctly.
     */
    it('CreateCorpusPath', () => {
        const adapter = new Storage_1.CdmStandardsAdapter();
        let corpusPath = adapter.createCorpusPath(`${cdmstandards.getRoot()}${EXTENSION_FILE_PATH}`);
        expect(corpusPath).toEqual(EXTENSION_FILE_PATH);
        corpusPath = adapter.createCorpusPath(`${cdmstandards.getRoot()}${FOUNDATIONS_FILE_PATH}`);
        expect(corpusPath).toEqual(FOUNDATIONS_FILE_PATH);
        // invalid paths
        corpusPath = adapter.createCorpusPath(INVALID_FILE_PATH);
        expect(corpusPath).toBeUndefined();
    });
    /**
     * Tests if the adapter path is created correctly.
     */
    it('CreateAdapterPath', () => {
        const adapter = new Storage_1.CdmStandardsAdapter();
        let adapterPath = adapter.createAdapterPath(EXTENSION_FILE_PATH);
        expect(adapterPath).toEqual(path.normalize(`${cdmstandards.getRoot()}${EXTENSION_FILE_PATH}`));
        adapterPath = adapter.createAdapterPath(FOUNDATIONS_FILE_PATH);
        expect(adapterPath).toEqual(path.normalize(`${cdmstandards.getRoot()}${FOUNDATIONS_FILE_PATH}`));
    });
    /**
     * Tests if the adapter is able to read correctly.
     */
    it('ReadAsync', () => __awaiter(void 0, void 0, void 0, function* () {
        const adapter = new Storage_1.CdmStandardsAdapter();
        const extensions = yield adapter.readAsync(EXTENSION_FILE_PATH);
        const foundations = yield adapter.readAsync(FOUNDATIONS_FILE_PATH);
        expect(extensions).toBeDefined();
        expect(foundations).toBeDefined();
        let errorWasThrown = false;
        try {
            yield adapter.readAsync(INVALID_FILE_PATH);
        }
        catch (e) {
            const errorMessageSubstring = 'ENOENT: no such file or directory';
            expect(e.message.substring(0, errorMessageSubstring.length)).toEqual(errorMessageSubstring);
            errorWasThrown = true;
        }
        expect(errorWasThrown).toBeTruthy();
    }));
});
//# sourceMappingURL=cdmStandardsAdapter.test.js.map