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: 9 additions & 5 deletions apps/api/src/routes/beacon.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ describe("beacon endpoint", () => {
vi.clearAllMocks();
});

function getExpectedVersion(clientVersion: string) {
return process.env.APP_VERSION ?? clientVersion;
}

it("should accept valid beacon data", async () => {
const beaconData = {
uuid: "123e4567-e89b-12d3-a456-426614174000",
Expand Down Expand Up @@ -46,7 +50,7 @@ describe("beacon endpoint", () => {
installation: beaconData.type,
timestamp: beaconData.timestamp,
source: "self_hosted_api",
version: beaconData.version,
version: getExpectedVersion(beaconData.version),
client_ip: null, // No IP headers provided
country: undefined,
region: undefined,
Expand Down Expand Up @@ -86,7 +90,7 @@ describe("beacon endpoint", () => {
installation: beaconData.type,
timestamp: beaconData.timestamp,
source: "self_hosted_api",
version: beaconData.version,
version: getExpectedVersion(beaconData.version),
client_ip: "203.0.113.42",
country: "US",
region: "California",
Expand Down Expand Up @@ -125,7 +129,7 @@ describe("beacon endpoint", () => {
installation: beaconData.type,
timestamp: beaconData.timestamp,
source: "self_hosted_api",
version: beaconData.version,
version: getExpectedVersion(beaconData.version),
client_ip: "198.51.100.25", // First IP from X-Forwarded-For
country: undefined, // GCP doesn't provide country in standard headers
region: "us-central1",
Expand Down Expand Up @@ -162,7 +166,7 @@ describe("beacon endpoint", () => {
installation: beaconData.type,
timestamp: beaconData.timestamp,
source: "self_hosted_api",
version: beaconData.version,
version: getExpectedVersion(beaconData.version),
client_ip: "192.0.2.123",
country: undefined,
region: undefined,
Expand Down Expand Up @@ -199,7 +203,7 @@ describe("beacon endpoint", () => {
installation: beaconData.type,
timestamp: beaconData.timestamp,
source: "self_hosted_api",
version: beaconData.version,
version: getExpectedVersion(beaconData.version),
client_ip: null,
country: undefined,
region: undefined,
Expand Down
2 changes: 1 addition & 1 deletion apps/api/src/routes/beacon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ beacon.openapi(beaconRoute, async (c) => {
installation: beaconData.type,
timestamp: beaconData.timestamp,
source: "self_hosted_api",
version: beaconData.version,
version: process.env.APP_VERSION ?? beaconData.version,
client_ip: clientIP,
country: regionInfo.country,
region: regionInfo.region,
Expand Down
Loading
Loading