Skip to content

Commit 336bf9a

Browse files
committed
test(e2e): add /auth/ mock route and whoami E2E tests
1 parent 6e13d53 commit 336bf9a

File tree

2 files changed

+48
-1
lines changed

2 files changed

+48
-1
lines changed

test/e2e/auth.test.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,46 @@ describe("sentry auth login --token", () => {
102102
});
103103
});
104104

105+
describe("sentry auth whoami", () => {
106+
test("requires authentication", async () => {
107+
const result = await ctx.run(["auth", "whoami"]);
108+
109+
const output = result.stdout + result.stderr;
110+
expect(output).toMatch(/not authenticated/i);
111+
expect(result.exitCode).toBe(1);
112+
});
113+
114+
test("shows current user identity", async () => {
115+
await ctx.setAuthToken(TEST_TOKEN);
116+
117+
const result = await ctx.run(["auth", "whoami"]);
118+
119+
expect(result.exitCode).toBe(0);
120+
expect(result.stdout).toContain("test@example.com");
121+
});
122+
123+
test("supports --json output", async () => {
124+
await ctx.setAuthToken(TEST_TOKEN);
125+
126+
const result = await ctx.run(["auth", "whoami", "--json"]);
127+
128+
expect(result.exitCode).toBe(0);
129+
const json = JSON.parse(result.stdout);
130+
expect(json.id).toBe("12345");
131+
expect(json.email).toBe("test@example.com");
132+
expect(json.username).toBe("testuser");
133+
});
134+
135+
test("sentry whoami top-level alias works", async () => {
136+
await ctx.setAuthToken(TEST_TOKEN);
137+
138+
const result = await ctx.run(["whoami"]);
139+
140+
expect(result.exitCode).toBe(0);
141+
expect(result.stdout).toContain("test@example.com");
142+
});
143+
});
144+
105145
describe("sentry auth logout", () => {
106146
test(
107147
"clears stored auth",

test/mocks/routes.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,14 @@ export const apiRoutes: MockRoute[] = [
5858
}),
5959
},
6060

61-
// Users
61+
// Auth / current user (works with all token types including OAuth)
62+
{
63+
method: "GET",
64+
path: "/api/0/auth/",
65+
response: userFixture,
66+
},
67+
68+
// Users (legacy endpoint, kept for backward compatibility)
6269
{
6370
method: "GET",
6471
path: "/api/0/users/me/",

0 commit comments

Comments
 (0)