Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/yale-swe/f23-here into main
Browse files Browse the repository at this point in the history
  • Loading branch information
TracyL5982 committed Nov 28, 2023
2 parents 70104b3 + 3c0e2cf commit 35327a1
Show file tree
Hide file tree
Showing 2 changed files with 128 additions and 8 deletions.
126 changes: 120 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,21 @@ Users can explore their surroundings and stumble upon messages from both old and
Beyond personal connections, our platform encourages participation in large-scale public discussions, allowing users to engage in meaningful discourse about the world around them.
Join us in redefining social interaction in the digital age with a fresh perspective on location-based AR communication.

# MVP Requirement Fullfillment
- [] Message Viewing Capability: Users can view all messages
- [] Message Visitng Capability at Specific Locations: Users can view all messages when they are within a predefined geographical area covered by the app.
- We have implemented the core logic.
- [] Range Specification for Reading Messages: Implemented a feature that allows users to read messages within a specified starting range. This range is essential for accessing both friends' and public messages.
- We have implemented the core logic.
- [] Location-Based Accessibility of Friends' Messages: Users can access messages from friends when they are within the designated range of the message's origin.
- We have implemented the core logic.
- [] Location-Based Accessibility of Public Messages: Public messages are available to users within the specified range, ensuring location-relevant content.
- We have implemented the core logic.
- [] Friend Addition Functionality: The app includes a feature to add friends by searching for their account IDs, facilitating user connections within the platform.
- [] Range Limitations for Message Accessibility: Enforced range limitations for reading messages to enhance user experience and data relevance based on location.
- We have implemented the core logic.


# Deployment
Requirements: iOS 16.0 and above
We are using TestFlight Internal to deploy Here Beta Version. To use this app:
Expand All @@ -16,6 +31,109 @@ We are using TestFlight Internal to deploy Here Beta Version. To use this app:

Refer to API_DOC.md for API Deployment.

# Additonal Changes Instructions

### Important Note

When introducing changes, always create a new branch from the main branch. After implementing your changes, initiate a pull request and request a code review from a teammate. Following approval, merge your changes into the main branch. Ensure that your merge passes all checks in GitHub Actions to maintain build integrity. Make sure there is at least 85% statement coverage across all files for the backend when implementing new changes.

### Adding Backend Routes
To add a new backend route, navigate to the `server` folder. In the `controllers` folder. Add a controller method corresponding to one of authentication (`auth.js`), message (`message.js`), reply (`reply.js`), and user (`user.js`). Then, navigate to the `routes` folder. Import the controller method and define/add the corresponding route.

1. **Plan the Endpoint:**
- Decide the HTTP method (GET, POST, PUT, DELETE) appropriate for the action.
- Choose a descriptive endpoint path that follows RESTful conventions and aligns with existing routes.

2. **Update or Create the Route File:**
- Locate the `routes` directory within the `server` folder.
- If a relevant route file (e.g., `message.js` for message-related features) exists, open it; otherwise, create a new `.js` file.

3. **Implement the Route:**
- Import necessary modules and middleware.
- Define the route using `router.METHOD(PATH, HANDLER)`.
- Use `handleSuccess`, `handleBadRequest`, `handleServerError`, and `handleNotFound` for response handling found in `utils`.

4. **Create Controller Functions:**
- Navigate to the `controllers` directory within the `server` folder.
- Create a new controller file or open an existing one that corresponds to the new route.
- Write a new controller function that includes:
- Input validation and sanitation.
- Interaction with the database through Mongoose models.
- Proper response with success or error messages.

5. **Testing:**
- Write unit tests for your new controller functions.
- For detailed instructions see the testing instructions below.
- Run tests to ensure your code behaves as expected.

6. **Documentation:**
- Comment your code to explain the functionality of routes and controllers.
- Update `API_DOC.md` the new endpoints and their usage.

### Example Route and Controller Implementation

```javascript
// In user.js route file
router.get("/:userId", getUserById);

// In user.js controller file
export const getUserById = async (req, res) => {
try {
const user = await UserModel.findById(req.params.userId);

if (!user) {
return handleNotFound(res, "User not found");
}

handleSuccess(res, user);
} catch (err) {
handleServerError(res, err);
}
};
```

### Adding Backend Tests

1. **Locate the Test File:** Navigate to the `__tests__` directory under `server`. Here, you'll find organized subdirectories for different aspects of the API, such as `controllers`, `models`, and `routes`.

2. **Create a Test File:** If a test file does not already exist in the section you edit, create one within the appropriate subdirectory. The file should be named after the feature with the suffix `Test.js`.

4. **Write Test Cases:**
- Import the necessary modules and mock dependencies.
- Use `describe` blocks to group related tests.
- Within each `describe` block, write individual `it` or `test` functions for each aspect of the feature you want to test.
- Use `expect` to assert expected outcomes.

5. **Mocking:**
- Mock any models or external calls that your feature interacts with to isolate the feature's functionality.
- Use `jest.mock()` to replace actual implementations with mock functions that return testable results.

6. **Running Tests:**
- To run your tests, use the command `npm test`.
- Ensure that your new tests pass without interfering with existing tests.

7. **Review and Refactor:**
- Review your tests to ensure they're comprehensive and cover all possible scenarios.

### Example

Here is an example of a basic test case:

```javascript
describe("Function", () => {
it("should return 400", async () => {
// Setup
// ...

// Execution
const result = await function();

// Assertion
expect(result).toBe(expectedResult);
});
});
```
# Testing
## Backend
To run our testing script in the backend, execute the following:
Expand All @@ -29,12 +147,6 @@ Current Coverge:
|---------|----------|---------|---------|-------------------|
| 89.72 | 91.89 | 85.18 | 89.86 | |
### Adding Backend Tests
To add a backend unit test, navigate to the `__test__` folder under `server`. You can choose to add a unit test to either one of the routes or the controllers using the `jest` framework.

### Adding Backend Routes
To add a new backend route, navigate to the `server` folder. In the `controllers` folder. Add a controller method corresponding to one of authentication (`auth.js`), message (`message.js`), reply (`reply.js`), and user (`user.js`). Then, navigate to the `routes` folder. Import the controller method and define/add the corresponding route.

## Frontend
To run our testing script in the frontend, execute the following command in XCode:
Expand All @@ -60,3 +172,5 @@ The bundle couldn’t be loaded. Try reinstalling the bundle.
We were told to not worry about getting 80% statement coverage for the frontend tests,
especially since we've met the requirement for backend tests. During break, we will
work on resolving this error and finishing the frontend tests.
10 changes: 8 additions & 2 deletions server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"helmet": "^7.0.0",
"mongoose": "^7.5.3",
"morgan": "^1.10.0",
"node-mocks-http": "^1.13.0"
"node-mocks-http": "^1.13.0",
"supertest": "^6.3.3"
},
"name": "server",
"version": "1.0.0",
Expand All @@ -22,7 +23,7 @@
"jest": "^29.7.0"
},
"scripts": {
"test": "node --experimental-vm-modules node_modules/.bin/jest",
"test": "node --experimental-vm-modules node_modules/.bin/jest ",
"build": "echo 'No build step required'",
"start": "node server.js"
},
Expand All @@ -37,6 +38,11 @@
"!**/__tests__/**",
"!**/coverage/lcov-report/**"
],
"coverageThreshold": {
"global": {
"statements": 85
}
},
"coverageDirectory": "coverage"
},
"keywords": [],
Expand Down

0 comments on commit 35327a1

Please sign in to comment.