-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(dca): add jest config and first DCA calculations test suite
- Loading branch information
1 parent
a6ebcb9
commit 71941cf
Showing
8 changed files
with
218 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
{ | ||
|
||
"tabWidth": 2, | ||
"semi": true, | ||
"singleQuote": false, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,54 @@ | ||
# React + TypeScript + Vite | ||
|
||
This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules. | ||
|
||
Currently, two official plugins are available: | ||
|
||
- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/README.md) uses [Babel](https://babeljs.io/) for Fast Refresh | ||
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh | ||
|
||
## Expanding the ESLint configuration | ||
|
||
If you are developing a production application, we recommend updating the configuration to enable type aware lint rules: | ||
|
||
- Configure the top-level `parserOptions` property like this: | ||
|
||
```js | ||
export default { | ||
// other rules... | ||
parserOptions: { | ||
ecmaVersion: 'latest', | ||
sourceType: 'module', | ||
project: ['./tsconfig.json', './tsconfig.node.json'], | ||
tsconfigRootDir: __dirname, | ||
}, | ||
} | ||
``` | ||
|
||
- Replace `plugin:@typescript-eslint/recommended` to `plugin:@typescript-eslint/recommended-type-checked` or `plugin:@typescript-eslint/strict-type-checked` | ||
- Optionally add `plugin:@typescript-eslint/stylistic-type-checked` | ||
- Install [eslint-plugin-react](https://github.com/jsx-eslint/eslint-plugin-react) and add `plugin:react/recommended` & `plugin:react/jsx-runtime` to the `extends` list | ||
# Buda DCA simulator | ||
|
||
## Requisitos | ||
|
||
Antes de comenzar, asegúrate de cumplir con uno de los siguientes requisitos: | ||
|
||
- Bun | ||
- Docker | ||
|
||
## Configuración del Entorno | ||
|
||
Para configurar el entorno, sigue estos pasos: | ||
|
||
1. Clona el repositorio: | ||
```bash | ||
git clone https://github.com/IgnacioPorte/buda-dca.git | ||
``` | ||
2. Navega al directorio del proyecto: | ||
```bash | ||
cd buda-dca | ||
``` | ||
### Dockerizado: | ||
|
||
3. 1. Buildea la imagen de Docker: | ||
```bash | ||
docker build . -t dca | ||
``` | ||
|
||
4. 1. Corre el contenedor de Docker: | ||
```bash | ||
docker run -p 8080:8080 dca | ||
``` | ||
### Local: | ||
|
||
3. 2. Instala las dependencias: | ||
```bash | ||
bun install | ||
``` | ||
4. 2. Corre el proyecto: | ||
```bash | ||
bun run dev | ||
``` | ||
5. Abre tu navegador y navega a `http://localhost:8080`. | ||
|
||
## Tests | ||
|
||
- Para correr los tests, ejecuta el siguiente comando: | ||
```bash | ||
bun test | ||
``` | ||
|
||
## Consideraciones | ||
- La aplicación tiene todos los requerimientos y deseables específicados | ||
- Los tests se corren con github actions |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
export default { | ||
preset: 'ts-jest', | ||
testEnvironment: 'jest-environment-jsdom', | ||
transform: { | ||
"^.+\\.tsx?$": "ts-jest" | ||
// process `*.tsx` files with `ts-jest` | ||
}, | ||
moduleNameMapper: { | ||
'\\.(gif|ttf|eot|svg|png)$': '<rootDir>/test/__ mocks __/fileMock.js', | ||
'^@/(.*)$': '<rootDir>/src/$1', | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
module.exports = { | ||
__esModule: true, | ||
default: 'test-file-stub', | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
import { calculateDCAInvestment } from "@/utils/dca"; | ||
import { HistoricalPrice, MonthlyDCAInvestment } from "@/types"; | ||
|
||
describe("calculateDCAInvestment", () => { | ||
const quantity = 20; | ||
const data: HistoricalPrice[] = [ | ||
{ | ||
date: "2021-01-01", | ||
price: 100, | ||
}, | ||
{ | ||
date: "2021-01-02", | ||
price: 200, | ||
}, | ||
{ | ||
date: "2021-01-03", | ||
price: 400, | ||
}, | ||
]; | ||
|
||
const expectedDCA: MonthlyDCAInvestment[] = [ | ||
{ | ||
cryptoPortfolio: 0.2, | ||
date: "2021-01-01", | ||
fiatInvestment: 20, | ||
gain: 0, | ||
gainPercentage: 0, | ||
portfolioFiatValue: 20, | ||
price: 100, | ||
}, | ||
{ | ||
cryptoPortfolio: 0.30000000000000004, | ||
date: "2021-01-02", | ||
fiatInvestment: 40, | ||
gain: 20.000000000000007, | ||
gainPercentage: 50.00000000000002, | ||
portfolioFiatValue: 60.00000000000001, | ||
price: 200, | ||
}, | ||
{ | ||
cryptoPortfolio: 0.35000000000000003, | ||
date: "2021-01-03", | ||
fiatInvestment: 60, | ||
gain: 80, | ||
gainPercentage: 133.33333333333331, | ||
portfolioFiatValue: 140, | ||
price: 400, | ||
}, | ||
]; | ||
|
||
const data2: HistoricalPrice[] = [ | ||
{ | ||
date: "2021-01-01", | ||
price: 100, | ||
}, | ||
{ | ||
date: "2021-01-02", | ||
price: 120, | ||
}, | ||
{ | ||
date: "2021-01-03", | ||
price: 140, | ||
}, | ||
{ | ||
date: "2021-01-04", | ||
price: 160, | ||
}, | ||
{ | ||
date: "2021-01-05", | ||
price: 180, | ||
}, | ||
]; | ||
|
||
const expectedDCA2: MonthlyDCAInvestment[] = [ | ||
{ | ||
cryptoPortfolio: 0.2, | ||
date: "2021-01-01", | ||
fiatInvestment: 20, | ||
gain: 0, | ||
gainPercentage: 0, | ||
portfolioFiatValue: 20, | ||
price: 100, | ||
}, | ||
{ | ||
cryptoPortfolio: 0.3666666666666667, | ||
date: "2021-01-02", | ||
fiatInvestment: 40, | ||
gain: 4, | ||
gainPercentage: 10, | ||
portfolioFiatValue: 44, | ||
price: 120, | ||
}, | ||
{ | ||
cryptoPortfolio: 0.5095238095238095, | ||
date: "2021-01-03", | ||
fiatInvestment: 60, | ||
gain: 11.333333333333329, | ||
gainPercentage: 18.88888888888888, | ||
portfolioFiatValue: 71.33333333333333, | ||
price: 140, | ||
}, | ||
{ | ||
cryptoPortfolio: 0.6345238095238095, | ||
date: "2021-01-04", | ||
fiatInvestment: 80, | ||
gain: 21.52380952380952, | ||
gainPercentage: 26.904761904761898, | ||
portfolioFiatValue: 101.52380952380952, | ||
price: 160, | ||
}, | ||
{ | ||
cryptoPortfolio: 0.7456349206349207, | ||
date: "2021-01-05", | ||
fiatInvestment: 100, | ||
gain: 34.21428571428572, | ||
gainPercentage: 34.21428571428572, | ||
portfolioFiatValue: 134.21428571428572, | ||
price: 180, | ||
}, | ||
]; | ||
|
||
it("should return empty array if data is empty", () => { | ||
const investment = calculateDCAInvestment([], quantity); | ||
expect(investment).toStrictEqual([]); | ||
}); | ||
|
||
it("Calculate simple DCA", () => { | ||
const investment = calculateDCAInvestment(data, quantity); | ||
expect(investment).toStrictEqual(expectedDCA); | ||
}); | ||
|
||
it("Caculate DCA complex", () => { | ||
const investment = calculateDCAInvestment(data2, quantity); | ||
expect(investment).toStrictEqual(expectedDCA2); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters