forked from PostHog/posthog-plugin-geoip
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
34 additions
and
43 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,35 @@ | ||
import { Plugin, PluginMeta } from '@posthog/plugin-scaffold' | ||
// @ts-ignore | ||
import { createPageview, clone } from '@posthog/plugin-scaffold/test/utils' | ||
import { createPageview, resetMeta } from '@posthog/plugin-scaffold/test/utils' | ||
import { join } from 'path' | ||
import { Reader } from '@maxmind/geoip2-node' | ||
import * as index from '.' | ||
|
||
// import { processEvent } from '..' | ||
const { processEvent } = index as Required<Plugin> | ||
|
||
// test('setupPlugin and processEvent with no DB', async () => { | ||
// const pageviewEvent = createPageview() | ||
// const processedPageviewEvent = await processEvent(clone(pageviewEvent)) | ||
// expect(processedPageviewEvent).toEqual(pageviewEvent) | ||
// }) | ||
async function resetMetaWithMmdb(file = 'GeoLite2-City-Test.mmdb'): Promise<PluginMeta> { | ||
const mmdb = await Reader.open(join(__dirname, file)) | ||
return resetMeta({ | ||
geoip: { | ||
locate: (ipAddress: string) => mmdb.city(ipAddress), | ||
}, | ||
}) as PluginMeta | ||
} | ||
|
||
// test('GeoLite2-City', async () => { | ||
// const event = await processEvent({ ...createPageview(), ip: '89.160.20.129' }) | ||
// expect(event!.properties).toEqual( | ||
// expect.objectContaining({ | ||
// $city_name: 'Linköping', | ||
// $country_name: 'Sweden', | ||
// $country_code: 'SE', | ||
// $continent_name: 'Europe', | ||
// $continent_code: 'EU', | ||
// $latitude: 58.4167, | ||
// $longitude: 15.6167, | ||
// $time_zone: 'Europe/Stockholm', | ||
// $subdivision_1_code: 'E', | ||
// $subdivision_1_name: 'Östergötland County', | ||
// }) | ||
// ) | ||
// }) | ||
|
||
// test('GeoIP2-City', async () => { | ||
// const event = await processEvent({ ...createPageview(), ip: '89.160.20.129' }) | ||
// expect(event!.properties).toEqual( | ||
// expect.objectContaining({ | ||
// $city_name: 'Linköping', | ||
// $country_name: 'Sweden', | ||
// $country_code: 'SE', | ||
// $continent_name: 'Europe', | ||
// $continent_code: 'EU', | ||
// $latitude: 58.4167, | ||
// $longitude: 15.6167, | ||
// $time_zone: 'Europe/Stockholm', | ||
// $subdivision_1_code: 'E', | ||
// $subdivision_1_name: 'Östergötland County', | ||
// }) | ||
// ) | ||
// }) | ||
test('GeoLite2-City', async () => { | ||
const event = await processEvent({ ...createPageview(), ip: '89.160.20.129' }, await resetMetaWithMmdb()) | ||
expect(event!.properties).toEqual( | ||
expect.objectContaining({ | ||
$city_name: 'Linköping', | ||
$country_name: 'Sweden', | ||
$country_code: 'SE', | ||
$continent_name: 'Europe', | ||
$continent_code: 'EU', | ||
$latitude: 58.4167, | ||
$longitude: 15.6167, | ||
$time_zone: 'Europe/Stockholm', | ||
$subdivision_1_code: 'E', | ||
$subdivision_1_name: 'Östergötland County', | ||
}) | ||
) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,7 +17,7 @@ | |
"homepage": "https://github.com/PostHog/posthog-plugin-geoip#readme", | ||
"author": "PostHog <[email protected]>", | ||
"scripts": { | ||
"test": "jest src", | ||
"test": "jest .", | ||
"lint": "eslint .", | ||
"lint:fix": "eslint --fix .", | ||
"format": "prettier --write .", | ||
|
@@ -27,6 +27,7 @@ | |
}, | ||
"dependencies": {}, | ||
"devDependencies": { | ||
"@maxmind/geoip2-node": "^2.3.1", | ||
"@posthog/plugin-scaffold": "0.4.2", | ||
"@types/jest": "^26.0.19", | ||
"@typescript-eslint/eslint-plugin": "^4.12.0", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters