### Introduction

> PLEASE READ [SEEDER DOCUMENTATION](./seeder/README.md) BEFORE USING THE SEEDER OR THE CLOUD FUNCTIONS EMULATOR

> Official Firebase Cloud Functionsx Documentation: <https://firebase.google.com/docs/functions>

The [functions](./../functions/) folder is all about the back-end functionality of the application. It utilizes Firebase's Cloud Functions to process Firestore triggers, Authentication triggers, complex and basic queries, upserts/delete/reads, and https functions (which we haven't used up to this point) and callable functions (used in favor of https functions for simplicity and handling of headers).

To effectively load and run the Cloud Functions locally, make sure to `npm run build` before or during an active `npm start` session under the root folder.

- THERE ARE TWO `package.json`'s, ONE IN THE [functions](../functions/) FOLDER AND ONE IN THE [root](../../neurotask_web/) FOLDER. YOU DO NOT NEED TO `npm start` IN THE FUNCTIONS FOLDER (THE `npm start` IN THE ROOT FOLDER AUTOMATICALLY LOADS THE FUNCTIONS FROM THE COMPILED TYPESCRIPT (in [lib](./lib/)) AFTER AN `npm run build` IN THE FUNCTIONS FOLDER)

### Testing

Testing is done via the [tests](./tests/) folder. There is a [testSetup.ts](./tests/testSetup.ts) file which contains the configurations for setting up the environment and the Firebase Emulator to use the correct endpoints. These are dependendent on the `.env`'s that contain the key/values. This ties in with the [config.ts](./config.ts) and the [global.d.ts](./global.d.ts), which are helpers for .env's.

We used `TsMockito` and `Jest` to perform the tests and the mocking.

- Make sure to have an instance of the app running for the tests to run or else you'll get errors relating to an instance of the Firebase app not being initialized along with similar errors regarding run time exceeding test time.

### Configurations

Different configurations are found through the `tsconfig`'s. These are practically already set up as is so not much needs to be touched upon, but please refer to the documentation if changes need to be made (as touching anything here can cause a tricky side effect).

### Emailing Services

We are using [Nodemailer](https://nodemailer.com/) for handling everything related to emails. As of right now, we are using custom gmail accounts for testing purposes but as the app grows, it would be wise to create specific domains to handle donotreply emails and support-related correspondence. 

The credentials for the different emails will be found in the [email file](./dev/emails.md).

> NOTE: The `notifications.neurotask@gmail.com` email is used for sending support like emails and donotreply's. The `neurotask.adm.test@gmail.com` is used to test admin like functionality like receiving emails when providers apply for an account in the facility you administrate.

When the app evolves to the point of specific domains, these emails will be swapped out.

You can find out code revolving around nodemailer under the [util](./src/util/) folder.