mirror of
https://github.com/outline/outline.git
synced 2026-11-25 15:15:15 +03:00
* chore: Rename APIContext to Context and flatten its fields Auth and transaction now live directly on the context instead of in ctx.state and a nested ctx.context, and model helpers read them directly. APIContext remains as a deprecated alias. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016MJXFeUxvU46KyvKnP8sXf * chore: Remove deprecated APIContext alias Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016MJXFeUxvU46KyvKnP8sXf * fix: Read auth from context in OAuth provider callbacks Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016MJXFeUxvU46KyvKnP8sXf * chore: Add withUser and withTransaction context helpers Replaces manual createContext rebuilds that copy fields from an existing context. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016MJXFeUxvU46KyvKnP8sXf * chore: Remove arbitrary property access from Koa context types AppContext and Context no longer inherit the any index signature from Koa's DefaultContext, custom fields are declared explicitly, and importing Koa's loose Context type is disallowed by lint. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016MJXFeUxvU46KyvKnP8sXf --------- Co-authored-by: Claude <noreply@anthropic.com>
39 lines
1.3 KiB
TypeScript
39 lines
1.3 KiB
TypeScript
import { buildMockContext } from "@server/test/support";
|
|
import { userAgent } from "./userAgent";
|
|
|
|
const chromeOnMac =
|
|
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36";
|
|
const safariOnIPhone =
|
|
"Mozilla/5.0 (iPhone; CPU iPhone OS 17_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.0 Mobile/15E148 Safari/604.1";
|
|
|
|
describe("userAgent middleware", () => {
|
|
it("should parse a desktop user agent", async () => {
|
|
const ctx = buildMockContext({ header: { "user-agent": chromeOnMac } });
|
|
const next = vi.fn();
|
|
|
|
await userAgent()(ctx, next);
|
|
|
|
expect(ctx.userAgent?.source).toEqual(chromeOnMac);
|
|
expect(ctx.userAgent?.isDesktop).toBe(true);
|
|
expect(ctx.userAgent?.isMobile).toBe(false);
|
|
expect(next).toHaveBeenCalled();
|
|
});
|
|
|
|
it("should parse a mobile user agent", async () => {
|
|
const ctx = buildMockContext({ header: { "user-agent": safariOnIPhone } });
|
|
|
|
await userAgent()(ctx, vi.fn());
|
|
|
|
expect(ctx.userAgent?.isMobile).toBe(true);
|
|
expect(ctx.userAgent?.isDesktop).toBe(false);
|
|
});
|
|
|
|
it("should use a placeholder when the header is missing", async () => {
|
|
const ctx = buildMockContext({ header: {} });
|
|
|
|
await userAgent()(ctx, vi.fn());
|
|
|
|
expect(ctx.userAgent?.source).toEqual("unknown");
|
|
});
|
|
});
|