-
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
Open
joehan
wants to merge
7
commits into
main
Choose a base branch
from
jh-tests1
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
02a2079
test: add unit tests for apphosting:backends:create
joehan acf0c54
formats
joehan dbdcab2
PR fixes
joehan a72108f
Merge branch 'main' into jh-tests1
joehan e836db9
Fix require auth stubbing
joehan 1efa83b
Merge branch 'main' into jh-tests1
joehan 506443b
Fix leaky noninteractive
joehan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,121 @@ | ||
| 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; | ||
|
|
||
| before(() => { | ||
| nock.disableNetConnect(); | ||
| }); | ||
|
|
||
| after(() => { | ||
| nock.enableNetConnect(); | ||
| }); | ||
|
|
||
| beforeEach(() => { | ||
| doSetupStub = sinon.stub(backend, "doSetup").resolves(); | ||
| sinon.stub(projectUtils, "needProjectId").returns(PROJECT_ID); | ||
| 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: [ | ||
| { | ||
| tosId: "APP_HOSTING_TOS", | ||
| serviceStatus: { | ||
| status: "ACCEPTED", | ||
| }, | ||
| }, | ||
| ], | ||
| }); | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| sinon.restore(); | ||
| nock.cleanAll(); | ||
| }); | ||
|
|
||
| [ | ||
| { | ||
| description: "missing required options", | ||
| options: { nonInteractive: true }, | ||
| }, | ||
| { | ||
| description: "just backend provided", | ||
| options: { nonInteractive: true, backend: BACKEND_ID }, | ||
| }, | ||
| { | ||
| description: "just region provided", | ||
| options: { nonInteractive: true, primaryRegion: REGION }, | ||
| }, | ||
| ].forEach(({ description, options }) => { | ||
| it(`should throw error if non-interactive and ${description}`, async () => { | ||
| await expect(command.runner()(options)).to.be.rejectedWith( | ||
| FirebaseError, | ||
| "requires --backend and --primary-region", | ||
| ); | ||
| }); | ||
| }); | ||
|
|
||
| it("should call doSetup with correct arguments in interactive mode", async () => { | ||
| before(() => { | ||
| sinon.stub(process.stdin, "isTTY").value(true); | ||
| }); | ||
| 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, | ||
| ); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This might not be intended, we do
.before(requireAuth)on all of our commands