-
-
Notifications
You must be signed in to change notification settings - Fork 348
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enabled devs to login, logout and CRUD against FireBase in Cypress tests
- Loading branch information
Showing
8 changed files
with
433 additions
and
180 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
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 |
---|---|---|
@@ -0,0 +1,36 @@ | ||
describe('FireBase + Cypress', () => { | ||
it('should logout and login', () => { | ||
cy.visit('/how-to') | ||
cy.logout() | ||
cy.get('[data-cy=create]').should('not.exist') | ||
|
||
cy.login('test1234@test.com', '12345678') | ||
cy.get('[data-cy=create]').should('be.visible') | ||
|
||
cy.logout() | ||
cy.get('[data-cy=create]').should('not.exist') | ||
}) | ||
|
||
it('should add/update/get/delete from FireStore', async () => { | ||
const firestore = await cy.firestore() | ||
const addRef = await firestore | ||
.collection('testCollection') | ||
.add({ name: 'Tony Stark', age: 45 }) | ||
console.log('Object added with ref ' + addRef.id) | ||
await firestore | ||
.collection('testCollection') | ||
.doc(addRef.id) | ||
.update({ name: 'Iron man', age: 40 }) | ||
console.log('Object updated ') | ||
const snapshot = await firestore.collection('testCollection').get() | ||
snapshot.forEach(doc => { | ||
console.log(`ID ${doc.id} => `, doc.data()) | ||
}) | ||
await firestore | ||
.collection('testCollection') | ||
.doc(addRef.id) | ||
.delete() | ||
console.log(`Object ${addRef.id} deleted`) | ||
cy.visit('/how-to') | ||
}) | ||
}) |
This file was deleted.
Oops, something went wrong.
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,70 @@ | ||
import * as firebase from 'firebase/app' | ||
import 'firebase/auth' | ||
import 'firebase/database' | ||
import 'firebase/firestore' | ||
import cypress from 'cypress' | ||
|
||
const projectId = 'precious-plastics-v4-dev' | ||
const apiKey = 'AIzaSyChVNSMiYxCkbGd9C95aChr9GxRJtW6NRA' | ||
const fbConfig = { | ||
apiKey, | ||
authDomain: `${projectId}.firebaseapp.com`, | ||
databaseURL: `https://${projectId}.firebaseio.com`, | ||
projectId: `${projectId}`, | ||
storageBucket: `${projectId}.appspot.com`, | ||
messagingSenderId: '174193431763', | ||
} | ||
firebase.initializeApp(fbConfig) | ||
|
||
declare global { | ||
namespace Cypress { | ||
// tslint:disable-next-line:interface-name | ||
interface Chainable { | ||
firestore(): Promise<firebase.firestore.Firestore> | ||
|
||
login( | ||
username: string, | ||
password: string, | ||
): Promise<firebase.auth.UserCredential> | ||
|
||
logout(): Promise<void> | ||
} | ||
} | ||
} | ||
|
||
const attachCustomCommands = ( | ||
Cypress, | ||
{ auth, firestore }: typeof firebase, | ||
) => { | ||
let currentUser: null | firebase.User = null | ||
auth().onAuthStateChanged(user => { | ||
currentUser = user | ||
}) | ||
|
||
Cypress.Commands.add('login', (email, password) => { | ||
Cypress.log({ | ||
displayName: 'login', | ||
consoleProps: () => { | ||
return { email, password } | ||
}, | ||
}) | ||
return auth().signInWithEmailAndPassword(email, password) | ||
}) | ||
|
||
Cypress.Commands.add('logout', () => { | ||
const userInfo = currentUser ? currentUser.email : 'Not login yet - Skipped' | ||
Cypress.log({ | ||
displayName: 'logout', | ||
consoleProps: () => { | ||
return { currentUser: userInfo } | ||
}, | ||
}) | ||
return auth().signOut() | ||
}) | ||
|
||
Cypress.Commands.add('firestore', () => { | ||
return firestore() | ||
}) | ||
} | ||
|
||
attachCustomCommands(Cypress, firebase) |
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
Oops, something went wrong.