Skip to content

Commit

Permalink
fix(firestore-general): fix tests reading from firebase
Browse files Browse the repository at this point in the history
  • Loading branch information
albertodigioacchino committed Jan 15, 2021
1 parent 7a5290a commit baaf09a
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 36 deletions.
40 changes: 23 additions & 17 deletions packages/firestore/test/create-game.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as firebase from "@firebase/rules-unit-testing";
import {getAuthedFirestore, reinitializeFirestore} from "./utils";
import {FirebaseCollections} from '@pipeline/common/build/cjs'
import {Game} from "@pipeline/common";
import {FirebaseCollection} from '@pipeline/common/build/cjs'
import {Card, Game} from "@pipeline/common";
import fb from "firebase";

const PROJECT_ID = "firestore-emulator-example-" + Math.floor(Math.random() * 1000);
Expand All @@ -21,7 +21,7 @@ describe("Game create", () => {

it("should not allow game creation if not authenticated", async () => {
const db = getAuthedFirestore(PROJECT_ID, undefined);
const gameRef = db.collection(FirebaseCollections.Games).doc('game1');
const gameRef = db.collection(FirebaseCollection.Games).doc('game1');
await firebase.assertFails(gameRef.set({
scenarioTitle: 'Title',
scenarioContent: 'Content',
Expand All @@ -38,7 +38,7 @@ describe("Game create", () => {
const userUID = 'id1';
const email = 'test@email.com';
const db = getAuthedFirestore(PROJECT_ID, {uid: userUID, email, email_verified: true});
const gameRef = db.collection(FirebaseCollections.Games).doc('game1');
const gameRef = db.collection(FirebaseCollection.Games).doc('game1');
await firebase.assertSucceeds(gameRef.set({
scenarioTitle: 'Title',
scenarioContent: 'Content',
Expand All @@ -55,7 +55,7 @@ describe("Game create", () => {
const userUID = 'id1';
const email = 'test@email.com';
const db = getAuthedFirestore(PROJECT_ID, {uid: userUID, email, email_verified: true});
const gameRef = db.collection(FirebaseCollections.Games).doc('game1');
const gameRef = db.collection(FirebaseCollection.Games).doc('game1');
await firebase.assertFails(gameRef.set({
scenarioTitle: 'Title',
scenarioContent: 'Content',
Expand All @@ -72,7 +72,7 @@ describe("Game create", () => {
const userUID = 'id1';
const email = 'test@email.com';
const db = getAuthedFirestore(PROJECT_ID, {uid: userUID, email, email_verified: true});
const gameRef = db.collection(FirebaseCollections.Games).doc('game1');
const gameRef = db.collection(FirebaseCollection.Games).doc('game1');
await firebase.assertFails(gameRef.set({
scenarioTitle: 'Title',
scenarioCardId: null,
Expand All @@ -88,7 +88,7 @@ describe("Game create", () => {
const userUID = 'id1';
const email = 'test@email.com';
const db = getAuthedFirestore(PROJECT_ID, {uid: userUID, email, email_verified: true});
const gameRef = db.collection(FirebaseCollections.Games).doc('game1');
const gameRef = db.collection(FirebaseCollection.Games).doc('game1');
await firebase.assertFails(gameRef.set({
scenarioTitle: 'Title',
scenarioContent: 'Content',
Expand All @@ -105,7 +105,7 @@ describe("Game create", () => {
const userUID = 'id1';
const email = 'test@email.com';
const db = getAuthedFirestore(PROJECT_ID, {uid: userUID, email, email_verified: true});
const gameRef = db.collection(FirebaseCollections.Games).doc('game1');
const gameRef = db.collection(FirebaseCollection.Games).doc('game1');
await firebase.assertFails(gameRef.set({
scenarioTitle: 'Title',
scenarioContent: 'Content',
Expand All @@ -122,7 +122,7 @@ describe("Game create", () => {
const userUID = 'id1';
const email = 'test@email.com';
const db = getAuthedFirestore(PROJECT_ID, {uid: userUID, email, email_verified: true});
const gameRef = db.collection(FirebaseCollections.Games).doc('game1');
const gameRef = db.collection(FirebaseCollection.Games).doc('game1');
await firebase.assertFails(gameRef.set({
scenarioTitle: 'x'.repeat(100),
scenarioContent: 'Content',
Expand All @@ -139,7 +139,7 @@ describe("Game create", () => {
const userUID = 'id1';
const email = 'test@email.com';
const db = getAuthedFirestore(PROJECT_ID, {uid: userUID, email, email_verified: true});
const gameRef = db.collection(FirebaseCollections.Games).doc('game1');
const gameRef = db.collection(FirebaseCollection.Games).doc('game1');
await firebase.assertFails(gameRef.set({
scenarioTitle: 'Title',
scenarioContent: 'x'.repeat(3000),
Expand All @@ -155,12 +155,15 @@ describe("Game create", () => {
it("should allow game creation if the scenario card id is present and coherent", async () => {
const userUID = 'id1';
const email = 'test@email.com';
const scenarioId = 'G5JfGVoM7SZ6jOsdjWWp';
const db = getAuthedFirestore(PROJECT_ID, {uid: userUID, email, email_verified: true});
const gameRef = db.collection(FirebaseCollections.Games).doc('game1');
const scenarioCardDoc = await db.doc(`${FirebaseCollection.Cards}/${scenarioId}`).get();
const scenarioCard = scenarioCardDoc.data() as Card;
const gameRef = db.collection(FirebaseCollection.Games).doc('game1');
await firebase.assertSucceeds(gameRef.set({
scenarioTitle: 'Fitness & Running Mobile App',
scenarioContent: 'Mobile exercise app monitors your running.\nGives feedback on lap time and coaches you towards your goals.\n• The system sends encouraging emails with weekly fitness\nsummaries.\nHandles potentially sensitive health data.\nYour competitor is a Silicon Valley startup using Python and their\ndeployment lead time is six hours.',
scenarioCardId: 'G5JfGVoM7SZ6jOsdjWWp',
scenarioTitle: scenarioCard.title,
scenarioContent: scenarioCard.content,
scenarioCardId: scenarioId,
facilitator: {
id: userUID
},
Expand All @@ -172,12 +175,15 @@ describe("Game create", () => {
it("should not allow game creation if the scenario card id is present but not coherent", async () => {
const userUID = 'id1';
const email = 'test@email.com';
const scenarioId = 'G5JfGVoM7SZ6jOsdjWWp';
const db = getAuthedFirestore(PROJECT_ID, {uid: userUID, email, email_verified: true});
const gameRef = db.collection(FirebaseCollections.Games).doc('game1');
const scenarioCardDoc = await db.doc(`${FirebaseCollection.Cards}/${scenarioId}`).get();
const scenarioCard = scenarioCardDoc.data() as Card;
const gameRef = db.collection(FirebaseCollection.Games).doc('game1');
await firebase.assertFails(gameRef.set({
scenarioTitle: 'Fitness & Running Mobile App',
scenarioTitle: scenarioCard.title,
scenarioContent: 'random',
scenarioCardId: 'G5JfGVoM7SZ6jOsdjWWp',
scenarioCardId: scenarioId,
facilitator: {
id: userUID
},
Expand Down
38 changes: 19 additions & 19 deletions packages/firestore/test/create-user.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as firebase from "@firebase/rules-unit-testing";
import {getAuthedFirestore, reinitializeFirestore} from "./utils";
import {FirebaseCollections, FirebaseDocs} from '@pipeline/common/build/cjs'
import {FirebaseCollection, FirebaseDoc} from '@pipeline/common/build/cjs'

const PROJECT_ID = "firestore-emulator-example-" + Math.floor(Math.random() * 1000);

Expand All @@ -22,9 +22,9 @@ describe("User create", () => {

it("should not allow user creation if not authenticated", async () => {
const db = getAuthedFirestore(PROJECT_ID, undefined);
const profile = db.collection(FirebaseCollections.Users).doc("alice");
const rolesDoc = await db.doc(`${FirebaseCollections.DynamicData}/${FirebaseDocs.GameRoles}`).get();
const maturitiesDoc = await db.doc(`${FirebaseCollections.DynamicData}/${FirebaseDocs.DevOpsMaturities}`).get();
const profile = db.collection(FirebaseCollection.Users).doc("alice");
const rolesDoc = await db.doc(`${FirebaseCollection.DynamicData}/${FirebaseDoc.GameRoles}`).get();
const maturitiesDoc = await db.doc(`${FirebaseCollection.DynamicData}/${FirebaseDoc.DevOpsMaturities}`).get();
const realRole = rolesDoc.data().roles[0];
const realMaturity = maturitiesDoc.data().maturities[0];
await firebase.assertFails(profile.set({
Expand All @@ -38,9 +38,9 @@ describe("User create", () => {
const userUID = 'test';
const email = 'test@email.com';
const db = getAuthedFirestore(PROJECT_ID, {uid: 'test', email});
const profile = db.collection(FirebaseCollections.Users).doc(userUID);
const rolesDoc = await db.doc(`${FirebaseCollections.DynamicData}/${FirebaseDocs.GameRoles}`).get();
const maturitiesDoc = await db.doc(`${FirebaseCollections.DynamicData}/${FirebaseDocs.DevOpsMaturities}`).get();
const profile = db.collection(FirebaseCollection.Users).doc(userUID);
const rolesDoc = await db.doc(`${FirebaseCollection.DynamicData}/${FirebaseDoc.GameRoles}`).get();
const maturitiesDoc = await db.doc(`${FirebaseCollection.DynamicData}/${FirebaseDoc.DevOpsMaturities}`).get();
const realRole = rolesDoc.data().roles[0];
const realMaturity = maturitiesDoc.data().maturities[0];
await firebase.assertSucceeds(profile.set({
Expand All @@ -54,8 +54,8 @@ describe("User create", () => {
const userUID = 'test';
const email = 'test@email.com';
const db = getAuthedFirestore(PROJECT_ID, {uid: 'test', email});
const profile = db.collection(FirebaseCollections.Users).doc(userUID);
const maturitiesDoc = await db.doc(`${FirebaseCollections.DynamicData}/${FirebaseDocs.DevOpsMaturities}`).get();
const profile = db.collection(FirebaseCollection.Users).doc(userUID);
const maturitiesDoc = await db.doc(`${FirebaseCollection.DynamicData}/${FirebaseDoc.DevOpsMaturities}`).get();
const realMaturity = maturitiesDoc.data().maturities[0];
await firebase.assertFails(profile.set({
email,
Expand All @@ -68,8 +68,8 @@ describe("User create", () => {
const userUID = 'test';
const email = 'test@email.com';
const db = getAuthedFirestore(PROJECT_ID, {uid: 'test', email});
const profile = db.collection(FirebaseCollections.Users).doc(userUID);
const rolesDoc = await db.doc(`${FirebaseCollections.DynamicData}/${FirebaseDocs.GameRoles}`).get();
const profile = db.collection(FirebaseCollection.Users).doc(userUID);
const rolesDoc = await db.doc(`${FirebaseCollection.DynamicData}/${FirebaseDoc.GameRoles}`).get();
const realRole = rolesDoc.data().roles[0];
await firebase.assertFails(profile.set({
email,
Expand All @@ -82,9 +82,9 @@ describe("User create", () => {
const userUID = 'test';
const email = 'test@email.com';
const db = getAuthedFirestore(PROJECT_ID, {uid: 'test', email});
const profile = db.collection(FirebaseCollections.Users).doc(userUID);
const rolesDoc = await db.doc(`${FirebaseCollections.DynamicData}/${FirebaseDocs.GameRoles}`).get();
const maturitiesDoc = await db.doc(`${FirebaseCollections.DynamicData}/${FirebaseDocs.DevOpsMaturities}`).get();
const profile = db.collection(FirebaseCollection.Users).doc(userUID);
const rolesDoc = await db.doc(`${FirebaseCollection.DynamicData}/${FirebaseDoc.GameRoles}`).get();
const maturitiesDoc = await db.doc(`${FirebaseCollection.DynamicData}/${FirebaseDoc.DevOpsMaturities}`).get();
const realRole = rolesDoc.data().roles[0];
const realMaturity = maturitiesDoc.data().maturities[0];
await firebase.assertFails(profile.set({
Expand All @@ -98,9 +98,9 @@ describe("User create", () => {
const userUID = 'test';
const email = 'test@email.com';
const db = getAuthedFirestore(PROJECT_ID, {uid: 'test', email});
const profile = db.collection(FirebaseCollections.Users).doc(userUID);
const rolesDoc = await db.doc(`${FirebaseCollections.DynamicData}/${FirebaseDocs.GameRoles}`).get();
const maturitiesDoc = await db.doc(`${FirebaseCollections.DynamicData}/${FirebaseDocs.DevOpsMaturities}`).get();
const profile = db.collection(FirebaseCollection.Users).doc(userUID);
const rolesDoc = await db.doc(`${FirebaseCollection.DynamicData}/${FirebaseDoc.GameRoles}`).get();
const maturitiesDoc = await db.doc(`${FirebaseCollection.DynamicData}/${FirebaseDoc.DevOpsMaturities}`).get();
const realRole = rolesDoc.data().roles[0];
const realMaturity = maturitiesDoc.data().maturities[0];
await firebase.assertFails(profile.set({
Expand All @@ -115,8 +115,8 @@ describe("User create", () => {
const userUID = 'test';
const email = 'test@email.com';
const db = getAuthedFirestore(PROJECT_ID, {uid: 'test', email});
const profile = db.collection(FirebaseCollections.Users).doc(userUID);
const rolesDoc = await db.doc(`${FirebaseCollections.DynamicData}/${FirebaseDocs.GameRoles}`).get();
const profile = db.collection(FirebaseCollection.Users).doc(userUID);
const rolesDoc = await db.doc(`${FirebaseCollection.DynamicData}/${FirebaseDoc.GameRoles}`).get();
const realRole = rolesDoc.data().roles[0];
await firebase.assertFails(profile.set({
email,
Expand Down

0 comments on commit baaf09a

Please sign in to comment.