Skip to content

Commit

Permalink
Merge pull request #24 from M2JT/final-walk-through
Browse files Browse the repository at this point in the history
finalize README + add back-end unit tests + delete dummy back-end
  • Loading branch information
hackrmann authored Dec 20, 2023
2 parents f517937 + 3020c22 commit 2c6e873
Show file tree
Hide file tree
Showing 712 changed files with 123 additions and 84,098 deletions.
69 changes: 66 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,47 @@
## Background & Objective
We all know how annoying it can be when our devices run out of battery, especially when we are out and about. Picture this: you forgot to charge your phone/laptop last night, but you’ve got a full day of outdoor work ahead. That’s why ChargeFinder is here. It is a handy app that saves you from the dreaded “low battery anxiety.” With ChargeFinder, you can quickly locate nearby spots where you can grab a shared power bank for a quick charge.

## Features
### Home Page
![home page](documentation/home%20page.png)

![home page demo](documentation/home%20page%20demo.png)

- Explore the map and find the charging stations near you! You can click on any stations to check its detail
- `Get Direction` will show you the route to a selected charging station based on the travel mode selected (walking, driving, bicycling, transit)
- Click `Rent` to rent a power bank, notice that this button won't appear unless you are logged-in
- The `You are here!` marker shows where you currently are on the map. If you don't give browser permission to access your location, a default location will be used instead
- Click the center icon on the top of the screen to have map recentered back to you

### Rental History Page
![rental history page](documentation/rental%20history%20page.png)

- View your current or past rental history. Current rental would have a `Rented` status and past rental would show `Returned`
- `Duration` field would show your current rental duration and is updated in real-time
- Click `Return` to return a power bank, you will be charged (simulation charge) based on the closest hours you have rented
- Be aware that you can't view your rental history unless you are logged-in

### Login Page
![login page](documentation/login%20page.png)

- Login using your newly created account credentials
- JWT authentication mechanism used
- Error message would show up if credentials don't match with what we stored in the database

### Register Page
![register page](documentation/register%20page.png)

- Create a new account on our site
- JWT authentication mechanism used
- Error message would show up if trying to register account with duplicate username or email
- Secure password-hashing using Bcrypt

### Account Page
![account page](documentation/account%20page.png)

- View your account information
- Click `Logout` to logout

## Team Members
- Jason Lai: full-stack developer
- Felina Korte: full-stack developer
Expand All @@ -11,10 +52,32 @@ We all know how annoying it can be when our devices run out of battery, especial
- Zayyan Farooqi: backend developer

## How To Run This Project
### Download and Install
1. [IntelliJ IDEA Community Edition](https://www.jetbrains.com/idea/download) (for back-end usage)
2. [JDK 17](https://www.oracle.com/java/technologies/javase/jdk17-archive-downloads.html) (use `java -version` to verify installation in terminal)
3. [Maven](https://maven.apache.org/download.cgi) (use `mvn -v` to verify installation in terminal)
4. [Visual Studio Code](https://code.visualstudio.com/download) (for front-end usage)
5. In IntelliJ, **Preferences** -> **Plugins**, install `Lombok` from the marketplace
![lombok](documentation/lombok.png)

### In the Back-end Directory
#### Set Up and Run the Back-end
1. In IntelliJ, click the reload icon to ensure all dependencies are installed, then click `clean` and `compile`, you should see `[INFO] BUILD SUCCESS` shown in the Run tab for each of these operations.
![reload back-end](documentation/reload%20back-end.png)
3. create a `env.properties` file and save it in the root directory. To ensure this file is configured with the correct environmental variables, please contact our developers for more information, as those data are sensitive and not allowed to be publicly shared on GitHub.
3. Go to **src** -> **main** -> **java** -> **com.opensourcedev.backend**, and run `MainApplication`, this will boot up the back-end.
![start back-end](documentation/run%20back-end.png)


### In the Front-end Directory
#### Set Up and Run the Front-end
1. Run `npm install` to install all dependencies listed in `package.json` onto your local machine. This is necessary before running our app, as the 3rd-party dependency code is excluded from version control by the `.gitignore` git settings file.
2. Create a `.env` file and save it in the current directory. To ensure this file is configured with the correct environmental variables, please contact our developers for more information, as those data are sensitive and not allowed to be publicly shared on GitHub.
1. In VS Code, Run `npm install` to install all dependencies listed in `package.json`.
2. Create a `.env` file and save it in the root directory. To ensure this file is configured with the correct environmental variables, please contact our developers for more information, as those data are sensitive and not allowed to be publicly shared on GitHub.
3. Run `npm start` to start the front-end.
4. Open [http://localhost:3000](http://localhost:3000) to view our app in your browser. The page will reload when you make changes.
4. Open [http://localhost:3000](http://localhost:3000) to view our app in your browser.

### Run the Tests
1. In IntelliJ, go to **src** -> **test** -> **java** -> **com.opensourcedev.backend**, and run `MainTest`
![unit tests](documentation/unit%20tests.png)
2. Alternatively, you can run `mvn test` in back-end's root directory using terminal.
![unit tests in terminal](documentation/unit%20tests%20terminal.png)
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
package com.opensourcedev.backend.dto;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.Date;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class RentalDetail {
private String username;
private Integer transactionId;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.opensourcedev.backend.model;

import lombok.AllArgsConstructor;
import lombok.Data;

@Data
@AllArgsConstructor
public class ChargingStation {
private Integer stationId;
private String stationName;
Expand Down
53 changes: 50 additions & 3 deletions back-end/src/test/java/com/opensourcedev/backend/MainTest.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
package com.opensourcedev.backend;

import com.opensourcedev.backend.controller.MainController;
import com.opensourcedev.backend.dto.RentalDetail;
import com.opensourcedev.backend.model.ChargingStation;
import com.opensourcedev.backend.model.Rental;
import com.opensourcedev.backend.service.MainService;

import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
import java.util.List;

import org.jetbrains.annotations.NotNull;
import org.junit.jupiter.api.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
Expand All @@ -28,8 +32,8 @@ class MainTest {
void testGetRentalHistory() {
String username = "test_user";
List<Rental> mockRentalHistory = Arrays.asList(
new Rental(10,27, 987654321, new Date(1640007900000L), 0, 9, "Returned", 2),
new Rental(11,27, 567892341, new Date(1639926060000L), 1, 18, "Returned", 2)
new Rental(10, 27, 987654321, new Date(1640007900000L), 0, 9, "Returned", 2),
new Rental(11, 27, 567892341, new Date(1639926060000L), 1, 18, "Returned", 2)
);
when(mainService.getRentalHistory(username)).thenReturn(mockRentalHistory);

Expand All @@ -49,4 +53,47 @@ void testGetRentalHistory() {
assertEquals(expectedRental.getChargingStationId(), actualRental.getChargingStationId());
}
}

@Test
void testGetAllStationsInfo() {
List<ChargingStation> mockStations = getChargingStations();

when(mainService.getAllStationsInfo()).thenReturn(mockStations);

List<ChargingStation> result = mainController.getAllStations();

assertEquals(mockStations, result);
}

@Test
void rentPowerBankSuccessful() {
RentalDetail rentalDetail = new RentalDetail("test_user", 123, new Date(), 2, 8, "Rented", 5);

when(mainService.rentPowerBank(rentalDetail)).thenReturn(true);

String result = mainController.rentPowerBank(rentalDetail);

assertEquals("rent successful!", result);
}

@Test
void rentPowerBankFailed() {
RentalDetail rentalDetail = new RentalDetail("test_user", 456, new Date(), 3, 10, "Rented", 8);

when(mainService.rentPowerBank(rentalDetail)).thenReturn(false);

String result = mainController.rentPowerBank(rentalDetail);

assertEquals("rent failed!", result);
}

@NotNull
private static List<ChargingStation> getChargingStations() {
ChargingStation station1 = new ChargingStation(1, "6 metro tech center", 40.694292, -73.985205, 18, 9);
ChargingStation station2 = new ChargingStation(2, "random place", 40.6933639, -73.9704101, 12, 6);

List<ChargingStation> mockStations = Arrays.asList(station1, station2);

return mockStations;
}
}
Binary file added documentation/account page.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added documentation/home page demo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added documentation/home page.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added documentation/login page.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added documentation/lombok.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added documentation/register page.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added documentation/reload back-end.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added documentation/rental history page.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added documentation/run back-end.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added documentation/unit tests terminal.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added documentation/unit tests.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
27 changes: 0 additions & 27 deletions dummy-backend/app.js

This file was deleted.

60 changes: 0 additions & 60 deletions dummy-backend/data/event.js

This file was deleted.

34 changes: 0 additions & 34 deletions dummy-backend/data/user.js

This file was deleted.

13 changes: 0 additions & 13 deletions dummy-backend/data/util.js

This file was deleted.

1 change: 0 additions & 1 deletion dummy-backend/events.json

This file was deleted.

12 changes: 0 additions & 12 deletions dummy-backend/node_modules/.bin/mime

This file was deleted.

17 changes: 0 additions & 17 deletions dummy-backend/node_modules/.bin/mime.cmd

This file was deleted.

28 changes: 0 additions & 28 deletions dummy-backend/node_modules/.bin/mime.ps1

This file was deleted.

Loading

0 comments on commit 2c6e873

Please sign in to comment.