Skip to content
Merged
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
1 change: 0 additions & 1 deletion src/application/commands/team/index.cli.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ const teamsResponse = {
id: "team-2",
name: "beta",
role: "member",
system_created: false,
},
],
};
Expand Down
28 changes: 23 additions & 5 deletions src/application/commands/team/shared.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ describe("listMemberTeams", () => {
]);
});

test("rejects a team item missing the required role or system_created field", async () => {
test("rejects a team item missing the required role", async () => {
const missingRole = await expectCliUserError(listMemberTeams(
testAccount,
createRequestContext({
Expand All @@ -122,16 +122,34 @@ describe("listMemberTeams", () => {
}),
));
expect(missingRole.key).toBe("errors.team.invalidResponse");
});

const missingSystemCreated = await expectCliUserError(listMemberTeams(
test("accepts a team without the system_created marker", async () => {
const teams = await listMemberTeams(
testAccount,
createRequestContext({
fetcher: async () => new Response(JSON.stringify({
fetcher: async () => Response.json({
teams: [{ id: "team-1", name: "acme", role: "creator" }],
})),
}),
}),
);

expect(teams).toEqual([
{ id: "team-1", name: "acme", role: "creator", systemCreated: false },
]);
});

test.each([null, "false", 0])("rejects an invalid system_created marker: %p", async (systemCreated) => {
const error = await expectCliUserError(listMemberTeams(
testAccount,
createRequestContext({
fetcher: async () => Response.json({
teams: [{ id: "team-1", name: "acme", role: "creator", system_created: systemCreated }],
}),
}),
));
expect(missingSystemCreated.key).toBe("errors.team.invalidResponse");

expect(error.key).toBe("errors.team.invalidResponse");
});

test("returns an empty list when the account has no teams", async () => {
Expand Down
10 changes: 3 additions & 7 deletions src/application/commands/team/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,13 @@ import type { AuthAccount } from "../../schemas/auth.ts";
import { z } from "zod";
import { probeOo, requestOo } from "../shared/oo-request.ts";

// One team the current account belongs to. The membership listing always
// carries `role` (exactly `creator` or `member`; any other value is treated as
// a plain membership) and `system_created`, which marks the team the backend
// provisions for every account (at most one at a time, and it cannot be
// deleted). Both fields are always present in the response, so both are
// required — a missing one is a malformed response, not a defaulted value.
// The backend may omit system_created for teams that were not provisioned
// automatically.
const teamResponseItemSchema = z.object({
id: z.string().min(1),
name: z.string().min(1),
role: z.string(),
system_created: z.boolean(),
system_created: z.boolean().default(false),
});

// `GET /v1/me/teams` wraps the memberships in a `teams` array. The array is
Expand Down
Loading