rework PR-comments

This commit is contained in:
Claus-Peter Hübner 2022-06-23 02:42:20 +02:00
parent 59ef2ea5d8
commit 47772a37b2
2 changed files with 12 additions and 46 deletions

View File

@ -1807,9 +1807,7 @@ describe('AdminResolver', () => {
}),
)
})
})
describe('createContributionLink', () => {
it('returns an error if missing startDate', async () => {
await expect(
mutate({
@ -1827,9 +1825,7 @@ describe('AdminResolver', () => {
}),
)
})
})
describe('createContributionLink', () => {
it('returns an error if missing endDate', async () => {
await expect(
mutate({
@ -1845,9 +1841,7 @@ describe('AdminResolver', () => {
}),
)
})
})
describe('createContributionLink', () => {
it('returns an error if endDate is before startDate', async () => {
await expect(
mutate({
@ -1861,16 +1855,12 @@ describe('AdminResolver', () => {
).resolves.toEqual(
expect.objectContaining({
errors: [
new GraphQLError(
`The validFrom=2022-06-18T00:00:00.001Z must be before or equals the validTo=2022-06-18T00:00:00.000Z!`,
),
new GraphQLError(`The value of validFrom must before or equals the validTo!`),
],
}),
)
})
})
describe('createContributionLink', () => {
it('returns an error if name is an empty string', async () => {
await expect(
mutate({
@ -1886,9 +1876,7 @@ describe('AdminResolver', () => {
}),
)
})
})
describe('createContributionLink', () => {
it('returns an error if name is shorter than 5 characters', async () => {
await expect(
mutate({
@ -1902,15 +1890,13 @@ describe('AdminResolver', () => {
expect.objectContaining({
errors: [
new GraphQLError(
'The name=123 with a length of 3 did not fulfill the requested bounderies min=5 and max=100',
`The value of 'name' with a length of 3 did not fulfill the requested bounderies min=5 and max=100`,
),
],
}),
)
})
})
describe('createContributionLink', () => {
it('returns an error if name is longer than 100 characters', async () => {
await expect(
mutate({
@ -1924,15 +1910,13 @@ describe('AdminResolver', () => {
expect.objectContaining({
errors: [
new GraphQLError(
'The name=12345678901234567892123456789312345678941234567895123456789612345678971234567898123456789912345678901 with a length of 101 did not fulfill the requested bounderies min=5 and max=100',
`The value of 'name' with a length of 101 did not fulfill the requested bounderies min=5 and max=100`,
),
],
}),
)
})
})
describe('createContributionLink', () => {
it('returns an error if memo is an empty string', async () => {
await expect(
mutate({
@ -1948,9 +1932,7 @@ describe('AdminResolver', () => {
}),
)
})
})
describe('createContributionLink', () => {
it('returns an error if memo is shorter than 5 characters', async () => {
await expect(
mutate({
@ -1964,15 +1946,13 @@ describe('AdminResolver', () => {
expect.objectContaining({
errors: [
new GraphQLError(
'The memo=123 with a length of 3 did not fulfill the requested bounderies min=5 and max=255',
`The value of 'memo' with a length of 3 did not fulfill the requested bounderies min=5 and max=255`,
),
],
}),
)
})
})
describe('createContributionLink', () => {
it('returns an error if memo is longer than 255 characters', async () => {
await expect(
mutate({
@ -1986,15 +1966,13 @@ describe('AdminResolver', () => {
expect.objectContaining({
errors: [
new GraphQLError(
'The memo=1234567890123456789212345678931234567894123456789512345678961234567897123456789812345678991234567890123456789012345678921234567893123456789412345678951234567896123456789712345678981234567899123456789012345678901234567892123456789312345678941234567895123456 with a length of 256 did not fulfill the requested bounderies min=5 and max=255',
`The value of 'memo' with a length of 256 did not fulfill the requested bounderies min=5 and max=255`,
),
],
}),
)
})
})
describe('createContributionLink', () => {
it('returns an error if amount is not positive', async () => {
await expect(
mutate({

View File

@ -179,7 +179,6 @@ export class AdminResolver {
@Args() { email, amount, memo, creationDate }: AdminCreateContributionArgs,
@Ctx() context: Context,
): Promise<Decimal[]> {
logger.trace('adminCreateContribution...')
const user = await dbUser.findOne({ email }, { withDeleted: true })
if (!user) {
throw new Error(`Could not find user with email: ${email}`)
@ -520,13 +519,7 @@ export class AdminResolver {
maxPerCycle,
}: ContributionLinkArgs,
): Promise<ContributionLink> {
logger.debug(
`createContributionLink(validFrom=${validFrom}, validTo=${validTo}, name=${name}, amount=${amount}, memo=${memo}, cycle=${cycle}, maxPerCycle=${maxPerCycle}, maxAmountPerMonth=${maxAmountPerMonth})...`,
)
if (!isStartEndDateValid(validFrom, validTo)) {
logger.error(`The validFrom=${validFrom} must be before or equals the validTo=${validTo}!`)
throw new Error(`The validFrom=${validFrom} must be before or equals the validTo=${validTo}!`)
}
isStartEndDateValid(validFrom, validTo)
if (!name) {
logger.error(`The name must be initialized!`)
throw new Error(`The name must be initialized!`)
@ -535,7 +528,7 @@ export class AdminResolver {
name.length < CONTRIBUTIONLINK_NAME_MIN_CHARS ||
name.length > CONTRIBUTIONLINK_NAME_MAX_CHARS
) {
const msg = `The name=${name} with a length of ${name.length} did not fulfill the requested bounderies min=${CONTRIBUTIONLINK_NAME_MIN_CHARS} and max=${CONTRIBUTIONLINK_NAME_MAX_CHARS}`
const msg = `The value of 'name' with a length of ${name.length} did not fulfill the requested bounderies min=${CONTRIBUTIONLINK_NAME_MIN_CHARS} and max=${CONTRIBUTIONLINK_NAME_MAX_CHARS}`
logger.error(`${msg}`)
throw new Error(`${msg}`)
}
@ -547,7 +540,7 @@ export class AdminResolver {
memo.length < CONTRIBUTIONLINK_MEMO_MIN_CHARS ||
memo.length > CONTRIBUTIONLINK_MEMO_MAX_CHARS
) {
const msg = `The memo=${memo} with a length of ${memo.length} did not fulfill the requested bounderies min=${CONTRIBUTIONLINK_MEMO_MIN_CHARS} and max=${CONTRIBUTIONLINK_MEMO_MAX_CHARS}`
const msg = `The value of 'memo' with a length of ${memo.length} did not fulfill the requested bounderies min=${CONTRIBUTIONLINK_MEMO_MIN_CHARS} and max=${CONTRIBUTIONLINK_MEMO_MAX_CHARS}`
logger.error(`${msg}`)
throw new Error(`${msg}`)
}
@ -581,7 +574,6 @@ export class AdminResolver {
@Args()
{ currentPage = 1, pageSize = 5, order = Order.DESC }: Paginated,
): Promise<ContributionLinkList> {
logger.debug('listContributionLinks()...')
const [links, count] = await DbContributionLink.findAndCount({
order: { createdAt: order },
skip: (currentPage - 1) * pageSize,
@ -596,7 +588,6 @@ export class AdminResolver {
@Authorized([RIGHTS.DELETE_CONTRIBUTION_LINK])
@Mutation(() => Date, { nullable: true })
async deleteContributionLink(@Arg('id', () => Int) id: number): Promise<Date | null> {
logger.debug(`deleteContributionLink(id=${id})`)
const contributionLink = await DbContributionLink.findOne(id)
if (!contributionLink) {
logger.error(`Contribution Link not found to given id: ${id}`)
@ -624,9 +615,6 @@ export class AdminResolver {
}: ContributionLinkArgs,
@Arg('id', () => Int) id: number,
): Promise<ContributionLink> {
logger.debug(
`updateContributionLink(id=${id}, amount=${amount}, name=${name}, memo=${memo}, cycle=${cycle}, validFrom=${validFrom}, validTo=${validTo}, maxAmountPerMonth=${maxAmountPerMonth}, maxPerCycle=${maxPerCycle})...`,
)
const dbContributionLink = await DbContributionLink.findOne(id)
if (!dbContributionLink) {
logger.error(`Contribution Link not found to given id: ${id}`)
@ -735,10 +723,10 @@ export const isContributionValid = (
return true
}
function isStartEndDateValid(
const isStartEndDateValid = (
startDate: string | null | undefined,
endDate: string | null | undefined,
) {
): void => {
if (!startDate) {
logger.error('Start-Date is not initialized. A Start-Date must be set!')
throw new Error('Start-Date is not initialized. A Start-Date must be set!')
@ -751,9 +739,9 @@ function isStartEndDateValid(
// check if endDate is before startDate
if (new Date(endDate).getTime() - new Date(startDate).getTime() < 0) {
return false
logger.error(`The value of validFrom must before or equals the validTo!`)
throw new Error(`The value of validFrom must before or equals the validTo!`)
}
return true
}
const getCreationMonths = (): number[] => {