Skip to content

Commit f0fbb45

Browse files
Merge pull request #132 from Real-Dev-Squad/feature/test-suite-documentation
[2] Added documentation for integrating firebase emulator
2 parents f634a7e + b4b3a0d commit f0fbb45

File tree

5 files changed

+93
-9
lines changed

5 files changed

+93
-9
lines changed

CONTRIBUTING.md

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
- [NPM Command Reference](#npm-command-reference)
66
- [Project Structure](#project-structure)
77
- [Generating Authentication Token](#generating-authentication-token)
8+
- [Testing Guidelines](#testing-guidelines)
9+
- [Using Firebase Emulator Locally](#using-firebase-emulator-locally)
810
- [Pull request guidelines](#pull-request-guidelines)
911

1012
## Getting Started
@@ -58,22 +60,27 @@ The following project structure should be followed:
5860
| |-- auth.js // the individual routes files should contain the OPEN API JSDOC reference
5961
|-- services
6062
| |-- authService.js // Files using any 3rd party library/service or providing any secific service in the project
63+
|-- scripts // Standalone scripts
6164
|-- test
6265
| |-- fixtures
6366
| | |-- auth
6467
| | |-- githubUserInfo.js
6568
| |-- integration // Integration tests
6669
| | |-- authController.test.js
6770
| |-- unit // Unit tests
71+
| | |-- middlewares
72+
| | |-- services
73+
| |-- utils // Utility functions to be used while testing
6874
|-- utils // Files containing utility functions
6975
| |-- logger.js
7076
|-- .github
7177
| |-- workflows
7278
| |-- // Github actions files
7379
|-- .gitignore
74-
|-- .*rc, .*js, .*json, .*yml // config files for dependencies
80+
|-- .*rc, .*js, .*json, .*yml // config files for dependencies
7581
|-- CONTRIBUTING.md
7682
|-- README.md
83+
|-- CHANGELOG.md
7784
|-- app.js
7885
|-- firestore-private-key.json // Firestore key file
7986
|-- package-lock.json
@@ -91,9 +98,31 @@ The following project structure should be followed:
9198
- For non-production environments, authentication is also supported with the `Authorization` header.
9299
- Authorization header: `Authorization: Bearer <token>`
93100
101+
## Testing Guidelines
102+
- Libraries used in testing in the project:
103+
- [mocha](https://mochajs.org/): Test framework
104+
- [chai](https://www.chaijs.com/): Assertion library
105+
- [sinon](https://sinonjs.org/): JavaScript test spies, stubs and mocks
106+
- [nock](https://github.com/nock/nock/blob/main/README.md): HTTP requests mocking
107+
- The test suite uses [Firebase Local Emulator Suite](https://firebase.google.com/docs/emulator-suite) for running firestore for tests([documentation](https://firebase.google.com/docs/emulator-suite/install_and_configure)).
108+
- Pre-requisites:
109+
- Node.js version 8.0 or higher.
110+
- Java version 1.8 or higher.
111+
- Firebase CLI: `npm install -g firebase-tools`
112+
113+
## Using Firebase Emulator Locally
114+
- [Firebase Local Emulator Suite](https://firebase.google.com/docs/emulator-suite) can be used locally as the DB for the project
115+
- Pre-requisites:
116+
- Node.js version 8.0 or higher.
117+
- Java version 1.8 or higher.
118+
- Firebase CLI: `npm install -g firebase-tools`
119+
- Run: `firebase emulators:start`
120+
- The emulator will be running on the port: 8080
121+
- You can view the emulator UI at: `http://localhost:4000`
122+
94123
## Pull request guidelines
95124
- Ensure that the tests pass locally before raising a PR.
96-
- All pull requests should be to the develop branch.
125+
- All pull requests should have base as the develop branch.
97126
- Every pull request should have associated issue(s) on our [issue tracker](https://github.com/Real-Dev-Squad/website-backend/issues).
98127
- For any non-trivial fixes and features, unit and integration tests must be added. The PR reviewer should not approve/merge PR(s) that lack these.
99128
- The PR(s) should be merged only after the CI passes.

README.md

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,31 @@
1717
This Project serves the backend APIs required for [Real Dev Squad](https://realdevsquad.com/) web projects. This project is built in [Express.js](https://expressjs.com/).
1818

1919
## Running the Project
20-
```shell script
20+
```shell
2121
$ npm install
22-
$ npm start
22+
$ npm start
2323
```
2424
#### Running in dev mode
25-
```shell script
25+
```shell
2626
$ npm run dev
2727
```
2828

29+
#### Test local setup
30+
```shell
31+
$ npm run test-config
32+
```
33+
2934
## Prerequisites
35+
- The application uses [node-config](https://github.com/lorenwest/node-config)([documentation](https://github.com/lorenwest/node-config/wiki/Configuration-Files)) for managing config.
3036
- Create a new file: `config/local.js`. Override the required config values from `config/development.js` and `config/default.js` into `config/local.js`.
3137
- Register the application for [GitHub OAuth](https://developer.github.com/apps/building-oauth-apps/authorizing-oauth-apps) to get the `clientId` and `clientSecret`. Add the callback URL as `http://<HOSTNAME>:<PORT>/auth/github/callback`
32-
- Create an application on [FireStore](https://firebase.google.com/docs/firestore) and [generate a service file](https://cloud.google.com/iam/docs/creating-managing-service-account-keys). Add the service file with the name `firestore-private-key.json` in the project root.
33-
- Make sure your local development setup is working properly by running the following command: `npm run test-config`.
38+
- Create an application on [FireStore](https://firebase.google.com/docs/firestore) and [generate a service file](https://cloud.google.com/iam/docs/creating-managing-service-account-keys). Add the service file with the name `firestore-private-key.json` in the project root.
3439

3540
## API Documentation:
3641
- Run the server and navigate to `http://<HOSTNAME>:<PORT>/api-docs` to view the API documentation.
3742
- Alternatively, you can import the file [API Schema](https://github.com/Real-Dev-Squad/website-backend/blob/develop/public/apiSchema.json) to [Postman](https://www.postman.com/) or [SwaggerHub](https://swagger.io/tools/swaggerhub/).
3843
- If any API changes have been made:
3944
- Write JS Doc on top of your routes using YAML based annotations in OPEN API 3.0 format.
4045
- Run `npm run generate-api-schema` to generate the API schema. A file `public/apiSchema.json` will be created/updated.
46+
47+
Read more about contributing to the project: [CONTRIBUTING](CONTRIBUTING.md)

package-lock.json

Lines changed: 47 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"dev": "cross-env NODE_ENV=development nodemon server.js",
88
"lint": "eslint .",
99
"lint-fix": "eslint . --fix",
10-
"test-config": "node local-test.js",
10+
"test-config": "node scripts/local-test.js",
1111
"test-integration": "./scripts/tests/testIntegration.sh",
1212
"test-unit": "./scripts/tests/testUnit.sh",
1313
"test": "npm run lint && npm run test-integration && npm run test-unit",
@@ -47,6 +47,7 @@
4747
"eslint-plugin-security": "^1.4.0",
4848
"eslint-plugin-standard": "^4.0.1",
4949
"mocha": "^8.1.1",
50+
"nock": "^13.0.5",
5051
"nodemon": "^2.0.4",
5152
"nyc": "^15.1.0",
5253
"pre-commit": "^1.2.2",

local-test.js renamed to scripts/local-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const fs = require('fs')
2-
const Firestore = require('./utils/firestore.js')
2+
const Firestore = require('../utils/firestore.js')
33
const config = require('config')
44

55
// check whether github credentials are not falsy

0 commit comments

Comments
 (0)