import assert from 'node:assert';
import { describe, it } from 'node:test';
import { Epsg } from '../../../epsg.js';
import { Projection } from '../../projection.js';
import { ProjectionLoader } from '../../projection.loader.js';
import { UtmZone } from '../../utmzone.js';
import { ProjJsons } from '../proj.json.js';
import { FakeData } from './fake.data.js';
describe('ProjJson', () => {
    it('should ensure that all supported EPSG codes have an Epsg and Projection', () => {
        for (const epsg of Epsg.Codes.values()) {
            // ensure that an Epsg and Projection already exist
            assert.doesNotThrow(() => Epsg.get(epsg.code));
            assert.doesNotThrow(() => Projection.get(epsg));
        }
    });
    it('should parse each unsupported EPSG code and ProjJSON pair into a runtime Epsg and Projection', async () => {
        for (const key of Object.keys(ProjJsons)) {
            const code = Number(key);
            // skip any already supported EPSG codes
            if (Epsg.tryGet(code) != null)
                continue;
            // ensure that neither an Epsg or Projection already exists
            assert.throws(() => Epsg.get(code));
            assert.throws(() => Projection.get(code));
            // ensure that both an Epsg and Projection now exist
            const epsg = await ProjectionLoader.load(code);
            assert.doesNotThrow(() => Epsg.get(code));
            assert.doesNotThrow(() => Projection.get(epsg));
        }
    });
    it('should generate a ProjJSON for a UTM Zone EPSG code that matches the spatialreference.org ProjJSON', async (t) => {
        /**
         * Simulate the spatialreference.org API call performed by the`fetchProjJson` method.
         */
        t.mock.method(ProjectionLoader, 'fetchProjJson', (code) => {
            return FakeData.ProjJson[code];
        });
        const codes = [32701, 32730, 32760];
        for (const code of codes) {
            const generatedProjJson = UtmZone.generateProjJson(code);
            const fetchedProjJson = await ProjectionLoader.fetchProjJson(code);
            /**
             * The 'area' property sometimes has extra text after the expected sentence.
             * Slice it off the fetched ProjJSON so it doesn't interrupt the comparison.
             *
             * @example https://spatialreference.org/ref/epsg/32701/projjson.json
             * @example https://spatialreference.org/ref/epsg/32760/projjson.json
             */
            fetchedProjJson.area = fetchedProjJson.area?.substring(0, fetchedProjJson.area.indexOf('.') + 1);
            assert.strictEqual(JSON.stringify(generatedProjJson), JSON.stringify(fetchedProjJson), `The generated and fetched ProjJSONs are not identical for code: ${code}`);
        }
    });
});
//# sourceMappingURL=proj.json.test.js.map