Skip to content

Commit

Permalink
pass message
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyjhuang committed Apr 27, 2024
1 parent 1c8d3aa commit 95d459c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 16 deletions.
8 changes: 3 additions & 5 deletions src/apphosting/index.ts
Expand Up @@ -408,10 +408,7 @@ export async function deleteBackendAndPoll(
/**
* Prompts the user for a location.
*/
export async function promptLocation(
projectId: string,
prompt = "Please select a location:",
): Promise<string> {
export async function promptLocation(projectId: string, prompt: string): Promise<string> {
const allowedLocations = (await apphosting.listLocations(projectId)).map((loc) => loc.locationId);

return (await promptOnce({
Expand All @@ -430,6 +427,7 @@ export async function promptLocation(
export async function getBackendForAmbiguousLocation(
projectId: string,
backendId: string,
locationDisambugationPrompt: string,
): Promise<apphosting.Backend> {
let { unreachable, backends } = await apphosting.listBackends(projectId, "-");
if (unreachable && unreachable.length !== 0) {
Expand All @@ -455,7 +453,7 @@ export async function getBackendForAmbiguousLocation(
const location = await promptOnce({

Check warning on line 453 in src/apphosting/index.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe assignment of an `any` value
name: "location",
type: "list",
message: "Please select the location of the backend you'd like to delete:",
message: locationDisambugationPrompt,
choices: [...backendsByLocation.keys()],
});
return backendsByLocation.get(location)!;
Expand Down
6 changes: 5 additions & 1 deletion src/commands/apphosting-backends-delete.ts
Expand Up @@ -19,7 +19,11 @@ export const command = new Command("apphosting:backends:delete <backend>")
let location = options.location as string;
let backend: apphosting.Backend;
if (location === "-" || location === "") {
backend = await getBackendForAmbiguousLocation(projectId, backendId);
backend = await getBackendForAmbiguousLocation(
projectId,
backendId,
"Please select the location of the backend you'd like to delete:",
);
location = apphosting.parseBackendName(backend.name).location;
} else {
backend = await getBackendForLocation(projectId, location, backendId);
Expand Down
20 changes: 10 additions & 10 deletions src/test/apphosting/index.spec.ts
Expand Up @@ -256,7 +256,7 @@ describe("apphosting setup functions", () => {
});
});

describe.only("getBackendForAmbiguousLocation", () => {
describe("getBackendForAmbiguousLocation", () => {
const backendFoo = {
name: `projects/${projectId}/locations/${location}/backends/foo`,
labels: {},
Expand Down Expand Up @@ -284,26 +284,26 @@ describe("apphosting setup functions", () => {
it("throws if there are no matching backends", async () => {
listBackendsStub.resolves({ backends: [] });

await expect(getBackendForAmbiguousLocation(projectId, "baz")).to.be.rejectedWith(
/No backend named "baz" found./,
);
await expect(
getBackendForAmbiguousLocation(projectId, "baz", /* prompt= */ ""),
).to.be.rejectedWith(/No backend named "baz" found./);
});

it("returns unambiguous backend", async () => {
listBackendsStub.resolves({ backends: [backendFoo, backendBar] });

await expect(getBackendForAmbiguousLocation(projectId, "foo")).to.eventually.equal(
backendFoo,
);
await expect(
getBackendForAmbiguousLocation(projectId, "foo", /* prompt= */ ""),
).to.eventually.equal(backendFoo);
});

it("prompts for location if backend is ambiguous", async () => {
listBackendsStub.resolves({ backends: [backendFoo, backendFooOtherRegion, backendBar] });
promptOnceStub.resolves(location);

await expect(getBackendForAmbiguousLocation(projectId, "foo")).to.eventually.equal(
backendFoo,
);
await expect(
getBackendForAmbiguousLocation(projectId, "foo", /* prompt= */ ""),
).to.eventually.equal(backendFoo);

expect(promptOnceStub).to.be.calledWith({
name: "location",
Expand Down

0 comments on commit 95d459c

Please sign in to comment.