Skip to content

Commit

Permalink
#13 - Added endpoint to update ride
Browse files Browse the repository at this point in the history
  • Loading branch information
douglascvas committed Sep 3, 2018
1 parent 5cdc7ba commit 603c3f3
Show file tree
Hide file tree
Showing 10 changed files with 58 additions and 42 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# hills-carpal

[![CircleCI](https://circleci.com/gh/RHoKAustralia/hills-carpal.svg?style=svg)](https://circleci.com/gh/RHoKAustralia/hills-carpal)

# Frontend



34 changes: 34 additions & 0 deletions backend/readme.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,39 @@
## Initial Setup

### Database
The project holds sql scripts that can be used to incrementally apply changes to the database.
You can therefore also use this scripts to initialize your local database.
To run it:
```
npm run refresh-db
```
By default it will try to connect to a local mysql database with username `root` and password `admin`. If you want to change those configurations you can set as environment variable, for instance:
```
MYSQL_USER=myuser MYSQL_PW=myPassword MYSQL_HOST=myHost MYSQL_PORT=3316 MYSQL_DB=myDB npm run refresh-db
```

### Running the application locally

The application was designed to work with AWS lambdas. Although an *expressJs* layer was added to be able to run the application locally. To start it:

```
npm start
```
**or** to be able to debug it:
```
node ./backend/src/test/expressApis.js
```

**Attention**: The application and tests make use of the database, therefore make sure that you have your environment variables set to configure them to run against the right mysql instance.


### Running the tests
In the `backend/` directory run:

```
npm test
```

### Deploying with serverless
Run the following in the ./infrastructure/services directory to create the API Gateway config and lambdas:
```
Expand Down
10 changes: 5 additions & 5 deletions backend/src/main/database/DatabaseManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ class DatabaseManager {

constructor(databaseConfig) {
this.databaseConfig = databaseConfig || {
host: process.env.MYSQL_HOST,
port: process.env.MYSQL_PORT,
user: process.env.MYSQL_USER,
password: process.env.MYSQL_PW,
database: 'carpal',
host: process.env.MYSQL_HOST || 'localhost',
port: process.env.MYSQL_PORT || 3306,
user: process.env.MYSQL_USER || 'root',
password: process.env.MYSQL_PW || 'admin',
database: process.env.MYSQL_DB || 'carpal',
multipleStatements: true
};
}
Expand Down
8 changes: 0 additions & 8 deletions backend/src/test/database/databaseTestConfig.js

This file was deleted.

13 changes: 0 additions & 13 deletions backend/src/test/database/refreshDatabase.js

This file was deleted.

3 changes: 1 addition & 2 deletions backend/src/test/expressApis.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@ const UpdateRideService = require('../main/rides/UpdateRideService');
const DatabaseManager = require('../main/database/DatabaseManager');
const ExpressRideApis = require('./rides/express/ExpressRidesApis');
const ExpressAuthApis = require('./auth/ExpressAuthApis');
const databaseConfig = require('./database/databaseTestConfig');
const AwsLambdaRideApis = require('../main/rides/aws/AwsLambdaRideApis');
const bodyParser = require('body-parser');
const databaseManager = new DatabaseManager(databaseConfig);
const databaseManager = new DatabaseManager();

const https = require('https');
const http = require('http');
Expand Down
5 changes: 2 additions & 3 deletions backend/src/test/rides/CreateRide.integration.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ const DatabaseManager = require('../../main/database/DatabaseManager');
const RideStatus = require('../../main/rides/RideStatus');
const CreateRideService = require('../../main/rides/CreateRideService');
const FindRideTestRepository = require('./RideTestRepository');
const databaseTestConfig = require('../database/databaseTestConfig');
const RandomUtils = require('../RandomUtils');
const moment = require('moment');
const chai = require('chai');
Expand All @@ -20,8 +19,8 @@ let loginData;
let pickupTimeAndDateInUTC;

before(async () => {
databaseManager = new DatabaseManager(databaseTestConfig);
mockDatabaseManager = new DatabaseManager(databaseTestConfig);
databaseManager = new DatabaseManager();
mockDatabaseManager = new DatabaseManager();
connection = databaseManager.createConnection() ;
mockDatabaseManager.createConnection = () => connection;
mockDatabaseManager.closeConnection = () => null;
Expand Down
5 changes: 2 additions & 3 deletions backend/src/test/rides/FindOneRide.integration.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
const DatabaseManager = require('../../main/database/DatabaseManager');
const FindOneRideService = require('../../main/rides/FindOneRideService');
const RideTestRepository = require('./RideTestRepository');
const databaseTestConfig = require('../database/databaseTestConfig');
const RideEntityBuilder = require('./RideEntityBuilder');
const RideRepository = require('../../main/rides/RideRepository');
const RandomUtils = require('../RandomUtils');
Expand All @@ -19,8 +18,8 @@ const assert = chai.assert;
chai.use(chaiExclude);

before(async () => {
databaseManager = new DatabaseManager(databaseTestConfig);
mockDatabaseManager = new DatabaseManager(databaseTestConfig);
databaseManager = new DatabaseManager();
mockDatabaseManager = new DatabaseManager();
connection = databaseManager.createConnection();
mockDatabaseManager.createConnection = () => connection;
mockDatabaseManager.closeConnection = () => Promise.resolve(null);
Expand Down
12 changes: 7 additions & 5 deletions backend/src/test/rides/ListRides.integration.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
const DatabaseManager = require('../../main/database/DatabaseManager');
const ListRidesController = require('../../main/rides/ListRidesService');
const FindRideTestRepository = require('./RideTestRepository');
const databaseTestConfig = require('../database/databaseTestConfig');
const RideEntityBuilder = require('./RideEntityBuilder');
const RideRepository = require('../../main/rides/RideRepository');
const RandomUtils = require('../RandomUtils');
Expand All @@ -19,8 +18,8 @@ const assert = chai.assert;
chai.use(chaiExclude);

before(async () => {
databaseManager = new DatabaseManager(databaseTestConfig);
mockDatabaseManager = new DatabaseManager(databaseTestConfig);
databaseManager = new DatabaseManager();
mockDatabaseManager = new DatabaseManager();
connection = databaseManager.createConnection();
mockDatabaseManager.createConnection = () => connection;
mockDatabaseManager.closeConnection = () => Promise.resolve(null);
Expand Down Expand Up @@ -80,9 +79,12 @@ describe('When listing rides', async () => {
await databaseContainsRides(ride1, ride2, ride3);

// when
const rides = await listRideController.listRides({}, loginData);
const rides = (await listRideController.listRides({}, loginData)).map(removeId);

assert.deepEqualExcluding(rides, [ride1, ride3], 'id');
assert.deepInclude(rides, ride1);
assert.deepInclude(rides, ride3);
assert.notDeepInclude(rides, ride2);
// assert.deepEqualExcluding(rides, [ride1, ride3], 'id');
});

async function databaseContainsRides(...rides) {
Expand Down
5 changes: 2 additions & 3 deletions backend/src/test/rides/UpdateRide.integration.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ const DatabaseManager = require('../../main/database/DatabaseManager');
const RideStatus = require('../../main/rides/RideStatus');
const UpdateRideService = require('../../main/rides/UpdateRideService');
const FindRideTestRepository = require('./RideTestRepository');
const databaseTestConfig = require('../database/databaseTestConfig');
const RideEntityBuilder = require('./RideEntityBuilder');
const RideRepository = require('../../main/rides/RideRepository');
const RandomUtils = require('../RandomUtils');
Expand All @@ -23,8 +22,8 @@ let pickupTimeAndDateInUTC;
let rideRepository;

before(async () => {
databaseManager = new DatabaseManager(databaseTestConfig);
mockDatabaseManager = new DatabaseManager(databaseTestConfig);
databaseManager = new DatabaseManager();
mockDatabaseManager = new DatabaseManager();
rideRepository = new RideRepository(databaseManager);
connection = databaseManager.createConnection();
mockDatabaseManager.createConnection = () => connection;
Expand Down

0 comments on commit 603c3f3

Please sign in to comment.