|
| 1 | +/** |
| 2 | + * @license |
| 3 | + * Copyright 2024 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 { deleteApp, FirebaseApp, initializeApp } from '@firebase/app'; |
| 19 | +import { expect } from 'chai'; |
| 20 | +import * as chai from 'chai'; |
| 21 | +import chaiAsPromised from 'chai-as-promised'; |
| 22 | + |
| 23 | +import { |
| 24 | + DataConnect, |
| 25 | + executeQuery, |
| 26 | + getDataConnect, |
| 27 | + mutationRef, |
| 28 | + queryRef |
| 29 | +} from '../../src'; |
| 30 | +import { Code, DataConnectError } from '../../src/core/error'; |
| 31 | +chai.use(chaiAsPromised); |
| 32 | + |
| 33 | +describe('Query Manager Tests', () => { |
| 34 | + let dc: DataConnect; |
| 35 | + let app: FirebaseApp; |
| 36 | + const APPID = 'MYAPPID'; |
| 37 | + const APPNAME = 'MYAPPNAME'; |
| 38 | + |
| 39 | + beforeEach(() => { |
| 40 | + app = initializeApp({ projectId: 'p', appId: APPID }, APPNAME); |
| 41 | + dc = getDataConnect(app, { |
| 42 | + connector: 'c', |
| 43 | + location: 'l', |
| 44 | + service: 's' |
| 45 | + }); |
| 46 | + }); |
| 47 | + afterEach(async () => { |
| 48 | + await dc._delete(); |
| 49 | + await deleteApp(app); |
| 50 | + }); |
| 51 | + |
| 52 | + it('should refuse to make requests to execute non-query operations', async () => { |
| 53 | + const query = queryRef<string>(dc, 'q'); |
| 54 | + const mutation = mutationRef<string>(dc, 'm'); |
| 55 | + |
| 56 | + const error = new DataConnectError( |
| 57 | + Code.INVALID_ARGUMENT, |
| 58 | + `ExecuteQuery can only execute query operation` |
| 59 | + ); |
| 60 | + |
| 61 | + // @ts-ignore |
| 62 | + expect(() => executeQuery(mutation)).to.throw(error.message); |
| 63 | + expect(() => executeQuery(query)).to.not.throw(error.message); |
| 64 | + }); |
| 65 | +}); |
0 commit comments