-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(Formatting): Add prettier config file
.prettierr
and reformat…
…ted existing files i Co-authored-by: Keith Brewster <kbrewster@tribalscale.com>
- Loading branch information
Alice Mao
committed
Jul 11, 2019
1 parent
2eb90dd
commit 06c285e
Showing
5 changed files
with
123 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"singleQuote": true, | ||
"printWidth": 80, | ||
"semi": false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,49 @@ | ||
# Firebase 2-Factor Authentication | ||
|
||
## Overview | ||
|
||
The [Firebase Authentication SDK](https://firebase.google.com/docs/auth) does not currently support 2 Factor Authentication ("2FA"). The purpose of this library is to provide both a starter react-native application and wrapper functions around the Friebase Authentication SDK to streamline development for 2FA apps using Firebase. | ||
|
||
## Getting Started | ||
|
||
_This section describes how to set up the project to develop and test, as well as how to use the project if it is an external package._ | ||
|
||
## Prerequisites | ||
|
||
_What needs to be done before development, testing, and/or usage can occur._ | ||
|
||
## Installing | ||
|
||
_How to install and run the project within a given environment._ | ||
|
||
## Documentation | ||
|
||
_Links to other supporting documents for the project._ | ||
|
||
## How to Use | ||
|
||
_Can include a general overview of how to use the project, code samples are strongly recommended here. Being as specific as possible is helpful to users, including a description of the API._ | ||
|
||
## Running the Tests | ||
|
||
_Steps to run the test suite of the project._ | ||
|
||
## Deployment | ||
|
||
_Steps for new development code get deployed to production._ | ||
|
||
## Technologies Used | ||
|
||
_A list of the major technologies used in the project._ | ||
|
||
## Contribute | ||
|
||
_Description of how other developers can contribute to this project (i.e. pull requests)._ | ||
|
||
## Versioning | ||
|
||
_Description of how to handle versioning of the project and which versioning pattern is being followed._ | ||
|
||
## Authors | ||
|
||
_Who is responsible for the project._ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,97 +1,96 @@ | ||
const firebase2FA = require("./index"); | ||
const fb = require("./src/firebase"); | ||
const firebase2FA = require('./index') | ||
const fb = require('./src/firebase') | ||
|
||
describe("Firebase2FA", () => { | ||
describe("Initialization", () => { | ||
test("it returns methods initializeWithConfig, initializeWithInstance", () => { | ||
const actual = firebase2FA; | ||
const methodsArray = ["initializeWithConfig", "initializeWithInstance"]; | ||
methodsArray.forEach(expected => expect(actual).toHaveProperty(expected)); | ||
}); | ||
describe('Firebase2FA', () => { | ||
describe('Initialization', () => { | ||
test('it returns methods initializeWithConfig, initializeWithInstance', () => { | ||
const actual = firebase2FA | ||
const methodsArray = ['initializeWithConfig', 'initializeWithInstance'] | ||
methodsArray.forEach(expected => expect(actual).toHaveProperty(expected)) | ||
}) | ||
|
||
test("initializeWithConfig fails when not provided a config object", () => { | ||
const expected = /Please provide a firebase app configuration./; | ||
const actual = firebase2FA.initializeWithConfig; | ||
expect(actual).toThrow(expected); | ||
}); | ||
|
||
["apiKey", "authDomain", "projectId", "appId"].forEach(key => { | ||
test('initializeWithConfig fails when not provided a config object', () => { | ||
const expected = /Please provide a firebase app configuration./ | ||
const actual = firebase2FA.initializeWithConfig | ||
expect(actual).toThrow(expected) | ||
}) | ||
;['apiKey', 'authDomain', 'projectId', 'appId'].forEach(key => { | ||
const config = { | ||
apiKey: "test", | ||
authDomain: "test", | ||
projectId: "test", | ||
appId: "test" | ||
}; | ||
delete config[key]; | ||
const actual = () => firebase2FA.initializeWithConfig(config); | ||
apiKey: 'test', | ||
authDomain: 'test', | ||
projectId: 'test', | ||
appId: 'test' | ||
} | ||
delete config[key] | ||
const actual = () => firebase2FA.initializeWithConfig(config) | ||
|
||
test(`intializeWithConfig fails when [${key}] config key is missing`, () => { | ||
const expected = `${key} value is required.`; | ||
expect(actual).toThrow(expected); | ||
}); | ||
}); | ||
const expected = `${key} value is required.` | ||
expect(actual).toThrow(expected) | ||
}) | ||
}) | ||
|
||
test("initializeWithConfig fails when app has already been initialized", () => { | ||
test('initializeWithConfig fails when app has already been initialized', () => { | ||
const config = { | ||
apiKey: "test", | ||
authDomain: "test", | ||
projectId: "test", | ||
appId: "test" | ||
}; | ||
firebase2FA.initializeWithConfig(config); | ||
const actual = () => firebase2FA.initializeWithConfig(config); | ||
const expected = /Firebase has already been initialized./; | ||
expect(actual).toThrow(expected); | ||
}); | ||
apiKey: 'test', | ||
authDomain: 'test', | ||
projectId: 'test', | ||
appId: 'test' | ||
} | ||
firebase2FA.initializeWithConfig(config) | ||
const actual = () => firebase2FA.initializeWithConfig(config) | ||
const expected = /Firebase has already been initialized./ | ||
expect(actual).toThrow(expected) | ||
}) | ||
|
||
test("initializeWithConfig succeeds when provided a valid config object", () => { | ||
test('initializeWithConfig succeeds when provided a valid config object', () => { | ||
const config = { | ||
apiKey: "test", | ||
authDomain: "test", | ||
projectId: "test", | ||
appId: "test" | ||
}; | ||
const actual = () => firebase2FA.initializeWithConfig(config); | ||
const expected = "function"; | ||
expect(typeof actual).toBe(expected); | ||
}); | ||
}); | ||
apiKey: 'test', | ||
authDomain: 'test', | ||
projectId: 'test', | ||
appId: 'test' | ||
} | ||
const actual = () => firebase2FA.initializeWithConfig(config) | ||
const expected = 'function' | ||
expect(typeof actual).toBe(expected) | ||
}) | ||
}) | ||
|
||
describe("User", () => { | ||
describe("Account Creation", () => { | ||
test("createAccountWithEmail fails when email is not provided", () => { | ||
describe('User', () => { | ||
describe('Account Creation', () => { | ||
test('createAccountWithEmail fails when email is not provided', () => { | ||
const userObj = { | ||
email: "", | ||
password: "test" | ||
}; | ||
const actual = () => firebase2FA.createAccountWithEmail(userObj); | ||
const expected = /Email is required./; | ||
expect(actual).toThrow(expected); | ||
}); | ||
email: '', | ||
password: 'test' | ||
} | ||
const actual = () => firebase2FA.createAccountWithEmail(userObj) | ||
const expected = /Email is required./ | ||
expect(actual).toThrow(expected) | ||
}) | ||
|
||
test("createAccountWithEmail fails when password is not provided", () => { | ||
test('createAccountWithEmail fails when password is not provided', () => { | ||
const userObj = { | ||
email: "test", | ||
password: "" | ||
}; | ||
const actual = () => firebase2FA.createAccountWithEmail(userObj); | ||
const expected = /Password is required./; | ||
expect(actual).toThrow(expected); | ||
}); | ||
email: 'test', | ||
password: '' | ||
} | ||
const actual = () => firebase2FA.createAccountWithEmail(userObj) | ||
const expected = /Password is required./ | ||
expect(actual).toThrow(expected) | ||
}) | ||
|
||
test("createAccountWithEmail is successful when email & password are provided", () => { | ||
test('createAccountWithEmail is successful when email & password are provided', () => { | ||
const userObj = { | ||
email: "test", | ||
password: "testpassword" | ||
}; | ||
email: 'test', | ||
password: 'testpassword' | ||
} | ||
|
||
const spy = jest.spyOn(fb, "createUser"); | ||
spy.mockReturnValue("mocked"); | ||
const spy = jest.spyOn(fb, 'createUser') | ||
spy.mockReturnValue('mocked') | ||
|
||
firebase2FA.createAccountWithEmail(userObj); | ||
expect(spy).toHaveBeenCalledWith(userObj); | ||
spy.mockRestore(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
firebase2FA.createAccountWithEmail(userObj) | ||
expect(spy).toHaveBeenCalledWith(userObj) | ||
spy.mockRestore() | ||
}) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,17 @@ | ||
const firebase = require("firebase"); | ||
const firebase = require('firebase') | ||
|
||
const initializeFirebase = config => { | ||
firebase.initializeApp(config); | ||
}; | ||
firebase.initializeApp(config) | ||
} | ||
|
||
const createUser = async ({ email, password }) => { | ||
return await firebase.auth().createUserWithEmailAndPassword(email, password); | ||
}; | ||
return await firebase.auth().createUserWithEmailAndPassword(email, password) | ||
} | ||
|
||
const checkInitializationState = () => firebase.apps.length > 0; | ||
const checkInitializationState = () => firebase.apps.length > 0 | ||
|
||
module.exports = { | ||
checkInitializationState, | ||
createUser, | ||
initializeFirebase | ||
}; | ||
} |