{"draft":null,"from":175,"to":318,"files":[{"path":"client/test/orgs.test.ts","added":47,"removed":6,"diff":"--- a/client/test/orgs.test.ts\n+++ b/client/test/orgs.test.ts\n@@ -31,13 +31,14 @@\n \n /** A stand-in server: answers from `routes` by path, and keeps what was asked. */\n function server(routes: Record<string, { status: number; body: unknown }>) {\n-\tconst asked: { url: string; method: string; auth: string | null }[] = [];\n+\tconst asked: { url: string; method: string; auth: string | null; body?: string }[] = [];\n \tconst fetcher = (async (url: string | URL | Request, init?: RequestInit) => {\n \t\tconst u = new URL(String(url));\n \t\tasked.push({\n \t\t\turl: String(url),\n \t\t\tmethod: init?.method ?? \"GET\",\n \t\t\tauth: new Headers(init?.headers).get(\"authorization\"),\n+\t\t\t...(typeof init?.body === \"string\" ? { body: init.body } : {}),\n \t\t});\n \t\tconst r = routes[u.pathname] ?? { status: 404, body: { error: \"no such route\" } };\n \t\treturn new Response(JSON.stringify(r.body), { status: r.status });\n@@ -156,11 +157,13 @@\n \t\t\t[[\"acme-labs\", \"--leave\"], /--leave is on acme-labs's People tab/],\n \t\t\t[[\"acme-labs\", \"--members\", \"read\"], /--members is on acme-labs's Settings tab/],\n \t\t\t[[\"acme-labs\", \"--projects-by\", \"owners\"], /--projects-by is on acme-labs's Settings tab/],\n-\t\t\t[[\"new\", \"acme-labs\", \"--name\", \"Acme Labs\"], /Make acme-labs at https:\\/\\/example\\.dev\\/orgs\\/new\\./],\n \t\t];\n \t\tfor (const [line, said] of cases) {\n \t\t\tawait assert.rejects(runOrg(args(line), SERVER, { home, fetch: s.fetcher }), said, line.join(\" \"));\n-\t\t\tawait assert.rejects(runOrg(args(line), SERVER, { home, fetch: s.fetcher }), /changed on the website for now/);\n+\t\t\tawait assert.rejects(\n+\t\t\t\trunOrg(args(line), SERVER, { home, fetch: s.fetcher }),\n+\t\t\t\t/Organizations are changed on the website/,\n+\t\t\t);\n \t\t}\n \t\tassert.deepEqual(s.asked, []);\n \t});\n@@ -188,11 +191,49 @@\n \t});\n });\n \n-describe(\"abso init --org\", () => {\n-\tit(\"says the project is made on the website for now, with the org as its owner\", () => {\n+describe(\"abso org new (abso 663)\", () => {\n+\tit(\"makes the org as the box's person, sending the box's sign-in and the shown name\", async () => {\n+\t\tconst home = signedIn();\n+\t\tconst s = server({ \"/box/orgs\": { status: 200, body: { name: \"acme-labs\", displayName: \"Acme Labs\" } } });\n+\t\tconst out = await runOrg(args([\"new\", \"acme-labs\", \"--name\", \"Acme Labs\"]), SERVER, { home, fetch: s.fetcher });\n+\t\tassert.match(\n+\t\t\tout.text,\n+\t\t\t/Made the organization acme-labs; you own it\\. Its page: https:\\/\\/example\\.dev\\/acme-labs\\./,\n+\t\t);\n+\t\tassert.equal(s.asked.length, 1);\n+\t\tassert.equal(s.asked[0]?.method, \"POST\");\n+\t\tassert.equal(s.asked[0]?.auth, `Box ${CREDENTIAL}`);\n+\t\tassert.deepEqual(JSON.parse(s.asked[0]?.body ?? \"{}\"), { name: \"acme-labs\", displayName: \"Acme Labs\" });\n+\t});\n+\tit(\"says what the server says when the box's grant is a list, and never shows the credential\", async () => {\n+\t\tconst home = signedIn();\n+\t\tconst s = server({\n+\t\t\t\"/box/orgs\": { status: 403, body: { error: \"only a box approved for all your projects makes organizations\" } },\n+\t\t});\n+\t\tawait assert.rejects(\n+\t\t\trunOrg(args([\"new\", \"acme-labs\"]), SERVER, { home, fetch: s.fetcher }),\n+\t\t\t(e: Error) =>\n+\t\t\t\t/refused \\(403\\): only a box approved for all your projects/.test(e.message) && !e.message.includes(CREDENTIAL),\n+\t\t);\n+\t});\n+\tit(\"needs a box signed in, and no other change flag\", async () => {\n+\t\tconst empty = mkdtempSync(join(tmpdir(), \"abso-orgs-\"));\n+\t\tawait assert.rejects(\n+\t\t\trunOrg(args([\"new\", \"acme-labs\"]), SERVER, { home: empty, fetch: server({}).fetcher }),\n+\t\t\t/abso login signs it in/,\n+\t\t);\n+\t\tawait assert.rejects(\n+\t\t\trunOrg(args([\"new\", \"acme-labs\", \"--leave\"]), SERVER, { home: signedIn(), fetch: server({}).fetcher }),\n+\t\t\t/takes --name only/,\n+\t\t);\n+\t});\n+});\n+\n+describe(\"abso init --org with no box signed in\", () => {\n+\tit(\"says to sign in, or where the website makes it\", () => {\n \t\tassert.throws(\n \t\t\t() => initInOrg(\"acme-labs\", SERVER),\n-\t\t\t/made on the website for now: New project at https:\\/\\/example\\.dev, with acme-labs as its owner/,\n+\t\t\t/isn't signed in to https:\\/\\/api\\.example\\.dev.*abso init --org acme-labs again; or New project at https:\\/\\/example\\.dev\\./,\n \t\t);\n \t});\n });"}],"unmatched":[]}