Skip to content

Commit

Permalink
Remove teams section from Firebase
Browse files Browse the repository at this point in the history
  • Loading branch information
liyasthomas committed Oct 21, 2020
1 parent 7e30a4a commit 774853a
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 135 deletions.
103 changes: 0 additions & 103 deletions helpers/__tests__/fb.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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(),
})
)
})
})
})
32 changes: 0 additions & 32 deletions helpers/fb.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ export class FirebaseInstance {
this.currentHistory = []
this.currentCollections = []
this.currentEnvironments = []
this.currentTeams = []

this.app.auth().onAuthStateChanged((user) => {
if (user) {
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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)

0 comments on commit 774853a

Please sign in to comment.