"use strict";
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());
    });
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const fs_1 = __importDefault(require("fs"));
const util_1 = require("util");
const position_fetcher_template_registry_1 = require("../../position/position-fetcher.template-registry");
const app_token_template_position_fetcher_1 = require("../../position/template/app-token.template.position-fetcher");
const harness_1 = require("./harness");
const access = (0, util_1.promisify)(fs_1.default.access);
describe('App Token Fetchers', () => {
    let testHarness;
    beforeAll(() => __awaiter(void 0, void 0, void 0, function* () {
        testHarness = new harness_1.TestHarness();
        yield testHarness.setup();
    }), 30 * 1000);
    afterAll(() => __awaiter(void 0, void 0, void 0, function* () {
        yield testHarness.teardown();
    }));
    it('should follow convention for filenames', () => __awaiter(void 0, void 0, void 0, function* () {
        const registry = testHarness.moduleRef.get(position_fetcher_template_registry_1.PositionFetcherTemplateRegistry);
        registry.onModuleInit();
        const templates = registry.getAllTemplates();
        const fileExists = yield Promise.all(templates.map((t) => __awaiter(void 0, void 0, void 0, function* () {
            const suffix = t instanceof app_token_template_position_fetcher_1.AppTokenTemplatePositionFetcher ? `token-fetcher` : `contract-position-fetcher`;
            return access(`src/apps/${t.appId}/${t.network}/${t.appId}.${t.groupId}.${suffix}.ts`)
                .then(() => true)
                .catch(() => false);
        })));
        const missingFiles = templates
            .filter((_t, i) => !fileExists[i])
            .map(t => `(${t.constructor.name}: ${t.appId}, ${t.groupId}, ${t === null || t === void 0 ? void 0 : t.network})`);
        expect(missingFiles, `${missingFiles.join(', ')} have incorrect filename conventions`).toHaveLength(0);
    }));
});
//# sourceMappingURL=app.fetchers.test.js.map