catch error for not existing users and test this

This commit is contained in:
Ulf Gebhardt 2023-02-27 15:44:14 +01:00
parent dec47d6dc5
commit 5f8702c3c4
Signed by: ulfgebhardt
GPG Key ID: DA6B843E748679C9
2 changed files with 25 additions and 1 deletions

View File

@ -600,6 +600,26 @@ describe('TransactionLinkResolver', () => {
resetToken()
})
describe('', () => {
it('throws error when user does not exists', async () => {
jest.clearAllMocks()
await expect(
mutate({
mutation: listTransactionLinksAdmin,
variables: {
userId: -1,
},
}),
).resolves.toMatchObject({
errors: [new GraphQLError('Could not find requested User')],
})
})
it('logs the error thrown', () => {
expect(logger.error).toBeCalledWith('Could not find requested User', -1)
})
})
describe('without any filters', () => {
it('finds 6 open transaction links and no deleted or redeemed', async () => {
await expect(

View File

@ -346,6 +346,10 @@ export class TransactionLinkResolver {
@Arg('userId', () => Int)
userId: number,
): Promise<TransactionLinkResult> {
return transactionLinkList(paginated, filters, await DbUser.findOneOrFail({ id: userId }))
const user = await DbUser.findOne({ id: userId })
if (!user) {
throw new LogError('Could not find requested User', userId)
}
return transactionLinkList(paginated, filters, user)
}
}