fix(account): bind pending downloads to user

This commit is contained in:
2026-05-19 01:02:53 +08:00
parent 4b81869b6e
commit b839e0770c
2 changed files with 85 additions and 4 deletions
@@ -269,4 +269,61 @@ describe("App download records", () => {
);
});
});
it("does not record a queued install under a later logged-in user", async () => {
render(App);
await fireEvent.click(
await screen.findByRole("button", { name: "全部应用 1" }),
);
await fireEvent.click(await screen.findByText("WPS"));
await fireEvent.click(await screen.findByRole("button", { name: "安装" }));
await waitFor(() => {
expect(send).toHaveBeenCalledWith(
"queue-install",
expect.stringContaining('"pkgname":"wps"'),
);
});
const queuedPayload = vi
.mocked(send)
.mock.calls.find(
([channel]) => channel === "queue-install",
)?.[1] as string;
const queuedDownload = JSON.parse(queuedPayload) as { id: number };
await fireEvent.click(screen.getByRole("button", { name: "Momen" }));
await fireEvent.click(await screen.findByText("退出登录"));
setAuthSession({
accessToken: "backend-token-b",
tokenType: "bearer",
user: {
id: 2,
flarumUserId: "84",
username: "second",
displayName: "Second User",
avatarUrl: "https://bbs.spark-app.store/avatar-b.png",
forumLevel: "用户",
forumGroups: ["用户"],
},
});
const completion: DownloadResult = {
id: queuedDownload.id,
time: Date.now(),
message: "installed",
success: true,
exitCode: 0,
status: "completed",
origin: "apm",
};
ipcHandlers.get("install-complete")?.({}, completion);
await waitFor(() => {
expect(recordDownloadedApp).not.toHaveBeenCalled();
});
});
});