Skip to content
This repository has been archived by the owner on Apr 19, 2023. It is now read-only.

Commit

Permalink
✨ Use Babel for building
Browse files Browse the repository at this point in the history
  • Loading branch information
AnandChowdhary committed Jul 15, 2019
2 parents ce9aed8 + 47d4ff3 commit 47afbd9
Show file tree
Hide file tree
Showing 8 changed files with 93 additions and 5 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ install:
- "yarn"
script:
- "yarn build"
- "yarn test"
env:
- YARN_GPG=no
11 changes: 10 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
{
"name": "staart-manager",
"version": "1.0.62",
"version": "1.0.65",
"main": "index.js",
"repository": "[email protected]:AnandChowdhary/staart.git",
"author": "Anand Chowdhary <[email protected]>",
"license": "MIT",
"scripts": {
"test": "jest",
"build": "touch .env && mkdir -p dist && cp .env dist/.env && npm run generate-routes && tsc",
"build-babel": "touch .env && babel src -d dist --extensions '.ts' && cp .env dist/.env",
"start": "npm run build-babel && node dist/index.js",
Expand All @@ -30,6 +31,14 @@
"engines": {
"node": "10.16.0"
},
"jest": {
"roots": [
"<rootDir>/src"
],
"transform": {
"^.+\\.tsx?$": "ts-jest"
}
},
"devDependencies": {
"@babel/cli": "^7.5.0",
"@babel/core": "^7.5.4",
Expand Down
2 changes: 1 addition & 1 deletion setup/internal/staart-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.0.62
1.0.65
33 changes: 33 additions & 0 deletions src/helpers/__tests__/location.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { getGeolocationFromIp } from "../location";

test("Gets a location from IP address", async () => {
const location = await getGeolocationFromIp("103.101.26.51");
expect(location).toBeDefined();
});

test("Gets city from IP address", async () => {
const location = await getGeolocationFromIp("103.101.26.51");
expect(location && location.city).toContain("Delhi");
});

test("Gets continent from IP address", async () => {
const location = await getGeolocationFromIp("103.101.26.51");
expect(location && location.continent).toBe("Asia");
});

test("Gets country from IP address", async () => {
const location = await getGeolocationFromIp("103.101.26.51");
expect(location && location.country_code).toBe("IN");
});

test("Gets timezone from IP address", async () => {
const location = await getGeolocationFromIp("103.101.26.51");
expect(location && location.time_zone).toBe("Asia/Kolkata");
});

test("Gets region from IP address", async () => {
const location = await getGeolocationFromIp("103.101.26.51");
expect(location && location.region_name).toBe(
"National Capital Territory of Delhi"
);
});
45 changes: 45 additions & 0 deletions src/helpers/__tests__/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import {
capitalizeEachFirstLetter,
capitalizeFirstAndLastLetter,
capitalizeFirstLetter,
dateToDateTime,
deleteSensitiveInfoUser,
anonymizeIpAddress,
createSlug
} from "../utils";

test("Capitalize name", () => {
expect(capitalizeEachFirstLetter("anand chowdhary")).toBe("Anand Chowdhary");
});

test("Capitalize name", () => {
expect(capitalizeFirstAndLastLetter("johannes van der waals")).toBe(
"Johannes van der Waals"
);
});

test("Capitalize first letter", () => {
expect(capitalizeFirstLetter("anand chowdhary")).toBe("Anand chowdhary");
});

test("Convert date to MySQL datetime", () => {
expect(dateToDateTime(new Date(1563170490000))).toBe("2019-07-15 06:01:30");
});

test("Remove sensitive info", () => {
expect(
deleteSensitiveInfoUser({
id: 1,
name: "Anand Chowdhary",
password: "1abc9c"
}).password
).toBeUndefined();
});

test("Anonymize an IP address", () => {
expect(anonymizeIpAddress("103.101.26.51")).toBe("103.101.26.0");
});

test("Create a slug", () => {
expect(createSlug("Anand Chowdhary")).toContain("anand-chowdhary-");
});
2 changes: 1 addition & 1 deletion src/helpers/jwt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ export const getLoginResponse = async (
{
...user,
location: location
? location.city || location.region_name || location.country
? location.city || location.region_name || location.country_code
: i18n.en.emails["unknown-location"],
token: await approveLocationToken(user.id, locals.ipAddress)
}
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/location.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { CacheCategories } from "../interfaces/enum";

export interface GeoLocation {
city?: string;
country?: string;
country_code?: string;
continent?: string;
latitude?: number;
longitude?: number;
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"emitDecoratorMetadata": true,
"declarationDir": "./dist",
"outDir": "./dist",
"typeRoots": ["src/types"]
"typeRoots": ["src/@types", "node_modules/@types"]
},
"include": ["src/**/*.ts"],
"exclude": ["node_modules"]
Expand Down

0 comments on commit 47afbd9

Please sign in to comment.