warlocks-of-the-midwest / mystic-get-together

Mystic the Get-Together
3 stars 3 forks source link

Add tests for Cloud Functions #20

Closed eeeeeric closed 5 years ago

eeeeeric commented 5 years ago

See the documentation. It will be better to test using a special test project, rather than using offline mode.

eeeeeric commented 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

Test Cases

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.

importDeckFunction

This function imports a deck from MTGGoldfish.

Test importing a standard commander deck (1 commander, 99 other)

Test importing a partner commander deck (2 commanders, 98 other)

Test importing a deck with an invalid or non-existent URI

parseDeckFunction

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.

populateDeckFunction

This function provides data from Scryfall for each card in the requested deck.

Test populating for a deck

Test populating a deck that does not exist

hostGameFunction

This creates a new Game that is initialized with the host player and a target deck.

Test starting a game

No negative tests for now.

joinGameFunction

This joins an existing game.

Test joining a game

startGameFunction

This starts a game by determining the turn order.

Start the game

eeeeeric commented 5 years ago

Some things I've realized as I'm working on this

Other notes

There are a number of TODO items in here which I will take care of after the meeting tomorrow.

eeeeeric commented 5 years ago

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.