From 311bb50eb8839adc999df346b999b90c5e2ad3dc Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Tue, 18 Apr 2023 16:14:44 +0200 Subject: [PATCH 1/4] refactor(backend): no email in user --- backend/src/graphql/model/User.ts | 14 -------------- backend/src/graphql/resolver/UserResolver.ts | 3 +-- 2 files changed, 1 insertion(+), 16 deletions(-) diff --git a/backend/src/graphql/model/User.ts b/backend/src/graphql/model/User.ts index c705ba912..5abbdadb7 100644 --- a/backend/src/graphql/model/User.ts +++ b/backend/src/graphql/model/User.ts @@ -2,7 +2,6 @@ import { User as dbUser } from '@entity/User' import { ObjectType, Field, Int } from 'type-graphql' import { KlickTipp } from './KlickTipp' -import { UserContact } from './UserContact' @ObjectType() export class User { @@ -10,10 +9,7 @@ export class User { this.id = user.id this.gradidoID = user.gradidoID this.alias = user.alias - this.emailId = user.emailId if (user.emailContact) { - this.email = user.emailContact.email - this.emailContact = new UserContact(user.emailContact) this.emailChecked = user.emailContact.emailChecked } this.firstName = user.firstName @@ -38,16 +34,6 @@ export class User { @Field(() => String, { nullable: true }) alias: string | null - @Field(() => Int, { nullable: true }) - emailId: number | null - - // TODO privacy issue here - @Field(() => String, { nullable: true }) - email: string | null - - @Field(() => UserContact) - emailContact: UserContact - @Field(() => String, { nullable: true }) firstName: string | null diff --git a/backend/src/graphql/resolver/UserResolver.ts b/backend/src/graphql/resolver/UserResolver.ts index 60b4403af..23b3c6aa4 100644 --- a/backend/src/graphql/resolver/UserResolver.ts +++ b/backend/src/graphql/resolver/UserResolver.ts @@ -130,7 +130,7 @@ export class UserResolver { // Elopage Status & Stored PublisherId user.hasElopage = await this.hasElopage(context) - logger.debug(`verifyLogin... successful: ${user.firstName}.${user.lastName}, ${user.email}`) + logger.debug(`verifyLogin... successful: ${user.firstName}.${user.lastName}`) return user } @@ -238,7 +238,6 @@ export class UserResolver { const user = new User(communityDbUser) user.id = sodium.randombytes_random() % (2048 * 16) // TODO: for a better faking derive id from email so that it will be always the same id when the same email comes in? user.gradidoID = uuidv4() - user.email = email user.firstName = firstName user.lastName = lastName user.language = language From 8370b4f27373ef3eb6de5e28554a9d5486063c42 Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Tue, 18 Apr 2023 16:25:02 +0200 Subject: [PATCH 2/4] test user resolver returns no emails --- backend/src/graphql/resolver/UserResolver.test.ts | 5 +---- backend/src/seeds/graphql/mutations.ts | 1 - backend/src/seeds/graphql/queries.ts | 1 - 3 files changed, 1 insertion(+), 6 deletions(-) diff --git a/backend/src/graphql/resolver/UserResolver.test.ts b/backend/src/graphql/resolver/UserResolver.test.ts index 77b08f0d6..f90f0e66c 100644 --- a/backend/src/graphql/resolver/UserResolver.test.ts +++ b/backend/src/graphql/resolver/UserResolver.test.ts @@ -674,7 +674,6 @@ describe('UserResolver', () => { expect.objectContaining({ data: { login: { - email: 'bibi@bloxberg.de', firstName: 'Bibi', hasElopage: false, id: expect.any(Number), @@ -947,7 +946,6 @@ describe('UserResolver', () => { expect.objectContaining({ data: { verifyLogin: { - email: 'bibi@bloxberg.de', firstName: 'Bibi', lastName: 'Bloxberg', language: 'de', @@ -1304,7 +1302,7 @@ describe('UserResolver', () => { expect.objectContaining({ data: { login: expect.objectContaining({ - email: 'bibi@bloxberg.de', + firstName: 'Benjamin', }), }, }), @@ -1451,7 +1449,6 @@ describe('UserResolver', () => { expect.objectContaining({ data: { login: { - email: 'bibi@bloxberg.de', firstName: 'Bibi', hasElopage: false, id: expect.any(Number), diff --git a/backend/src/seeds/graphql/mutations.ts b/backend/src/seeds/graphql/mutations.ts index b0716ff74..7de6fb520 100644 --- a/backend/src/seeds/graphql/mutations.ts +++ b/backend/src/seeds/graphql/mutations.ts @@ -305,7 +305,6 @@ export const login = gql` mutation ($email: String!, $password: String!, $publisherId: Int) { login(email: $email, password: $password, publisherId: $publisherId) { id - email firstName lastName language diff --git a/backend/src/seeds/graphql/queries.ts b/backend/src/seeds/graphql/queries.ts index 8da5211a4..cc1edbc9d 100644 --- a/backend/src/seeds/graphql/queries.ts +++ b/backend/src/seeds/graphql/queries.ts @@ -3,7 +3,6 @@ import { gql } from 'graphql-tag' export const verifyLogin = gql` query { verifyLogin { - email firstName lastName language From ad4418d29784c0d3c75777bdfcfd24e95cad4e96 Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Mon, 8 May 2023 09:35:14 +0200 Subject: [PATCH 3/4] test transaction list query to raise coverage --- .../resolver/TransactionResolver.test.ts | 43 +++++++++++++++++++ backend/src/seeds/graphql/queries.ts | 26 +++++------ 2 files changed, 54 insertions(+), 15 deletions(-) diff --git a/backend/src/graphql/resolver/TransactionResolver.test.ts b/backend/src/graphql/resolver/TransactionResolver.test.ts index 1a2f04838..24fa4e48c 100644 --- a/backend/src/graphql/resolver/TransactionResolver.test.ts +++ b/backend/src/graphql/resolver/TransactionResolver.test.ts @@ -20,12 +20,15 @@ import { login, sendCoins, } from '@/seeds/graphql/mutations' +import { transactionsQuery } from '@/seeds/graphql/queries' import { bobBaumeister } from '@/seeds/users/bob-baumeister' import { garrickOllivander } from '@/seeds/users/garrick-ollivander' import { peterLustig } from '@/seeds/users/peter-lustig' import { stephenHawking } from '@/seeds/users/stephen-hawking' let mutate: ApolloServerTestClient['mutate'], con: Connection +let query: ApolloServerTestClient['query'] + let testEnv: { mutate: ApolloServerTestClient['mutate'] query: ApolloServerTestClient['query'] @@ -35,6 +38,7 @@ let testEnv: { beforeAll(async () => { testEnv = await testEnvironment(logger) mutate = testEnv.mutate + query = testEnv.query con = testEnv.con await cleanDB() }) @@ -442,3 +446,42 @@ describe('send coins', () => { }) }) }) + +describe('transactionList', () => { + describe('unauthenticated', () => { + it('throws an error', async () => { + await expect(query({ query: transactionsQuery })).resolves.toMatchObject({ + errors: [new GraphQLError('401 Unauthorized')], + }) + }) + }) + + describe('authenticated', () => { + describe('no transactions', () => { + beforeAll(async () => { + await userFactory(testEnv, bobBaumeister) + await mutate({ + mutation: login, + variables: { + email: 'bob@baumeister.de', + password: 'Aa12345_', + }, + }) + }) + + it('has no transactions and balance 0', async () => { + await expect(query({ query: transactionsQuery })).resolves.toMatchObject({ + data: { + transactionList: { + balance: expect.objectContaining({ + balance: expect.decimalEqual(0), + }), + transactions: [], + }, + }, + errors: undefined, + }) + }) + }) + }) +}) diff --git a/backend/src/seeds/graphql/queries.ts b/backend/src/seeds/graphql/queries.ts index cc1edbc9d..bc8fa95e8 100644 --- a/backend/src/seeds/graphql/queries.ts +++ b/backend/src/seeds/graphql/queries.ts @@ -23,31 +23,26 @@ export const queryOptIn = gql` ` export const transactionsQuery = gql` - query ( - $currentPage: Int = 1 - $pageSize: Int = 25 - $order: Order = DESC - $onlyCreations: Boolean = false - ) { - transactionList( - currentPage: $currentPage - pageSize: $pageSize - order: $order - onlyCreations: $onlyCreations - ) { - balanceGDT - count - balance + query ($currentPage: Int = 1, $pageSize: Int = 25, $order: Order = DESC) { + transactionList(currentPage: $currentPage, pageSize: $pageSize, order: $order) { + balance { + balance + balanceGDT + count + linkCount + } transactions { id typeId amount balance + previousBalance balanceDate memo linkedUser { firstName lastName + gradidoID } decay { decay @@ -55,6 +50,7 @@ export const transactionsQuery = gql` end duration } + linkId } } } From 9ad3b704df9dc7b51f4231401caff3f7d71e4433 Mon Sep 17 00:00:00 2001 From: mahula Date: Mon, 8 May 2023 12:10:43 +0200 Subject: [PATCH 4/4] adapt cypress env loginQuery to changes in backend --- e2e-tests/cypress.config.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/e2e-tests/cypress.config.ts b/e2e-tests/cypress.config.ts index 7205ef9cb..e26259626 100644 --- a/e2e-tests/cypress.config.ts +++ b/e2e-tests/cypress.config.ts @@ -58,7 +58,7 @@ export default defineConfig({ mailserverURL: 'http://localhost:1080', loginQuery: `mutation ($email: String!, $password: String!, $publisherId: Int) { login(email: $email, password: $password, publisherId: $publisherId) { - email + id firstName lastName language