Skip to content

Commit b4eca5c

Browse files
authored
Merge branch 'development' into feature-ticketing
2 parents c8b4f78 + a0b1bf3 commit b4eca5c

File tree

7 files changed

+184
-35
lines changed

7 files changed

+184
-35
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
---
2+
name: Bug Report
3+
about: Create a report to help us improve
4+
title: "[BUG]"
5+
labels: bug
6+
assignees: ''
7+
8+
---
9+
10+
**Describe the bug**
11+
A clear and concise description of what the bug is.
12+
13+
**Steps to Reproduce**
14+
Steps to reproduce the behaviour:
15+
1. Go to '...'
16+
2. Click on '....'
17+
3. Scroll down to '....'
18+
4. See error
19+
20+
**Expected behaviour**
21+
A clear and concise description of what you expected to happen.
22+
23+
**Screenshots**
24+
If applicable, add screenshots to help explain your problem.
25+
26+
**Console Log Output**
27+
If available, add console log output.
28+
29+
**Desktop (please complete the following information):**
30+
- Browser [e.g. chrome, safari]
31+
32+
**Additional context**
33+
Add any other context about the problem here.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
name: Feature Request
3+
about: Suggest an idea for this project
4+
title: "[FEATURE]"
5+
labels: feature
6+
assignees: ''
7+
8+
---
9+
10+
**Is your feature request related to a problem? Please describe.**
11+
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
12+
13+
**Describe the solution you'd like**
14+
A clear and concise description of what you want to happen.
15+
16+
**Describe alternatives you've considered**
17+
A clear and concise description of any alternative solutions or features you've considered.
18+
19+
**Additional context**
20+
Add any other context or screenshots about the feature request here.

.github/workflows/image-workflow.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
run: docker build . --file Dockerfile.prod --tag $IMAGE_NAME
2424

2525
- name: Log into registry
26-
run: docker login --username {{ secrets.DOCKER_USERNAME }} --password {{ secrets.DOCKER_PASSWORD }}
26+
run: echo "{{ secrets.DOCKER_PASSWORD }}" | docker login -u {{ secrets.DOCKER_USERNAME }} --password-stdin
2727
- name: Push image
2828
run: |
2929
IMAGE_ID=$REGISTRY_NAME/$REPO_NAME/$IMAGE_NAME

README.md

Lines changed: 93 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -21,47 +21,91 @@
2121
</a>
2222
</p>
2323

24-
### STEPS
2524

26-
```.sh
27-
npm install
25+
## Prerequisite:
26+
27+
These are the requirement that should be installed locally on your machine.
28+
29+
- Node.js
30+
- MongoDB
31+
- Redis
32+
33+
34+
## How to setup node.js on your machine?
35+
36+
- Move to: [link](https://nodejs.org/en/download/) choose the operating system as per your machine and start downloading and setup by clicking recommended settings in the installation wizard.
37+
38+
## How to setup MongoDB on your machine?
39+
40+
- Move to: [link](https://docs.mongodb.com/manual/administration/install-community/) look at the left sidebar and choose the operating system according to your machine. Then follow the steps recommended in the official docs.
41+
42+
```
43+
Note: You can also use the MongoDB servers like Mlab or MongoDB Cluster server
2844
```
2945

30-
#### Package descriptions
46+
## How to setup redis on your machine?
3147

32-
- bcrypt :- hash your plain password and store hashed password in database.
33-
- body-parser :- Parse incoming request bodies in a middleware before your handlers, available under the req.bodyproperty.
34-
- express :- Express is a minimal and flexible Node.js web application framework that provides a robust set of features for web and mobile applications.
35-
- jsonwebtoken :- JSON Web Token (JWT) is an open standard (RFC 7519) that defines a compact and self-contained way for securely transmitting information between parties as a JSON object.
36-
- mongoose :- Mongoose is a MongoDB object modeling tool designed to work in an asynchronous environment.
37-
- morgan :- HTTP request logger middleware for node.js.
38-
- nodemon :- nodemon will watch the files in the directory in which nodemon was started, and if any files change, nodemon will automatically restart your node application.
48+
- Follow the steps provided in the [link](https://auth0.com/blog/introduction-to-redis-install-cli-commands-and-data-types/) to install redis on your operating system
3949

50+
## How to set up this project locally?
4051

41-
These are the Donut APIs
52+
- Move to: https://github.com/codeuino/social-platform-donut-backend
53+
- Fork the repo
54+
- Clone the repo using:
55+
```sh
56+
git clone https://github.com/codeuino/social-platform-donut-backend.git
57+
```
58+
- Now move to the project directory on your machine.
59+
```
60+
cd social-platform-donut-backend
61+
```
62+
- Now use ```git checkout development``` to move to the development branch.
63+
- Install all the dependencies using:
64+
```sh
65+
npm install
66+
```
67+
- Run the development server using:
68+
```sh
69+
npm run dev
70+
```
71+
- Now the server is running on PORT 5000 or the PORT mentioned in the environment **.env.dev** variables
4272

43-
## API Response Format
44-
The response body for all the APIs will use the following format and it will contain one of them ( data | errors ).
45-
<pre>
46-
{
47-
data: {
48-
/../
49-
},
50-
errors: {
51-
/../
52-
}
53-
}
54-
</pre>
55-
56-
## Error Objects
57-
Error objects provide additional information about problems encountered while performing an operation. Error objects MUST be returned as an array keyed by errors in the top level of a JSON:API document.
73+
```
74+
Note: Setup the environment variables as mentioned below
75+
```
76+
77+
78+
## Run unit test
79+
Use the given below command to run all the unit test cases.
80+
```
81+
npm run test
82+
```
5883

59-
### An error object MAY have the following members:
6084

61-
- `status` : the HTTP status code applicable to this problem, expressed as a string value.
62-
- `code` : an application-specific error code, expressed as a string value.
63-
- `title` : a short, human-readable summary of the problem that SHOULD NOT change from occurrence to occurrence of the problem, except for purposes of localization.
64-
- `detail` : a human-readable explanation specific to this occurrence of the problem. Like title, this field’s value can be localized.
85+
## What are the environment variables required to run the project locally on a machine?
86+
- Follow these steps to set the environment variable for development:
87+
- Move to the root directory of the project and open **.env.dev** (for development) or **.env.test** (for testing)
88+
- PORT = 5000
89+
- NODE_ENV = "development"
90+
- JWT_SECRET="<YOUR SECRET KEY>"
91+
- DATABASE_URL="<YOUR DB URL>"
92+
- SENDGRID_API_KEY = '<YOUR SENDGRID API KEY>'
93+
- SOCKET_PORT = 8810
94+
95+
Note: To get **SENDGRID_API_KEY** follow the Sendgrid official [docs](https://sendgrid.com/docs/ui/account-and-settings/api-keys/#creating-an-api-key)
96+
97+
## Workflow (After setup)
98+
99+
Must follow the steps to use the platform:
100+
1. Create an organization - [API](https://docs.codeuino.org/donut-social-networking-platform/rest-apis/organization-api#create-an-organization)
101+
2. Register as an admin - [API](https://docs.codeuino.org/donut-social-networking-platform/rest-apis/post-api#create-a-user)
102+
3. Now login and use the features implemented - [API](https://docs.codeuino.org/donut-social-networking-platform/rest-apis/post-api#login-user)
103+
4. To know more about features please go through the docs - [Docs](https://docs.codeuino.org/donut-social-networking-platform/rest-apis/post-api)
104+
105+
```
106+
NOTE: Please make sure when you setup for the first time your database is empty.
107+
```
108+
65109

66110
## Allowed HTTPs requests:
67111
<pre>
@@ -122,5 +166,21 @@ DELETE : To delete resource
122166
<td><code>409</code></td>
123167
<td><code>Conflict</code></td>
124168
<td>resourse with given id already exist.</td>
169+
</tr>
170+
<tr>
171+
<td><code>429</code></td>
172+
<td><code>Too many requests</code></td>
173+
<td>sent too many requests to the server in short span of time</td>
125174
</tr>
126-
</table>
175+
</table>
176+
<br></br>
177+
178+
## Contributing 💻
179+
We are happy to see you here and we welcome your contributions towards Donut-Platform.
180+
Contributions are not limited to coding only, you can help in many other ways which includes leaving constructive feedback to people's Pull Request threads also.
181+
182+
Donut platform also provides an extensive list of issues, some of them includes labels like good-first-issue, help-wanted. You can take a look at good-first-issue issues if you are new here but you are free to choose any issue you would like to work on.
183+
184+
If there's no issue available currently, you can setup the project locally and find out the bugs/new features and open issues for that and discuss the bugs or features with the project maintainers or admins.
185+
186+
After choosing an issue and doing changes in the code regarding that, you can open up a Pull Request (PR) to development branch to get your work reviewed and merged!

app/middleware/rateLimiter.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const redis = require('../../config/redis')
22
const redisClient = redis.redisClient
33
const moment = require('moment')
44
const WINDOW_SIZE_IN_HOURS = 24
5-
const MAX_WINDOW_REQUEST_COUNT = process.env.NODE_ENV === 'testing' ? 20000 : 1000000
5+
const MAX_WINDOW_REQUEST_COUNT = process.env.NODE_ENV === 'testing' ? 20 : 500
66
const WINDOW_LOG_INTERVAL_IN_HOURS = 1
77

88
module.exports = {

test/organisation.test.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const HttpStatus = require('http-status-codes')
55
const Organization = require('../app/models/Organisation')
66
const User = require('../app/models/User')
77
const jwt = require('jsonwebtoken')
8+
const redis = require('../config/redis').redisClient
89
const adminId = new mongoose.Types.ObjectId()
910
const moderatorId = new mongoose.Types.ObjectId()
1011
const randomDigit = Math.floor(Math.random() * 90 + 10)
@@ -107,6 +108,7 @@ let server
107108
*/
108109
beforeAll(async (done) => {
109110
await Organization.deleteMany()
111+
await redis.flushall()
110112
await new User(testUser).save()
111113
server = app.listen(4000, () => {
112114
global.agent = request.agent(server)
@@ -272,6 +274,8 @@ afterAll(async () => {
272274
await Organization.deleteMany()
273275
// delete all the user created
274276
await User.deleteMany()
277+
// flush redis
278+
await redis.flushall()
275279
// Closing the DB connection allows Jest to exit successfully.
276280
await mongoose.connection.close()
277281
})

test/user.test.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,38 @@ test('Should not update profile or unauthenticated user', async () => {
225225
.expect(HttpStatus.UNAUTHORIZED)
226226
})
227227

228+
/** Should update user profile */
229+
test('Should update profile or authenticated user', async () => {
230+
await request(app)
231+
.patch('/user/me')
232+
.set('Authorization', `Bearer ${testUser.tokens[0].token}`)
233+
.send({
234+
email: 'updated@example.com'
235+
})
236+
.expect(HttpStatus.OK)
237+
})
238+
239+
/** Should fail to make updates that are not allowed to user profile */
240+
test('Should be able to make only allowed updates to authenticated user', async () => {
241+
await request(app)
242+
.patch('/user/me')
243+
.set('Authorization', `Bearer ${testUser.tokens[0].token}`)
244+
.send({
245+
gender: 'Male'
246+
})
247+
.expect(HttpStatus.BAD_REQUEST)
248+
})
249+
250+
/** Should Fail updating profile of unauthenticate user */
251+
test('Should not update profile or unauthenticated user', async () => {
252+
await request(app)
253+
.patch('/user/me')
254+
.send({
255+
email: 'updated@example.com'
256+
})
257+
.expect(HttpStatus.UNAUTHORIZED)
258+
})
259+
228260
/** Delete authenticated user profile */
229261
test('Should delete profile of authenticated user', async () => {
230262
await request(app)

0 commit comments

Comments
 (0)