1616 */
1717import { expect } from 'chai' ;
1818import * as sinon from 'sinon' ;
19- import * as mocks from '../../resources/mocks' ;
2019import { ConnectorConfig , validateAdminArgs } from '../../../src/data-connect' ;
2120import { DataConnect , DataConnectService } from '../../../src/data-connect/data-connect' ;
2221import { OperationOptions } from '../../../lib/data-connect' ;
2322import {
2423 DATA_CONNECT_ERROR_CODE_MAPPING ,
2524 FirebaseDataConnectError
2625} from '../../../src/data-connect/data-connect-api-client-internal' ;
27- import { FirebaseApp } from '../../../src/app/firebase-app' ;
26+ import firebase from '@firebase/app-compat' ;
27+ import { projectId } from '../../resources/mocks' ;
28+ import { apiKey } from '../../integration/setup' ;
2829
2930interface IdVars {
3031 id : string
3132}
3233
3334describe ( 'validateAdminArgs()' , ( ) => {
34- const mockOptions = {
35- credential : new mocks . MockCredential ( ) ,
36- projectId : 'test-project' ,
37- } ;
38-
39- let app : FirebaseApp ;
40-
41- let sandbox : sinon . SinonSandbox ;
42-
43- beforeEach ( ( ) => {
44- sandbox = sinon . createSandbox ( ) ;
45- app = mocks . appWithOptions ( mockOptions ) ;
46- } ) ;
47-
48- afterEach ( ( ) => {
49- sandbox . restore ( ) ;
50- if ( process . env . DATA_CONNECT_EMULATOR_HOST ) {
51- delete process . env . DATA_CONNECT_EMULATOR_HOST ;
52- }
53- return app . delete ( ) ;
35+ before ( ( ) => {
36+ firebase . initializeApp ( {
37+ apiKey,
38+ authDomain : projectId + '.firebaseapp.com' ,
39+ } ) ;
5440 } ) ;
55-
41+
5642 const connectorConfig : ConnectorConfig = {
5743 location : 'us-west2' ,
5844 serviceId : 'my-service' ,
@@ -194,66 +180,60 @@ describe('validateAdminArgs()', () => {
194180 describe ( 'and validateVars = true' , ( ) => {
195181 describe ( 'should succeed if vars WERE provided' , ( ) => {
196182 it ( 'and the first argument is a DataConnect instance' , ( ) => {
197- expect ( validateAdminArgs (
198- connectorConfig , providedDcInstance , variables , undefined , true , true
199- ) ) . to . not . throw ( invalidVariablesError ) ;
200-
201- const { dc : dcInstance , vars : inputVars , options : inputOpts } = validateAdminArgs (
202- connectorConfig , providedDcInstance , variables , undefined , true , true
203- ) ;
204- expect ( dcInstance ) . to . deep . equal ( providedDcInstance ) ;
205- expect ( inputVars ) . to . deep . equal ( inputVars ) ;
206- expect ( inputOpts ) . to . be . undefined ;
183+ expect ( ( ) => {
184+ const { dc : dcInstance , vars : inputVars , options : inputOpts } = validateAdminArgs (
185+ connectorConfig , providedDcInstance , variables , undefined , true , true
186+ ) ;
187+ expect ( dcInstance ) . to . deep . equal ( providedDcInstance ) ;
188+ expect ( inputVars ) . to . deep . equal ( inputVars ) ;
189+ expect ( inputOpts ) . to . be . undefined ;
190+ } ) . to . not . throw ( invalidVariablesError ) ;
207191 } ) ;
208192
209193 it ( 'and the first argument is variables instance' , ( ) => {
210- expect ( validateAdminArgs (
211- connectorConfig , variables , undefined , undefined , true , true
212- ) ) . to . not . throw ( invalidVariablesError ) ;
213-
214- const { dc : dcInstance , vars : inputVars , options : inputOpts } = validateAdminArgs (
215- connectorConfig , variables , undefined , undefined , true , true
216- ) ;
217- expect ( dcInstance ) . to . deep . equal ( stubDcInstance ) ;
218- expect ( inputVars ) . to . deep . equal ( inputVars ) ;
219- expect ( inputOpts ) . to . be . undefined ;
194+ expect ( ( ) => {
195+ const { dc : dcInstance , vars : inputVars , options : inputOpts } = validateAdminArgs (
196+ connectorConfig , variables , undefined , undefined , true , true
197+ ) ;
198+ expect ( dcInstance ) . to . deep . equal ( stubDcInstance ) ;
199+ expect ( inputVars ) . to . deep . equal ( inputVars ) ;
200+ expect ( inputOpts ) . to . be . undefined ;
201+ } ) . to . not . throw ( invalidVariablesError ) ;
220202 } ) ;
221203 } ) ;
222204
223205 describe ( 'should throw if vars were NOT provided' , ( ) => {
224206 it ( 'and the first argument is a DataConnect instance' , ( ) => {
225- expect ( validateAdminArgs (
226- connectorConfig , providedDcInstance , undefined , undefined , true , true
227- ) ) . to . throw ( invalidVariablesError ) ;
207+ expect ( ( ) => {
208+ validateAdminArgs ( connectorConfig , providedDcInstance , undefined , undefined , true , true ) ;
209+ } ) . to . throw ( ) . and . have . property ( 'code' , invalidVariablesError . code ) ;
228210 } ) ;
229211
230212 it ( 'and the first argument is undefined variables' , ( ) => {
231213 expect ( validateAdminArgs (
232214 connectorConfig , undefined , undefined , undefined , true , true
233- ) ) . to . throw ( invalidVariablesError ) ;
215+ ) ) . to . throw ( ) . and . have . property ( 'code' , invalidVariablesError . code ) ;
234216 } ) ;
235217 } ) ;
236218 } ) ;
237219
238220 describe ( 'and validateVars = false' , ( ) => {
239221 describe ( 'should succeed if vars WERE provided' , ( ) => {
240222 it ( 'and the first argument is a DataConnect instance' , ( ) => {
241- expect ( validateAdminArgs (
242- connectorConfig , providedDcInstance , variables , undefined , true , false
243- ) ) . to . not . throw ( invalidVariablesError ) ;
244-
245- const { dc : dcInstance , vars : inputVars , options : inputOpts } = validateAdminArgs (
246- connectorConfig , providedDcInstance , variables , undefined , true , false
247- ) ;
248- expect ( dcInstance ) . to . deep . equal ( providedDcInstance ) ;
249- expect ( inputVars ) . to . be . undefined ;
250- expect ( inputOpts ) . to . be . undefined ;
223+ expect ( ( ) => {
224+ const { dc : dcInstance , vars : inputVars , options : inputOpts } = validateAdminArgs (
225+ connectorConfig , providedDcInstance , variables , undefined , true , false
226+ ) ;
227+ expect ( dcInstance ) . to . deep . equal ( providedDcInstance ) ;
228+ expect ( inputVars ) . to . be . undefined ;
229+ expect ( inputOpts ) . to . be . undefined ;
230+ } ) . to . not . throw ( invalidVariablesError ) ;
251231 } ) ;
252232
253233 it ( 'and the first argument is variables instance' , ( ) => {
254- expect ( validateAdminArgs (
255- connectorConfig , variables , undefined , undefined , true , false
256- ) ) . to . not . throw ( invalidVariablesError ) ;
234+ expect ( ( ) => {
235+ validateAdminArgs ( connectorConfig , variables , undefined , undefined , true , false ) ;
236+ } ) . to . not . throw ( invalidVariablesError ) ;
257237
258238 const { dc : dcInstance , vars : inputVars , options : inputOpts } = validateAdminArgs (
259239 connectorConfig , variables , undefined , undefined , true , false
@@ -266,29 +246,25 @@ describe('validateAdminArgs()', () => {
266246
267247 describe ( 'should succeed if vars were NOT provided' , ( ) => {
268248 it ( 'and the first argument is a DataConnect instance' , ( ) => {
269- expect ( validateAdminArgs (
270- connectorConfig , providedDcInstance , undefined , undefined , true , false
271- ) ) . to . not . throw ( invalidVariablesError ) ;
272-
273- const { dc : dcInstance , vars : inputVars , options : inputOpts } = validateAdminArgs (
274- connectorConfig , providedDcInstance , undefined , undefined , true , false
275- ) ;
276- expect ( dcInstance ) . to . deep . equal ( providedDcInstance ) ;
277- expect ( inputVars ) . to . deep . equal ( inputVars ) ;
278- expect ( inputOpts ) . to . be . undefined ;
249+ expect ( ( ) => {
250+ const { dc : dcInstance , vars : inputVars , options : inputOpts } = validateAdminArgs (
251+ connectorConfig , providedDcInstance , undefined , undefined , true , false
252+ ) ;
253+ expect ( dcInstance ) . to . deep . equal ( providedDcInstance ) ;
254+ expect ( inputVars ) . to . deep . equal ( inputVars ) ;
255+ expect ( inputOpts ) . to . be . undefined ;
256+ } ) . to . not . throw ( invalidVariablesError ) ;
279257 } ) ;
280258
281259 it ( 'and the first argument is undefined variables' , ( ) => {
282- expect ( validateAdminArgs (
283- connectorConfig , undefined , undefined , undefined , true , false
284- ) ) . to . not . throw ( invalidVariablesError ) ;
285-
286- const { dc : dcInstance , vars : inputVars , options : inputOpts } = validateAdminArgs (
287- connectorConfig , undefined , undefined , undefined , true , false
288- ) ;
289- expect ( dcInstance ) . to . deep . equal ( stubDcInstance ) ;
290- expect ( inputVars ) . to . be . undefined ;
291- expect ( inputOpts ) . to . be . undefined ;
260+ expect ( ( ) => {
261+ const { dc : dcInstance , vars : inputVars , options : inputOpts } = validateAdminArgs (
262+ connectorConfig , undefined , undefined , undefined , true , false
263+ ) ;
264+ expect ( dcInstance ) . to . deep . equal ( stubDcInstance ) ;
265+ expect ( inputVars ) . to . be . undefined ;
266+ expect ( inputOpts ) . to . be . undefined ;
267+ } ) . to . not . throw ( invalidVariablesError ) ;
292268 } ) ;
293269 } ) ;
294270 } ) ;
0 commit comments