mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
feat: Setup Unit Tests for Backend
This commit is contained in:
parent
367713e77c
commit
fc0cf9d63e
1
backend/.gitignore
vendored
1
backend/.gitignore
vendored
@ -2,5 +2,6 @@
|
|||||||
/.env
|
/.env
|
||||||
/build/
|
/build/
|
||||||
|
|
||||||
|
coverage
|
||||||
# emacs
|
# emacs
|
||||||
*~
|
*~
|
||||||
6
backend/jest.config.js
Normal file
6
backend/jest.config.js
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
|
||||||
|
module.exports = {
|
||||||
|
verbose: true,
|
||||||
|
preset: 'ts-jest',
|
||||||
|
collectCoverageFrom: ['src/**/*.ts', '!**/node_modules/**', '!**/?(*.)+test.ts'],
|
||||||
|
}
|
||||||
@ -12,9 +12,11 @@
|
|||||||
"clean": "tsc --build --clean",
|
"clean": "tsc --build --clean",
|
||||||
"start": "node build/index.js",
|
"start": "node build/index.js",
|
||||||
"dev": "nodemon -w src --ext ts --exec ts-node src/index.ts",
|
"dev": "nodemon -w src --ext ts --exec ts-node src/index.ts",
|
||||||
"lint": "eslint . --ext .js,.ts"
|
"lint": "eslint . --ext .js,.ts",
|
||||||
|
"test": "jest --coverage"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@types/jest": "^27.0.2",
|
||||||
"apollo-server-express": "^2.25.2",
|
"apollo-server-express": "^2.25.2",
|
||||||
"axios": "^0.21.1",
|
"axios": "^0.21.1",
|
||||||
"class-validator": "^0.13.1",
|
"class-validator": "^0.13.1",
|
||||||
@ -22,9 +24,11 @@
|
|||||||
"dotenv": "^10.0.0",
|
"dotenv": "^10.0.0",
|
||||||
"express": "^4.17.1",
|
"express": "^4.17.1",
|
||||||
"graphql": "^15.5.1",
|
"graphql": "^15.5.1",
|
||||||
|
"jest": "^27.2.4",
|
||||||
"jsonwebtoken": "^8.5.1",
|
"jsonwebtoken": "^8.5.1",
|
||||||
"mysql2": "^2.3.0",
|
"mysql2": "^2.3.0",
|
||||||
"reflect-metadata": "^0.1.13",
|
"reflect-metadata": "^0.1.13",
|
||||||
|
"ts-jest": "^27.0.5",
|
||||||
"type-graphql": "^1.1.1",
|
"type-graphql": "^1.1.1",
|
||||||
"typeorm": "^0.2.37"
|
"typeorm": "^0.2.37"
|
||||||
},
|
},
|
||||||
|
|||||||
11
backend/src/util/decay.test.ts
Normal file
11
backend/src/util/decay.test.ts
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
import decayFunction from './decay'
|
||||||
|
|
||||||
|
describe('utils/decay', () => {
|
||||||
|
it('has base 0.99999997802044727', () => {
|
||||||
|
const now = new Date()
|
||||||
|
now.setSeconds(1)
|
||||||
|
const oneSecondAgo = new Date(now.getTime())
|
||||||
|
oneSecondAgo.setSeconds(0)
|
||||||
|
expect(decayFunction(1.0, oneSecondAgo, now)).toBe(0.99999997802044727)
|
||||||
|
})
|
||||||
|
})
|
||||||
@ -1,4 +1,6 @@
|
|||||||
export default function (amount: number, from: Date, to: Date): number {
|
export default function (amount: number, from: Date, to: Date): number {
|
||||||
|
// what happens when from > to
|
||||||
|
// Do we want to have negative decay?
|
||||||
const decayDuration = (to.getTime() - from.getTime()) / 1000
|
const decayDuration = (to.getTime() - from.getTime()) / 1000
|
||||||
return amount * Math.pow(0.99999997802044727, decayDuration)
|
return amount * Math.pow(0.99999997802044727, decayDuration)
|
||||||
}
|
}
|
||||||
|
|||||||
2026
backend/yarn.lock
2026
backend/yarn.lock
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user