Skip to content
This repository has been archived by the owner on Mar 29, 2022. It is now read-only.

API Key is invalid on tests with Karma + Jasmine #63

Closed
thiagorossener opened this issue Aug 17, 2016 · 6 comments
Closed

API Key is invalid on tests with Karma + Jasmine #63

thiagorossener opened this issue Aug 17, 2016 · 6 comments

Comments

@thiagorossener
Copy link

Hi,

I'm struggling to use firebase-server with Karma + Jasmine.

I have a web app made with AngularJS, in my app.js I make something like this:

angular.module('siteAdminApp', [
    'config',
    'ngAnimate',
    'ngCookies',
    'ngResource',
    'ngRoute',
    'ngSanitize',
    'ngTouch',
    'ngTagsInput',
    'ngMask',
    'ngImgCrop',
    'ngFileUpload',
    'ngMessages',
    'firebase',
    'firebase.ref',
    'firebase.auth',
    'firebase.time',
    'ui.select',
    'ui.sortable',
    'ui.bootstrap',
    'mgcrea.ngStrap',
    'ui.utils.masks',
    'translate'
  ])
  .config(['CONF', '$windowProvider', function (CONF, $windowProvider) {
    // Workaround to make tests work and avoid get multiple instances of Firebase on tests
    var $window = $windowProvider.$get();
    try {
      $window.firebaseApp = $window.firebase.app('myapp');
    } catch (err) {
      $window.firebaseApp = $window.firebase.initializeApp(CONF.firebase.config, 'myapp');
    }
  }]);

CONF is a factory which returns the Firebase 3 configuration with databaseURL, apiKey, etc...

I'm using "browserify" with Karma, to be able to load modules to my tests, so my test looks like:

'use strict';

var FirebaseServer = require('firebase-server');

describe('Any test', function () {

  var server = new FirebaseServer(5555, 'ws://127.0.1', {});

  it('Testing', function (done) {
    done();
  });

});

I already made other tests work using firebase-server running by command line and then running tests.

But now I'm trying not do do this, but use FirebaseServer inside my tests, and with that scenario I'm getting that error:

Error: Your API key is invalid, please check you have copied it correctly. in /var/folders/06/m9yhsng108ndr6tlrncl0lpc0000gn/T/7363266c7b7f8c1d39ccc00c08e1be9f.browserify (line 61882)
    xm@/var/folders/06/m9yhsng108ndr6tlrncl0lpc0000gn/T/7363266c7b7f8c1d39ccc00c08e1be9f.browserify:61882:634 <- node_modules/firebase/firebase.js:298:0
    /var/folders/06/m9yhsng108ndr6tlrncl0lpc0000gn/T/7363266c7b7f8c1d39ccc00c08e1be9f.browserify:61903:359 <- node_modules/firebase/firebase.js:319:0
    R@/var/folders/06/m9yhsng108ndr6tlrncl0lpc0000gn/T/7363266c7b7f8c1d39ccc00c08e1be9f.browserify:61609:94 <- node_modules/firebase/firebase.js:25:0
    [native code]
    /var/folders/06/m9yhsng108ndr6tlrncl0lpc0000gn/T/7363266c7b7f8c1d39ccc00c08e1be9f.browserify:61904:88 <- node_modules/firebase/firebase.js:320:0
    /var/folders/06/m9yhsng108ndr6tlrncl0lpc0000gn/T/7363266c7b7f8c1d39ccc00c08e1be9f.browserify:61606:273 <- node_modules/firebase/firebase.js:22:0
    forEach@[native code]
    initializeApp@/var/folders/06/m9yhsng108ndr6tlrncl0lpc0000gn/T/7363266c7b7f8c1d39ccc00c08e1be9f.browserify:61606:252 <- node_modules/firebase/firebase.js:22:0
    Fire/Users/thiago/Documents/Projects/Sheeper/sheeper-webServer@http://localhost:8080/var/folders/06/m9yhsng108ndr6tlrncl0lpc0000gn/T/7363266c7b7f8c1d39ccc00c08e1be9f.browserify:38960:35 <- node_modules/firebase-server/index.js:79:0

So, I know firebase-server is just starting to support Firebase 3.

What I need to know is, is there a way to make this work? Or is better I keep going with command line to run my tests?

@cheriot
Copy link

cheriot commented Aug 23, 2016

What's the exact value of CONF.firebase.config?

Where connecting to a real firebase is

firebase.initializeApp({
  serviceAccount: "path/to/serviceAccountCredentials.json",
  databaseURL: "https://databaseName.firebaseio.com"
});

I was able to connect to firebase-server with

firebase.initializeApp({
  apiKey: 'fake-api-key',
  databaseURL: 'ws://localhost.firebaseio.com:5000'
});

@thiagorossener
Copy link
Author

@cheriot CONF is a service to provide the config for my environments.

Here is the value when I'm testing.

"firebase": {
  "config": {
    "apiKey": "whatever",
    "authDomain": "whatever",
    "databaseURL": "ws://127.0.1:5000",
    "storageBucket": "whatever"
  }
}

@pinn3
Copy link

pinn3 commented Dec 4, 2016

@cheriot Your solution no longer seem to work as firebase will complain when trying to parse the databaseURL parameter, as it now seems to require https.

Any clues? (@urish)

@prescottprue
Copy link

prescottprue commented Oct 18, 2017

Believe seeing this every now and then too. For now I have been re-running CI builds, and it seems to fix things.

@mjmaix
Copy link

mjmaix commented Nov 20, 2017

I'm getting consistent invalid API key errors

@urish
Copy link
Owner

urish commented Jan 12, 2018

See firebase/firebase-js-sdk#426 - seems like the 127.0.1 hack is no longer required.

@urish urish closed this as completed Jan 12, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants