Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
24 changes: 11 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
<div align="center">
<h1>Fireboost</h1>
<h1>FireBoost</h1>
</div>

![npm](https://img.shields.io/npm/v/fireboost.svg)
![Travis](https://img.shields.io/travis/39ro/fireboost)
[![npm](https://img.shields.io/npm/v/fireboost.svg)](https://www.npmjs.com/package/fireboost)
[![Travis](https://img.shields.io/travis/39ro/fireboost)](https://travis-ci.com/github/39ro/fireboost)
![NPM](https://img.shields.io/npm/l/fireboost)
[![Code Style: Google](https://img.shields.io/badge/code%20style-google-blueviolet.svg)](https://github.com/google/gts)

<hr>

Helpers used for common admin tasks on Firebase (Authentication, Firestore).
A library including methods to `boost` your development with Firebase (Authentication, Firestore).


### Installation:
## Installation:

- To install fireboost using npm, open a terminal/console window and enter the following command:
```
Expand All @@ -28,13 +28,12 @@ const fireBoost = new FireBoost();

<hr>

### Documentation:
## Documentation:

### Authentication
Initializate fireboost with a Firebase App
```javascript
import * as admin from 'firebase-admin';
import {FireBoost} from 'fireboost';

const serviceAccount = require('./service-account.json');

Expand All @@ -43,18 +42,17 @@ const app = admin.initializeApp({
databaseURL: "__YOUR__DATABASE_URL__"
});

const appAuthRef = new FireBoost().auth(app);
const appAuthRef = fireBoost.auth(app);
```

###### API

- **deleteAllUsers**<br>
_Delete all userRecors found in your Firebase App_
_Delete all userRecords found in your Firebase App_
```javascript
appAuthRef.deleteAllUsers()
// teardown
.then(() => app.delete())
.catch(console.log);
// teardown
.then(() => app.delete())
```


Expand Down Expand Up @@ -111,7 +109,7 @@ utilDocRef.renameField({oldFieldKey: 'newFieldKey'})


### Just a reminder
This in a unofficial library for Firestore (https://firebase.google.com/docs/firestore) we recommend replicating the operation, where it's possible, in a test project to check if the output is what expected before to run any operation in a production environment.
This in a unofficial library for Firebase (Authentication, Firestore) we recommend replicating the operation, where it's possible, in a test project to check if the output is what expected before to run any operation in a production environment.
Thanks for using and testing this library!

### Contributing
Expand Down
8 changes: 7 additions & 1 deletion src/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ export class FireBoostAuth {
this.auth = app.auth();
}

/*
* Delete all existing users found in initialized Firebase app
* appAuthRef.deleteAllUsers()
* // teardown
* .then(() => app.delete())
*/
async deleteAllUsers(nextPageToken?: string): Promise<void> {
const listUsersResult = await this.auth.listUsers(10, nextPageToken);
const usersID: string[] = listUsersResult.users.map(
Expand All @@ -18,7 +24,7 @@ export class FireBoostAuth {

for (const uid of listUsers.usersID) {
await this.auth.deleteUser(uid);
console.log('Deleted Auth User: ', uid);
console.log('Deleted user: ', uid);
}

if (listUsers.token) {
Expand Down
6 changes: 3 additions & 3 deletions src/fireboost.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { FirestoreAdminUtils } from './firestore';
import { FireBoostFirestore } from './firestore';
import { FireBoostAuth } from './auth';
import * as admin from 'firebase-admin';

Expand All @@ -7,7 +7,7 @@ export class FireBoost {
return new FireBoostAuth(app);
}

firestore(): FirestoreAdminUtils {
return new FirestoreAdminUtils();
firestore(): FireBoostFirestore {
return new FireBoostFirestore();
}
}
2 changes: 1 addition & 1 deletion src/firestore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ export class CollectionReferenceHelper extends ReferenceHelper<
}
}

export class FirestoreAdminUtils {
export class FireBoostFirestore {
ref(r: DocumentReference): DocumentReferenceHelper;
ref(r: CollectionReference): CollectionReferenceHelper;
ref<T extends CollectionReference | DocumentReference>(r: T) {
Expand Down
10 changes: 0 additions & 10 deletions test/integration/auth.test.ts

This file was deleted.

34 changes: 32 additions & 2 deletions test/integration/fireboost.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,36 @@
import * as admin from 'firebase-admin';
import { FireBoost } from '../../src/fireboost';
import { FirestoreAdminUtils } from '../../src/firestore';

import { CollectionReferenceHelper, DocumentReferenceHelper, FireBoostFirestore } from '../../src/firestore';
import { FireBoostAuth } from '../../src/auth';

let db: admin.firestore.Firestore;
let app: admin.app.App;

beforeAll(async () => {
// Init application
app = admin.initializeApp();
db = app.firestore();
});

afterAll(async () => {
await admin.app().delete();
});

test('FireBoost().firestore()', () => {
expect(new FireBoost().firestore()).toBeInstanceOf(FirestoreAdminUtils);
expect(new FireBoost().firestore()).toBeInstanceOf(FireBoostFirestore);
});

test('FireBoost().auth()', () => {
expect(new FireBoost().auth(app)).toBeInstanceOf(FireBoostAuth);
});

test('FireBoost().firestore().ref() as Collection', () => {
const colRef = db.collection('test');
expect(new FireBoost().firestore().ref(colRef)).toBeInstanceOf(CollectionReferenceHelper);
});

test('FireBoost().firestore().ref() as Document', () => {
const docRef = db.collection('test').doc('123');
expect(new FireBoost().firestore().ref(docRef)).toBeInstanceOf(DocumentReferenceHelper);
});
27 changes: 0 additions & 27 deletions test/integration/firestore.test.ts

This file was deleted.

6 changes: 3 additions & 3 deletions test/unit/firestore/collection.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as firebaseTesting from '@firebase/testing';
import { TestFirestoreAdminUtils } from '../../utils/firestore-test';
import { TestFireBoostFirestore } from '../../utils/firestore-test';

const adminUtilsFirestore = new TestFirestoreAdminUtils();
const adminUtilsFirestore = new TestFireBoostFirestore();

jest.mock('firebase-admin', () => {
return {
Expand All @@ -13,7 +13,7 @@ jest.mock('firebase-admin', () => {

const PROJECT_ID = `firestore-utils-project-${new Date().getTime()}`;

let app;
let app: firebase.app.App;
let db: firebaseTesting.firestore.Firestore;

beforeAll(async () => {
Expand Down
6 changes: 3 additions & 3 deletions test/unit/firestore/document.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as firebaseTesting from '@firebase/testing';
import { TestFirestoreAdminUtils } from '../../utils/firestore-test';
import { TestFireBoostFirestore } from '../../utils/firestore-test';

const adminUtilsFirestore = new TestFirestoreAdminUtils();
const adminUtilsFirestore = new TestFireBoostFirestore();

jest.mock('firebase-admin', () => {
return {
Expand All @@ -13,7 +13,7 @@ jest.mock('firebase-admin', () => {

const PROJECT_ID = `firestore-utils-project-${new Date().getTime()}`;

let app;
let app: firebase.app.App;
let db: firebaseTesting.firestore.Firestore;

beforeAll(async () => {
Expand Down
4 changes: 2 additions & 2 deletions test/utils/firestore-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import {

import TestCollectionReference = firebaseTesting.firestore.CollectionReference;
import TestDocumentReference = firebaseTesting.firestore.DocumentReference;
import { CollectionReferenceHelper, DocumentReferenceHelper, FirestoreAdminUtils } from '../../src/firestore';
import { CollectionReferenceHelper, DocumentReferenceHelper, FireBoostFirestore } from '../../src/firestore';

export class TestFirestoreAdminUtils implements FirestoreAdminUtils {
export class TestFireBoostFirestore implements FireBoostFirestore {
ref(r: TestDocumentReference): DocumentReferenceHelper;
ref(r: TestCollectionReference): CollectionReferenceHelper;
ref(r: DocumentReference): DocumentReferenceHelper;
Expand Down