|
| 1 | +/** |
| 2 | + * @license |
| 3 | + * Copyright 2025 Google LLC |
| 4 | + * |
| 5 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | + * you may not use this file except in compliance with the License. |
| 7 | + * You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + */ |
| 17 | + |
| 18 | +import * as sinon from 'sinon'; |
| 19 | +import { expect, use } from 'chai'; |
| 20 | +import { DatabaseId } from '../../../src/core/database_info'; |
| 21 | +import { makeDatabaseInfo } from '../../../src/lite-api/components'; |
| 22 | +import { |
| 23 | + FirestoreSettingsImpl, |
| 24 | + PrivateSettings |
| 25 | +} from '../../../src/lite-api/settings'; |
| 26 | +import { ResourcePath } from '../../../src/model/path'; |
| 27 | +import { FetchConnection } from '../../../src/platform/browser_lite/fetch_connection'; |
| 28 | +import sinonChai from 'sinon-chai'; |
| 29 | +import chaiAsPromised from 'chai-as-promised'; |
| 30 | + |
| 31 | +use(sinonChai); |
| 32 | +use(chaiAsPromised); |
| 33 | + |
| 34 | +describe('Fetch Connection', () => { |
| 35 | + it('should pass in credentials if using emulator and cloud workstation', async () => { |
| 36 | + const privateSettings: PrivateSettings = { |
| 37 | + emulatorOptions: {}, |
| 38 | + host: 'abc.cloudworkstations.dev' |
| 39 | + }; |
| 40 | + console.log( |
| 41 | + makeDatabaseInfo( |
| 42 | + DatabaseId.empty(), |
| 43 | + '', |
| 44 | + '', |
| 45 | + new FirestoreSettingsImpl(privateSettings) |
| 46 | + ) |
| 47 | + ); |
| 48 | + const stub = sinon.stub(globalThis, 'fetch'); |
| 49 | + stub.resolves({ |
| 50 | + ok: true, |
| 51 | + json() { |
| 52 | + return Promise.resolve(); |
| 53 | + } |
| 54 | + } as Response); |
| 55 | + const fetchConnection = new FetchConnection( |
| 56 | + makeDatabaseInfo( |
| 57 | + DatabaseId.empty(), |
| 58 | + '', |
| 59 | + '', |
| 60 | + new FirestoreSettingsImpl({ |
| 61 | + host: 'abc.cloudworkstations.dev', |
| 62 | + emulatorOptions: {} |
| 63 | + }) |
| 64 | + ) |
| 65 | + ); |
| 66 | + await fetchConnection.invokeRPC( |
| 67 | + 'Commit', |
| 68 | + new ResourcePath([]), |
| 69 | + {}, |
| 70 | + null, |
| 71 | + null |
| 72 | + ); |
| 73 | + expect(stub).to.have.been.calledWithMatch( |
| 74 | + 'https://abc.cloudworkstations.dev/v1/:commit', |
| 75 | + { credentials: 'include' } |
| 76 | + ); |
| 77 | + stub.restore(); |
| 78 | + }); |
| 79 | +}); |
0 commit comments