From 40dff503646a758546856db156c6ec7f31d9b778 Mon Sep 17 00:00:00 2001 From: elweyn Date: Fri, 10 Dec 2021 11:54:00 +0100 Subject: [PATCH 1/8] state-balance balanceDate can't get the date of the last transaction cause creation is a new transaction. --- 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 749f2f591..8bc95280d 100644 --- a/backend/src/graphql/resolver/AdminResolver.ts +++ b/backend/src/graphql/resolver/AdminResolver.ts @@ -196,7 +196,7 @@ export class AdminResolver { userBalance.userId = pendingCreation.userId userBalance.amount = Number(newBalance) userBalance.modified = new Date() - userBalance.recordDate = userBalance.recordDate ? userBalance.recordDate : new Date() + userBalance.recordDate = new Date() await balanceRepository.save(userBalance) await pendingCreationRepository.delete(pendingCreation) From cb3c6002169a738e14822d5df5241f0da6dfac57 Mon Sep 17 00:00:00 2001 From: elweyn Date: Fri, 10 Dec 2021 12:10:38 +0100 Subject: [PATCH 2/8] Adding decay calculation to the creation. --- backend/src/graphql/resolver/AdminResolver.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/backend/src/graphql/resolver/AdminResolver.ts b/backend/src/graphql/resolver/AdminResolver.ts index 8bc95280d..4296ba049 100644 --- a/backend/src/graphql/resolver/AdminResolver.ts +++ b/backend/src/graphql/resolver/AdminResolver.ts @@ -16,6 +16,7 @@ import { TransactionCreation } from '@entity/TransactionCreation' import { UserTransaction } from '@entity/UserTransaction' import { UserTransactionRepository } from '../../typeorm/repository/UserTransaction' import { BalanceRepository } from '../../typeorm/repository/Balance' +import { calculateDecay } from '../../util/decay' @Resolver() export class AdminResolver { @@ -174,7 +175,11 @@ export class AdminResolver { if (!lastUserTransaction) { newBalance = 0 } else { - newBalance = lastUserTransaction.balance + newBalance = await calculateDecay( + lastUserTransaction.balance, + lastUserTransaction.balanceDate, + new Date(), + ) } newBalance = Number(newBalance) + Number(parseInt(pendingCreation.amount.toString())) From 284984c2965d7f6a338ffd4103c82da2bd08fa43 Mon Sep 17 00:00:00 2001 From: elweyn Date: Mon, 13 Dec 2021 11:24:09 +0100 Subject: [PATCH 3/8] When creating coins we store the receivedDate at the start of the call and write this value in each date field. --- backend/src/graphql/resolver/AdminResolver.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/backend/src/graphql/resolver/AdminResolver.ts b/backend/src/graphql/resolver/AdminResolver.ts index 4296ba049..db587aa0d 100644 --- a/backend/src/graphql/resolver/AdminResolver.ts +++ b/backend/src/graphql/resolver/AdminResolver.ts @@ -146,6 +146,7 @@ export class AdminResolver { @Mutation(() => Boolean) async confirmPendingCreation(@Arg('id') id: number): Promise { + const receivedCallDate = new Date() const pendingCreationRepository = getCustomRepository(PendingCreationRepository) const pendingCreation = await pendingCreationRepository.findOneOrFail(id) @@ -153,7 +154,7 @@ export class AdminResolver { let transaction = new Transaction() transaction.transactionTypeId = 1 transaction.memo = pendingCreation.memo - transaction.received = new Date() + transaction.received = receivedCallDate transaction.blockchainTypeId = 1 transaction = await transactionRepository.save(transaction) if (!transaction) throw new Error('Could not create transaction') @@ -178,7 +179,7 @@ export class AdminResolver { newBalance = await calculateDecay( lastUserTransaction.balance, lastUserTransaction.balanceDate, - new Date(), + receivedCallDate, ) } newBalance = Number(newBalance) + Number(parseInt(pendingCreation.amount.toString())) @@ -200,8 +201,8 @@ export class AdminResolver { if (!userBalance) userBalance = balanceRepository.create() userBalance.userId = pendingCreation.userId userBalance.amount = Number(newBalance) - userBalance.modified = new Date() - userBalance.recordDate = new Date() + userBalance.modified = receivedCallDate + userBalance.recordDate = receivedCallDate await balanceRepository.save(userBalance) await pendingCreationRepository.delete(pendingCreation) From fb001b88862af1a1506ba5a632a60116fcb13318 Mon Sep 17 00:00:00 2001 From: elweyn Date: Mon, 13 Dec 2021 11:26:30 +0100 Subject: [PATCH 4/8] Change emplacement of receivedDate after possible errors so we don't create the object when we don't need it. --- 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 db587aa0d..27e60815b 100644 --- a/backend/src/graphql/resolver/AdminResolver.ts +++ b/backend/src/graphql/resolver/AdminResolver.ts @@ -146,11 +146,11 @@ export class AdminResolver { @Mutation(() => Boolean) async confirmPendingCreation(@Arg('id') id: number): Promise { - const receivedCallDate = new Date() const pendingCreationRepository = getCustomRepository(PendingCreationRepository) const pendingCreation = await pendingCreationRepository.findOneOrFail(id) const transactionRepository = getCustomRepository(TransactionRepository) + const receivedCallDate = new Date() let transaction = new Transaction() transaction.transactionTypeId = 1 transaction.memo = pendingCreation.memo From fa245d0b640df1fbf4c8ff17a17380657050572d Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Mon, 13 Dec 2021 11:52:20 +0100 Subject: [PATCH 5/8] feat: Frontend Tests and Optimization --- frontend/src/views/Pages/SendOverview.vue | 5 ----- 1 file changed, 5 deletions(-) diff --git a/frontend/src/views/Pages/SendOverview.vue b/frontend/src/views/Pages/SendOverview.vue index fc0dc5692..822cc3117 100644 --- a/frontend/src/views/Pages/SendOverview.vue +++ b/frontend/src/views/Pages/SendOverview.vue @@ -70,11 +70,6 @@ export default { default: true, }, }, - computed: { - showContext() { - return this.currentTransactionStep === 0 - }, - }, methods: { setTransaction(data) { this.transactionData = { ...data } From c9581196da1782f51b4844a9cbb3aa7dabf1e955 Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Mon, 13 Dec 2021 12:16:13 +0100 Subject: [PATCH 6/8] test admin and setVisible methods, test elopage links --- .../views/Layout/DashboardLayout_gdd.spec.js | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/frontend/src/views/Layout/DashboardLayout_gdd.spec.js b/frontend/src/views/Layout/DashboardLayout_gdd.spec.js index 3e03bec2e..4ea2e86b2 100644 --- a/frontend/src/views/Layout/DashboardLayout_gdd.spec.js +++ b/frontend/src/views/Layout/DashboardLayout_gdd.spec.js @@ -52,6 +52,7 @@ describe('DashboardLayoutGdd', () => { publisherId: 123, firstName: 'User', lastName: 'Example', + token: 'valid-token', }, dispatch: storeDispatchMock, commit: storeCommitMock, @@ -222,6 +223,65 @@ describe('DashboardLayoutGdd', () => { expect(toasterMock).toBeCalledWith('Ouch!') }) }) + + describe('set visible method', () => { + beforeEach(() => { + wrapper.findComponent({ name: 'Navbar' }).vm.$emit('set-visible', true) + }) + + it('sets visible to true', () => { + expect(wrapper.vm.visible).toBe(true) + }) + }) + + describe('elopage URI', () => { + describe('user has no publisher ID and no elopage', () => { + beforeEach(() => { + mocks.$store.state.publisherId = null + mocks.$store.state.hasElopage = false + wrapper = Wrapper() + }) + + it('links to basic-de', () => { + expect(wrapper.vm.elopageUri).toBe( + 'https://elopage.com/s/gradido/basic-de/payment?locale=en&prid=111&pid=2896&firstName=User&lastName=Example&email=user@example.org', + ) + }) + }) + + describe('user has elopage', () => { + beforeEach(() => { + mocks.$store.state.publisherId = '123' + mocks.$store.state.hasElopage = true + wrapper = Wrapper() + }) + + it('links to sign in for elopage', () => { + expect(wrapper.vm.elopageUri).toBe('https://elopage.com/s/gradido/sign_in?locale=en') + }) + }) + }) + + describe('admin method', () => { + const windowLocationMock = jest.fn() + beforeEach(() => { + delete window.location + window.location = { + assign: windowLocationMock, + } + wrapper.findComponent({ name: 'Navbar' }).vm.$emit('admin') + }) + + it('dispatches logout to store', () => { + expect(storeDispatchMock).toBeCalled() + }) + + it('changes window location to admin interface', () => { + expect(windowLocationMock).toBeCalledWith( + 'http://localhost/admin/authenticate?token=valid-token', + ) + }) + }) }) }) }) From 041c5a7024a983a5a7da9e20e93e0df10d0a22a6 Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Mon, 13 Dec 2021 12:29:26 +0100 Subject: [PATCH 7/8] Test global directives --- frontend/src/plugins/globalDirectives.js | 2 -- frontend/src/plugins/globalDirectives.test.js | 21 +++++++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 frontend/src/plugins/globalDirectives.test.js diff --git a/frontend/src/plugins/globalDirectives.js b/frontend/src/plugins/globalDirectives.js index 1ef005f5b..836643706 100755 --- a/frontend/src/plugins/globalDirectives.js +++ b/frontend/src/plugins/globalDirectives.js @@ -1,4 +1,3 @@ -// import clickOutside from '@/directives/click-ouside.js' import { focus } from 'vue-focus' /** @@ -7,7 +6,6 @@ import { focus } from 'vue-focus' const GlobalDirectives = { install(Vue) { - // Vue.directive('click-outside', clickOutside) Vue.directive('focus', focus) }, } diff --git a/frontend/src/plugins/globalDirectives.test.js b/frontend/src/plugins/globalDirectives.test.js new file mode 100644 index 000000000..385ccb651 --- /dev/null +++ b/frontend/src/plugins/globalDirectives.test.js @@ -0,0 +1,21 @@ +import GlobalDirectives from './globalDirectives' +import { focus } from 'vue-focus' +import Vue from 'vue' + +jest.mock('vue-focus', () => { + return { + __esModule: true, + focus: jest.fn(), + } +}) +jest.mock('vue') + +const vueDirectiveMock = jest.fn() +Vue.directive = vueDirectiveMock + +describe('globalDirectives', () => { + it('installs the focus directive', () => { + GlobalDirectives.install(Vue) + expect(vueDirectiveMock).toBeCalledWith('focus', focus) + }) +}) From d2fb2e86e2af22d17b1014ba081cb648b7827eb1 Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Mon, 13 Dec 2021 15:29:04 +0100 Subject: [PATCH 8/8] coverage frontend to 94% --- .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 24aec5fff..526c15cca 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -399,7 +399,7 @@ jobs: report_name: Coverage Frontend type: lcov result_path: ./coverage/lcov.info - min_coverage: 90 + min_coverage: 94 token: ${{ github.token }} ##############################################################################