Web framework for hobbyist and freelance bartenders 🍸
These instructions assume you're in the /bartop-ui
directory.
The UI has a Storybook for quickly designing & developing components. If you just want to make some visual changes, this is the fastest & easiest way.
- Install the dependencies -
npm install
- Run the storybook -
npm run storybook
- View the storybook at localhost:9001
In order to develop for the UI with auth & data, you need to establish an Auth0 tenant and run the API. Read below for instructions to setup this full system.
npm install
The UI is continuously deployed at the following URLs:
https://dev.bartop.io -> pushes to dev
deploy here
https://bartop.io -> pushes to prod
deploy here (but currently redirecting to this repo)
When a PR is made against these branches, Netlify will deploy a preview that can be used for testing & validating the bug fix or feature.
The UI is configured using a .env
file. Use the .env.example
file as a template to create a local version.
- The
Auth0
environment variables require that you create an Auth0 tenant. Once created, add the suppliedAUTH0_DOMAIN
andAUTH0_CLIENT_ID
. - Add two rules to your tenant:
- The first rule should add the user's
loginsCount
toidToken
:
function(user, context, callback) { var namespace = 'https://yournamespace'; context.idToken[namespace + '/loginsCount'] = context.stats.loginsCount; callback(null, user, context); }
- The second should add the user's
name
toidToken
:
function (user, context, callback) { var namespace = 'https://yournamespace'; context.idToken[namespace + '/name'] = user.user_metadata && user.user_metadata.name || undefined; callback(null, user, context); }
- Set your
AUTH0_CLAIM_NAMESPACE
environment variable to thenamespace
you chose in your rules
- The first rule should add the user's
- BarTop uses the JWT Tokens provided by Auth0 to secure our API. In order to do this, we need to tell Auth0 who the audience of our
accessToken
is. Set theAUTH0_BARTOP_API_AUDIENCE
accordingly. - For local development, set your
REACT_APP_URL
to http://localhost:3000 - For local development, set your
REACT_APP_API_URL
to http://localhost:3001. CRA automatically proxies requests to whichever port you specify in theproxy
field of yourpackage.json
, so make sure they match.
-
Make sure you have all your environment variables set.
-
Run the API
-
Run the UI with
npm start
-
Visit http://localhost:3000 to view the UI
SIDENOTE BarTop is using Create React App as the starter for our UI. If you run into problems, please check out their User Guide or reach out with questions
- Execute the UI unit tests with
npm test
- Optionally, you can run the tests in watch mode with
npm run watch-test
. This is nice when you're working on specific tests and want it to run on changes. - When making visual changes, it can help to view the storybook to play with components in an isolated environment.
These instructions assume you're in the /bartop-api
directory
npm install
The API is configured using a .env
file. Use the .env.example
file as a template to create a local version. Every variable listed in the .env.example
is required to run the API server.
BarTop API uses RethinkDB for its persistence layer. Running the API locally requires a local of installation of RethinkDB.
Once installed, start a local instance of the database:
npm run database
The default database, named test
, is reserved for running the integration tests. Using this as your development database will have pretty unfortunate consequences, so you will want to create a new one.
To create a new database use the RethinkDB dashboard (while the database is running). Click on + Add Database
and enter your desired development database name. Make sure the name of this database matches the BARTOP_DB_NAME variable in your .env
file. This dashboard is also useful for exploring your data.
First, make sure the database is running. Then, start the API server:
npm start
The API will be available for requests at http://localhost:3001 (if you set BARTOP_API_PORT to 3001 in your .env
file, which is recommended). Requests to the API in development do not need to be authorized. For testing and production, the API requires authentication/authorization using JSON Web Tokens.
Note Starting the API in development mode will automatically configure the database to assist with client development. The first time the server is started with a fresh database, it will create the following tables:
users
drinks
menus
sessions
orders
and will seed the drinks
table with sample drink objects.
The REST API is available under the route /api/v1
. Use a tool like Postman to test different endpoints. Documentation coming soon...
The GraphQL API is available under the single endpoint /api/graphql
. The recommended way to explore this API is using the GraphIQL tool, available by visiting the above route in a browser. Here, there is an environment to test queries alongside a panel with documentation. If desired, the GraphQL API can also be explored using a tool like Postman.
The API test suite currently consists of mostly integration tests and some unit tests.
The integration tests are used to test actual functionality of the API server by making requests and verifying responses with as little mocking as possible.
The unit tests are used to test individual modules, especially behavior that is very difficult to produce in the integration tests (like RethinkDB post-write errors) but still needs to be accounted for.
To run the full test suite: npm run test
To run the integration tests: npm run integration-tests
To run the unit tests: npm run unit-tests
To run the integration tests, you must be running a local instance of RethinkDB. See this section for more information.
Travis CI will automatically run all tests when a branch is pushed.