Skip to content

Commit 4743e37

Browse files
committed
fix tests
1 parent fe8e0f0 commit 4743e37

File tree

3 files changed

+17
-56
lines changed

3 files changed

+17
-56
lines changed

src/init/features/project.spec.ts

Lines changed: 1 addition & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -96,26 +96,6 @@ describe("project", () => {
9696
displayName: "my-project",
9797
});
9898
});
99-
100-
it("should throw if project ID is empty after prompt", async () => {
101-
const options = {};
102-
const setup = { config: {}, rcfile: {} };
103-
prompt.select.onFirstCall().resolves("Create a new project");
104-
prompt.input.resolves("");
105-
configstoreSetStub.onFirstCall().resolves();
106-
107-
let err;
108-
try {
109-
await doSetup(setup, emptyConfig, options);
110-
} catch (e: any) {
111-
err = e;
112-
}
113-
114-
expect(err.message).to.equal("Project ID cannot be empty");
115-
expect(prompt.select).to.be.calledOnce;
116-
expect(prompt.input).to.be.calledTwice;
117-
expect(createFirebaseProjectStub).to.be.not.called;
118-
});
11999
});
120100

121101
describe('with "Add Firebase resources to GCP project" option', () => {
@@ -139,27 +119,6 @@ describe("project", () => {
139119
expect(promptAvailableProjectIdStub).to.be.calledOnce;
140120
expect(addFirebaseProjectStub).to.be.calledOnceWith("my-project-123");
141121
});
142-
143-
it("should throw if project ID is empty after prompt", async () => {
144-
const options = {};
145-
const setup = { config: {}, rcfile: {} };
146-
prompt.select
147-
.onFirstCall()
148-
.resolves("Add Firebase to an existing Google Cloud Platform project");
149-
promptAvailableProjectIdStub.onFirstCall().resolves("");
150-
151-
let err;
152-
try {
153-
await doSetup(setup, emptyConfig, options);
154-
} catch (e: any) {
155-
err = e;
156-
}
157-
158-
expect(err.message).to.equal("Project ID cannot be empty");
159-
expect(prompt.select).to.be.calledOnce;
160-
expect(promptAvailableProjectIdStub).to.be.calledOnce;
161-
expect(addFirebaseProjectStub).to.be.not.called;
162-
});
163122
});
164123

165124
describe(`with "Don't set up a default project" option`, () => {
@@ -183,6 +142,7 @@ describe("project", () => {
183142
options = {};
184143
setup = { config: {}, rcfile: { projects: { default: "my-project-123" } } };
185144
getProjectStub.onFirstCall().resolves(TEST_FIREBASE_PROJECT);
145+
configstoreSetStub.onFirstCall().resolves();
186146
});
187147

188148
it("should not prompt", async () => {

src/init/features/project.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import * as utils from "../../utils";
1515
import * as prompt from "../../prompt";
1616
import { requireAuth } from "../../requireAuth";
1717
import { Constants } from "../../emulator/constants";
18+
import { FirebaseError } from "../../error";
1819

1920
const OPTION_NO_PROJECT = "Don't set up a default project";
2021
const OPTION_USE_PROJECT = "Use an existing project";
@@ -116,6 +117,9 @@ async function usingProjectMetadata(
116117
config: any,
117118
pm: FirebaseProjectMetadata,
118119
): Promise<void> {
120+
if (!pm) {
121+
throw new FirebaseError("null FirebaseProjectMetadata");
122+
}
119123
// write "default" alias and activate it immediately
120124
_.set(setup.rcfile, "projects.default", pm.projectId);
121125
setup.projectId = pm.projectId;

src/management/projects.ts

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -186,15 +186,20 @@ export async function selectProjectInteractively(
186186
if (nextPageToken) {
187187
// Prompt user for project ID if we can't list all projects in 1 page
188188
logger.debug(`Found more than ${projects.length} projects, selecting via prompt`);
189-
return selectProjectByPrompting();
189+
return await getFirebaseProject(await selectProjectByPrompting());
190190
}
191191
return selectProjectFromList(projects);
192192
}
193193

194-
async function selectProjectByPrompting(): Promise<FirebaseProjectMetadata> {
194+
async function selectProjectByPrompting(): Promise<string> {
195195
const projectId = await prompt.input("Please input the project ID you would like to use:");
196-
197-
return await getFirebaseProject(projectId);
196+
if (!projectId) {
197+
throw new FirebaseError("Project ID cannot be empty");
198+
}
199+
if (Constants.isDemoProject(projectId)) {
200+
throw new FirebaseError("Project ID cannot starts with demo-");
201+
}
202+
return projectId;
198203
}
199204

200205
/**
@@ -255,17 +260,9 @@ export async function promptAvailableProjectId(): Promise<string> {
255260
}
256261

257262
if (nextPageToken) {
258-
// Prompt for project ID if we can't list all projects in 1 page
259-
const projectId = await prompt.input(
260-
"Please input the ID of the Google Cloud Project you would like to add Firebase:",
261-
);
262-
if (!projectId) {
263-
throw new FirebaseError("Project ID cannot be empty");
264-
}
265-
if (Constants.isDemoProject(projectId)) {
266-
throw new FirebaseError("Project ID cannot starts with demo-");
267-
}
268-
return projectId;
263+
// Prompt user for project ID if we can't list all projects in 1 page
264+
logger.debug(`Found more than ${projects.length} projects, selecting via prompt`);
265+
return await selectProjectByPrompting();
269266
} else {
270267
const choices = projects
271268
.filter((p: CloudProjectInfo) => !!p)

0 commit comments

Comments
 (0)