Closed eeeeeric closed 5 years ago
We have 6 functions which can be tested:
// Deck Functions
export const importDeckFunction = Decklist.importDeckFunction;
export const parseDeckFunction = Decklist.parseDeckFunction;
export const populateDeckFunction = Decklist.populateDeckFunction;
// Game Functions
export const hostGameFunction = Game.hostGameFunction;
export const joinGameFunction = Game.joinGameFunction;
export const startGameFunction = Game.startGameFunction;
I am mostly interested in white-box testing here, so I believe our ideal approach would be to use a dedicated test project in Firebase. This will allow us to test things as they would be in production and perform the inspections we desire (e.g. this document was created with the following fields).
The scope of this project does not include any CI/CD support, but I will make reference to what we will need to do to achieve that since that is an eventual goal (#19).
To run the tests, we will need to
/firebase/.firebaserc
will need to include a test
project, see the documentationfunction-tests-user-1@example.com
password
function-tests-user-2@example.com
password
These cases are not as thorough as they can be, but provide what I feel is the most value for us at this time.
Many of these functions depend on another function in one way or another, so cleanup after each test does not strike me as worthwhile (e.g. I need the imported deck to test starting a game). Cleanup should be run before the tests begin. This allow manual inspection of Firestore contents after a failed test run.
These tests should be run sequentially and in order due to their dependency on each other.
This function imports a deck from MTGGoldfish.
Users/<uid>/Decks/<deckId>
existsDRAGONS
The Ur-Dragon
is listed as the commander (Scryfall ID is 7e78b70b-0c67-4f14-8ad7-c9f8e3f59743
)Users/<uid>/Decks/<deckId>
existsExample deck with partner commanders
Akiri, Line-Slinger
and Bruse Tarl, Boorish Herder
are listed as the commanders (Scryfall IDs are 3b951e0c-a4dd-4a20-87c6-eaa947e33aa4
and 125b552b-45ea-4e0b-94a9-8131c97a04c0
)https://www.mtggoldfish.com/deck/1630110FAKE#paper
This function parses a deck from MTGGoldfish. The output produced is an intermediary format that is intended for use by a future deck editor feature, which we may or may not ever implement. The backing logic is the same as that for the importDeckFunction
, so I don't think it is necessary to add tests for this function.
This function provides data from Scryfall for each card in the requested deck.
name
and id
.Akiri, Line-Slinger
, Bruse Tarl, Boorish Herder
, Mountain
, and Plains
FAKEID
This creates a new Game that is initialized with the host player and a target deck.
Games/<gameId>/Players/<userId>
exists, and has
life
set to 40uid
set to meta.deck_id
set to the correct value for the DRAGONS deckGames/<gameId>/Cards
contains 100 documentsscryfall_id
equals 7e78b70b-0c67-4f14-8ad7-c9f8e3f59743
, state.zone
equals Command
, and state.owner
equals <userId for user 1>No negative tests for now.
This joins an existing game.
Games/<gameId>/Players/<userId>
exists, and has
life
set to 40uid
set to meta.deckId
set to the correct value for the partner commander deckGames/<gameId>/Cards
contains 200 documentsscryfall_id
equals 3b951e0c-a4dd-4a20-87c6-eaa947e33aa4
, state.zone
equals Command
, and state.owner
equals <userId for user 2>scryfall_id
equals 125b552b-45ea-4e0b-94a9-8131c97a04c0
, state.zone
equals Command
, and state.owner
equals <userId for user 2>This starts a game by determining the turn order.
Games/<gameId>
has a turn_order
field, containing properties 0
and 1
, one of which points to user1 and the other to user2Some things I've realized as I'm working on this
qty
distinct cards). I'm glad I'm writing tests.Command
vs command
depending on if you are looking at a deck stored for a player vs a card stored for a game.turn_order
field on the game document probably could be a simple array, since we write once and read onceOther notes
Warning, FIREBASE_CONFIG environment variable is missing. Initializing firebase-admin will fail
npm run fb-clean
) to do it via the CLI.There are a number of TODO items in here which I will take care of after the meeting tomorrow.
I see this when running tests, I need to figure out why and how best to fix it
Warning, FIREBASE_CONFIG environment variable is missing. Initializing firebase-admin will fail
Regarding this warning - it seems that this env var is auto populated in cloud environments and provides some configuration that we currently don't need, so this is benign, for now. I doubt it will be difficult to fix should the time come so I'm going to do nothing for it. (You can make it go away for now by just running export FIREBASE_CONFIG={}
before running the tests).
This, along with the above issues I opened, should track all the TODOs from my last comment.
See the documentation. It will be better to test using a special test project, rather than using offline mode.