1
1
import * as firebase from "@firebase/rules-unit-testing" ;
2
2
import { getAuthedFirestore , reinitializeFirestore } from "./utils" ;
3
- import { FirebaseCollections } from '@pipeline/common/build/cjs'
4
- import { Game } from "@pipeline/common" ;
3
+ import { FirebaseCollection } from '@pipeline/common/build/cjs'
4
+ import { Card , Game } from "@pipeline/common" ;
5
5
import fb from "firebase" ;
6
6
7
7
const PROJECT_ID = "firestore-emulator-example-" + Math . floor ( Math . random ( ) * 1000 ) ;
@@ -21,7 +21,7 @@ describe("Game create", () => {
21
21
22
22
it ( "should not allow game creation if not authenticated" , async ( ) => {
23
23
const db = getAuthedFirestore ( PROJECT_ID , undefined ) ;
24
- const gameRef = db . collection ( FirebaseCollections . Games ) . doc ( 'game1' ) ;
24
+ const gameRef = db . collection ( FirebaseCollection . Games ) . doc ( 'game1' ) ;
25
25
await firebase . assertFails ( gameRef . set ( {
26
26
scenarioTitle : 'Title' ,
27
27
scenarioContent : 'Content' ,
@@ -38,7 +38,7 @@ describe("Game create", () => {
38
38
const userUID = 'id1' ;
39
39
const email = 'test@email.com' ;
40
40
const db = getAuthedFirestore ( PROJECT_ID , { uid : userUID , email, email_verified : true } ) ;
41
- const gameRef = db . collection ( FirebaseCollections . Games ) . doc ( 'game1' ) ;
41
+ const gameRef = db . collection ( FirebaseCollection . Games ) . doc ( 'game1' ) ;
42
42
await firebase . assertSucceeds ( gameRef . set ( {
43
43
scenarioTitle : 'Title' ,
44
44
scenarioContent : 'Content' ,
@@ -55,7 +55,7 @@ describe("Game create", () => {
55
55
const userUID = 'id1' ;
56
56
const email = 'test@email.com' ;
57
57
const db = getAuthedFirestore ( PROJECT_ID , { uid : userUID , email, email_verified : true } ) ;
58
- const gameRef = db . collection ( FirebaseCollections . Games ) . doc ( 'game1' ) ;
58
+ const gameRef = db . collection ( FirebaseCollection . Games ) . doc ( 'game1' ) ;
59
59
await firebase . assertFails ( gameRef . set ( {
60
60
scenarioTitle : 'Title' ,
61
61
scenarioContent : 'Content' ,
@@ -72,7 +72,7 @@ describe("Game create", () => {
72
72
const userUID = 'id1' ;
73
73
const email = 'test@email.com' ;
74
74
const db = getAuthedFirestore ( PROJECT_ID , { uid : userUID , email, email_verified : true } ) ;
75
- const gameRef = db . collection ( FirebaseCollections . Games ) . doc ( 'game1' ) ;
75
+ const gameRef = db . collection ( FirebaseCollection . Games ) . doc ( 'game1' ) ;
76
76
await firebase . assertFails ( gameRef . set ( {
77
77
scenarioTitle : 'Title' ,
78
78
scenarioCardId : null ,
@@ -88,7 +88,7 @@ describe("Game create", () => {
88
88
const userUID = 'id1' ;
89
89
const email = 'test@email.com' ;
90
90
const db = getAuthedFirestore ( PROJECT_ID , { uid : userUID , email, email_verified : true } ) ;
91
- const gameRef = db . collection ( FirebaseCollections . Games ) . doc ( 'game1' ) ;
91
+ const gameRef = db . collection ( FirebaseCollection . Games ) . doc ( 'game1' ) ;
92
92
await firebase . assertFails ( gameRef . set ( {
93
93
scenarioTitle : 'Title' ,
94
94
scenarioContent : 'Content' ,
@@ -105,7 +105,7 @@ describe("Game create", () => {
105
105
const userUID = 'id1' ;
106
106
const email = 'test@email.com' ;
107
107
const db = getAuthedFirestore ( PROJECT_ID , { uid : userUID , email, email_verified : true } ) ;
108
- const gameRef = db . collection ( FirebaseCollections . Games ) . doc ( 'game1' ) ;
108
+ const gameRef = db . collection ( FirebaseCollection . Games ) . doc ( 'game1' ) ;
109
109
await firebase . assertFails ( gameRef . set ( {
110
110
scenarioTitle : 'Title' ,
111
111
scenarioContent : 'Content' ,
@@ -122,7 +122,7 @@ describe("Game create", () => {
122
122
const userUID = 'id1' ;
123
123
const email = 'test@email.com' ;
124
124
const db = getAuthedFirestore ( PROJECT_ID , { uid : userUID , email, email_verified : true } ) ;
125
- const gameRef = db . collection ( FirebaseCollections . Games ) . doc ( 'game1' ) ;
125
+ const gameRef = db . collection ( FirebaseCollection . Games ) . doc ( 'game1' ) ;
126
126
await firebase . assertFails ( gameRef . set ( {
127
127
scenarioTitle : 'x' . repeat ( 100 ) ,
128
128
scenarioContent : 'Content' ,
@@ -139,7 +139,7 @@ describe("Game create", () => {
139
139
const userUID = 'id1' ;
140
140
const email = 'test@email.com' ;
141
141
const db = getAuthedFirestore ( PROJECT_ID , { uid : userUID , email, email_verified : true } ) ;
142
- const gameRef = db . collection ( FirebaseCollections . Games ) . doc ( 'game1' ) ;
142
+ const gameRef = db . collection ( FirebaseCollection . Games ) . doc ( 'game1' ) ;
143
143
await firebase . assertFails ( gameRef . set ( {
144
144
scenarioTitle : 'Title' ,
145
145
scenarioContent : 'x' . repeat ( 3000 ) ,
@@ -155,12 +155,15 @@ describe("Game create", () => {
155
155
it ( "should allow game creation if the scenario card id is present and coherent" , async ( ) => {
156
156
const userUID = 'id1' ;
157
157
const email = 'test@email.com' ;
158
+ const scenarioId = 'G5JfGVoM7SZ6jOsdjWWp' ;
158
159
const db = getAuthedFirestore ( PROJECT_ID , { uid : userUID , email, email_verified : true } ) ;
159
- const gameRef = db . collection ( FirebaseCollections . Games ) . doc ( 'game1' ) ;
160
+ const scenarioCardDoc = await db . doc ( `${ FirebaseCollection . Cards } /${ scenarioId } ` ) . get ( ) ;
161
+ const scenarioCard = scenarioCardDoc . data ( ) as Card ;
162
+ const gameRef = db . collection ( FirebaseCollection . Games ) . doc ( 'game1' ) ;
160
163
await firebase . assertSucceeds ( gameRef . set ( {
161
- scenarioTitle : 'Fitness & Running Mobile App' ,
162
- 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.' ,
163
- scenarioCardId : 'G5JfGVoM7SZ6jOsdjWWp' ,
164
+ scenarioTitle : scenarioCard . title ,
165
+ scenarioContent : scenarioCard . content ,
166
+ scenarioCardId : scenarioId ,
164
167
facilitator : {
165
168
id : userUID
166
169
} ,
@@ -172,12 +175,15 @@ describe("Game create", () => {
172
175
it ( "should not allow game creation if the scenario card id is present but not coherent" , async ( ) => {
173
176
const userUID = 'id1' ;
174
177
const email = 'test@email.com' ;
178
+ const scenarioId = 'G5JfGVoM7SZ6jOsdjWWp' ;
175
179
const db = getAuthedFirestore ( PROJECT_ID , { uid : userUID , email, email_verified : true } ) ;
176
- const gameRef = db . collection ( FirebaseCollections . Games ) . doc ( 'game1' ) ;
180
+ const scenarioCardDoc = await db . doc ( `${ FirebaseCollection . Cards } /${ scenarioId } ` ) . get ( ) ;
181
+ const scenarioCard = scenarioCardDoc . data ( ) as Card ;
182
+ const gameRef = db . collection ( FirebaseCollection . Games ) . doc ( 'game1' ) ;
177
183
await firebase . assertFails ( gameRef . set ( {
178
- scenarioTitle : 'Fitness & Running Mobile App' ,
184
+ scenarioTitle : scenarioCard . title ,
179
185
scenarioContent : 'random' ,
180
- scenarioCardId : 'G5JfGVoM7SZ6jOsdjWWp' ,
186
+ scenarioCardId : scenarioId ,
181
187
facilitator : {
182
188
id : userUID
183
189
} ,
0 commit comments