Skip to content

Commit

Permalink
feat(firestore-rules): update rules
Browse files Browse the repository at this point in the history
  • Loading branch information
albertodigioacchino committed Jan 28, 2021
1 parent 36a5c16 commit d7e425e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 36 deletions.
6 changes: 5 additions & 1 deletion packages/firestore/firestore.rules
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ service cloud.firestore {
isStringShorterThan(gameData.scenarioTitle, 100) &&
isStringShorterThan(gameData.scenarioContent, 3000))
) &&
exists(/databases/$(database)/documents/decks/$(gameData.deckId)) &&
existsDocumentData(/decks/$(gameData.deckId)) &&
isMapBigAs(gameData.facilitator, 1) &&
isServerCreationTime(gameData.createdAt) &&
facilitatorId == gameData.facilitator.id &&
Expand Down Expand Up @@ -84,6 +84,10 @@ service cloud.firestore {
return get(/databases/$(database)/documents/$(documentPath)).data;
}

function existsDocumentData(documentPath) {
return exists(/databases/$(database)/documents/$(documentPath));
}

function getDataToWrite() {
return request.resource.data;
}
Expand Down
48 changes: 13 additions & 35 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 {FirebaseCollection} from '@pipeline/common/build/cjs'
import {Card} from "@pipeline/common";
import {FirebaseCollection} from '@pipeline/common/build/cjs';
import {Card, DEFAULT_BOARD_DIMENSIONS} from "@pipeline/common";
import fb from "firebase";
import {Game} from "../models/Game";

Expand Down Expand Up @@ -34,9 +34,7 @@ describe("Game create", () => {
deckId: '7p5qqvE8kCV9WWysVc2n',
rtdbInstance: null,
cards: null,
boardDimensions: {
x: 3840, y: 2160
}
boardDimensions: DEFAULT_BOARD_DIMENSIONS
} as Game));
});

Expand All @@ -56,9 +54,7 @@ describe("Game create", () => {
deckId: '7p5qqvE8kCV9WWysVc2n',
rtdbInstance: null,
cards: null,
boardDimensions: {
x: 3840, y: 2160
}
boardDimensions: DEFAULT_BOARD_DIMENSIONS
} as Game));
});

Expand All @@ -78,9 +74,7 @@ describe("Game create", () => {
deckId: 'randomDeckId',
rtdbInstance: null,
cards: null,
boardDimensions: {
x: 3840, y: 2160
}
boardDimensions: DEFAULT_BOARD_DIMENSIONS
} as Game));
});

Expand All @@ -99,9 +93,7 @@ describe("Game create", () => {
deckId: '7p5qqvE8kCV9WWysVc2n',
rtdbInstance: null,
cards: null,
boardDimensions: {
x: 3840, y: 2160
}
boardDimensions: DEFAULT_BOARD_DIMENSIONS
}));
});

Expand All @@ -121,9 +113,7 @@ describe("Game create", () => {
deckId: '7p5qqvE8kCV9WWysVc2n',
rtdbInstance: null,
cards: null,
boardDimensions: {
x: 3840, y: 2160
}
boardDimensions: DEFAULT_BOARD_DIMENSIONS
} as Game));
});

Expand All @@ -143,9 +133,7 @@ describe("Game create", () => {
deckId: '7p5qqvE8kCV9WWysVc2n',
rtdbInstance: null,
cards: null,
boardDimensions: {
x: 3840, y: 2160
}
boardDimensions: DEFAULT_BOARD_DIMENSIONS
} as Game));
});

Expand All @@ -165,9 +153,7 @@ describe("Game create", () => {
deckId: '7p5qqvE8kCV9WWysVc2n',
rtdbInstance: null,
cards: null,
boardDimensions: {
x: 3840, y: 2160
}
boardDimensions: DEFAULT_BOARD_DIMENSIONS
} as Game));
});

Expand All @@ -187,9 +173,7 @@ describe("Game create", () => {
deckId: '7p5qqvE8kCV9WWysVc2n',
rtdbInstance: null,
cards: null,
boardDimensions: {
x: 3840, y: 2160
}
boardDimensions: DEFAULT_BOARD_DIMENSIONS
} as Game));
});

Expand All @@ -212,9 +196,7 @@ describe("Game create", () => {
deckId: '7p5qqvE8kCV9WWysVc2n',
rtdbInstance: null,
cards: null,
boardDimensions: {
x: 3840, y: 2160
}
boardDimensions: DEFAULT_BOARD_DIMENSIONS
} as Game));
});

Expand Down Expand Up @@ -257,9 +239,7 @@ describe("Game create", () => {
deckId: '7p5qqvE8kCV9WWysVc2n',
rtdbInstance: 'random',
cards: null,
boardDimensions: {
x: 3840, y: 2160
},
boardDimensions: DEFAULT_BOARD_DIMENSIONS
} as Game));
});

Expand All @@ -279,9 +259,7 @@ describe("Game create", () => {
deckId: '7p5qqvE8kCV9WWysVc2n',
rtdbInstance: null,
cards: {},
boardDimensions: {
x: 3840, y: 2160
},
boardDimensions: DEFAULT_BOARD_DIMENSIONS
} as Game));
});

Expand Down

0 comments on commit d7e425e

Please sign in to comment.