digipinjs
Version:
A comprehensive TypeScript library for encoding and decoding Indian geographic coordinates into DIGIPIN format (Indian Postal Digital PIN system). Features CLI tools, caching, batch processing, and Express middleware for seamless integration.
30 lines (29 loc) • 1.48 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const chai_1 = require("chai");
const cache_1 = require("../cache");
const core_1 = require("../core");
describe('Cache Functions', () => {
beforeEach(() => {
(0, cache_1.clearCache)();
});
it('caches encode results by coordinate and format', () => {
const lat = 28.6139;
const lng = 77.2090;
const pin = (0, core_1.getDigiPin)(lat, lng, { format: 'hyphenated', useCache: false });
(0, chai_1.expect)((0, cache_1.getCachedEncode)(lat, lng, 'hyphenated')).to.be.undefined;
(0, cache_1.setCachedEncode)(lat, lng, pin, 'hyphenated');
(0, chai_1.expect)((0, cache_1.getCachedEncode)(lat, lng, 'hyphenated')).to.equal(pin);
// different format stores independently
const compact = (0, core_1.getDigiPin)(lat, lng, { format: 'compact', useCache: false });
(0, cache_1.setCachedEncode)(lat, lng, compact, 'compact');
(0, chai_1.expect)((0, cache_1.getCachedEncode)(lat, lng, 'compact')).to.equal(compact);
});
it('caches decode results by pin', () => {
const pin = '39J-438-TJC7';
const coords = (0, core_1.getLatLngFromDigiPin)(pin, { useCache: false });
(0, chai_1.expect)((0, cache_1.getCachedDecode)(pin)).to.be.undefined;
(0, cache_1.setCachedDecode)(pin, coords);
(0, chai_1.expect)((0, cache_1.getCachedDecode)(pin)).to.deep.equal(coords);
});
});