Remove teams section from Firebase
This commit is contained in:
@@ -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(),
|
||||
})
|
||||
)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user