add test for geoip

This commit is contained in:
undefined committed 2020-08-29 20:23:59 +08:00
1 parent 7651b0a697
commit a8bdfa8f30
7 files changed
+26 -13

No files matched your search

+6 -4
View File
@@ -14,7 +14,7 @@ export interface Result {
display: string
}
function lookup(ip: string, locale: string) {
export function lookup(ip: string, locale: string): any {
const res: any = reader.get(ip);
if (!res) return {};
const ret: Result = { display: '' };
@@ -25,11 +25,13 @@ function lookup(ip: string, locale: string) {
|| (res.country || res.registered_country).names.en;
}
if (res.city) ret.city = res.city.names[locale] || res.city.names.en;
ret.display = `${ret.continent} ${ret.country} ${ret.city}`;
ret.display = `${ret.continent} ${ret.country}${ret.city ? ` ${ret.city}` : ''}`;
return ret;
}
global.Hydro.lib.geoip = exports = {
provider: '<a href="http://www.maxmind.com" target="_blank">MaxMind</a>',
export const provider = '<a href="http://www.maxmind.com" target="_blank">MaxMind</a>';
global.Hydro.lib.geoip = {
provider,
lookup,
};
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@hydrooj/geoip",
"version": "1.1.7",
"version": "1.1.8",
"main": "package.json",
"repository": "git@github.com:hydro-dev/Hydro.git",
"author": "undefined <masnn0@outlook.com>",
+9
View File
@@ -0,0 +1,9 @@
jest.mock('hydrooj/src/loader');
import * as lib from '@hydrooj/geoip/lib';
describe('geoip', () => {
test('MD5', () => {
expect(lib.lookup('127.0.0.1', 'zh_CN')).toStrictEqual({});
expect(lib.lookup('1.1.1.1', 'zh-CN').display).toStrictEqual('大洋洲 澳大利亚');
});
});