Skip to content

Commit c52b690

Browse files
Merge pull request #131 from Real-Dev-Squad/feature/test-suite
[1] Integrate firestore emulator in test suite
2 parents cf0e619 + f0fbb45 commit c52b690

18 files changed

+1133
-149
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ jobs:
2828
uses: actions/setup-node@v1
2929
with:
3030
node-version: ${{ matrix.node-version }}
31+
- run: npm install -g firebase-tools
3132
- run: npm install
3233
- run: npm run build --if-present
3334
- run: npm test

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ lib-cov
2222

2323
# Coverage directory used by tools like istanbul
2424
coverage
25+
.coverage
2526
*.lcov
2627

2728
# nyc test coverage

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)

config/test.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,11 @@ module.exports = {
4747
'QnrvpfRSihRktA2dDQJAH+dQBx3nG3bZ9khVAZQ1jTJ7j0cKixaGndFuYS1TJvJ2\n' +
4848
'Zzn584h/xbSIcP9/4SXmEK3wtoueUtMkvS3yKTvk+w==\n' +
4949
'-----END RSA PRIVATE KEY-----'
50+
},
51+
52+
db: {
53+
firestore: {
54+
projectId: 'rds-dev'
55+
}
5056
}
5157
}

firebase.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"emulators": {
3+
"firestore": {
4+
"port": 8080
5+
},
6+
"ui": {
7+
"enabled": true,
8+
"port": 4000
9+
}
10+
}
11+
}

nyc.config.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/**
2+
* Nyc coverage config
3+
* Documentation: https://github.com/istanbuljs/nyc#common-configuration-options
4+
*/
5+
module.exports = {
6+
all: true,
7+
exclude: [
8+
'**/test.js'
9+
],
10+
reporter: ['text', 'lcov', 'text-summary'],
11+
reportDir: '.coverage',
12+
tempDir: '.coverage'
13+
}

0 commit comments

Comments
 (0)