Skip to content

Commit

Permalink
fix: linted
Browse files Browse the repository at this point in the history
  • Loading branch information
ZavenArra committed Feb 8, 2022
1 parent d90b147 commit 84d0232
Show file tree
Hide file tree
Showing 26 changed files with 570 additions and 586 deletions.
70 changes: 34 additions & 36 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,38 +1,36 @@
{
"env": {
"node": true,
"mocha": true,
"commonjs": true
},
"plugins": ["prettier", "simple-import-sort", "eslint-plugin-import"],
"extends": [
"airbnb-base",
"prettier"
],
"parserOptions": {
"ecmaVersion": 12
},
"rules": {
"simple-import-sort/imports": "error",
"no-underscore-dangle": "off",
"camelcase":"off",
"no-unused-vars":"warn",
"func-names": "off",
"no-param-reassign": "warn",
"consistent-return":"warn",
"no-restricted-syntax":"warn",
"global-require":"off",
"radix":"off",
"no-await-in-loop":"off",
"class-methods-use-this":"warn",
"no-return-await":"warn",
"no-new-wrappers": "warn",
"prefer-destructuring": "warn",
"no-shadow":"warn",
"import/order": "warn",
"no-unused-expressions": "warn",
"import/no-extraneous-dependencies": "warn" ,
"import/no-unresolved": "warn",
"no-plusplus":"warn",
"no-continue":"off" }
"env": {
"node": true,
"mocha": true,
"commonjs": true
},
"plugins": ["prettier", "simple-import-sort", "eslint-plugin-import"],
"extends": ["airbnb-base", "prettier"],
"parserOptions": {
"ecmaVersion": 12
},
"rules": {
"simple-import-sort/imports": "error",
"no-underscore-dangle": "off",
"camelcase": "off",
"no-unused-vars": "warn",
"func-names": "off",
"no-param-reassign": "warn",
"consistent-return": "warn",
"no-restricted-syntax": "warn",
"global-require": "off",
"radix": "off",
"no-await-in-loop": "off",
"class-methods-use-this": "warn",
"no-return-await": "warn",
"no-new-wrappers": "warn",
"prefer-destructuring": "warn",
"no-shadow": "warn",
"import/order": "warn",
"no-unused-expressions": "warn",
"import/no-extraneous-dependencies": "warn",
"import/no-unresolved": "warn",
"no-plusplus": "warn",
"no-continue": "off"
}
}
29 changes: 14 additions & 15 deletions .github/workflows/treetracker-api-build-deploy-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,9 @@ jobs:
- name: run ESLint
run: npm run lint
working-directory: ${{ env.project-directory }}
# - name: run api tests
# run: npm run test
# working-directory: ${{ env.project-directory }}

# - name: run api tests
# run: npm run test
# working-directory: ${{ env.project-directory }}

release:
name: Release
Expand All @@ -41,38 +40,38 @@ jobs:
github.repository == "Greenstand/${{ github.event.repository.name }}"
steps:
- uses: actions/checkout@v2

- name: Use Node.js 16.x
uses: actions/setup-node@v1
with:
node-version: '16.x'

- name: npm clean install
run: npm ci
working-directory: ${{ env.project-directory }}

- run: npm i -g semantic-release @semantic-release/{git,exec,changelog}

- run: semantic-release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: get-npm-version
id: package-version
uses: martinbeentjes/npm-get-version-action@master

- name: Set up QEMU
uses: docker/setup-qemu-action@v1

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1

- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Build snapshot and push on merge
id: docker_build_release
uses: docker/build-push-action@v2
Expand All @@ -81,12 +80,12 @@ jobs:
file: ./Dockerfile
push: true
tags: greenstand/${{ github.event.repository.name }}:${{ steps.package-version.outputs.current-version }}

- id: export_bumped_version
run: |
export BUMPED_VERSION="${{ steps.package-version.outputs.current-version }}"
echo "::set-output name=bumped_version::${BUMPED_VERSION}"
outputs:
bumped_version: ${{ steps.export_bumped_version.outputs.bumped_version }}

Expand Down
132 changes: 53 additions & 79 deletions CHANGELOG.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

Create your local git branch and rebase it from the shared master branch. Please make sure to rebuild your local database schemas using the migrations (as illustrated in the Database Setup section above) to capture any latest updates/changes.

When you are ready to submit a pull request from your local branch, please rebase your branch off of the shared master branch again to integrate any new updates in the codebase before submitting. Any developers joining the project should feel free to review any outstanding pull requests and assign themselves to any open tickets on the Issues list.
When you are ready to submit a pull request from your local branch, please rebase your branch off of the shared master branch again to integrate any new updates in the codebase before submitting. Any developers joining the project should feel free to review any outstanding pull requests and assign themselves to any open tickets on the Issues list.
39 changes: 18 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
# Name of this microservice

Description of this microservice

# Development toolkit

This repository was created from Greenstand's template for microservice projects. This means it comes with many development tools that we use for development and deployment. As a contributor to this repository, you should learn and use these tools. They are outlined below.
This repository was created from Greenstand's template for microservice projects. This means it comes with many development tools that we use for development and deployment. As a contributor to this repository, you should learn and use these tools. They are outlined below.

## db-migrate

## Conventional Commits

## husky

## prettier / lint

## github actions
## mocha

## mocha

# Getting Started

## Project Setup

Open terminal and navigate to a folder to install this project:
Expand All @@ -24,14 +28,13 @@ Open terminal and navigate to a folder to install this project:
git clone https://github.com/Greenstand/treetracker-repository-name.git
```
Install all necessary dependencies:

Install all necessary dependencies:

```
npm install
```



### Database Setup

This repository using db-migrate to manage database migrations for its schema.
Expand All @@ -52,37 +55,34 @@ Documentation for db-migrate: https://db-migrate.readthedocs.io/en/latest/

This project use multiple layer structure to build the whole system. Similar with MVC structure:

![layers](/layers.png "layers")

![layers](/layers.png 'layers')

* **Protocol layer**
- **Protocol layer**

Wallet API offers RESTFul API interace based on HTTP protocol. We use Express to handle all HTTP requests.

The Express-routers work like the controller role in MVC, they receive the requests and parameters from client, and translate it and dispatch tasks to appropriate business objects. Then receive the result from them, translate to the 'view', the JSON response, to client.

* **Service layer**
- **Service layer**

Both service layer and model layer are where all the business logic is located. Comparing to the Model , `service` object don't have state (stateless).
Both service layer and model layer are where all the business logic is located. Comparing to the Model , `service` object don't have state (stateless).

Please put business logic code into service object when it is hard to put them into the `Model` object.

Because we didn't use Factory or dependency injection to create object, so service layer also can be used as Factory to create `model` object.

* **Model layer**
- **Model layer**

The business model, major business logic is here. They are real object, in the perspective of object oriented programming: they have states, they have the method to do stuff.
The business model, major business logic is here. They are real object, in the perspective of object oriented programming: they have states, they have the method to do stuff.

There are more discussion about this, check below selection.

* **Repository layer**
- **Repository layer**

Repository is responsible for communicate with the real database, this isolation brings flexibility for us, for example, we can consider replace the implementation of the storage infrastructure in the future.

All the SQL statements should be here.



# How to test

## Unit test
Expand All @@ -106,6 +106,7 @@ npm run test-integration
```

## Database seeding test

In order to efficiently run our integration tests, we rely on automated database seeding/clearing functions to mock database entries. To test these functions, run:

```
Expand Down Expand Up @@ -135,7 +136,3 @@ npm run server-test
```

This command would run a API server locally, and seed some basic data into DB (the same with the data we used in the integration test).




20 changes: 10 additions & 10 deletions __tests__/api-tests/earnings-api.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ const {
} = require('./seed-data-creation');
const { GenericObject } = require('./generic-class');

const jwtToken = 'Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MSwidXNlck5hbWUiOiJhZG1pbiIsImZpcnN0TmFtZSI6IkFkbWluIiwibGFzdE5hbWUiOiJQYW5lbCIsInBhc3N3b3JkSGFzaCI6IjQ0ZDE0MmNkMjBhMWQxZTE1YzQxOWZhOThkZTc5Y2U5OTc0MWNjNDY4NjZhYzI2MjY4N2ViNDQ2MGM0Y2NiNDIzZTdjMzU2ZDlmYzQwYjMxYWVjZmU2ODYyMzYyNjMzOWNmZmQ4YTg5YzYxYjMyOTdlY2I1YzRiZTYzZDFkMDY5Iiwic2FsdCI6IkQ4OFdDcCIsImVtYWlsIjoiYWRtaW5AZ3JlZW5zdGFuZC5vcmciLCJhY3RpdmUiOnRydWUsImNyZWF0ZWRBdCI6IjIwMjAtMDgtMDNUMTg6NDc6NDcuMjU4WiIsImVuYWJsZWQiOnRydWUsInJvbGUiOls0NiwxLDJdLCJyb2xlTmFtZXMiOlsiRWFybmluZ3MgTWFuYWdlciIsIkFkbWluIiwiVHJlZSBNYW5hZ2Vy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lsIjoiYWRtaW5AZ3JlZW5zdGFuZC5vcmciLCJhY3RpdmUiOnRydWUsImNyZWF0ZWRBdCI6IjIwMjAtMDgtMDNUMTg6NDc6NDcuMjU4WiIsImVuYWJsZWQiOnRydWUsInJvbGUiOls0NiwxLDJdLCJyb2xlTmFtZXMiOlsiRWFybmluZ3MgTWFuYWdlciIsIkFkbWluIiwiVHJlZSBNYW5hZ2VyIl0sInBvbGljeSI6eyJwb2xpY2llcyI6W3sibmFtZSI6Imxpc3RfZWFybmluZ3MiLCJkZXNjcmlwdGlvbiI6IkNhbiB2aWV3IGVhcm5pbmdzIn0seyJuYW1lIjoibWFuYWdlX2Vhcm5pbmdzIiwiZGVzY3JpcHRpb24iOiJDYW4gbW9kaWZ5L2V4cG9ydCBlYXJuaW5ncyJ9LHsibmFtZSI6InN1cGVyX3Blcm1pc3Npb24iLCJkZXNjcmlwdGlvbiI6IkNhbiBkbyBhbnl0aGluZyJ9LHsibmFtZSI6Imxpc3RfdXNlciIsImRlc2NyaXB0aW9uIjoiQ2FuIHZpZXcgYWRtaW4gdXNlcnMifSx7Im5hbWUiOiJtYW5hZ2VyX3VzZXIiLCJkZXNjcmlwdGlvbiI6IkNhbiBjcmVhdGUvbW9kaWZ5IGFkbWluIHVzZXIifSx7Im5hbWUiOiJsaXN0X3RyZWUiLCJkZXNjcmlwdGlvbiI6IkNhbiB2aWV3IHRyZWVzIn0seyJuYW1lIjoiYXBwcm92ZV90cmVlIiwiZGVzY3JpcHRpb24iOiJDYW4gYXBwcm92ZS9yZWplY3QgdHJlZXMifV19LCJpYXQiOjE2NDI4NzIyNjV9.JYWYUo7B6y2jNyoaaw9uA0jTU4AYIZLXg0oGwF3XoVE';

describe('Earnings API tests.', () => {
describe('Earnings PATCH', () => {
Expand Down Expand Up @@ -471,7 +471,7 @@ describe('Earnings API tests.', () => {
let earnings_updated = false;
for (const earning of res.body.earnings) {
expect(earning).to.have.keys([
'id',
'id',
'grower',
'funder',
'phone',
Expand Down Expand Up @@ -559,7 +559,7 @@ describe('Earnings API tests.', () => {
request(server)
.patch(`/earnings/batch`)
.set('Accept', 'multipart/form-data')
.set('authorization', jwtToken)
.set('authorization', jwtToken)
.attach(
'csv',
'./__tests__/api-tests/earningsFailedTestInvalidHeader2.csv',
Expand All @@ -575,7 +575,7 @@ describe('Earnings API tests.', () => {
request(server)
.patch(`/earnings/batch`)
.set('Accept', 'multipart/form-data')
.set('authorization', jwtToken)
.set('authorization', jwtToken)
.attach(
'csv',
'./__tests__/api-tests/earningsFailedTestInvalidHeader3.csv',
Expand All @@ -590,7 +590,7 @@ describe('Earnings API tests.', () => {
it(`Should raise validation error with error code 422 -- invalid headers; amount does not exist `, function (done) {
request(server)
.patch(`/earnings/batch`)
.set('authorization', jwtToken)
.set('authorization', jwtToken)
.set('Accept', 'multipart/form-data')
.attach(
'csv',
Expand All @@ -607,7 +607,7 @@ describe('Earnings API tests.', () => {
request(server)
.patch(`/earnings/batch`)
.set('Accept', 'multipart/form-data')
.set('authorization', jwtToken)
.set('authorization', jwtToken)
.attach(
'csv',
'./__tests__/api-tests/earningsFailedTestInvalidHeader5.csv',
Expand All @@ -623,7 +623,7 @@ describe('Earnings API tests.', () => {
request(server)
.patch(`/earnings/batch`)
.set('Accept', 'multipart/form-data')
.set('authorization', jwtToken)
.set('authorization', jwtToken)
.attach(
'csv',
'./__tests__/api-tests/earningsFailedTestInvalidHeader6.csv',
Expand All @@ -639,7 +639,7 @@ describe('Earnings API tests.', () => {
request(server)
.patch(`/earnings/batch`)
.set('Accept', 'multipart/form-data')
.set('authorization', jwtToken)
.set('authorization', jwtToken)
.attach(
'csv',
'./__tests__/api-tests/earningsFailedTestRowWithNotCalculatedStatus.csv',
Expand All @@ -655,7 +655,7 @@ describe('Earnings API tests.', () => {
request(server)
.patch(`/earnings/batch`)
.set('Accept', 'multipart/form-data')
.set('authorization', jwtToken)
.set('authorization', jwtToken)
.attach('csv', './__tests__/api-tests/earningsSuccessfulTest.csv')
.expect(200)
.end(function (err, res) {
Expand Down
2 changes: 1 addition & 1 deletion commitlint.config.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
module.exports = {extends: ['@commitlint/config-conventional']};
module.exports = { extends: ['@commitlint/config-conventional'] };
Loading

0 comments on commit 84d0232

Please sign in to comment.