From ad4418d29784c0d3c75777bdfcfd24e95cad4e96 Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Mon, 8 May 2023 09:35:14 +0200 Subject: [PATCH] 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 } } }