feat: Setup Unit Tests for Backend

This commit is contained in:
Moriz Wahl 2021-09-29 20:34:40 +02:00
parent 367713e77c
commit fc0cf9d63e
6 changed files with 2020 additions and 32 deletions

1
backend/.gitignore vendored
View File

@ -2,5 +2,6 @@
/.env
/build/
coverage
# emacs
*~

6
backend/jest.config.js Normal file
View 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'],
}

View File

@ -12,9 +12,11 @@
"clean": "tsc --build --clean",
"start": "node build/index.js",
"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": {
"@types/jest": "^27.0.2",
"apollo-server-express": "^2.25.2",
"axios": "^0.21.1",
"class-validator": "^0.13.1",
@ -22,9 +24,11 @@
"dotenv": "^10.0.0",
"express": "^4.17.1",
"graphql": "^15.5.1",
"jest": "^27.2.4",
"jsonwebtoken": "^8.5.1",
"mysql2": "^2.3.0",
"reflect-metadata": "^0.1.13",
"ts-jest": "^27.0.5",
"type-graphql": "^1.1.1",
"typeorm": "^0.2.37"
},

View 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)
})
})

View File

@ -1,4 +1,6 @@
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
return amount * Math.pow(0.99999997802044727, decayDuration)
}

File diff suppressed because it is too large Load Diff