Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion .github/workflows/static-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,19 @@ jobs:
bun install --frozen-lockfile

- name: Lint
run: bun lint
run: bun run lint --max-warnings=0
formatt:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: oven-sh/setup-bun@v1

- name: Bun Install
run: |
bun install --frozen-lockfile

- name: Format
run: bun run format --check

verify-open-api-doc:
runs-on: ubuntu-latest
Expand Down
40 changes: 39 additions & 1 deletion .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1 +1,39 @@
bun lint --fix
# Restore stashed unstaged changes. On conflict, restore working tree and re-apply stash.
restore_stash() {
if git stash apply stash@{0} 2>/dev/null; then
git stash drop stash@{0}
else
git restore .
git stash pop
echo "⚠️ Lint/format fixes conflicted with unstaged changes; restored your working tree."
exit 1
fi
}

# Get staged .ts and .json files
staged=$(git diff --cached --name-only | grep -E '\.(ts|json)$' || true)

if [ -n "$staged" ]; then
stash_used=
# Stash unstaged changes so lint/format only see staged content
if ! git diff --quiet; then
git stash push -m "pre-commit: unstaged changes" --keep-index
stash_used=1
fi

echo "$staged" | xargs bunx eslint --fix --max-warnings=0 || { [ -n "$stash_used" ] && restore_stash; exit 1; }
echo "$staged" | xargs bunx prettier --write

# Fail if lint/format changed any of the files we ran on
diff=$(echo "$staged" | xargs git diff --name-only -- 2>/dev/null | sort -u)
if [ -n "$diff" ]; then
[ -n "$stash_used" ] && restore_stash
echo "🚨 Lint or format applied fixes. Stage them and commit again."
echo "$diff" | while read -r f; do
printf '\033[31m%s\033[0m\n' "$f"
done
exit 1
fi

[ -n "$stash_used" ] && restore_stash
fi
Binary file modified bun.lockb
Binary file not shown.
9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,18 @@
"scripts": {
"prepare": "husky",
"dev": "bun --watch ./src/index.ts",
"test": "bun test tests/",
"typecheck": "tsc --noEmit",
"lint": "eslint . --ext .ts,.json",
"format": "prettier '**/*.{ts,json}'",
"format": "bun prettier '**/*.{ts,json}' --write",
"docs": "bun run ./open-api/generate.ts",
"compile": "bun build --compile --sourcemap ./src/index.ts --outfile $1"
},
"lint-staged": {
"*.{ts,json}": [
"eslint --fix"
],
"*.js": "eslint --cache --fix"
"eslint --fix --max-warnings=0",
"prettier --write"
]
},
"devDependencies": {
"@asteasolutions/zod-to-openapi": "^6.3.1",
Expand Down
4 changes: 2 additions & 2 deletions src/auth/admin.test.ts → tests/auth/admin.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { describe, expect, test } from "bun:test"
import express from "express"
import request from "supertest"
import { adminProtected } from "./admin"
import { generateJWT } from "./jwt"
import { adminProtected } from "@/auth/admin"
import { generateJWT } from "@/auth/jwt"

const app = express()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import express from "express"
import request from "supertest"
import { z } from "zod"

import { RaidHubRoute } from "./RaidHubRoute"
import { RaidHubRoute } from "@/core/RaidHubRoute"

const app = express()

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { afterAll, beforeEach, describe, expect, spyOn, test } from "bun:test"
import { getDestinyManifest, transferItem } from "bungie-net-core/endpoints/Destiny2"
import { bungiePlatformHttp } from "./client"
import { BungieApiError } from "./error"
import { bungiePlatformHttp } from "@/integrations/bungie/client"
import { BungieApiError } from "@/integrations/bungie/error"

describe("bungie http client", () => {
const bungieHttp = bungiePlatformHttp({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { afterAll, beforeEach, describe, expect, spyOn, test } from "bun:test"
import { InternalApiError, internalApiFetch } from "./internal-api-client"
import { InternalApiError, internalApiFetch } from "@/lib/utils/internal-api-client"

describe("internalApiFetch", () => {
const spyFetch = spyOn(globalThis, "fetch")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { describe, expect, test } from "bun:test"
import express from "express"
import request from "supertest"
import { cacheControl } from "./cache-control"
import { cacheControl } from "@/middleware/cache-control"

const app = express()

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expectErr, expectOk } from "@/lib/test-utils"
import { describe, test } from "bun:test"
import { adminQueryRoute } from "./query"
import { adminQueryRoute } from "@/routes/admin/query"

describe("admin query 200", () => {
const t = async (query: string, type: string, ignoreCost?: boolean) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { expectErr, expectOk } from "@/lib/test-utils"
import { ErrorCode } from "@/schema/errors/ErrorCode"
import { describe, expect, test } from "bun:test"
import { reportingStandingInstanceRoute } from "./instance-standing"
import { reportingStandingInstanceRoute } from "@/routes/admin/reporting/instance-standing"

describe("instance standing 200", () => {
const t = async (instanceId: string) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { expectErr, expectOk } from "@/lib/test-utils"
import { describe, expect, test } from "bun:test"
import jwt from "jsonwebtoken"
import { adminAuthorizationRoute } from "./admin"
import { adminAuthorizationRoute } from "@/routes/authorize/admin"

describe("authorize 200", () => {
test("admin", async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { expectErr, expectOk } from "@/lib/test-utils"
import { describe, expect, test } from "bun:test"
import jwt from "jsonwebtoken"
import { userAuthorizationRoute } from "./user"
import { userAuthorizationRoute } from "@/routes/authorize/user"

describe("authorize 200", () => {
test("user", async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { expectErr, expectOk } from "@/lib/test-utils"
import { ErrorCode } from "@/schema/errors/ErrorCode"
import { afterAll, beforeEach, describe, expect, spyOn, test } from "bun:test"
import { PlatformErrorCodes } from "bungie-net-core/enums"
import { clanStatsRoute } from "./clanStats"
import { clanStatsRoute } from "@/routes/clanStats"

describe("clan 200", () => {
const spyClanQueueSend = spyOn(clanQueue, "send")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { afterAll, beforeEach, describe, expect, spyOn, test } from "bun:test"
import { instanceCharacterQueue, playersQueue } from "@/integrations/rabbitmq/queues"
import { expectErr, expectOk } from "@/lib/test-utils"

import { instanceRoute } from "./instance"
import { instanceRoute } from "@/routes/instance"

describe("activity 200", () => {
const spyCharQueueSend = spyOn(instanceCharacterQueue, "sendJson")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expectOk } from "@/lib/test-utils"
import { describe, expect, test } from "bun:test"
import { clanLeaderboardRoute } from "./clan"
import { clanLeaderboardRoute } from "@/routes/leaderboard/clan"

describe("clan leaderboard 200", () => {
const t = async (query?: Record<string, unknown>) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expectErr, expectOk } from "@/lib/test-utils"
import { describe, expect, test } from "bun:test"
import { leaderboardTeamContestRoute } from "./contest"
import { leaderboardTeamContestRoute } from "@/routes/leaderboard/team/contest"

describe("contest leaderboard 200", () => {
const t = async (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expectErr, expectOk } from "@/lib/test-utils"
import { describe, expect, test } from "bun:test"
import { leaderboardTeamFirstActivityVersionRoute } from "./first"
import { leaderboardTeamFirstActivityVersionRoute } from "@/routes/leaderboard/team/first"

describe("first leaderboard 200", () => {
const t = async (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expectErr, expectOk } from "@/lib/test-utils"
import { describe, expect, test } from "bun:test"
import { leaderboardIndividualGlobalRoute } from "./global"
import { leaderboardIndividualGlobalRoute } from "@/routes/leaderboard/individual/global"

describe("global leaderboard 200", () => {
const t = async (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expectErr, expectOk } from "@/lib/test-utils"
import { describe, expect, test } from "bun:test"
import { leaderboardIndividualPantheonRoute } from "./pantheon"
import { leaderboardIndividualPantheonRoute } from "@/routes/leaderboard/individual/pantheon"

describe("pantheon leaderboard 200", () => {
const t = async (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expectErr, expectOk } from "@/lib/test-utils"
import { describe, expect, test } from "bun:test"
import { leaderboardIndividualRaidRoute } from "./raid"
import { leaderboardIndividualRaidRoute } from "@/routes/leaderboard/individual/raid"

describe("raid leaderboard 200", () => {
const t = async (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expectOk } from "@/lib/test-utils"
import { test } from "bun:test"
import { manifestRoute } from "./manifest"
import { manifestRoute } from "@/routes/manifest"

test("manifest 200", async () => {
const result = await manifestRoute.$mock()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expectOk } from "@/lib/test-utils"
import { describe, expect, test } from "bun:test"
import { dailyPlayerPopulationRoute } from "./dailyPlayerPopulation"
import { dailyPlayerPopulationRoute } from "@/routes/metrics/dailyPlayerPopulation"

describe("player population 200", () => {
test("it works", async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expectOk } from "@/lib/test-utils"
import { describe, expect, test } from "bun:test"
import { weaponsRollingWeekRoute } from "./weaponsRollingWeek"
import { weaponsRollingWeekRoute } from "@/routes/metrics/weaponsRollingWeek"

describe("weekly weapon meta 200", () => {
const t = async (query: unknown) => {
Expand Down
2 changes: 1 addition & 1 deletion src/routes/pgcr.test.ts → tests/routes/pgcr.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { describe, test } from "bun:test"

import { expectErr, expectOk } from "@/lib/test-utils"

import { pgcrRoute } from "./pgcr"
import { pgcrRoute } from "@/routes/pgcr"

describe("pgcr 200", () => {
const t = async (instanceId: string) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { describe, test } from "bun:test"

import { expectErr, expectOk } from "@/lib/test-utils"

import { playerBasicRoute } from "./basic"
import { playerBasicRoute } from "@/routes/player/membershipId/basic"

describe("player basic 200", () => {
const t = async (membershipId: string) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { expectErr, expectOk } from "@/lib/test-utils"
import express from "express"
import request from "supertest"

import { playerHistoryRoute } from "./history"
import { playerHistoryRoute } from "@/routes/player/membershipId/history"

describe("player activities 200", () => {
const t = async (membershipId: string, cursor?: Date) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { generateJWT } from "@/auth/jwt"
import { expectErr, expectOk } from "@/lib/test-utils"
import { ErrorCode } from "@/schema/errors/ErrorCode"

import { playerInstancesRoute } from "./instances"
import { playerInstancesRoute } from "@/routes/player/membershipId/instances"

describe("instances 200", () => {
const membershipId = "4611686018488107374"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { describe, test } from "bun:test"
import { generateJWT } from "@/auth/jwt"
import { expectErr, expectOk } from "@/lib/test-utils"

import { playerProfileRoute } from "./profile"
import { playerProfileRoute } from "@/routes/player/membershipId/profile"

describe("player profile 200", () => {
const t = async (membershipId: string) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expectOk } from "@/lib/test-utils"
import { describe, expect, test } from "bun:test"
import { playerSearchRoute } from "./search"
import { playerSearchRoute } from "@/routes/player/search"

describe("player search 200", () => {
const t = async (query: unknown) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { describe, test } from "bun:test"
import { generateJWT } from "@/auth/jwt"
import { expectErr, expectOk } from "@/lib/test-utils"

import { playerTeammatesRoute } from "./teammates"
import { playerTeammatesRoute } from "@/routes/player/membershipId/teammates"

describe("teammates 200", () => {
const t = async (membershipId: string) => {
Expand Down
2 changes: 1 addition & 1 deletion src/routes/status.test.ts → tests/routes/status.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import * as BungieCoreEndpoints from "bungie-net-core/endpoints/Core"
import { BungieNetResponse } from "bungie-net-core/interfaces"
import { CoreSettingsConfiguration } from "bungie-net-core/models"

import { statusRoute, statusState } from "./status"
import { statusRoute, statusState } from "@/routes/status"

describe("status 200", async () => {
const spyGetAtlasStatus = spyOn(AtlasModule, "getAtlasStatus")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { afterAll, beforeEach, describe, expect, spyOn, test } from "bun:test"
import { getAtlasStatus } from "."
import { getAtlasStatus } from "@/services/atlas"

describe("getAtlasStatus with mock", () => {
const spyFetch = spyOn(globalThis, "fetch")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { getClanMembers } from "@/integrations/bungie"
import { zClanStats } from "@/schema/components/Clan"
import { describe, expect, test } from "bun:test"
import { getClanStats } from "./clan-stats"
import { getClanStats } from "@/services/clans/clan-stats"

describe("getClanStats", () => {
test("returns the correct shape", async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { zClanLeaderboardEntry } from "@/schema/components/Clan"
import { describe, expect, test } from "bun:test"
import { z } from "zod"
import { getClanLeaderboard } from "./leaderboard"
import { getClanLeaderboard } from "@/services/clans/leaderboard"

describe("getClanLeaderboard", () => {
test("returns the correct shape", async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as MockRabbitAPI from "@/integrations/rabbitmq/api"
import { afterAll, beforeEach, describe, expect, spyOn, test } from "bun:test"
import { getFloodgatesRecentId, getFloodgatesStatus } from "."
import { getFloodgatesRecentId, getFloodgatesStatus } from "@/services/floodgates"

describe("getFloodgatesRecentId with mock", () => {
const spyFetch = spyOn(globalThis, "fetch")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
getInstanceExtended,
getInstanceMetadataByHash,
getLeaderboardEntryForInstance
} from "./instance"
} from "@/services/instance/instance"

describe("getInstance", () => {
test("returns the correct shape", async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
listFeatDefinitions,
listHashes,
listVersionDefinitions
} from "./definitions"
} from "@/services/manifest/definitions"

describe("getRaidId", () => {
test("returns the correct shape", async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { zWeaponMetric } from "@/schema/components/Metrics"
import { describe, expect, test } from "bun:test"
import { z } from "zod"
import { getRollingWeaponMeta } from "./rolling-weapon-meta"
import { getRollingWeaponMeta } from "@/services/metrics/rolling-weapon-meta"

describe("getRollingWeaponMeta", () => {
test("returns the correct shape", async () => {
Expand Down
2 changes: 1 addition & 1 deletion src/services/pgcr.test.ts → tests/services/pgcr.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describe, expect, test } from "bun:test"
import { z } from "zod"
import { getRawCompressedPGCR } from "./pgcr"
import { getRawCompressedPGCR } from "@/services/pgcr"

describe("getRawCompressedPGCR", () => {
test("returns the correct shape", async () => {
Expand Down
Loading