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.
45 lines (44 loc) • 2 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('should cache and retrieve values', () => {
const lat = 28.6139;
const lng = 77.2090;
const pin = (0, core_1.getDigiPin)(lat, lng);
// Initially not cached
(0, chai_1.expect)((0, cache_1.getCached)(lat, lng)).to.be.undefined;
// Set cache
(0, cache_1.setCached)(lat, lng, pin);
(0, chai_1.expect)((0, cache_1.getCached)(lat, lng)).to.equal(pin);
});
it('should handle different coordinates', () => {
const coords1 = { lat: 28.6139, lng: 77.2090 }; // Delhi
const coords2 = { lat: 19.0760, lng: 72.8777 }; // Mumbai
const pin1 = (0, core_1.getDigiPin)(coords1.lat, coords1.lng);
const pin2 = (0, core_1.getDigiPin)(coords2.lat, coords2.lng);
(0, cache_1.setCached)(coords1.lat, coords1.lng, pin1);
(0, cache_1.setCached)(coords2.lat, coords2.lng, pin2);
(0, chai_1.expect)((0, cache_1.getCached)(coords1.lat, coords1.lng)).to.equal(pin1);
(0, chai_1.expect)((0, cache_1.getCached)(coords2.lat, coords2.lng)).to.equal(pin2);
});
it('should handle cache misses', () => {
(0, chai_1.expect)((0, cache_1.getCached)(0, 0)).to.be.undefined;
(0, chai_1.expect)((0, cache_1.getCached)(90, 180)).to.be.undefined;
});
it('should handle cache updates', () => {
const lat = 28.6139;
const lng = 77.2090;
const pin1 = 'ABC-123-DEF';
const pin2 = 'XYZ-789-UVW';
(0, cache_1.setCached)(lat, lng, pin1);
(0, chai_1.expect)((0, cache_1.getCached)(lat, lng)).to.equal(pin1);
(0, cache_1.setCached)(lat, lng, pin2);
(0, chai_1.expect)((0, cache_1.getCached)(lat, lng)).to.equal(pin2);
});
});