|
15 | 15 | * limitations under the License. |
16 | 16 | */ |
17 | 17 |
|
18 | | -import { initializeApp } from '@firebase/app'; |
19 | | -import { FirebaseAuthTokenData } from '@firebase/auth-interop-types'; |
| 18 | +import { deleteApp, FirebaseApp, initializeApp } from '@firebase/app'; |
20 | 19 | import { expect } from 'chai'; |
21 | 20 | import * as chai from 'chai'; |
22 | 21 | import chaiAsPromised from 'chai-as-promised'; |
23 | 22 |
|
24 | 23 | import { |
| 24 | + DataConnect, |
25 | 25 | DataConnectOptions, |
| 26 | + executeQuery, |
26 | 27 | getDataConnect, |
27 | | - MUTATION_STR, |
28 | | - QUERY_STR, |
29 | | - QueryRef |
| 28 | + mutationRef, |
| 29 | + queryRef, |
30 | 30 | } from '../../src'; |
31 | 31 | import { Code, DataConnectError } from '../../src/core/error'; |
32 | | -import { |
33 | | - AuthTokenListener, |
34 | | - AuthTokenProvider |
35 | | -} from '../../src/core/FirebaseAuthProvider'; |
36 | | -import { QueryManager } from '../../src/core/QueryManager'; |
37 | | -import { RESTTransport } from '../../src/network/transport/rest'; |
38 | 32 | chai.use(chaiAsPromised); |
39 | 33 | const options: DataConnectOptions = { |
40 | 34 | connector: 'c', |
41 | 35 | location: 'l', |
42 | 36 | projectId: 'p', |
43 | 37 | service: 's' |
44 | 38 | }; |
45 | | -const INITIAL_TOKEN = 'initial token'; |
46 | | -class FakeAuthProvider implements AuthTokenProvider { |
47 | | - private token: string | null = INITIAL_TOKEN; |
48 | | - addTokenChangeListener(listener: AuthTokenListener): void {} |
49 | | - getToken(forceRefresh: boolean): Promise<FirebaseAuthTokenData | null> { |
50 | | - if (!forceRefresh) { |
51 | | - return Promise.resolve({ accessToken: this.token! }); |
52 | | - } |
53 | | - return Promise.resolve({ accessToken: 'testToken' }); |
54 | | - } |
55 | | - setToken(_token: string | null): void { |
56 | | - this.token = _token; |
57 | | - } |
58 | | -} |
59 | 39 |
|
60 | 40 | describe('Query Manager Tests', () => { |
61 | | - it('should refuse to make requests to execute non-query operations', async () => { |
62 | | - const authProvider = new FakeAuthProvider(); |
63 | | - const rt = new RESTTransport(options, undefined, undefined, authProvider); |
64 | | - const qm = new QueryManager(rt); |
65 | | - const app = initializeApp({ projectId: 'p' }); |
66 | | - const dc = getDataConnect(app, { |
67 | | - connector: 'c', |
68 | | - location: 'l', |
69 | | - service: 's' |
70 | | - }); |
| 41 | + let dc: DataConnect; |
| 42 | + let app: FirebaseApp; |
71 | 43 |
|
72 | | - const mutationRef: QueryRef<string, string> = { |
73 | | - name: 'm', |
74 | | - variables: 'v', |
75 | | - dataConnect: dc, |
76 | | - refType: MUTATION_STR as 'query' |
77 | | - }; |
| 44 | + beforeEach(() => { |
| 45 | + app = initializeApp({ projectId: 'p' }); |
| 46 | + dc = getDataConnect(app, options); |
| 47 | + }); |
| 48 | + afterEach(async () => { |
| 49 | + await dc._delete(); |
| 50 | + await deleteApp(app); |
| 51 | + }); |
78 | 52 |
|
79 | | - const queryRef: QueryRef<string, string> = { |
80 | | - name: 'm', |
81 | | - variables: 'v', |
82 | | - dataConnect: dc, |
83 | | - refType: QUERY_STR |
84 | | - }; |
| 53 | + it('should refuse to make requests to execute non-query operations', async () => { |
| 54 | + const query = queryRef<string>(dc, 'q'); |
| 55 | + const mutation = mutationRef<string>(dc, 'm'); |
85 | 56 |
|
86 | 57 | const error = new DataConnectError( |
87 | 58 | Code.INVALID_ARGUMENT, |
88 | 59 | `ExecuteQuery can only execute query operation` |
89 | 60 | ); |
90 | 61 |
|
91 | | - expect(() => qm.executeQuery(mutationRef)).to.throw(error.message); |
92 | | - expect(() => qm.executeQuery(queryRef)).to.not.throw(error.message); |
| 62 | + // @ts-ignore |
| 63 | + expect(() => executeQuery(mutation)).to.throw(error.message); |
| 64 | + expect(() => executeQuery(query)).to.not.throw(error.message); |
93 | 65 | }); |
94 | 66 | }); |
0 commit comments