From 5eb955c52b686454beef173fb976ce6842400a20 Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Fri, 10 Dec 2021 00:34:19 +0100 Subject: [PATCH 1/7] fix corrupted balance error when calculating decay (this is not to be multiplied with 10000 --- .../src/graphql/resolver/TransactionResolver.ts | 2 +- frontend/src/views/Pages/Login.vue | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/backend/src/graphql/resolver/TransactionResolver.ts b/backend/src/graphql/resolver/TransactionResolver.ts index 58eb695ea..b2f4b4db5 100644 --- a/backend/src/graphql/resolver/TransactionResolver.ts +++ b/backend/src/graphql/resolver/TransactionResolver.ts @@ -428,7 +428,7 @@ async function addUserTransaction( if (lastUserTransaction) { newBalance += Number( await calculateDecay( - Number(lastUserTransaction.balance * 10000), + Number(lastUserTransaction.balance), lastUserTransaction.balanceDate, transaction.received, ).catch(() => { diff --git a/frontend/src/views/Pages/Login.vue b/frontend/src/views/Pages/Login.vue index d5d3e25a4..cd5f9fd88 100755 --- a/frontend/src/views/Pages/Login.vue +++ b/frontend/src/views/Pages/Login.vue @@ -104,13 +104,13 @@ export default { this.$router.push('/overview') loader.hide() }) - .catch((error) => { - if (error.message.includes('No user with this credentials')) { - this.$toasted.global.error(this.$t('error.no-account')) - } else { - // : this.$t('error.no-email-verify') - this.$router.push('/reset/login') - } + .catch((/* error */) => { + // if (error.message.includes('No user with this credentials')) { + this.$toasted.global.error(this.$t('error.no-account')) + // } else { + // this.$t('error.no-email-verify') + // this.$router.push('/reset/login') + // } loader.hide() }) }, From eef7403f0ff5fe3571182188dacd34566fc75f71 Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Fri, 10 Dec 2021 00:35:04 +0100 Subject: [PATCH 2/7] Revert "Auxiliary commit to revert individual files from 5eb955c52b686454beef173fb976ce6842400a20" This reverts commit f1d9e9096abe110698c3e9d756c377a991a15b3c. --- frontend/src/views/Pages/Login.vue | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/frontend/src/views/Pages/Login.vue b/frontend/src/views/Pages/Login.vue index cd5f9fd88..d5d3e25a4 100755 --- a/frontend/src/views/Pages/Login.vue +++ b/frontend/src/views/Pages/Login.vue @@ -104,13 +104,13 @@ export default { this.$router.push('/overview') loader.hide() }) - .catch((/* error */) => { - // if (error.message.includes('No user with this credentials')) { - this.$toasted.global.error(this.$t('error.no-account')) - // } else { - // this.$t('error.no-email-verify') - // this.$router.push('/reset/login') - // } + .catch((error) => { + if (error.message.includes('No user with this credentials')) { + this.$toasted.global.error(this.$t('error.no-account')) + } else { + // : this.$t('error.no-email-verify') + this.$router.push('/reset/login') + } loader.hide() }) }, From 2f8e1affa445e88bbd526954a3fa55c058950959 Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Fri, 10 Dec 2021 01:23:11 +0100 Subject: [PATCH 3/7] fix the i18n to load the keys again - witht he bable transform this no longer happend --- frontend/babel.config.js | 1 - frontend/package.json | 1 - frontend/yarn.lock | 9 +-------- 3 files changed, 1 insertion(+), 10 deletions(-) diff --git a/frontend/babel.config.js b/frontend/babel.config.js index 7acdca661..5907ab074 100644 --- a/frontend/babel.config.js +++ b/frontend/babel.config.js @@ -1,7 +1,6 @@ module.exports = { presets: ['@babel/preset-env'], plugins: [ - 'transform-require-context', [ 'component', { diff --git a/frontend/package.json b/frontend/package.json index 86b127676..5fbdcb0d8 100755 --- a/frontend/package.json +++ b/frontend/package.json @@ -24,7 +24,6 @@ "babel-core": "^7.0.0-bridge.0", "babel-jest": "^27.3.1", "babel-plugin-require-context-hook": "^1.0.0", - "babel-plugin-transform-require-context": "^0.1.1", "babel-preset-vue": "^2.0.2", "bootstrap": "4.3.1", "bootstrap-vue": "^2.5.0", diff --git a/frontend/yarn.lock b/frontend/yarn.lock index ec95b138a..d1d6eacd0 100644 --- a/frontend/yarn.lock +++ b/frontend/yarn.lock @@ -1217,7 +1217,7 @@ dependencies: regenerator-runtime "^0.13.4" -"@babel/template@7", "@babel/template@^7.12.13", "@babel/template@^7.16.0", "@babel/template@^7.3.3": +"@babel/template@^7.12.13", "@babel/template@^7.16.0", "@babel/template@^7.3.3": version "7.16.0" resolved "https://registry.yarnpkg.com/@babel/template/-/template-7.16.0.tgz#d16a35ebf4cd74e202083356fab21dd89363ddd6" integrity sha512-MnZdpFD/ZdYhXwiunMqqgyZyucaYsbL0IrjoGjaVhGilz+x8YB++kRfygSOIj1yOtWKPlx7NBp+9I1RQSgsd5A== @@ -3345,13 +3345,6 @@ babel-plugin-transform-es2015-modules-commonjs@^6.26.0, babel-plugin-transform-e babel-template "^6.26.0" babel-types "^6.26.0" -babel-plugin-transform-require-context@^0.1.1: - version "0.1.1" - resolved "https://registry.yarnpkg.com/babel-plugin-transform-require-context/-/babel-plugin-transform-require-context-0.1.1.tgz#319b545ca83080b5062776b46cc9b8b346fea9a6" - integrity sha512-4ceqYOtzgmq4/QsB8dP7pUrUOCjY/jrRYdt7YkIOWHxtGDQbcf6YZDyLCiPQf6KsEIcIbSQiTRXOsbLiuJfgNQ== - dependencies: - "@babel/template" "7" - babel-plugin-transform-strict-mode@^6.24.1: version "6.24.1" resolved "https://registry.yarnpkg.com/babel-plugin-transform-strict-mode/-/babel-plugin-transform-strict-mode-6.24.1.tgz#d5faf7aa578a65bbe591cf5edae04a0c67020758" From 5ff262df9105b9113945b85ff15856033ae51aea Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Fri, 10 Dec 2021 04:14:26 +0100 Subject: [PATCH 4/7] reinclude moriz's solution but only in test environment --- frontend/babel.config.js | 19 +++++++++++++++---- frontend/package.json | 2 +- frontend/yarn.lock | 14 ++++++++------ 3 files changed, 24 insertions(+), 11 deletions(-) diff --git a/frontend/babel.config.js b/frontend/babel.config.js index 5907ab074..fab7b82b8 100644 --- a/frontend/babel.config.js +++ b/frontend/babel.config.js @@ -1,11 +1,22 @@ -module.exports = { - presets: ['@babel/preset-env'], - plugins: [ +module.exports = function (api) { + api.cache(true) + + const presets = ['@babel/preset-env'] + const plugins = [ [ 'component', { styleLibraryName: 'theme-chalk', }, ], - ], + ] + + if (process.env.NODE_ENV === 'test') { + plugins.push('transform-require-context') + } + + return { + presets, + plugins, + } } diff --git a/frontend/package.json b/frontend/package.json index 5fbdcb0d8..cfa7be87c 100755 --- a/frontend/package.json +++ b/frontend/package.json @@ -23,7 +23,6 @@ "axios": "^0.21.1", "babel-core": "^7.0.0-bridge.0", "babel-jest": "^27.3.1", - "babel-plugin-require-context-hook": "^1.0.0", "babel-preset-vue": "^2.0.2", "bootstrap": "4.3.1", "bootstrap-vue": "^2.5.0", @@ -89,6 +88,7 @@ "@vue/eslint-config-prettier": "^4.0.1", "babel-eslint": "^10.1.0", "babel-plugin-component": "^1.1.0", + "babel-plugin-transform-require-context": "^0.1.1", "dotenv-webpack": "^7.0.3", "node-sass": "^6.0.1", "sass-loader": "^10", diff --git a/frontend/yarn.lock b/frontend/yarn.lock index d1d6eacd0..2bc1361be 100644 --- a/frontend/yarn.lock +++ b/frontend/yarn.lock @@ -1217,7 +1217,7 @@ dependencies: regenerator-runtime "^0.13.4" -"@babel/template@^7.12.13", "@babel/template@^7.16.0", "@babel/template@^7.3.3": +"@babel/template@7", "@babel/template@^7.12.13", "@babel/template@^7.16.0", "@babel/template@^7.3.3": version "7.16.0" resolved "https://registry.yarnpkg.com/@babel/template/-/template-7.16.0.tgz#d16a35ebf4cd74e202083356fab21dd89363ddd6" integrity sha512-MnZdpFD/ZdYhXwiunMqqgyZyucaYsbL0IrjoGjaVhGilz+x8YB++kRfygSOIj1yOtWKPlx7NBp+9I1RQSgsd5A== @@ -3325,11 +3325,6 @@ babel-plugin-polyfill-regenerator@^0.1.2: dependencies: "@babel/helper-define-polyfill-provider" "^0.1.2" -babel-plugin-require-context-hook@^1.0.0: - version "1.0.0" - resolved "https://registry.yarnpkg.com/babel-plugin-require-context-hook/-/babel-plugin-require-context-hook-1.0.0.tgz#3f0e7cce87c338f53639b948632fd4e73834632d" - integrity sha512-EMZD1563QUqLhzrqcThk759RhuNVX/ZJdrtGK6drwzgvnR+ARjWyXIHPbu+tUNaMGtPz/gQeAM2M6VUw2UiUeA== - babel-plugin-syntax-jsx@^6.18.0: version "6.18.0" resolved "https://registry.yarnpkg.com/babel-plugin-syntax-jsx/-/babel-plugin-syntax-jsx-6.18.0.tgz#0af32a9a6e13ca7a3fd5069e62d7b0f58d0d8946" @@ -3345,6 +3340,13 @@ babel-plugin-transform-es2015-modules-commonjs@^6.26.0, babel-plugin-transform-e babel-template "^6.26.0" babel-types "^6.26.0" +babel-plugin-transform-require-context@^0.1.1: + version "0.1.1" + resolved "https://registry.yarnpkg.com/babel-plugin-transform-require-context/-/babel-plugin-transform-require-context-0.1.1.tgz#319b545ca83080b5062776b46cc9b8b346fea9a6" + integrity sha512-4ceqYOtzgmq4/QsB8dP7pUrUOCjY/jrRYdt7YkIOWHxtGDQbcf6YZDyLCiPQf6KsEIcIbSQiTRXOsbLiuJfgNQ== + dependencies: + "@babel/template" "7" + babel-plugin-transform-strict-mode@^6.24.1: version "6.24.1" resolved "https://registry.yarnpkg.com/babel-plugin-transform-strict-mode/-/babel-plugin-transform-strict-mode-6.24.1.tgz#d5faf7aa578a65bbe591cf5edae04a0c67020758" From fcd355e486e0d48b93cd2cf6865192797b342044 Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Fri, 10 Dec 2021 04:27:13 +0100 Subject: [PATCH 5/7] run frontend tests in test environment --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 0435d0c76..42c83ff06 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -380,7 +380,7 @@ jobs: ########################################################################## - name: frontend | Unit tests run: | - docker run -v ~/coverage:/app/coverage --rm gradido/frontend:test yarn run test + docker run --env NODE_ENV=test -v ~/coverage:/app/coverage --rm gradido/frontend:test yarn run test cp -r ~/coverage ./coverage ########################################################################## # COVERAGE REPORT FRONTEND ############################################### From 9eb4e8603a7adc81ea7a5a3afa00608b7f8bce43 Mon Sep 17 00:00:00 2001 From: elweyn Date: Fri, 10 Dec 2021 09:08:54 +0100 Subject: [PATCH 6/7] Withdrew * 10000 and / 10000 since we need to store the full value. --- backend/src/graphql/resolver/AdminResolver.ts | 4 ++-- backend/src/graphql/resolver/TransactionResolver.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/backend/src/graphql/resolver/AdminResolver.ts b/backend/src/graphql/resolver/AdminResolver.ts index 3c03227d5..5be947cde 100644 --- a/backend/src/graphql/resolver/AdminResolver.ts +++ b/backend/src/graphql/resolver/AdminResolver.ts @@ -176,7 +176,7 @@ export class AdminResolver { } else { newBalance = lastUserTransaction.balance } - newBalance = Number(newBalance) + Number(parseInt(pendingCreation.amount.toString()) / 10000) + newBalance = Number(newBalance) + Number(parseInt(pendingCreation.amount.toString())) const newUserTransaction = new UserTransaction() newUserTransaction.userId = pendingCreation.userId @@ -194,7 +194,7 @@ export class AdminResolver { if (!userBalance) userBalance = balanceRepository.create() userBalance.userId = pendingCreation.userId - userBalance.amount = Number(newBalance * 10000) + userBalance.amount = Number(newBalance) userBalance.modified = new Date() userBalance.recordDate = userBalance.recordDate ? userBalance.recordDate : new Date() await balanceRepository.save(userBalance) diff --git a/backend/src/graphql/resolver/TransactionResolver.ts b/backend/src/graphql/resolver/TransactionResolver.ts index 58eb695ea..b2f4b4db5 100644 --- a/backend/src/graphql/resolver/TransactionResolver.ts +++ b/backend/src/graphql/resolver/TransactionResolver.ts @@ -428,7 +428,7 @@ async function addUserTransaction( if (lastUserTransaction) { newBalance += Number( await calculateDecay( - Number(lastUserTransaction.balance * 10000), + Number(lastUserTransaction.balance), lastUserTransaction.balanceDate, transaction.received, ).catch(() => { From 56dd218ee28daecbb10d51179a51ff737feeb2ce Mon Sep 17 00:00:00 2001 From: elweyn Date: Fri, 10 Dec 2021 09:14:22 +0100 Subject: [PATCH 7/7] Fix updatePendingCreation amount that is send back. --- backend/src/graphql/resolver/AdminResolver.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/src/graphql/resolver/AdminResolver.ts b/backend/src/graphql/resolver/AdminResolver.ts index 5be947cde..749f2f591 100644 --- a/backend/src/graphql/resolver/AdminResolver.ts +++ b/backend/src/graphql/resolver/AdminResolver.ts @@ -83,7 +83,7 @@ export class AdminResolver { await pendingCreationRepository.save(updatedCreation) const result = new UpdatePendingCreation() - result.amount = parseInt(updatedCreation.amount.toString()) + result.amount = parseInt(amount.toString()) result.memo = updatedCreation.memo result.date = updatedCreation.date result.moderator = updatedCreation.moderator