From 677581b76e8bef2fa8c42450016ce58a32b6fcd1 Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Fri, 18 Mar 2022 03:13:00 +0100 Subject: [PATCH 01/54] enforce config on backend --- backend/.env.dist | 2 ++ backend/.env.template | 2 ++ backend/src/config/index.ts | 17 +++++++++++++++++ 3 files changed, 21 insertions(+) diff --git a/backend/.env.dist b/backend/.env.dist index b1b16972f..85ad886f1 100644 --- a/backend/.env.dist +++ b/backend/.env.dist @@ -1,3 +1,5 @@ +CONFIG_VERSION=v1.2022-03-18 + # Server PORT=4000 JWT_SECRET=secret123 diff --git a/backend/.env.template b/backend/.env.template index b3a5eb4c6..454b25d3c 100644 --- a/backend/.env.template +++ b/backend/.env.template @@ -1,3 +1,5 @@ +CONFIG_VERSION=$BACKEND_CONFIG_VERSION + # Server JWT_SECRET=$JWT_SECRET JWT_EXPIRES_IN=10m diff --git a/backend/src/config/index.ts b/backend/src/config/index.ts index 79101856c..2a2bd6008 100644 --- a/backend/src/config/index.ts +++ b/backend/src/config/index.ts @@ -12,6 +12,11 @@ Decimal.set({ const constants = { DB_VERSION: '0032-add-transaction-link-to-transaction', DECAY_START_TIME: new Date('2021-05-13 17:46:31'), // GMT+0 + CONFIG_VERSION: { + DEFAULT: 'DEFAULT', + EXPECTED: 'v1.2022-03-18', + CURRENT: '', + }, } const server = { @@ -78,6 +83,18 @@ const webhook = { // This is needed by graphql-directive-auth process.env.APP_SECRET = server.JWT_SECRET +// Check config version +constants.CONFIG_VERSION.CURRENT = process.env.CONFIG_VERSION || constants.CONFIG_VERSION.DEFAULT +if ( + ![constants.CONFIG_VERSION.EXPECTED, constants.CONFIG_VERSION.DEFAULT].includes( + constants.CONFIG_VERSION.CURRENT, + ) +) { + throw new Error( + `Fatal: Config Version incorrect - expected "${constants.CONFIG_VERSION.EXPECTED}" or "${constants.CONFIG_VERSION.DEFAULT}", but found "${constants.CONFIG_VERSION.CURRENT}"`, + ) +} + const CONFIG = { ...constants, ...server, From c9177bbce3fbaf648fd239f4bb3d4aeb1ff06e5f Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Fri, 18 Mar 2022 03:13:11 +0100 Subject: [PATCH 02/54] enforce config database --- database/.env.dist | 2 ++ database/.env.template | 2 ++ database/src/config/index.ts | 22 +++++++++++++++++++++- 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/database/.env.dist b/database/.env.dist index 689e4f509..58362a7b9 100644 --- a/database/.env.dist +++ b/database/.env.dist @@ -1,3 +1,5 @@ +CONFIG_VERSION=v1.2022-03-18 + DB_HOST=localhost DB_PORT=3306 DB_USER=root diff --git a/database/.env.template b/database/.env.template index 5b8554bcf..f2517a397 100644 --- a/database/.env.template +++ b/database/.env.template @@ -1,3 +1,5 @@ +CONFIG_VERSION=$DATABASE_CONFIG_VERSION + DB_HOST=localhost DB_PORT=3306 DB_USER=$DB_USER diff --git a/database/src/config/index.ts b/database/src/config/index.ts index 2dde06c96..ba41f11d4 100644 --- a/database/src/config/index.ts +++ b/database/src/config/index.ts @@ -3,6 +3,14 @@ import dotenv from 'dotenv' dotenv.config() +const constants = { + CONFIG_VERSION: { + DEFAULT: 'DEFAULT', + EXPECTED: 'v1.2022-03-18', + CURRENT: '', + }, +} + const database = { DB_HOST: process.env.DB_HOST || 'localhost', DB_PORT: process.env.DB_PORT ? parseInt(process.env.DB_PORT) : 3306, @@ -15,6 +23,18 @@ const migrations = { MIGRATIONS_TABLE: process.env.MIGRATIONS_TABLE || 'migrations', } -const CONFIG = { ...database, ...migrations } +// Check config version +constants.CONFIG_VERSION.CURRENT = process.env.CONFIG_VERSION || constants.CONFIG_VERSION.DEFAULT +if ( + ![constants.CONFIG_VERSION.EXPECTED, constants.CONFIG_VERSION.DEFAULT].includes( + constants.CONFIG_VERSION.CURRENT, + ) +) { + throw new Error( + `Fatal: Config Version incorrect - expected "${constants.CONFIG_VERSION.EXPECTED}" or "${constants.CONFIG_VERSION.DEFAULT}", but found "${constants.CONFIG_VERSION.CURRENT}"`, + ) +} + +const CONFIG = { ...constants, ...database, ...migrations } export default CONFIG From 28588ae25c8ab5b08e2330e554a4c9157aa172c7 Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Fri, 18 Mar 2022 03:17:48 +0100 Subject: [PATCH 03/54] deployment .env.dist config versions --- deployment/bare_metal/.env.dist | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/deployment/bare_metal/.env.dist b/deployment/bare_metal/.env.dist index 9a9d57b4c..ee0ac3cc3 100644 --- a/deployment/bare_metal/.env.dist +++ b/deployment/bare_metal/.env.dist @@ -18,6 +18,8 @@ WEBHOOK_GITHUB_SECRET=secret WEBHOOK_GITHUB_BRANCH=master # backend +BACKEND_CONFIG_VERSION=v1.2022-03-18 + EMAIL=true EMAIL_USERNAME=peter@lustig.de EMAIL_SENDER=peter@lustig.de @@ -43,6 +45,9 @@ KLICKTIPP_PASSWORD= KLICKTIPP_APIKEY_DE= KLICKTIPP_APIKEY_EN= +# database +DATABASE_CONFIG_VERSION=v1.2022-03-18 + # frontend GRAPHQL_URI=https://stage1.gradido.net/graphql ADMIN_AUTH_URL=https://stage1.gradido.net/admin/authenticate?token={token} From 2fb5cf2d81b0f3388197128fac46138b4207a790 Mon Sep 17 00:00:00 2001 From: ogerly Date: Mon, 21 Mar 2022 10:27:14 +0100 Subject: [PATCH 04/54] delete redeemCode from store --- frontend/src/store/store.js | 5 ----- frontend/src/store/store.test.js | 11 +---------- 2 files changed, 1 insertion(+), 15 deletions(-) diff --git a/frontend/src/store/store.js b/frontend/src/store/store.js index fb74624fb..458c8c8de 100644 --- a/frontend/src/store/store.js +++ b/frontend/src/store/store.js @@ -47,9 +47,6 @@ export const mutations = { hasElopage: (state, hasElopage) => { state.hasElopage = hasElopage }, - redeemCode: (state, redeemCode) => { - state.redeemCode = redeemCode - }, } export const actions = { @@ -76,7 +73,6 @@ export const actions = { commit('hasElopage', false) commit('publisherId', null) commit('isAdmin', false) - commit('redeemCode', null) localStorage.clear() }, } @@ -106,7 +102,6 @@ try { }, hasElopage: false, publisherId: null, - redeemCode: null, }, getters: {}, // Syncronous mutation of the state diff --git a/frontend/src/store/store.test.js b/frontend/src/store/store.test.js index 29a703e8f..ea40d9474 100644 --- a/frontend/src/store/store.test.js +++ b/frontend/src/store/store.test.js @@ -26,7 +26,6 @@ const { isAdmin, community, hasElopage, - redeemCode, } = mutations const { login, logout } = actions @@ -142,14 +141,6 @@ describe('Vuex store', () => { hasElopage(state, true) expect(state.hasElopage).toBeTruthy() }) - - describe('redeemCode', () => { - it('sets the state of token', () => { - const state = { redeemCode: null } - redeemCode(state, 'a0000b0000c0000') - expect(state.redeemCode).toEqual('a0000b0000c0000') - }) - }) }) }) @@ -228,7 +219,7 @@ describe('Vuex store', () => { it('calls nine commits', () => { logout({ commit, state }) - expect(commit).toHaveBeenCalledTimes(10) + expect(commit).toHaveBeenCalledTimes(9) }) it('commits token', () => { From 6c87a6f32a05b98ca081e6d9d00704b766b45413 Mon Sep 17 00:00:00 2001 From: ogerly Date: Mon, 21 Mar 2022 10:28:12 +0100 Subject: [PATCH 05/54] changed code from store to param --- frontend/src/pages/Register.vue | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/frontend/src/pages/Register.vue b/frontend/src/pages/Register.vue index b2df16e0f..4ffe92512 100755 --- a/frontend/src/pages/Register.vue +++ b/frontend/src/pages/Register.vue @@ -118,7 +118,7 @@ {{ messageError }} - +
@@ -130,7 +130,7 @@ readonly id="redeem-code" type="text" - v-model="$store.state.redeemCode" + v-model="redeemCode" >
@@ -234,7 +234,7 @@ export default { messageError: '', register: true, publisherId: this.$store.state.publisherId, - redeemCode: this.$store.state.redeemCode, + redeemCode: this.$route.params.code, } }, methods: { @@ -248,9 +248,6 @@ export default { commitStorePublisherId(val) { this.$store.commit('publisherId', val) }, - commitStoreRedeemCode(val) { - this.$store.commit('redeemCode', val) - }, async onSubmit() { this.$apollo .mutate({ @@ -261,7 +258,7 @@ export default { lastName: this.form.lastname, language: this.language, publisherId: this.$store.state.publisherId, - redeemCode: this.$store.state.redeemCode, + redeemCode: this.redeemCode, }, }) .then(() => { @@ -296,10 +293,5 @@ export default { return !(this.namesFilled && this.emailFilled && this.form.agree && !!this.language) }, }, - created() { - if (this.$route.params.code) { - this.commitStoreRedeemCode(this.$route.params.code) - } - }, } From 1f1cd67b9e76824613993fa850e9a9076559f60a Mon Sep 17 00:00:00 2001 From: ogerly Date: Mon, 21 Mar 2022 10:29:13 +0100 Subject: [PATCH 06/54] add redeemCode --- backend/src/graphql/arg/CreateUserArgs.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/backend/src/graphql/arg/CreateUserArgs.ts b/backend/src/graphql/arg/CreateUserArgs.ts index 0d63e76bb..59462aa2a 100644 --- a/backend/src/graphql/arg/CreateUserArgs.ts +++ b/backend/src/graphql/arg/CreateUserArgs.ts @@ -16,4 +16,7 @@ export default class CreateUserArgs { @Field(() => Int, { nullable: true }) publisherId: number + + @Field(() => String, { nullable: true }) + redeemCode: string } From 3992882962fedb69714d651aecffbf1fc0548bd8 Mon Sep 17 00:00:00 2001 From: ogerly Date: Mon, 21 Mar 2022 10:29:56 +0100 Subject: [PATCH 07/54] add redeemCode on UserResolver.ts --- backend/src/graphql/resolver/UserResolver.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/src/graphql/resolver/UserResolver.ts b/backend/src/graphql/resolver/UserResolver.ts index 04c5fdf63..4ee564977 100644 --- a/backend/src/graphql/resolver/UserResolver.ts +++ b/backend/src/graphql/resolver/UserResolver.ts @@ -313,7 +313,7 @@ export class UserResolver { @Authorized([RIGHTS.CREATE_USER]) @Mutation(() => User) async createUser( - @Args() { email, firstName, lastName, language, publisherId }: CreateUserArgs, + @Args() { email, firstName, lastName, language, publisherId, redeemCode }: CreateUserArgs, ): Promise { // TODO: wrong default value (should be null), how does graphql work here? Is it an required field? // default int publisher_id = 0; From 15e0186381522fb60a8d9efe0852353f46eff643 Mon Sep 17 00:00:00 2001 From: ogerly Date: Mon, 21 Mar 2022 10:54:56 +0100 Subject: [PATCH 08/54] add redeemCode on register process for createUser --- backend/src/graphql/resolver/UserResolver.ts | 10 +++++++--- backend/src/seeds/graphql/mutations.ts | 2 ++ backend/src/webhook/elopage.ts | 1 + frontend/src/graphql/mutations.js | 2 ++ 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/backend/src/graphql/resolver/UserResolver.ts b/backend/src/graphql/resolver/UserResolver.ts index 4ee564977..80e927da7 100644 --- a/backend/src/graphql/resolver/UserResolver.ts +++ b/backend/src/graphql/resolver/UserResolver.ts @@ -367,11 +367,15 @@ export class UserResolver { // TODO: this has duplicate code with sendResetPasswordEmail const emailOptIn = await createEmailOptIn(dbUser.id, queryRunner) - const activationLink = CONFIG.EMAIL_LINK_VERIFICATION.replace( + let activationLink = CONFIG.EMAIL_LINK_VERIFICATION.replace( /{code}/g, emailOptIn.verificationCode.toString(), ) + if (redeemCode !== '') { + activationLink += '/' + redeemCode + } + // eslint-disable-next-line @typescript-eslint/no-unused-vars const emailSent = await sendAccountActivationEmail({ link: activationLink, @@ -380,13 +384,13 @@ export class UserResolver { email, }) - /* uncomment this, when you need the activation link on the console + // uncomment this, when you need the activation link on the console // In case EMails are disabled log the activation link for the user if (!emailSent) { // eslint-disable-next-line no-console console.log(`Account confirmation link: ${activationLink}`) } - */ + await queryRunner.commitTransaction() } catch (e) { await queryRunner.rollbackTransaction() diff --git a/backend/src/seeds/graphql/mutations.ts b/backend/src/seeds/graphql/mutations.ts index 19ca2a8d0..cab864c4e 100644 --- a/backend/src/seeds/graphql/mutations.ts +++ b/backend/src/seeds/graphql/mutations.ts @@ -45,6 +45,7 @@ export const createUser = gql` $email: String! $language: String! $publisherId: Int + $redeemCode: String ) { createUser( email: $email @@ -52,6 +53,7 @@ export const createUser = gql` lastName: $lastName language: $language publisherId: $publisherId + redeemCode: $redeemCode ) { id } diff --git a/backend/src/webhook/elopage.ts b/backend/src/webhook/elopage.ts index d5eaef521..ee8c3fc94 100644 --- a/backend/src/webhook/elopage.ts +++ b/backend/src/webhook/elopage.ts @@ -140,6 +140,7 @@ export const elopageWebhook = async (req: any, res: any): Promise => { firstName, lastName, publisherId: loginElopageBuy.publisherId || 0, // This seemed to be the default value if not set + redeemCode: '', }) } catch (error) { // eslint-disable-next-line no-console diff --git a/frontend/src/graphql/mutations.js b/frontend/src/graphql/mutations.js index d3a177866..95c811f8d 100644 --- a/frontend/src/graphql/mutations.js +++ b/frontend/src/graphql/mutations.js @@ -45,6 +45,7 @@ export const createUser = gql` $email: String! $language: String! $publisherId: Int + $redeemCode: String ) { createUser( email: $email @@ -52,6 +53,7 @@ export const createUser = gql` lastName: $lastName language: $language publisherId: $publisherId + redeemCode: $redeemCode ) { id } From a23777b6ec5dccfd5e11b1a8e29b5c329c9747da Mon Sep 17 00:00:00 2001 From: ogerly Date: Mon, 21 Mar 2022 12:07:59 +0100 Subject: [PATCH 09/54] uncomment code activationLink --- backend/src/graphql/resolver/UserResolver.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/backend/src/graphql/resolver/UserResolver.ts b/backend/src/graphql/resolver/UserResolver.ts index 80e927da7..311916aad 100644 --- a/backend/src/graphql/resolver/UserResolver.ts +++ b/backend/src/graphql/resolver/UserResolver.ts @@ -384,12 +384,13 @@ export class UserResolver { email, }) - // uncomment this, when you need the activation link on the console + /* uncomment this, when you need the activation link on the console // In case EMails are disabled log the activation link for the user if (!emailSent) { // eslint-disable-next-line no-console console.log(`Account confirmation link: ${activationLink}`) } + */ await queryRunner.commitTransaction() } catch (e) { From cdd13cf24e890760563ff043f483ab13bc61ae8d Mon Sep 17 00:00:00 2001 From: ogerly Date: Mon, 21 Mar 2022 12:09:07 +0100 Subject: [PATCH 10/54] add params on thx and checkEmail --- frontend/src/routes/routes.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frontend/src/routes/routes.js b/frontend/src/routes/routes.js index 5e0b09c5e..a6586c201 100755 --- a/frontend/src/routes/routes.js +++ b/frontend/src/routes/routes.js @@ -47,7 +47,7 @@ const routes = [ component: () => import('@/pages/Register.vue'), }, { - path: '/thx/:comingFrom', + path: '/thx/:comingFrom/:code?', component: () => import('@/pages/thx.vue'), beforeEnter: (to, from, next) => { const validFrom = ['forgot-password', 'reset-password', 'register', 'login', 'checkEmail'] @@ -79,7 +79,7 @@ const routes = [ component: () => import('@/pages/ResetPassword.vue'), }, { - path: '/checkEmail/:optin', + path: '/checkEmail/:optin/:code?', component: () => import('@/pages/ResetPassword.vue'), }, { From 6d257825e2aee4e5f9710c9e7c73666d2bdeed67 Mon Sep 17 00:00:00 2001 From: ogerly Date: Mon, 21 Mar 2022 12:11:19 +0100 Subject: [PATCH 11/54] add redeemCode to login button --- frontend/src/pages/thx.vue | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/frontend/src/pages/thx.vue b/frontend/src/pages/thx.vue index 41c63c7d8..308c354fa 100644 --- a/frontend/src/pages/thx.vue +++ b/frontend/src/pages/thx.vue @@ -9,7 +9,11 @@

{{ $t(displaySetup.subtitle) }}


- + + + {{ $t(displaySetup.button) }} + + {{ $t(displaySetup.button) }} @@ -65,6 +69,11 @@ export default { this.displaySetup = textFields[this.$route.params.comingFrom] }, }, + computed: { + redeemLoginLink() { + return this.$route.params.code ? '/login/' + this.$route.params.code : '/login' + }, + }, created() { this.setDisplaySetup() }, From 042741a9aab75f05b0f74857d53ed9b658ee8d67 Mon Sep 17 00:00:00 2001 From: ogerly Date: Mon, 21 Mar 2022 12:11:59 +0100 Subject: [PATCH 12/54] add code to push --- frontend/src/pages/ResetPassword.vue | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/frontend/src/pages/ResetPassword.vue b/frontend/src/pages/ResetPassword.vue index b0194c0ba..b6de8cb97 100644 --- a/frontend/src/pages/ResetPassword.vue +++ b/frontend/src/pages/ResetPassword.vue @@ -96,7 +96,11 @@ export default { .then(() => { this.form.password = '' if (this.$route.path.includes('checkEmail')) { - this.$router.push('/thx/checkEmail') + if (this.$route.params.code) { + this.$router.push('/thx/checkEmail/' + this.$route.params.code) + } else { + this.$router.push('/thx/checkEmail') + } } else { this.$router.push('/thx/resetPassword') } From f8882fa63a8f052b96188bf36874542cd1d7de76 Mon Sep 17 00:00:00 2001 From: ogerly Date: Mon, 21 Mar 2022 14:41:50 +0100 Subject: [PATCH 13/54] remove computed --- frontend/src/pages/thx.vue | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/frontend/src/pages/thx.vue b/frontend/src/pages/thx.vue index 308c354fa..ee6338d26 100644 --- a/frontend/src/pages/thx.vue +++ b/frontend/src/pages/thx.vue @@ -9,7 +9,7 @@

{{ $t(displaySetup.subtitle) }}


- + {{ $t(displaySetup.button) }} @@ -69,11 +69,6 @@ export default { this.displaySetup = textFields[this.$route.params.comingFrom] }, }, - computed: { - redeemLoginLink() { - return this.$route.params.code ? '/login/' + this.$route.params.code : '/login' - }, - }, created() { this.setDisplaySetup() }, From 2b7d9d8c1a987eed7164692157fe9fdc94946831 Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Mon, 21 Mar 2022 17:23:56 +0100 Subject: [PATCH 14/54] save referrer ID when present on register --- backend/src/graphql/resolver/UserResolver.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/backend/src/graphql/resolver/UserResolver.ts b/backend/src/graphql/resolver/UserResolver.ts index 33fba47a2..3b3ef394c 100644 --- a/backend/src/graphql/resolver/UserResolver.ts +++ b/backend/src/graphql/resolver/UserResolver.ts @@ -7,6 +7,7 @@ import { getConnection, getCustomRepository, QueryRunner } from '@dbTools/typeor import CONFIG from '@/config' import { User } from '@model/User' import { User as DbUser } from '@entity/User' +import { TransactionLink as dbTransactionLink } from '@entity/TransactionLink' import { encode } from '@/auth/JWT' import CreateUserArgs from '@arg/CreateUserArgs' import UnsecureLoginArgs from '@arg/UnsecureLoginArgs' @@ -338,6 +339,12 @@ export class UserResolver { dbUser.language = language dbUser.publisherId = publisherId dbUser.passphrase = passphrase.join(' ') + if (redeemCode) { + const transactionLink = await dbTransactionLink.findOne({ code: redeemCode }) + if (transactionLink) { + dbUser.referrerId = transactionLink.userId + } + } // TODO this field has no null allowed unlike the loginServer table // dbUser.pubKey = Buffer.from(randomBytes(32)) // Buffer.alloc(32, 0) default to 0000... // dbUser.pubkey = keyPair[0] From 67ea4e61f8e39e113a19fa5309a5dfd502d65efe Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Mon, 21 Mar 2022 20:31:12 +0100 Subject: [PATCH 15/54] query linked user email in transaction --- frontend/src/graphql/queries.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/frontend/src/graphql/queries.js b/frontend/src/graphql/queries.js index d330d84f3..60b929c6d 100644 --- a/frontend/src/graphql/queries.js +++ b/frontend/src/graphql/queries.js @@ -67,6 +67,9 @@ export const transactionsQuery = gql` end duration } + linkedUser { + email + } } } } From c38b126635390ce4a04fbbacf1bc8700963985c2 Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Mon, 21 Mar 2022 20:48:18 +0100 Subject: [PATCH 16/54] linked user email as param to /send --- frontend/src/components/TransactionRows/AmountAndNameRow.vue | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/frontend/src/components/TransactionRows/AmountAndNameRow.vue b/frontend/src/components/TransactionRows/AmountAndNameRow.vue index fd9be6bf8..fd54b2761 100644 --- a/frontend/src/components/TransactionRows/AmountAndNameRow.vue +++ b/frontend/src/components/TransactionRows/AmountAndNameRow.vue @@ -10,7 +10,10 @@
- {{ itemText }} + + {{ itemText }} + + {{ itemText }}
From ec354eafad6b17f2db5193853abe880190acf56c Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Mon, 21 Mar 2022 20:52:04 +0100 Subject: [PATCH 17/54] remove error handler --- frontend/src/components/GddTransactionList.spec.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/frontend/src/components/GddTransactionList.spec.js b/frontend/src/components/GddTransactionList.spec.js index 043dd8d54..ba45d93d4 100644 --- a/frontend/src/components/GddTransactionList.spec.js +++ b/frontend/src/components/GddTransactionList.spec.js @@ -3,10 +3,6 @@ import GddTransactionList from './GddTransactionList' const localVue = global.localVue -const errorHandler = jest.fn() - -localVue.config.errorHandler = errorHandler - const scrollToMock = jest.fn() global.scrollTo = scrollToMock From f0132593b8edf36cae04eacf140b7f18a2cdfb44 Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Mon, 21 Mar 2022 21:09:00 +0100 Subject: [PATCH 18/54] test link to send with param email --- .../TransactionRows/AmountAndNameRow.spec.js | 61 +++++++++++++++++++ .../TransactionRows/AmountAndNameRow.vue | 6 +- 2 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 frontend/src/components/TransactionRows/AmountAndNameRow.spec.js diff --git a/frontend/src/components/TransactionRows/AmountAndNameRow.spec.js b/frontend/src/components/TransactionRows/AmountAndNameRow.spec.js new file mode 100644 index 000000000..d221d46f0 --- /dev/null +++ b/frontend/src/components/TransactionRows/AmountAndNameRow.spec.js @@ -0,0 +1,61 @@ +import { mount } from '@vue/test-utils' +import AmountAndNameRow from './AmountAndNameRow' + +const localVue = global.localVue + +const mocks = {} + +const propsData = { + amount: '19.99', + text: 'Some text', +} + +describe('AmountAndNameRow', () => { + let wrapper + + const Wrapper = () => { + return mount(AmountAndNameRow, { localVue, mocks, propsData }) + } + + describe('mount', () => { + beforeEach(() => { + wrapper = Wrapper() + }) + + it('renders the component', () => { + expect(wrapper.find('div.amount-and-name-row').exists()).toBe(true) + }) + + describe('without linked user', () => { + it('has a span with the text', () => { + expect(wrapper.find('div.gdd-transaction-list-item-name').text()).toBe('Some text') + }) + + it('has no link', () => { + expect(wrapper.find('div.gdd-transaction-list-item-name').find('a').exists()).toBe(false) + }) + }) + + describe('with linked user', () => { + beforeEach(async () => { + await wrapper.setProps({ + linkedUser: { firstName: 'Bibi', lastName: 'Bloxberg', email: 'bibi@bloxberg.de' }, + }) + }) + + it('has a link with first and last name', () => { + expect(wrapper.find('div.gdd-transaction-list-item-name').text()).toBe('Bibi Bloxberg') + }) + + it('has a link', () => { + expect(wrapper.find('div.gdd-transaction-list-item-name').find('a').exists()).toBe(true) + }) + + it('links with param email', () => { + expect( + wrapper.find('div.gdd-transaction-list-item-name').find('a').attributes('href'), + ).toBe('/send?email=bibi@bloxberg.de') + }) + }) + }) +}) diff --git a/frontend/src/components/TransactionRows/AmountAndNameRow.vue b/frontend/src/components/TransactionRows/AmountAndNameRow.vue index fd54b2761..0fa82efe9 100644 --- a/frontend/src/components/TransactionRows/AmountAndNameRow.vue +++ b/frontend/src/components/TransactionRows/AmountAndNameRow.vue @@ -10,7 +10,11 @@
- + {{ itemText }} {{ itemText }} From 4675c5679068abafde0e51bdb2252a57a6cbcc1b Mon Sep 17 00:00:00 2001 From: ogerly Date: Mon, 21 Mar 2022 21:38:28 +0100 Subject: [PATCH 19/54] test router.test.js fixed --- frontend/src/routes/router.test.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/frontend/src/routes/router.test.js b/frontend/src/routes/router.test.js index 85f765c69..925b3ffca 100644 --- a/frontend/src/routes/router.test.js +++ b/frontend/src/routes/router.test.js @@ -112,7 +112,7 @@ describe('router', () => { }) describe('thx', () => { - const thx = routes.find((r) => r.path === '/thx/:comingFrom') + const thx = routes.find((r) => r.path === '/thx/:comingFrom/:code?') it('loads the "Thx" page', async () => { const component = await thx.component() @@ -177,7 +177,9 @@ describe('router', () => { describe('checkEmail', () => { it('loads the "CheckEmail" page', async () => { - const component = await routes.find((r) => r.path === '/checkEmail/:optin').component() + const component = await routes + .find((r) => r.path === '/checkEmail/:optin/:code?') + .component() expect(component.default.name).toBe('ResetPassword') }) }) From 4621ee35d11dc2902c2bee00545e2d2b4f5d39ae Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Mon, 21 Mar 2022 21:43:23 +0100 Subject: [PATCH 20/54] use router push to navigate to send --- .../TransactionRows/AmountAndNameRow.spec.js | 21 ++++++++++++++----- .../TransactionRows/AmountAndNameRow.vue | 3 +-- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/frontend/src/components/TransactionRows/AmountAndNameRow.spec.js b/frontend/src/components/TransactionRows/AmountAndNameRow.spec.js index d221d46f0..157aa93af 100644 --- a/frontend/src/components/TransactionRows/AmountAndNameRow.spec.js +++ b/frontend/src/components/TransactionRows/AmountAndNameRow.spec.js @@ -3,7 +3,11 @@ import AmountAndNameRow from './AmountAndNameRow' const localVue = global.localVue -const mocks = {} +const mocks = { + $router: { + push: jest.fn(), + }, +} const propsData = { amount: '19.99', @@ -51,10 +55,17 @@ describe('AmountAndNameRow', () => { expect(wrapper.find('div.gdd-transaction-list-item-name').find('a').exists()).toBe(true) }) - it('links with param email', () => { - expect( - wrapper.find('div.gdd-transaction-list-item-name').find('a').attributes('href'), - ).toBe('/send?email=bibi@bloxberg.de') + describe('click link', () => { + beforeEach(async () => { + await wrapper.find('div.gdd-transaction-list-item-name').find('a').trigger('click') + }) + + it('pushes the rpute with query for email', () => { + expect(mocks.$router.push).toBeCalledWith({ + path: '/send', + query: { email: 'bibi@bloxberg.de' }, + }) + }) }) }) }) diff --git a/frontend/src/components/TransactionRows/AmountAndNameRow.vue b/frontend/src/components/TransactionRows/AmountAndNameRow.vue index 0fa82efe9..f295af26d 100644 --- a/frontend/src/components/TransactionRows/AmountAndNameRow.vue +++ b/frontend/src/components/TransactionRows/AmountAndNameRow.vue @@ -12,8 +12,7 @@
{{ itemText }} From b2d8760f211b755468955692d272e2aed6cae995 Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Mon, 21 Mar 2022 21:44:22 +0100 Subject: [PATCH 21/54] catch email from route query --- frontend/src/components/GddSend/TransactionForm.vue | 3 ++- frontend/src/pages/Send.vue | 6 +++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/frontend/src/components/GddSend/TransactionForm.vue b/frontend/src/components/GddSend/TransactionForm.vue index ec4aff4d3..4f611fbaf 100644 --- a/frontend/src/components/GddSend/TransactionForm.vue +++ b/frontend/src/components/GddSend/TransactionForm.vue @@ -160,13 +160,14 @@ export default { }, props: { balance: { type: Number, default: 0 }, + email: { type: String, default: null }, }, data() { return { amountFocused: false, emailFocused: false, form: { - email: '', + email: this.email ? this.email : '', amount: '', memo: '', amountValue: 0.0, diff --git a/frontend/src/pages/Send.vue b/frontend/src/pages/Send.vue index 89eb1bbe2..c650b96ae 100644 --- a/frontend/src/pages/Send.vue +++ b/frontend/src/pages/Send.vue @@ -3,7 +3,11 @@ @@ -31,6 +32,7 @@ class="list-group-item" v-bind="transactions[index]" :decayStartBlock="decayStartBlock" + v-on="$listeners" /> diff --git a/frontend/src/components/TransactionRows/AmountAndNameRow.spec.js b/frontend/src/components/TransactionRows/AmountAndNameRow.spec.js index 157aa93af..172f5f401 100644 --- a/frontend/src/components/TransactionRows/AmountAndNameRow.spec.js +++ b/frontend/src/components/TransactionRows/AmountAndNameRow.spec.js @@ -60,10 +60,13 @@ describe('AmountAndNameRow', () => { await wrapper.find('div.gdd-transaction-list-item-name').find('a').trigger('click') }) - it('pushes the rpute with query for email', () => { + it('emits set tunneled email', () => { + expect(wrapper.emitted('set-tunneled-email')).toEqual([['bibi@bloxberg.de']]) + }) + + it('pushes the route with query for email', () => { expect(mocks.$router.push).toBeCalledWith({ path: '/send', - query: { email: 'bibi@bloxberg.de' }, }) }) }) diff --git a/frontend/src/components/TransactionRows/AmountAndNameRow.vue b/frontend/src/components/TransactionRows/AmountAndNameRow.vue index f295af26d..be71b57f6 100644 --- a/frontend/src/components/TransactionRows/AmountAndNameRow.vue +++ b/frontend/src/components/TransactionRows/AmountAndNameRow.vue @@ -10,10 +10,7 @@
- + {{ itemText }} {{ itemText }} @@ -39,6 +36,12 @@ export default { required: false, }, }, + methods: { + tunnelEmail() { + this.$emit('set-tunneled-email', this.linkedUser.email) + this.$router.push({ path: '/send' }) + }, + }, computed: { itemText() { return this.linkedUser diff --git a/frontend/src/components/Transactions/TransactionReceive.vue b/frontend/src/components/Transactions/TransactionReceive.vue index eade4a30c..d1947a91a 100644 --- a/frontend/src/components/Transactions/TransactionReceive.vue +++ b/frontend/src/components/Transactions/TransactionReceive.vue @@ -13,7 +13,7 @@ - + diff --git a/frontend/src/components/Transactions/TransactionSend.vue b/frontend/src/components/Transactions/TransactionSend.vue index 8183a5734..dfe50225a 100644 --- a/frontend/src/components/Transactions/TransactionSend.vue +++ b/frontend/src/components/Transactions/TransactionSend.vue @@ -13,7 +13,7 @@ - + diff --git a/frontend/src/layouts/DashboardLayout_gdd.vue b/frontend/src/layouts/DashboardLayout_gdd.vue index 9c7cf9c0c..87ce91dd4 100755 --- a/frontend/src/layouts/DashboardLayout_gdd.vue +++ b/frontend/src/layouts/DashboardLayout_gdd.vue @@ -29,6 +29,7 @@ :decayStartBlock="decayStartBlock" @update-balance="updateBalance" @update-transactions="updateTransactions" + @set-tunneled-email="setTunneledEmail" >
@@ -64,6 +65,12 @@ export default { pending: true, visible: false, decayStartBlock: new Date(), + tunneledEmail: null, + } + }, + provide() { + return { + getTunneledEmail: () => this.tunneledEmail, } }, methods: { @@ -122,6 +129,9 @@ export default { setVisible(bool) { this.visible = bool }, + setTunneledEmail(email) { + this.tunneledEmail = email + }, }, computed: { elopageUri() { diff --git a/frontend/src/pages/Overview.vue b/frontend/src/pages/Overview.vue index 93344b3ee..d42576bf8 100644 --- a/frontend/src/pages/Overview.vue +++ b/frontend/src/pages/Overview.vue @@ -22,6 +22,7 @@ :transaction-count="transactionCount" :transactionLinkCount="transactionLinkCount" @update-transactions="updateTransactions" + v-on="$listeners" />
diff --git a/frontend/src/pages/Send.spec.js b/frontend/src/pages/Send.spec.js index ad1234dd3..93698b801 100644 --- a/frontend/src/pages/Send.spec.js +++ b/frontend/src/pages/Send.spec.js @@ -39,7 +39,16 @@ describe('Send', () => { } const Wrapper = () => { - return mount(Send, { localVue, mocks, propsData }) + return mount(Send, { + localVue, + mocks, + propsData, + provide: { + getTunneledEmail() { + return null + }, + }, + }) } describe('mount', () => { diff --git a/frontend/src/pages/Send.vue b/frontend/src/pages/Send.vue index c650b96ae..a894facc0 100644 --- a/frontend/src/pages/Send.vue +++ b/frontend/src/pages/Send.vue @@ -3,11 +3,7 @@ diff --git a/frontend/src/components/Transactions/TransactionCreation.vue b/frontend/src/components/Transactions/TransactionCreation.vue index bb131d39a..f343a92ac 100644 --- a/frontend/src/components/Transactions/TransactionCreation.vue +++ b/frontend/src/components/Transactions/TransactionCreation.vue @@ -12,7 +12,7 @@ - + From 31dcf30c4608ea1f1cbb3fe65f7e5dcc1f09190b Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Tue, 22 Mar 2022 14:59:24 +0100 Subject: [PATCH 34/54] load provide from dashboard layout, test set tunneled email --- frontend/src/components/GddSend/TransactionForm.spec.js | 7 ++----- frontend/src/layouts/DashboardLayout_gdd.spec.js | 9 +++++++++ frontend/src/pages/Send.spec.js | 7 ++----- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/frontend/src/components/GddSend/TransactionForm.spec.js b/frontend/src/components/GddSend/TransactionForm.spec.js index cf7e1b05e..e4e3d54cf 100644 --- a/frontend/src/components/GddSend/TransactionForm.spec.js +++ b/frontend/src/components/GddSend/TransactionForm.spec.js @@ -1,6 +1,7 @@ import { mount } from '@vue/test-utils' import TransactionForm from './TransactionForm' import flushPromises from 'flush-promises' +import DashboardLayout from '@/layouts/DashboardLayout_gdd.vue' const localVue = global.localVue @@ -29,11 +30,7 @@ describe('TransactionForm', () => { localVue, mocks, propsData, - provide: { - getTunneledEmail() { - return null - }, - }, + provide: DashboardLayout.provide, }) } diff --git a/frontend/src/layouts/DashboardLayout_gdd.spec.js b/frontend/src/layouts/DashboardLayout_gdd.spec.js index 2a8b7bf42..4aa64b90f 100644 --- a/frontend/src/layouts/DashboardLayout_gdd.spec.js +++ b/frontend/src/layouts/DashboardLayout_gdd.spec.js @@ -284,5 +284,14 @@ describe('DashboardLayoutGdd', () => { }) }) }) + + describe('set tunneled email', () => { + it('updates tunneled email', async () => { + await wrapper + .findComponent({ ref: 'router-view' }) + .vm.$emit('set-tunneled-email', 'bibi@bloxberg.de') + expect(wrapper.vm.tunneledEmail).toBe('bibi@bloxberg.de') + }) + }) }) }) diff --git a/frontend/src/pages/Send.spec.js b/frontend/src/pages/Send.spec.js index 93698b801..99b8e6aba 100644 --- a/frontend/src/pages/Send.spec.js +++ b/frontend/src/pages/Send.spec.js @@ -3,6 +3,7 @@ import Send, { SEND_TYPES } from './Send' import { toastErrorSpy, toastSuccessSpy } from '@test/testSetup' import { TRANSACTION_STEPS } from '@/components/GddSend.vue' import { sendCoins, createTransactionLink } from '@/graphql/mutations.js' +import DashboardLayout from '@/layouts/DashboardLayout_gdd.vue' const apolloMutationMock = jest.fn() apolloMutationMock.mockResolvedValue('success') @@ -43,11 +44,7 @@ describe('Send', () => { localVue, mocks, propsData, - provide: { - getTunneledEmail() { - return null - }, - }, + provide: DashboardLayout.provide, }) } From 0a3f80ddc9ee883edf24557030f8cfb2ba1e5b4b Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Tue, 22 Mar 2022 17:53:51 +0100 Subject: [PATCH 35/54] add default properties to restore data when transaction is canceled in confirmation step --- frontend/src/components/GddSend/TransactionForm.vue | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/frontend/src/components/GddSend/TransactionForm.vue b/frontend/src/components/GddSend/TransactionForm.vue index ec4aff4d3..c1acf9925 100644 --- a/frontend/src/components/GddSend/TransactionForm.vue +++ b/frontend/src/components/GddSend/TransactionForm.vue @@ -160,15 +160,18 @@ export default { }, props: { balance: { type: Number, default: 0 }, + email: { type: String, default: '' }, + amount: { type: Number, default: 0 }, + memo: { type: String, default: '' }, }, data() { return { amountFocused: false, emailFocused: false, form: { - email: '', - amount: '', - memo: '', + email: this.email, + amount: this.amount ? String(this.amount) : '', + memo: this.memo, amountValue: 0.0, }, selected: SEND_TYPES.send, From e08e1b7ea8618d675aea2ae23b5ff31616cdecf8 Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Tue, 22 Mar 2022 17:54:55 +0100 Subject: [PATCH 36/54] remove update balance method and event. We want to have the data always from the backend and do no calculation in the frontend --- frontend/src/layouts/DashboardLayout_gdd.spec.js | 8 -------- frontend/src/layouts/DashboardLayout_gdd.vue | 4 ---- 2 files changed, 12 deletions(-) diff --git a/frontend/src/layouts/DashboardLayout_gdd.spec.js b/frontend/src/layouts/DashboardLayout_gdd.spec.js index 2a8b7bf42..fd45b9f05 100644 --- a/frontend/src/layouts/DashboardLayout_gdd.spec.js +++ b/frontend/src/layouts/DashboardLayout_gdd.spec.js @@ -140,14 +140,6 @@ describe('DashboardLayoutGdd', () => { }) }) - describe('update balance', () => { - it('updates the amount correctelly', async () => { - await wrapper.findComponent({ ref: 'router-view' }).vm.$emit('update-balance', 5) - await flushPromises() - expect(wrapper.vm.balance).toBe(-5) - }) - }) - describe('update transactions', () => { beforeEach(async () => { apolloMock.mockResolvedValue({ diff --git a/frontend/src/layouts/DashboardLayout_gdd.vue b/frontend/src/layouts/DashboardLayout_gdd.vue index 9c7cf9c0c..a2a76d88c 100755 --- a/frontend/src/layouts/DashboardLayout_gdd.vue +++ b/frontend/src/layouts/DashboardLayout_gdd.vue @@ -27,7 +27,6 @@ :transactionLinkCount="transactionLinkCount" :pending="pending" :decayStartBlock="decayStartBlock" - @update-balance="updateBalance" @update-transactions="updateTransactions" > @@ -112,9 +111,6 @@ export default { // what to do when loading balance fails? }) }, - updateBalance(ammount) { - this.balance -= ammount - }, admin() { window.location.assign(CONFIG.ADMIN_AUTH_URL.replace('{token}', this.$store.state.token)) this.$store.dispatch('logout') // logout without redirect From 8c8d06d87c5c89f571ef65450ac54c6545b6fb9a Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Tue, 22 Mar 2022 17:56:34 +0100 Subject: [PATCH 37/54] bind the transaction data to the transaction form to allow data restoration after canceling transaction confirmation, use always update transaction to update balance --- frontend/src/pages/Send.vue | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/frontend/src/pages/Send.vue b/frontend/src/pages/Send.vue index bce9a6069..38f232fda 100644 --- a/frontend/src/pages/Send.vue +++ b/frontend/src/pages/Send.vue @@ -3,7 +3,11 @@