test transaction list query to raise coverage

This commit is contained in:
Moriz Wahl 2023-05-08 09:35:14 +02:00
parent c42ee8d264
commit ad4418d297
2 changed files with 54 additions and 15 deletions

View File

@ -20,12 +20,15 @@ import {
login, login,
sendCoins, sendCoins,
} from '@/seeds/graphql/mutations' } from '@/seeds/graphql/mutations'
import { transactionsQuery } from '@/seeds/graphql/queries'
import { bobBaumeister } from '@/seeds/users/bob-baumeister' import { bobBaumeister } from '@/seeds/users/bob-baumeister'
import { garrickOllivander } from '@/seeds/users/garrick-ollivander' import { garrickOllivander } from '@/seeds/users/garrick-ollivander'
import { peterLustig } from '@/seeds/users/peter-lustig' import { peterLustig } from '@/seeds/users/peter-lustig'
import { stephenHawking } from '@/seeds/users/stephen-hawking' import { stephenHawking } from '@/seeds/users/stephen-hawking'
let mutate: ApolloServerTestClient['mutate'], con: Connection let mutate: ApolloServerTestClient['mutate'], con: Connection
let query: ApolloServerTestClient['query']
let testEnv: { let testEnv: {
mutate: ApolloServerTestClient['mutate'] mutate: ApolloServerTestClient['mutate']
query: ApolloServerTestClient['query'] query: ApolloServerTestClient['query']
@ -35,6 +38,7 @@ let testEnv: {
beforeAll(async () => { beforeAll(async () => {
testEnv = await testEnvironment(logger) testEnv = await testEnvironment(logger)
mutate = testEnv.mutate mutate = testEnv.mutate
query = testEnv.query
con = testEnv.con con = testEnv.con
await cleanDB() 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,
})
})
})
})
})

View File

@ -23,31 +23,26 @@ export const queryOptIn = gql`
` `
export const transactionsQuery = gql` export const transactionsQuery = gql`
query ( query ($currentPage: Int = 1, $pageSize: Int = 25, $order: Order = DESC) {
$currentPage: Int = 1 transactionList(currentPage: $currentPage, pageSize: $pageSize, order: $order) {
$pageSize: Int = 25 balance {
$order: Order = DESC balance
$onlyCreations: Boolean = false balanceGDT
) { count
transactionList( linkCount
currentPage: $currentPage }
pageSize: $pageSize
order: $order
onlyCreations: $onlyCreations
) {
balanceGDT
count
balance
transactions { transactions {
id id
typeId typeId
amount amount
balance balance
previousBalance
balanceDate balanceDate
memo memo
linkedUser { linkedUser {
firstName firstName
lastName lastName
gradidoID
} }
decay { decay {
decay decay
@ -55,6 +50,7 @@ export const transactionsQuery = gql`
end end
duration duration
} }
linkId
} }
} }
} }