-
Notifications
You must be signed in to change notification settings - Fork 1.1k
test: add unit tests for apphosting:backends:create #9839
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
02a2079
acf0c54
dbdcab2
a72108f
e836db9
1efa83b
506443b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,120 @@ | ||
| import { expect } from "chai"; | ||
| import * as sinon from "sinon"; | ||
| import * as nock from "nock"; | ||
| import { command } from "./apphosting-backends-create"; | ||
| import * as backend from "../apphosting/backend"; | ||
| import * as projectUtils from "../projectUtils"; | ||
| import * as requireAuthModule from "../requireAuth"; | ||
| import { FirebaseError } from "../error"; | ||
|
|
||
| describe("apphosting:backends:create", () => { | ||
| const PROJECT_ID = "test-project"; | ||
| const WEB_APP_ID = "test-web-app"; | ||
| const BACKEND_ID = "test-backend"; | ||
| const REGION = "us-central1"; | ||
| const SERVICE_ACCOUNT = "test-sa"; | ||
| const ROOT_DIR = "."; | ||
|
|
||
| let doSetupStub: sinon.SinonStub; | ||
| let needProjectIdStub: sinon.SinonStub; | ||
|
Check failure on line 19 in src/commands/apphosting-backends-create.spec.ts
|
||
| let requireAuthStub: sinon.SinonStub; | ||
|
Check failure on line 20 in src/commands/apphosting-backends-create.spec.ts
|
||
|
|
||
| before(() => { | ||
| nock.disableNetConnect(); | ||
| }); | ||
|
|
||
| after(() => { | ||
| nock.enableNetConnect(); | ||
| }); | ||
|
|
||
| beforeEach(() => { | ||
| doSetupStub = sinon.stub(backend, "doSetup").resolves(); | ||
| needProjectIdStub = sinon.stub(projectUtils, "needProjectId").returns(PROJECT_ID); | ||
| requireAuthStub = sinon.stub(requireAuthModule, "requireAuth").resolves(); | ||
|
|
||
| // Stub ensureApiEnabled calls | ||
| nock("https://serviceusage.googleapis.com") | ||
| .get(`/v1/projects/${PROJECT_ID}/services/firebaseapphosting.googleapis.com`) | ||
| .query(true) // match any query params | ||
| .reply(200, { state: "ENABLED" }); | ||
|
|
||
| // Stub TOS acceptance check | ||
| nock("https://mobilesdk-pa.googleapis.com") | ||
| .get("/v1/accessmanagement/tos:getStatus") | ||
| .query(true) | ||
| .reply(200, { | ||
| perServiceStatus: [{ | ||
|
Check failure on line 46 in src/commands/apphosting-backends-create.spec.ts
|
||
| tosId: "APP_HOSTING_TOS", | ||
|
Check failure on line 47 in src/commands/apphosting-backends-create.spec.ts
|
||
| serviceStatus: { | ||
|
Check failure on line 48 in src/commands/apphosting-backends-create.spec.ts
|
||
| status: "ACCEPTED" | ||
|
Check failure on line 49 in src/commands/apphosting-backends-create.spec.ts
|
||
| } | ||
|
Check failure on line 50 in src/commands/apphosting-backends-create.spec.ts
|
||
| }] | ||
|
Check failure on line 51 in src/commands/apphosting-backends-create.spec.ts
|
||
| }); | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| sinon.restore(); | ||
| nock.cleanAll(); | ||
| }); | ||
|
|
||
| it("should throw error if non-interactive but missing required options", async () => { | ||
| const options = { nonInteractive: true }; | ||
| await expect(command.runner()(options)).to.be.rejectedWith( | ||
| FirebaseError, | ||
| "requires --backend and --primary-region" | ||
|
Check failure on line 64 in src/commands/apphosting-backends-create.spec.ts
|
||
| ); | ||
| }); | ||
|
|
||
| it("should throw error if non-interactive and just backend provided", async () => { | ||
| const options = { nonInteractive: true, backend: BACKEND_ID }; | ||
| await expect(command.runner()(options)).to.be.rejectedWith( | ||
| FirebaseError, | ||
| "requires --backend and --primary-region" | ||
|
Check failure on line 72 in src/commands/apphosting-backends-create.spec.ts
|
||
| ); | ||
| }); | ||
|
|
||
| it("should throw error if non-interactive and just region provided", async () => { | ||
| const options = { nonInteractive: true, primaryRegion: REGION }; | ||
| await expect(command.runner()(options)).to.be.rejectedWith( | ||
| FirebaseError, | ||
| "requires --backend and --primary-region" | ||
| ); | ||
| }); | ||
joehan marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| it("should call doSetup with correct arguments in interactive mode", async () => { | ||
| const options = {}; | ||
| await command.runner()(options); | ||
|
|
||
| expect(doSetupStub).to.have.been.calledWith( | ||
| PROJECT_ID, | ||
| undefined, // nonInteractive | ||
| undefined, // webAppId | ||
| undefined, // backendId | ||
| undefined, // serviceAccount | ||
| undefined, // primaryRegion | ||
| undefined // rootDir | ||
| ); | ||
| }); | ||
|
|
||
| it("should call doSetup with passed options in non-interactive mode", async () => { | ||
| const options = { | ||
| nonInteractive: true, | ||
| backend: BACKEND_ID, | ||
| primaryRegion: REGION, | ||
| app: WEB_APP_ID, | ||
| serviceAccount: SERVICE_ACCOUNT, | ||
| rootDir: ROOT_DIR, | ||
| }; | ||
| await command.runner()(options); | ||
|
|
||
| expect(doSetupStub).to.have.been.calledWith( | ||
| PROJECT_ID, | ||
| true, | ||
| WEB_APP_ID, | ||
| BACKEND_ID, | ||
| SERVICE_ACCOUNT, | ||
| REGION, | ||
| ROOT_DIR | ||
| ); | ||
| }); | ||
| }); | ||
Uh oh!
There was an error while loading. Please reload this page.