From 774853af7a447106c9da1bcb91702465557b1453 Mon Sep 17 00:00:00 2001 From: Liyas Thomas Date: Wed, 21 Oct 2020 10:11:56 +0530 Subject: [PATCH] Remove teams section from Firebase --- helpers/__tests__/fb.spec.js | 103 ----------------------------------- helpers/fb.js | 32 ----------- 2 files changed, 135 deletions(-) diff --git a/helpers/__tests__/fb.spec.js b/helpers/__tests__/fb.spec.js index f7d2c38863..ead98b043e 100644 --- a/helpers/__tests__/fb.spec.js +++ b/helpers/__tests__/fb.spec.js @@ -121,35 +121,6 @@ beforeEach(async () => { value: true, }) - await mocksdk - .firestore() - .collection("users") - .doc(testuser.uid) - .collection("settings") - .doc("syncTeams") - .set({ - author: testuser.uid, - author_image: testuser.photoURL, - author_name: testuser.displayName, - name: "syncTeams", - updatedOn: new Date(1598703948000), - value: true, - }) - - await mocksdk - .firestore() - .collection("users") - .doc(testuser.uid) - .collection("teams") - .doc("sync") - .set({ - author: testuser.uid, - author_image: testuser.photoURL, - author_name: testuser.displayName, - team: [], - updatedOn: new Date(1598703948000), - }) - await mocksdk .firestore() .collection("users") @@ -1232,78 +1203,4 @@ describe("FirebaseInstance", () => { ) }) }) - - describe("writeTeams", () => { - test("resolves for proper authenticated request", async () => { - const fb = new FirebaseInstance(mocksdk) - - signInUser() - - await expect(fb.writeTeams([])).resolves.toBeUndefined() - }) - - test("rejects for non-authenticated request", async () => { - const fb = new FirebaseInstance(mocksdk) - - signOutUser() - - await expect(fb.writeTeams([])).rejects.toBeDefined() - }) - - test("stores data on firestore with proper structure", async () => { - const fb = new FirebaseInstance(mocksdk) - - signInUser() - - await fb.writeTeams([]) - - const doc = ( - await mocksdk - .firestore() - .collection("users") - .doc(testuser.uid) - .collection("teams") - .doc("sync") - .get() - ).data() - - expect(doc).toEqual( - expect.objectContaining({ - updatedOn: expect.any(Date), - author: expect.any(String), - author_name: expect.any(String), - author_image: expect.any(String), - team: expect.anything(), - }) - ) - }) - - test("stores data on firestore with fields having proper values", async () => { - const fb = new FirebaseInstance(mocksdk) - - signInUser() - - await fb.writeTeams([]) - - const doc = ( - await mocksdk - .firestore() - .collection("users") - .doc(testuser.uid) - .collection("teams") - .doc("sync") - .get() - ).data() - - expect(doc).toEqual( - expect.objectContaining({ - updatedOn: expect.any(Date), - author: testuser.uid, - author_name: testuser.displayName, - author_image: testuser.photoURL, - team: expect.anything(), - }) - ) - }) - }) }) diff --git a/helpers/fb.js b/helpers/fb.js index f564448d89..30c3dd7d84 100644 --- a/helpers/fb.js +++ b/helpers/fb.js @@ -32,7 +32,6 @@ export class FirebaseInstance { this.currentHistory = [] this.currentCollections = [] this.currentEnvironments = [] - this.currentTeams = [] this.app.auth().onAuthStateChanged((user) => { if (user) { @@ -121,19 +120,6 @@ export class FirebaseInstance { this.currentEnvironments = environments[0].environment } }) - - this.usersCollection - .doc(this.currentUser.uid) - .collection("teams") - .onSnapshot((teamsRef) => { - const teams = [] - teamsRef.forEach((doc) => { - const team = doc.data() - team.id = doc.id - teams.push(team) - }) - this.currentTeams = teams[0].team - }) } else { this.currentUser = null } @@ -302,24 +288,6 @@ export class FirebaseInstance { throw e } } - - async writeTeams(team) { - const ev = { - updatedOn: new Date(), - author: this.currentUser.uid, - author_name: this.currentUser.displayName, - author_image: this.currentUser.photoURL, - team, - } - - try { - await this.usersCollection.doc(this.currentUser.uid).collection("teams").doc("sync").set(ev) - } catch (e) { - console.error("error updating", ev, e) - - throw e - } - } } export const fb = new FirebaseInstance(firebase.initializeApp(firebaseConfig), authProviders)