Update hivegrid-cloud reference to latest main
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
e98d38e716
commit
7b21524c86
3781 files changed
+373484
-225607
No files matched your search
+13
-13
@@ -8,15 +8,15 @@ const TEST_TOKEN = "test-service-token";
|
||||
|
||||
let mockStore: Map<string, { id: string; userId: string; tenantId: string | null; platform: string; token: string; pushProvider: string; appVersion: string | null; createdAt: Date; lastSeenAt: Date; revokedAt: Date | null }>;
|
||||
|
||||
vi.mock("@toolctrl/db/device-tokens.server", () => ({
|
||||
vi.mock("@hivegrid/db/device-tokens.server", () => ({
|
||||
parseDevicePlatform: (value: unknown) => {
|
||||
return value === "ios" || value === "android" || value === "web" ? value : null;
|
||||
return value === "web" ? value : null;
|
||||
},
|
||||
parsePushProvider: (value: unknown) => {
|
||||
return value === "fcm" || value === "apns" || value === "webpush" ? value : null;
|
||||
return value === "webpush" ? value : null;
|
||||
},
|
||||
async registerDeviceToken(input: { userId: string; tenantId: string | null; platform: "ios" | "android" | "web"; token: string; pushProvider?: "fcm" | "apns" | "webpush"; appVersion?: string | null }) {
|
||||
const provider = input.pushProvider ?? (input.platform === "ios" ? "apns" : input.platform === "android" ? "fcm" : "webpush");
|
||||
async registerDeviceToken(input: { userId: string; tenantId: string | null; platform: "web"; token: string; pushProvider?: "webpush"; appVersion?: string | null }) {
|
||||
const provider = input.pushProvider ?? "webpush";
|
||||
const now = new Date();
|
||||
const existing = mockStore.get(input.token);
|
||||
if (existing) {
|
||||
@@ -102,7 +102,7 @@ describe("POST /v1/devices/register", () => {
|
||||
|
||||
it("rejects missing userId", async () => {
|
||||
const app = buildApp();
|
||||
const response = await postRegister(app, { platform: "ios", token: "t" });
|
||||
const response = await postRegister(app, { platform: "web", token: "t" });
|
||||
expect(response.status).toBe(400);
|
||||
const json = (await response.json()) as { error: { params: { field: string } } };
|
||||
expect(json.error.params.field).toBe("userId");
|
||||
@@ -116,7 +116,7 @@ describe("POST /v1/devices/register", () => {
|
||||
|
||||
it("rejects missing token", async () => {
|
||||
const app = buildApp();
|
||||
const response = await postRegister(app, { userId: "u1", platform: "ios" });
|
||||
const response = await postRegister(app, { userId: "u1", platform: "web" });
|
||||
expect(response.status).toBe(400);
|
||||
const json = (await response.json()) as { error: { params: { field: string } } };
|
||||
expect(json.error.params.field).toBe("token");
|
||||
@@ -127,23 +127,23 @@ describe("POST /v1/devices/register", () => {
|
||||
const response = await postRegister(app, {
|
||||
userId: "u-1",
|
||||
tenantId: "t-1",
|
||||
platform: "ios",
|
||||
platform: "web",
|
||||
token: "tok-1",
|
||||
appVersion: "1.2.3",
|
||||
});
|
||||
expect(response.status).toBe(200);
|
||||
const json = (await response.json()) as { success: boolean; data: { pushProvider: string; platform: string; appVersion: string | null } };
|
||||
expect(json.success).toBe(true);
|
||||
expect(json.data.platform).toBe("ios");
|
||||
expect(json.data.pushProvider).toBe("apns");
|
||||
expect(json.data.platform).toBe("web");
|
||||
expect(json.data.pushProvider).toBe("webpush");
|
||||
expect(json.data.appVersion).toBe("1.2.3");
|
||||
expect(mockStore.size).toBe(1);
|
||||
});
|
||||
|
||||
it("is idempotent: re-registering the same token bumps lastSeenAt without duplicating", async () => {
|
||||
const app = buildApp();
|
||||
await postRegister(app, { userId: "u-1", tenantId: null, platform: "android", token: "tok-x" });
|
||||
const second = await postRegister(app, { userId: "u-1", tenantId: null, platform: "android", token: "tok-x" });
|
||||
await postRegister(app, { userId: "u-1", tenantId: null, platform: "web", token: "tok-x" });
|
||||
const second = await postRegister(app, { userId: "u-1", tenantId: null, platform: "web", token: "tok-x" });
|
||||
expect(second.status).toBe(200);
|
||||
expect(mockStore.size).toBe(1);
|
||||
});
|
||||
@@ -152,7 +152,7 @@ describe("POST /v1/devices/register", () => {
|
||||
describe("POST /v1/devices/revoke", () => {
|
||||
it("revokes a known token", async () => {
|
||||
const app = buildApp();
|
||||
await postRegister(app, { userId: "u-1", platform: "ios", token: "tok-a" });
|
||||
await postRegister(app, { userId: "u-1", platform: "web", token: "tok-a" });
|
||||
const response = await app.request("/v1/devices/revoke", {
|
||||
method: "POST",
|
||||
headers: { "content-type": "application/json", authorization: `Bearer ${TEST_TOKEN}` },
|
||||
|
||||
Reference in new issue
Block a user