Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Making it possible to run integration tests againsty any Firebase pro…
…ject
  • Loading branch information
Hiranya Jayathilaka committed May 9, 2017
commit 8c8c4fa1cec8ad5f0dcec9cb2882cd839058b8a5
15 changes: 9 additions & 6 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,14 +134,17 @@ $ gulp # Lint, build, and run unit test suite
To run the integration test suite:

```
$ node test/integration # Run integration test suite
$ node test/integration <apiKey> # Run integration test suite
```

The integration test suite requires you to generate a service account key JSON file for the
**admin-sdks-test** Firebase project and save it to `test/resources/key.json`. You can generate this
from the
[**Service Accounts**](https://console.firebase.google.com/project/admin-sdks-test/settings/serviceaccounts/adminsdk)
tab of that project's settings page.
The integration test suite requires you to generate a service account key JSON file for a
Firebase project and save it to `test/resources/key.json`. Create a new project in the
[Firebase console](https://console.firebase.google.com) if you do not already have one.
Use a separate, dedicated project for integration tests since the test suite makes a large
number of writes to the Firebase realtime database. Download the service account key file
from the "Settings > Service Accounts" page of the project, and copy it to
`test/resources/key.json`. Also obtain the API key for the same project from "Settings > General".
This API key should be passed into the test suite as a command-line argument.

### Repo Organization

Expand Down
2 changes: 1 addition & 1 deletion test/integration/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ function test(utils) {
);

utils.assert(
defaultApp.options.databaseURL === 'https://admin-sdks-test.firebaseio.com',
defaultApp.options.databaseURL === 'https://' + utils.getProjectId() + '.firebaseio.com',
'app.options.databaseURL',
'databaseURL is incorrect.'
);
Expand Down
5 changes: 3 additions & 2 deletions test/integration/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ var _ = require('lodash');
var firebase = require('firebase');

var admin = require('../../lib/index');
var testutils = require('./utils');

firebase.initializeApp({
apiKey: "AIzaSyB9merDS-vSCzloW_WpTibO_-NzgoFR2JA",
authDomain: "admin-sdks-test.firebaseapp.com",
apiKey: testutils.getApiKey(),
authDomain: testutils.getProjectId() + ".firebaseapp.com",
});

function test(utils) {
Expand Down
19 changes: 5 additions & 14 deletions test/integration/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,32 +26,23 @@ var auth = require('./auth');
var database = require('./database');
var messaging = require('./messaging');

var serviceAccount;
try {
serviceAccount = require('../resources/key.json');
} catch(error) {
console.log(chalk.red(
'The integration test suite requires a service account key JSON file for the ' +
'`admin-sdks-test` project to be saved to `test/resources/key.json`.',
error
));
process.exit(1);
}
var serviceAccount = utils.getCredential();
var databaseURL = 'https://' + utils.getProjectId() + '.firebaseio.com';

var defaultApp = admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
databaseURL: 'https://admin-sdks-test.firebaseio.com',
databaseURL: databaseURL,
});

var nullApp = admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
databaseURL: 'https://admin-sdks-test.firebaseio.com',
databaseURL: databaseURL,
databaseAuthVariableOverride: null,
}, 'null');

var nonNullApp = admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
databaseURL: 'https://admin-sdks-test.firebaseio.com',
databaseURL: databaseURL,
databaseAuthVariableOverride: {
uid: utils.generateRandomString(20),
},
Expand Down
47 changes: 46 additions & 1 deletion test/integration/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,48 @@ var successCount = 0;
var failure = chalk.red;
var success = chalk.green;

var serviceAccount;

try {
serviceAccount = require('../resources/key.json');
} catch(error) {
console.log(chalk.red(
'The integration test suite requires a service account key JSON file for a ' +
'Firebase project to be saved to `test/resources/key.json`.',
error
));
process.exit(1);
}

var apiKey = process.argv[2];
if (apiKey == undefined) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typeof apiKey === 'undefined'

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

console.log(chalk.red(
'The integration test suite requires a API key for a ' +
'Firebase project to be specified as a command-line argument.'));
process.exit(1);
}

/**
* Returns the service account credential used for runnnig integration tests.
*
* @return {Object} A service account credential.
*/
function getCredential() {
return serviceAccount;
}

/**
* Returns the ID of the project the integration tests are executed against.
*
* @return {string} A project ID.
*/
function getProjectId() {
return serviceAccount.project_id;
}

function getApiKey() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: add javadoc for this function like you did for the ones above.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

return apiKey;
}

/**
* Logs a message to the console in green text.
Expand Down Expand Up @@ -125,5 +167,8 @@ module.exports = {
logFailure: logFailure,
logSuccess: logSuccess,
logResults: logResults,
generateRandomString: generateRandomString
generateRandomString: generateRandomString,
getCredential: getCredential,
getProjectId: getProjectId,
getApiKey: getApiKey
}