-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2403 from concord-consortium/188211348-local-stor…
…age-dev-root refactor firebase root id computation
- Loading branch information
Showing
9 changed files
with
132 additions
and
37 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
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,46 @@ | ||
import { DB } from "./db"; | ||
import { Firebase } from "./firebase"; | ||
|
||
const mockStores = { | ||
appMode: "authed", | ||
demo: { name: "demo" }, | ||
user: { portal: "test-portal" } | ||
}; | ||
const mockDB = { | ||
stores: mockStores | ||
} as DB; | ||
|
||
describe("Firebase class", () => { | ||
describe("initialization", () => { | ||
it("should create a valid Firebase object", () => { | ||
const firebase = new Firebase(mockDB); | ||
expect(firebase).toBeDefined(); | ||
}); | ||
}); | ||
describe("getRootFolder", () => { | ||
it("should handle authed mode", () => { | ||
const firebase = new Firebase(mockDB); | ||
expect(firebase.getRootFolder()).toBe("/authed/portals/test-portal/"); | ||
}); | ||
describe("should handle the demo appMode", () => { | ||
it("handles basic demo name", () => { | ||
const stores = {...mockStores, | ||
appMode: "demo", demo: { name: "test-demo" }}; | ||
const firebase = new Firebase({stores} as DB); | ||
expect(firebase.getRootFolder()).toBe("/demo/test-demo/portals/test-portal/"); | ||
}); | ||
it("handles empty demo name", () => { | ||
const stores = {...mockStores, | ||
appMode: "demo", demo: { name: "" }}; | ||
const firebase = new Firebase({stores} as DB); | ||
expect(firebase.getRootFolder()).toBe("/demo/test-portal/portals/test-portal/"); | ||
}); | ||
it("handles empty demo name and empty portal", () => { | ||
const stores = {...mockStores, | ||
appMode: "demo", demo: { name: "" }, user: { portal: ""}}; | ||
const firebase = new Firebase({stores} as DB); | ||
expect(firebase.getRootFolder()).toBe("/demo/demo/portals//"); | ||
}); | ||
}); | ||
}); | ||
}); |
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
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,30 @@ | ||
import { IStores } from "../models/stores/stores"; | ||
import { escapeKey } from "./fire-utils"; | ||
|
||
type IRootDocIdStores = Pick<IStores, "appMode" | "demo" | "user">; | ||
|
||
export function getRootId(stores: IRootDocIdStores, firebaseUserId: string) { | ||
const { appMode, demo: { name: demoName }, user: { portal } } = stores; | ||
const escapedPortal = portal ? escapeKey(portal) : portal; | ||
|
||
switch (appMode) { | ||
case "authed": { | ||
return escapedPortal; | ||
} | ||
case "demo": { | ||
// Legacy Note: Previously if the demoName was "", the root id in the realtime database | ||
// and Firestore would be different. The paths would end up being: | ||
// database: /demo/portals/demo/ (root id is skipped) | ||
// firestore: /demo/{firebaseUserId}/ | ||
// Now the root id will be the default "demo" in this case so the paths will be: | ||
// database: /demo/demo/portals/demo/ | ||
// firestore: /demo/demo/ | ||
const escapedDemoName = demoName ? escapeKey(demoName) : demoName; | ||
return escapedDemoName || escapedPortal || "demo"; | ||
} | ||
// "dev", "qa", and "test" | ||
default: { | ||
return firebaseUserId; | ||
} | ||
} | ||
} |
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