# Local testing

## 🧰 Initial setup

### Clone the repo

If you don't have one, create a directory for Github repos: `$ mkdir ~/Documents/GitHub`&#x20;

From your repo directory, clone Moped: `$ git clone https://github.com/cityofaustin/atd-moped`

### Install Docker & Docker Compose

Follow the docker documentation to install docker in your system.

* For Mac: <https://docs.docker.com/docker-for-mac/install>
* For Windows: <https://docs.docker.com/docker-for-windows/install>

### Install the Hasura CLI

Run `$ curl -L https://github.com/hasura/graphql-engine/raw/stable/cli/get.sh | bash`.&#x20;

This will install the Hasura CLI in `/usr/local/bin`. You might have to provide your sudo password depending on the permissions of your `/usr/local/bin` location.

### Install nvm

We use [Node Version Manager](https://github.com/nvm-sh/nvm) (nvm) to keep our `node` versions in sync with our environments.

1. Install the Xcode Command Line Developer Tools: `$ xcode-select --install`
2. Install nvm according to the [directions on their website](https://github.com/nvm-sh/nvm?tab=readme-ov-file#installing-and-updating).
3. From the `moped editor` directory, activate the current `node` and `npm` version required for this project: `$ nvm use`
4. Install dependencies: `$ npm install`

## 🛵 Running Moped

### Update your local code

From the `atd-moped` directory, run `$ git fetch` to download the most recent code, files, and branches from Github. If you want to test a branch other than `main`, run `$ git checkout <branch-name>`.

You may be notified that your local code is behind the current state of the branch. Use `$ git pull` to update.&#x20;

### Open Docker

You don't need to actively do anything with Docker Desktop, but you need the application running.&#x20;

{% hint style="info" %}
You can disable the default "Open Docker Dashboard when Docker Desktop starts" setting if you don't want a window to pop up. Instead, just click the Docker logo in the Finder menu bar to see the green dot and "Docker Desktop is running" status.&#x20;
{% endhint %}

### Start the database

Our tool [hasura-cluster](https://github.com/cityofaustin/atd-moped/blob/main/moped-database/hasura-cluster) provides [shortcuts](https://atd-dts.gitbook.io/moped-documentation/dev-guides/how-tos/how-do-i-start-the-hasura-cluster-locally#hasura-cluster-reference) for the Hasura commands we need frequently in Moped.  &#x20;

1. Start the cluster: `$ ./hasura-cluster start`
2. Optionally, open the Hasura console in your browser: `$ ./hasura-cluster console` or `$ hasura console`

### Start the application

1. In a second Terminal tab, from the `moped editor` directory, run `$ npm install` to ensure that any new packages are installed.
2. Start the server: `$ npm run start`
3. Open <https://localhost:3000/moped> in your browser.
4. To login, locate the username and pw in the DTS password store under the named "Moped Test Editor (local, staging, prod)."

### Switching branches

When testing multiple PRs in a sitting, you need to run `$ ./hasura-cluster restart` every time you check out a new branch. \
You shouldn't need to re-run `$ npm install` or log out of Moped.&#x20;

## 🛑 When you're finished

1. In the Terminal tab running the application, end the npm process by typing Ctrl+C.
2. In the Terminal tab with the database, close the Hasura console (if running) by typing Ctrl+C. Then stop the database: `$ ./hasura-cluster stop`
