# Booking Server Skeleton for Node.js

This is a reference implementation of
[API v3 Booking Server for Standard Integration](https://developers.google.com/actions-center/verticals/reservations/waitlists/integration-steps/implement-booking-server)
based on Node.js

### Prerequisites

Requires an installation of

- [Node.js](https://nodejs.org/)

## Getting Started

The Booking Server is implemented using standard Node.js without any
additional libraries or frameworks, for illustration purposes. If you are
using any other frameworks, you could easily change this implementation to
Express.js, MEAN.js, or any other Node.js-based framework of your choice.

The implementation is also not using protocol buffer libraries, but instead
relies on simple JSON serialization and its JSON.parse() and JSON.stringify()
methods.

To download the project, execute the following command:

```javascript
git clone https://maps-booking.googlesource.com/js-maps-booking-rest-server-v3-skeleton
```

The entire code base consists of only two JavaScript files:

- bookingserver.js - HTTP server and requests handling logic, including authentication
- apiv3methods.js - methods implementing API v3 interface

After you download the files, you can start the Booking Server by running
the command:

```javascript
node bookingserver.js
```

The skeleton writes all incoming and outgoing requests to the console, so you
can monitor its execution for tracing purposes.

Should you need an IDE for code changes or debugging, you can use
[Visual Studio Code](https://code.visualstudio.com/) or any other
editor of your choice. Debug the project by starting bookingserver.js in the
Node.js environment and set breakpoints where needed.

## Testing your Booking Server

Download
[Booking test utility](https://maps-booking.googlesource.com/maps-booking-v3/). To install it, follow the provided installation
instructions in its README page.

For the tests, you need to create a text file to store your credentials.
Enter your username and password on a single line, for example, in a file
named cred.txt:

username:password

You also need a local copy of an Availability feed for your test merchants.
In the samples commands below, the Availability feed is avail.json.

Now, you can test your Booking Server with these commands:

- Test calls to HealthCheck method:

  ```javascript
  bin/bookingClient -server_addr="localhost:8080" -health_check_test=true -credentials_file="./cred.txt"
  ```
- Test calls to CheckAvailability method:

  ```javascript
  bin/bookingClient -server_addr="localhost:8080" -check_availability_test=true -availability_feed="./avail.json" -credentials_file="./cred.txt"
  ```
- Test calls to CreateBooking and UpdateBooking methods:

  ```javascript
  bin/bookingClient -server_addr="localhost:8080" -booking_test=true -availability_feed="./avail.json" -credentials_file="./cred.txt"
  ```

As you are implementing your own Booking Server, you may need to run
additional tests against it (e.g. list_bookings_test, rescheduling_test, etc)
with the goal of all tests passing (-all_tests=true).