From 381b96a81221f3da0d798f99bd83d722b007b220 Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Thu, 30 Mar 2023 16:24:24 +0200 Subject: [PATCH 01/19] removed obsolete yarn cron docu --- deployment/bare_metal/setup.md | 36 ---------------------------------- 1 file changed, 36 deletions(-) diff --git a/deployment/bare_metal/setup.md b/deployment/bare_metal/setup.md index 627aa4a2d..b1204b1b3 100644 --- a/deployment/bare_metal/setup.md +++ b/deployment/bare_metal/setup.md @@ -196,42 +196,6 @@ Use it as pattern to do all steps manually in your terminal shell. Follow the commands in `./install.sh` as installation pattern. -## Define Cronjob To Compensate Yarn Output In `/tmp` - -`yarn` creates output in `/tmp` directory, which must be deleted regularly and will be done per Cron-Job. - -### On `stage1` - -An hourly job is necessary on `stage1` by setting the following job in the `crontab` for the `gradido` user. - -Run: - -```bash -crontab -e -``` - -This opens the crontab in edit-mode and insert the following entry: - -```bash -0 * * * * find /tmp -name "yarn--*" -cmin +60 -exec rm -r {} \; > /dev/null -``` - -### On `stage2` - -A daily job is necessary on `stage2` by setting the following job in the `crontab` for the `gradido` user. - -Run: - -```bash -crontab -e -``` - -This opens the `crontab` in edit-mode and insert the following entry: - -```bash -0 4 * * * find /tmp -name "yarn--*" -ctime +1 -exec rm -r {} \; > /dev/null -``` - ## Define Cronjob To start backup script automatically At least at production stage we need a daily backup of our database. This can be done by adding a cronjob From 0db94ea58865ed5f78e6bf8011ad2a9919d38a73 Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Wed, 5 Apr 2023 03:58:55 +0200 Subject: [PATCH 02/19] lint jest only for test files --- backend/.eslintrc.js | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/backend/.eslintrc.js b/backend/.eslintrc.js index 7c1fa8c93..1d7905058 100644 --- a/backend/.eslintrc.js +++ b/backend/.eslintrc.js @@ -5,7 +5,7 @@ module.exports = { node: true, }, parser: '@typescript-eslint/parser', - plugins: ['prettier', '@typescript-eslint', 'type-graphql', 'jest', 'import', 'n'], + plugins: ['prettier', '@typescript-eslint', 'type-graphql', 'import', 'n'], extends: [ 'standard', 'eslint:recommended', @@ -33,12 +33,6 @@ module.exports = { htmlWhitespaceSensitivity: 'ignore', }, ], - // jest - 'jest/no-disabled-tests': 'error', - 'jest/no-focused-tests': 'error', - 'jest/no-identical-title': 'error', - 'jest/prefer-to-have-length': 'error', - 'jest/valid-expect': 'error', // import 'import/export': 'error', 'import/no-deprecated': 'error', @@ -168,5 +162,18 @@ module.exports = { EXPERIMENTAL_useSourceOfProjectReferenceRedirect: true, }, }, + { + files: ['*.test.ts'], + plugins: ['jest'], + rules: { + 'jest/no-disabled-tests': 'error', + 'jest/no-focused-tests': 'error', + 'jest/no-identical-title': 'error', + 'jest/prefer-to-have-length': 'error', + 'jest/valid-expect': 'error', + '@typescript-eslint/unbound-method': 'off', + 'jest/unbound-method': 'error', + }, + }, ], } From fc887b9ad69012f84eb1050bce14884c9105f146 Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Wed, 5 Apr 2023 03:59:16 +0200 Subject: [PATCH 03/19] remove unound-method ignore --- backend/src/emails/sendEmailTranslated.test.ts | 1 - backend/src/federation/validateCommunities.test.ts | 1 - backend/src/graphql/resolver/CommunityResolver.test.ts | 1 - backend/src/graphql/resolver/ContributionLinkResolver.test.ts | 1 - backend/src/graphql/resolver/ContributionMessageResolver.test.ts | 1 - backend/src/graphql/resolver/ContributionResolver.test.ts | 1 - backend/src/graphql/resolver/TransactionLinkResolver.test.ts | 1 - backend/src/graphql/resolver/TransactionResolver.test.ts | 1 - backend/src/graphql/resolver/UserResolver.test.ts | 1 - backend/src/server/LogError.test.ts | 1 - 10 files changed, 10 deletions(-) diff --git a/backend/src/emails/sendEmailTranslated.test.ts b/backend/src/emails/sendEmailTranslated.test.ts index 85074344a..90e6515b7 100644 --- a/backend/src/emails/sendEmailTranslated.test.ts +++ b/backend/src/emails/sendEmailTranslated.test.ts @@ -1,5 +1,4 @@ /* eslint-disable @typescript-eslint/no-unsafe-assignment */ -/* eslint-disable @typescript-eslint/unbound-method */ import { createTransport } from 'nodemailer' import { logger, i18n } from '@test/testSetup' diff --git a/backend/src/federation/validateCommunities.test.ts b/backend/src/federation/validateCommunities.test.ts index d90664b63..7819e77bc 100644 --- a/backend/src/federation/validateCommunities.test.ts +++ b/backend/src/federation/validateCommunities.test.ts @@ -1,5 +1,4 @@ /* eslint-disable @typescript-eslint/no-unsafe-member-access */ -/* eslint-disable @typescript-eslint/unbound-method */ /* eslint-disable @typescript-eslint/no-unsafe-assignment */ /* eslint-disable @typescript-eslint/no-unsafe-call */ /* eslint-disable @typescript-eslint/no-explicit-any */ diff --git a/backend/src/graphql/resolver/CommunityResolver.test.ts b/backend/src/graphql/resolver/CommunityResolver.test.ts index 5b4b26cad..a73917412 100644 --- a/backend/src/graphql/resolver/CommunityResolver.test.ts +++ b/backend/src/graphql/resolver/CommunityResolver.test.ts @@ -1,7 +1,6 @@ /* eslint-disable @typescript-eslint/no-unsafe-assignment */ /* eslint-disable @typescript-eslint/no-unsafe-call */ /* eslint-disable @typescript-eslint/no-unsafe-member-access */ -/* eslint-disable @typescript-eslint/unbound-method */ /* eslint-disable @typescript-eslint/no-explicit-any */ /* eslint-disable @typescript-eslint/explicit-module-boundary-types */ diff --git a/backend/src/graphql/resolver/ContributionLinkResolver.test.ts b/backend/src/graphql/resolver/ContributionLinkResolver.test.ts index d37e60111..977c9c517 100644 --- a/backend/src/graphql/resolver/ContributionLinkResolver.test.ts +++ b/backend/src/graphql/resolver/ContributionLinkResolver.test.ts @@ -1,5 +1,4 @@ /* eslint-disable @typescript-eslint/no-unsafe-call */ -/* eslint-disable @typescript-eslint/unbound-method */ /* eslint-disable @typescript-eslint/no-unsafe-assignment */ /* eslint-disable @typescript-eslint/no-unsafe-member-access */ /* eslint-disable @typescript-eslint/no-explicit-any */ diff --git a/backend/src/graphql/resolver/ContributionMessageResolver.test.ts b/backend/src/graphql/resolver/ContributionMessageResolver.test.ts index 1d6f3f9e0..8d83b9164 100644 --- a/backend/src/graphql/resolver/ContributionMessageResolver.test.ts +++ b/backend/src/graphql/resolver/ContributionMessageResolver.test.ts @@ -1,6 +1,5 @@ /* eslint-disable @typescript-eslint/no-unsafe-call */ /* eslint-disable @typescript-eslint/no-unsafe-member-access */ -/* eslint-disable @typescript-eslint/unbound-method */ /* eslint-disable @typescript-eslint/no-unsafe-return */ /* eslint-disable @typescript-eslint/no-unsafe-assignment */ /* eslint-disable @typescript-eslint/no-explicit-any */ diff --git a/backend/src/graphql/resolver/ContributionResolver.test.ts b/backend/src/graphql/resolver/ContributionResolver.test.ts index 88a62b656..60b31bc02 100644 --- a/backend/src/graphql/resolver/ContributionResolver.test.ts +++ b/backend/src/graphql/resolver/ContributionResolver.test.ts @@ -1,7 +1,6 @@ /* eslint-disable @typescript-eslint/no-unsafe-assignment */ /* eslint-disable @typescript-eslint/no-unsafe-call */ /* eslint-disable @typescript-eslint/no-unsafe-member-access */ -/* eslint-disable @typescript-eslint/unbound-method */ /* eslint-disable @typescript-eslint/no-unsafe-return */ /* eslint-disable @typescript-eslint/no-explicit-any */ /* eslint-disable @typescript-eslint/explicit-module-boundary-types */ diff --git a/backend/src/graphql/resolver/TransactionLinkResolver.test.ts b/backend/src/graphql/resolver/TransactionLinkResolver.test.ts index a510fc94f..b860f97a0 100644 --- a/backend/src/graphql/resolver/TransactionLinkResolver.test.ts +++ b/backend/src/graphql/resolver/TransactionLinkResolver.test.ts @@ -2,7 +2,6 @@ /* eslint-disable @typescript-eslint/no-unsafe-member-access */ /* eslint-disable @typescript-eslint/no-unsafe-assignment */ /* eslint-disable @typescript-eslint/restrict-template-expressions */ -/* eslint-disable @typescript-eslint/unbound-method */ /* eslint-disable @typescript-eslint/no-explicit-any */ /* eslint-disable @typescript-eslint/explicit-module-boundary-types */ /* eslint-disable @typescript-eslint/no-unsafe-argument */ diff --git a/backend/src/graphql/resolver/TransactionResolver.test.ts b/backend/src/graphql/resolver/TransactionResolver.test.ts index 9aeb56008..5b16a37ab 100644 --- a/backend/src/graphql/resolver/TransactionResolver.test.ts +++ b/backend/src/graphql/resolver/TransactionResolver.test.ts @@ -1,7 +1,6 @@ /* eslint-disable @typescript-eslint/no-unsafe-call */ /* eslint-disable @typescript-eslint/no-unsafe-member-access */ /* eslint-disable @typescript-eslint/no-unsafe-assignment */ -/* eslint-disable @typescript-eslint/unbound-method */ /* eslint-disable @typescript-eslint/no-explicit-any */ /* eslint-disable @typescript-eslint/explicit-module-boundary-types */ /* eslint-disable @typescript-eslint/no-unsafe-argument */ diff --git a/backend/src/graphql/resolver/UserResolver.test.ts b/backend/src/graphql/resolver/UserResolver.test.ts index 9c25eec31..89f26a502 100644 --- a/backend/src/graphql/resolver/UserResolver.test.ts +++ b/backend/src/graphql/resolver/UserResolver.test.ts @@ -2,7 +2,6 @@ /* eslint-disable @typescript-eslint/no-unsafe-member-access */ /* eslint-disable @typescript-eslint/no-unsafe-assignment */ /* eslint-disable @typescript-eslint/no-unsafe-return */ -/* eslint-disable @typescript-eslint/unbound-method */ /* eslint-disable @typescript-eslint/no-explicit-any */ /* eslint-disable @typescript-eslint/explicit-module-boundary-types */ /* eslint-disable @typescript-eslint/no-unsafe-argument */ diff --git a/backend/src/server/LogError.test.ts b/backend/src/server/LogError.test.ts index 5aa1cae21..3a557061f 100644 --- a/backend/src/server/LogError.test.ts +++ b/backend/src/server/LogError.test.ts @@ -1,5 +1,4 @@ /* eslint-disable @typescript-eslint/no-unsafe-member-access */ -/* eslint-disable @typescript-eslint/unbound-method */ import { logger } from '@test/testSetup' import LogError from './LogError' From c65279269bef4612cbf304e5736131c5335b4f5f Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Wed, 5 Apr 2023 04:50:33 +0200 Subject: [PATCH 04/19] have tests more typesafe --- backend/src/emails/sendEmailVariants.test.ts | 11 +- .../federation/validateCommunities.test.ts | 16 +-- .../resolver/CommunityResolver.test.ts | 17 ++- .../resolver/ContributionLinkResolver.test.ts | 16 ++- .../ContributionMessageResolver.test.ts | 12 +- .../resolver/ContributionResolver.test.ts | 106 +++++++++--------- .../graphql/resolver/EmailOptinCodes.test.ts | 16 ++- .../resolver/TransactionLinkResolver.test.ts | 16 ++- .../resolver/TransactionResolver.test.ts | 20 ++-- .../src/graphql/resolver/UserResolver.test.ts | 17 ++- .../src/graphql/resolver/semaphore.test.ts | 13 ++- .../graphql/resolver/util/creations.test.ts | 16 +-- 12 files changed, 155 insertions(+), 121 deletions(-) diff --git a/backend/src/emails/sendEmailVariants.test.ts b/backend/src/emails/sendEmailVariants.test.ts index 44d996fa8..1b8be027d 100644 --- a/backend/src/emails/sendEmailVariants.test.ts +++ b/backend/src/emails/sendEmailVariants.test.ts @@ -1,8 +1,9 @@ /* eslint-disable @typescript-eslint/no-unsafe-member-access */ -/* eslint-disable @typescript-eslint/no-explicit-any */ /* eslint-disable @typescript-eslint/no-unsafe-return */ /* eslint-disable @typescript-eslint/no-unsafe-call */ /* eslint-disable @typescript-eslint/no-unsafe-assignment */ +import { Connection } from '@dbTools/typeorm' +import { ApolloServerTestClient } from 'apollo-server-testing' import { Decimal } from 'decimal.js-light' import { testEnvironment } from '@test/helpers' @@ -23,8 +24,12 @@ import { sendTransactionReceivedEmail, } from './sendEmailVariants' -let con: any -let testEnv: any +let con: Connection +let testEnv: { + mutate: ApolloServerTestClient['mutate'] + query: ApolloServerTestClient['query'] + con: Connection +} beforeAll(async () => { testEnv = await testEnvironment(logger, localization) diff --git a/backend/src/federation/validateCommunities.test.ts b/backend/src/federation/validateCommunities.test.ts index 7819e77bc..ab426b603 100644 --- a/backend/src/federation/validateCommunities.test.ts +++ b/backend/src/federation/validateCommunities.test.ts @@ -1,18 +1,18 @@ -/* eslint-disable @typescript-eslint/no-unsafe-member-access */ -/* eslint-disable @typescript-eslint/no-unsafe-assignment */ -/* eslint-disable @typescript-eslint/no-unsafe-call */ -/* eslint-disable @typescript-eslint/no-explicit-any */ -/* eslint-disable @typescript-eslint/explicit-module-boundary-types */ - +import { Connection } from '@dbTools/typeorm' import { Community as DbCommunity } from '@entity/Community' +import { ApolloServerTestClient } from 'apollo-server-testing' import { testEnvironment, cleanDB } from '@test/helpers' import { logger } from '@test/testSetup' import { validateCommunities } from './validateCommunities' -let con: any -let testEnv: any +let con: Connection +let testEnv: { + mutate: ApolloServerTestClient['mutate'] + query: ApolloServerTestClient['query'] + con: Connection +} beforeAll(async () => { testEnv = await testEnvironment(logger) diff --git a/backend/src/graphql/resolver/CommunityResolver.test.ts b/backend/src/graphql/resolver/CommunityResolver.test.ts index a73917412..f50fafc05 100644 --- a/backend/src/graphql/resolver/CommunityResolver.test.ts +++ b/backend/src/graphql/resolver/CommunityResolver.test.ts @@ -1,20 +1,19 @@ /* eslint-disable @typescript-eslint/no-unsafe-assignment */ -/* eslint-disable @typescript-eslint/no-unsafe-call */ -/* eslint-disable @typescript-eslint/no-unsafe-member-access */ -/* eslint-disable @typescript-eslint/no-explicit-any */ -/* eslint-disable @typescript-eslint/explicit-module-boundary-types */ - +import { Connection } from '@dbTools/typeorm' import { Community as DbCommunity } from '@entity/Community' +import { ApolloServerTestClient } from 'apollo-server-testing' import { testEnvironment } from '@test/helpers' import { getCommunities } from '@/seeds/graphql/queries' -let query: any - // to do: We need a setup for the tests that closes the connection -let con: any -let testEnv: any +let query: ApolloServerTestClient['query'], con: Connection +let testEnv: { + mutate: ApolloServerTestClient['mutate'] + query: ApolloServerTestClient['query'] + con: Connection +} beforeAll(async () => { testEnv = await testEnvironment() diff --git a/backend/src/graphql/resolver/ContributionLinkResolver.test.ts b/backend/src/graphql/resolver/ContributionLinkResolver.test.ts index 977c9c517..627ddbd56 100644 --- a/backend/src/graphql/resolver/ContributionLinkResolver.test.ts +++ b/backend/src/graphql/resolver/ContributionLinkResolver.test.ts @@ -1,11 +1,9 @@ -/* eslint-disable @typescript-eslint/no-unsafe-call */ /* eslint-disable @typescript-eslint/no-unsafe-assignment */ /* eslint-disable @typescript-eslint/no-unsafe-member-access */ -/* eslint-disable @typescript-eslint/no-explicit-any */ -/* eslint-disable @typescript-eslint/no-unsafe-argument */ - +import { Connection } from '@dbTools/typeorm' import { ContributionLink as DbContributionLink } from '@entity/ContributionLink' import { Event as DbEvent } from '@entity/Event' +import { ApolloServerTestClient } from 'apollo-server-testing' import { Decimal } from 'decimal.js-light' import { GraphQLError } from 'graphql' @@ -24,8 +22,14 @@ import { listContributionLinks } from '@/seeds/graphql/queries' import { bibiBloxberg } from '@/seeds/users/bibi-bloxberg' import { peterLustig } from '@/seeds/users/peter-lustig' -let mutate: any, query: any, con: any -let testEnv: any +let mutate: ApolloServerTestClient['mutate'], + query: ApolloServerTestClient['query'], + con: Connection +let testEnv: { + mutate: ApolloServerTestClient['mutate'] + query: ApolloServerTestClient['query'] + con: Connection +} beforeAll(async () => { testEnv = await testEnvironment() diff --git a/backend/src/graphql/resolver/ContributionMessageResolver.test.ts b/backend/src/graphql/resolver/ContributionMessageResolver.test.ts index 8d83b9164..5534064c4 100644 --- a/backend/src/graphql/resolver/ContributionMessageResolver.test.ts +++ b/backend/src/graphql/resolver/ContributionMessageResolver.test.ts @@ -3,9 +3,9 @@ /* eslint-disable @typescript-eslint/no-unsafe-return */ /* eslint-disable @typescript-eslint/no-unsafe-assignment */ /* eslint-disable @typescript-eslint/no-explicit-any */ -/* eslint-disable @typescript-eslint/explicit-module-boundary-types */ -/* eslint-disable @typescript-eslint/no-unsafe-argument */ +import { Connection } from '@dbTools/typeorm' import { Event as DbEvent } from '@entity/Event' +import { ApolloServerTestClient } from 'apollo-server-testing' import { GraphQLError } from 'graphql' import { cleanDB, resetToken, testEnvironment } from '@test/helpers' @@ -35,8 +35,12 @@ jest.mock('@/emails/sendEmailVariants', () => { } }) -let mutate: any, con: any -let testEnv: any +let mutate: ApolloServerTestClient['mutate'], con: Connection +let testEnv: { + mutate: ApolloServerTestClient['mutate'] + query: ApolloServerTestClient['query'] + con: Connection +} let result: any beforeAll(async () => { diff --git a/backend/src/graphql/resolver/ContributionResolver.test.ts b/backend/src/graphql/resolver/ContributionResolver.test.ts index 60b31bc02..c6dc03843 100644 --- a/backend/src/graphql/resolver/ContributionResolver.test.ts +++ b/backend/src/graphql/resolver/ContributionResolver.test.ts @@ -1,22 +1,18 @@ /* eslint-disable @typescript-eslint/no-unsafe-assignment */ -/* eslint-disable @typescript-eslint/no-unsafe-call */ /* eslint-disable @typescript-eslint/no-unsafe-member-access */ -/* eslint-disable @typescript-eslint/no-unsafe-return */ /* eslint-disable @typescript-eslint/no-explicit-any */ -/* eslint-disable @typescript-eslint/explicit-module-boundary-types */ -/* eslint-disable @typescript-eslint/no-unsafe-argument */ +import { Connection } from '@dbTools/typeorm' import { Contribution } from '@entity/Contribution' import { Event as DbEvent } from '@entity/Event' import { Transaction as DbTransaction } from '@entity/Transaction' import { User } from '@entity/User' import { UserInputError } from 'apollo-server-express' +import { ApolloServerTestClient } from 'apollo-server-testing' import { Decimal } from 'decimal.js-light' import { GraphQLError } from 'graphql' import { ContributionStatus } from '@enum/ContributionStatus' import { Order } from '@enum/Order' -import { ContributionListResult } from '@model/Contribution' -import { UnconfirmedContribution } from '@model/UnconfirmedContribution' import { cleanDB, resetToken, @@ -62,8 +58,14 @@ import { stephenHawking } from '@/seeds/users/stephen-hawking' jest.mock('@/emails/sendEmailVariants') -let mutate: any, query: any, con: any -let testEnv: any +let mutate: ApolloServerTestClient['mutate'], + query: ApolloServerTestClient['query'], + con: Connection +let testEnv: { + mutate: ApolloServerTestClient['mutate'] + query: ApolloServerTestClient['query'] + con: Connection +} let creation: Contribution | void let admin: User let pendingContribution: any @@ -165,7 +167,7 @@ describe('ContributionResolver', () => { describe('createContribution', () => { describe('unauthenticated', () => { it('returns an error', async () => { - const { errors: errorObjects }: { errors: [GraphQLError] } = await mutate({ + const { errors: errorObjects } = await mutate({ mutation: createContribution, variables: { amount: 100.0, memo: 'Test Contribution', creationDate: 'not-valid' }, }) @@ -190,7 +192,7 @@ describe('ContributionResolver', () => { it('throws error when memo length smaller than 5 chars', async () => { jest.clearAllMocks() const date = new Date() - const { errors: errorObjects }: { errors: [GraphQLError] } = await mutate({ + const { errors: errorObjects } = await mutate({ mutation: createContribution, variables: { amount: 100.0, @@ -209,7 +211,7 @@ describe('ContributionResolver', () => { it('throws error when memo length greater than 255 chars', async () => { jest.clearAllMocks() const date = new Date() - const { errors: errorObjects }: { errors: [GraphQLError] } = await mutate({ + const { errors: errorObjects } = await mutate({ mutation: createContribution, variables: { amount: 100.0, @@ -226,7 +228,7 @@ describe('ContributionResolver', () => { it('throws error when creationDate not-valid', async () => { jest.clearAllMocks() - const { errors: errorObjects }: { errors: [GraphQLError] } = await mutate({ + const { errors: errorObjects } = await mutate({ mutation: createContribution, variables: { amount: 100.0, @@ -249,7 +251,7 @@ describe('ContributionResolver', () => { it('throws error when creationDate 3 month behind', async () => { jest.clearAllMocks() const date = new Date() - const { errors: errorObjects }: { errors: [GraphQLError] } = await mutate({ + const { errors: errorObjects } = await mutate({ mutation: createContribution, variables: { amount: 100.0, @@ -297,7 +299,7 @@ describe('ContributionResolver', () => { describe('updateContribution', () => { describe('unauthenticated', () => { it('returns an error', async () => { - const { errors: errorObjects }: { errors: [GraphQLError] } = await mutate({ + const { errors: errorObjects } = await mutate({ mutation: updateContribution, variables: { contributionId: 1, @@ -326,7 +328,7 @@ describe('ContributionResolver', () => { it('throws error', async () => { jest.clearAllMocks() const date = new Date() - const { errors: errorObjects }: { errors: [GraphQLError] } = await mutate({ + const { errors: errorObjects } = await mutate({ mutation: updateContribution, variables: { contributionId: pendingContribution.data.createContribution.id, @@ -347,7 +349,7 @@ describe('ContributionResolver', () => { it('throws error', async () => { jest.clearAllMocks() const date = new Date() - const { errors: errorObjects }: { errors: [GraphQLError] } = await mutate({ + const { errors: errorObjects } = await mutate({ mutation: updateContribution, variables: { contributionId: pendingContribution.data.createContribution.id, @@ -399,7 +401,7 @@ describe('ContributionResolver', () => { it('throws an error', async () => { jest.clearAllMocks() - const { errors: errorObjects }: { errors: [GraphQLError] } = await mutate({ + const { errors: errorObjects } = await mutate({ mutation: updateContribution, variables: { contributionId: pendingContribution.data.createContribution.id, @@ -432,7 +434,7 @@ describe('ContributionResolver', () => { it('throws an error', async () => { jest.clearAllMocks() - const { errors: errorObjects }: { errors: GraphQLError[] } = await mutate({ + const { errors: errorObjects } = await mutate({ mutation: adminUpdateContribution, variables: { id: pendingContribution.data.createContribution.id, @@ -511,7 +513,7 @@ describe('ContributionResolver', () => { it('throws an error', async () => { jest.clearAllMocks() - const { errors: errorObjects }: { errors: GraphQLError[] } = await mutate({ + const { errors: errorObjects } = await mutate({ mutation: updateContribution, variables: { contributionId: pendingContribution.data.createContribution.id, @@ -540,7 +542,7 @@ describe('ContributionResolver', () => { it('throws an error', async () => { jest.clearAllMocks() const date = new Date() - const { errors: errorObjects }: { errors: GraphQLError[] } = await mutate({ + const { errors: errorObjects } = await mutate({ mutation: updateContribution, variables: { contributionId: pendingContribution.data.createContribution.id, @@ -563,7 +565,7 @@ describe('ContributionResolver', () => { it('updates contribution', async () => { const { data: { updateContribution: contribution }, - }: { data: { updateContribution: UnconfirmedContribution } } = await mutate({ + } = await mutate({ mutation: updateContribution, variables: { contributionId: pendingContribution.data.createContribution.id, @@ -602,7 +604,7 @@ describe('ContributionResolver', () => { describe('denyContribution', () => { describe('unauthenticated', () => { it('returns an error', async () => { - const { errors: errorObjects }: { errors: GraphQLError[] } = await mutate({ + const { errors: errorObjects } = await mutate({ mutation: denyContribution, variables: { id: 1, @@ -625,7 +627,7 @@ describe('ContributionResolver', () => { }) it('returns an error', async () => { - const { errors: errorObjects }: { errors: GraphQLError[] } = await mutate({ + const { errors: errorObjects } = await mutate({ mutation: denyContribution, variables: { id: 1, @@ -650,7 +652,7 @@ describe('ContributionResolver', () => { describe('wrong contribution id', () => { it('throws an error', async () => { jest.clearAllMocks() - const { errors: errorObjects }: { errors: GraphQLError[] } = await mutate({ + const { errors: errorObjects } = await mutate({ mutation: denyContribution, variables: { id: -1, @@ -694,7 +696,7 @@ describe('ContributionResolver', () => { }, }) - const { errors: errorObjects }: { errors: GraphQLError[] } = await mutate({ + const { errors: errorObjects } = await mutate({ mutation: denyContribution, variables: { id: contribution.data.createContribution.id, @@ -739,7 +741,7 @@ describe('ContributionResolver', () => { variables: { email: 'peter@lustig.de', password: 'Aa12345_' }, }) - const { errors: errorObjects }: { errors: GraphQLError[] } = await mutate({ + const { errors: errorObjects } = await mutate({ mutation: denyContribution, variables: { id: contribution.data.createContribution.id, @@ -784,7 +786,7 @@ describe('ContributionResolver', () => { }, }) - const { errors: errorObjects }: { errors: GraphQLError[] } = await mutate({ + const { errors: errorObjects } = await mutate({ mutation: denyContribution, variables: { id: contribution.data.createContribution.id, @@ -806,7 +808,7 @@ describe('ContributionResolver', () => { }) const { data: { denyContribution: isDenied }, - }: { data: { denyContribution: boolean } } = await mutate({ + } = await mutate({ mutation: denyContribution, variables: { id: contributionToDeny.data.createContribution.id, @@ -845,8 +847,8 @@ describe('ContributionResolver', () => { describe('deleteContribution', () => { describe('unauthenticated', () => { it('returns an error', async () => { - const { errors: errorObjects }: { errors: [GraphQLError] } = await mutate({ - query: deleteContribution, + const { errors: errorObjects } = await mutate({ + mutation: deleteContribution, variables: { id: -1, }, @@ -870,7 +872,7 @@ describe('ContributionResolver', () => { describe('wrong contribution id', () => { it('returns an error', async () => { jest.clearAllMocks() - const { errors: errorObjects }: { errors: [GraphQLError] } = await mutate({ + const { errors: errorObjects } = await mutate({ mutation: deleteContribution, variables: { id: -1, @@ -898,7 +900,7 @@ describe('ContributionResolver', () => { }) it('returns an error', async () => { - const { errors: errorObjects }: { errors: [GraphQLError] } = await mutate({ + const { errors: errorObjects } = await mutate({ mutation: deleteContribution, variables: { id: contributionToDelete.data.createContribution.id, @@ -934,7 +936,7 @@ describe('ContributionResolver', () => { it('deletes successfully', async () => { const { data: { deleteContribution: isDenied }, - }: { data: { deleteContribution: boolean } } = await mutate({ + } = await mutate({ mutation: deleteContribution, variables: { id: contributionToDelete.data.createContribution.id, @@ -973,7 +975,7 @@ describe('ContributionResolver', () => { mutation: login, variables: { email: 'bibi@bloxberg.de', password: 'Aa12345_' }, }) - const { errors: errorObjects }: { errors: [GraphQLError] } = await mutate({ + const { errors: errorObjects } = await mutate({ mutation: deleteContribution, variables: { id: contributionToConfirm.data.createContribution.id, @@ -997,7 +999,7 @@ describe('ContributionResolver', () => { describe('listContributions', () => { describe('unauthenticated', () => { it('returns an error', async () => { - const { errors: errorObjects }: { errors: [GraphQLError] } = await query({ + const { errors: errorObjects } = await query({ query: listContributions, variables: { currentPage: 1, @@ -1025,7 +1027,7 @@ describe('ContributionResolver', () => { it('returns creations', async () => { const { data: { listContributions: contributionListResult }, - }: { data: { listContributions: ContributionListResult } } = await query({ + } = await query({ query: listContributions, variables: { currentPage: 1, @@ -1077,7 +1079,7 @@ describe('ContributionResolver', () => { it('returns only unconfirmed creations', async () => { const { data: { listContributions: contributionListResult }, - }: { data: { listContributions: ContributionListResult } } = await query({ + } = await query({ query: listContributions, variables: { currentPage: 1, @@ -1127,7 +1129,7 @@ describe('ContributionResolver', () => { describe('listAllContribution', () => { describe('unauthenticated', () => { it('returns an error', async () => { - const { errors: errorObjects }: { errors: [GraphQLError] } = await query({ + const { errors: errorObjects } = await query({ query: listAllContributions, variables: { currentPage: 1, @@ -1153,7 +1155,7 @@ describe('ContributionResolver', () => { }) it('throws an error with "NOT_VALID" in statusFilter', async () => { - const { errors: errorObjects }: { errors: [GraphQLError | UserInputError] } = await query({ + const { errors: errorObjects } = await query({ query: listAllContributions, variables: { currentPage: 1, @@ -1170,7 +1172,7 @@ describe('ContributionResolver', () => { }) it('throws an error with a null in statusFilter', async () => { - const { errors: errorObjects }: { errors: [Error] } = await query({ + const { errors: errorObjects } = await query({ query: listAllContributions, variables: { currentPage: 1, @@ -1187,7 +1189,7 @@ describe('ContributionResolver', () => { }) it('throws an error with null and "NOT_VALID" in statusFilter', async () => { - const { errors: errorObjects }: { errors: [Error] } = await query({ + const { errors: errorObjects } = await query({ query: listAllContributions, variables: { currentPage: 1, @@ -1209,7 +1211,7 @@ describe('ContributionResolver', () => { it('returns all contributions without statusFilter', async () => { const { data: { listAllContributions: contributionListObject }, - }: { data: { listAllContributions: ContributionListResult } } = await query({ + } = await query({ query: listAllContributions, variables: { currentPage: 1, @@ -1273,7 +1275,7 @@ describe('ContributionResolver', () => { it('returns all contributions for statusFilter = null', async () => { const { data: { listAllContributions: contributionListObject }, - }: { data: { listAllContributions: ContributionListResult } } = await query({ + } = await query({ query: listAllContributions, variables: { currentPage: 1, @@ -1338,7 +1340,7 @@ describe('ContributionResolver', () => { it('returns all contributions for statusFilter = []', async () => { const { data: { listAllContributions: contributionListObject }, - }: { data: { listAllContributions: ContributionListResult } } = await query({ + } = await query({ query: listAllContributions, variables: { currentPage: 1, @@ -1403,7 +1405,7 @@ describe('ContributionResolver', () => { it('returns all CONFIRMED contributions', async () => { const { data: { listAllContributions: contributionListObject }, - }: { data: { listAllContributions: ContributionListResult } } = await query({ + } = await query({ query: listAllContributions, variables: { currentPage: 1, @@ -1453,7 +1455,7 @@ describe('ContributionResolver', () => { it('returns all PENDING contributions', async () => { const { data: { listAllContributions: contributionListObject }, - }: { data: { listAllContributions: ContributionListResult } } = await query({ + } = await query({ query: listAllContributions, variables: { currentPage: 1, @@ -1491,7 +1493,7 @@ describe('ContributionResolver', () => { it('returns all IN_PROGRESS Creation', async () => { const { data: { listAllContributions: contributionListObject }, - }: { data: { listAllContributions: ContributionListResult } } = await query({ + } = await query({ query: listAllContributions, variables: { currentPage: 1, @@ -1529,7 +1531,7 @@ describe('ContributionResolver', () => { it('returns all DENIED Creation', async () => { const { data: { listAllContributions: contributionListObject }, - }: { data: { listAllContributions: ContributionListResult } } = await query({ + } = await query({ query: listAllContributions, variables: { currentPage: 1, @@ -1573,7 +1575,7 @@ describe('ContributionResolver', () => { it('does not return any DELETED Creation', async () => { const { data: { listAllContributions: contributionListObject }, - }: { data: { listAllContributions: ContributionListResult } } = await query({ + } = await query({ query: listAllContributions, variables: { currentPage: 1, @@ -1592,7 +1594,7 @@ describe('ContributionResolver', () => { it('returns all CONFIRMED and PENDING Creation', async () => { const { data: { listAllContributions: contributionListObject }, - }: { data: { listAllContributions: ContributionListResult } } = await query({ + } = await query({ query: listAllContributions, variables: { currentPage: 1, @@ -2675,7 +2677,7 @@ describe('ContributionResolver', () => { it('returns 17 creations in total', async () => { const { data: { adminListContributions: contributionListObject }, - }: { data: { adminListContributions: ContributionListResult } } = await query({ + } = await query({ query: adminListContributions, }) expect(contributionListObject.contributionList).toHaveLength(17) @@ -2842,7 +2844,7 @@ describe('ContributionResolver', () => { it('returns two pending creations with page size set to 2', async () => { const { data: { adminListContributions: contributionListObject }, - }: { data: { adminListContributions: ContributionListResult } } = await query({ + } = await query({ query: adminListContributions, variables: { currentPage: 1, diff --git a/backend/src/graphql/resolver/EmailOptinCodes.test.ts b/backend/src/graphql/resolver/EmailOptinCodes.test.ts index cc8d4e534..e8dbba082 100644 --- a/backend/src/graphql/resolver/EmailOptinCodes.test.ts +++ b/backend/src/graphql/resolver/EmailOptinCodes.test.ts @@ -1,10 +1,8 @@ -/* eslint-disable @typescript-eslint/no-unsafe-call */ /* eslint-disable @typescript-eslint/no-unsafe-member-access */ /* eslint-disable @typescript-eslint/no-unsafe-assignment */ -/* eslint-disable @typescript-eslint/no-explicit-any */ -/* eslint-disable @typescript-eslint/explicit-module-boundary-types */ - +import { Connection } from '@dbTools/typeorm' import { User as DbUser } from '@entity/User' +import { ApolloServerTestClient } from 'apollo-server-testing' import { GraphQLError } from 'graphql' import { testEnvironment, cleanDB } from '@test/helpers' @@ -13,8 +11,14 @@ import CONFIG from '@/config' import { createUser, setPassword, forgotPassword } from '@/seeds/graphql/mutations' import { queryOptIn } from '@/seeds/graphql/queries' -let mutate: any, query: any, con: any -let testEnv: any +let mutate: ApolloServerTestClient['mutate'], + query: ApolloServerTestClient['query'], + con: Connection +let testEnv: { + mutate: ApolloServerTestClient['mutate'] + query: ApolloServerTestClient['query'] + con: Connection +} CONFIG.EMAIL_CODE_VALID_TIME = 1440 CONFIG.EMAIL_CODE_REQUEST_TIME = 10 diff --git a/backend/src/graphql/resolver/TransactionLinkResolver.test.ts b/backend/src/graphql/resolver/TransactionLinkResolver.test.ts index b860f97a0..528f7684a 100644 --- a/backend/src/graphql/resolver/TransactionLinkResolver.test.ts +++ b/backend/src/graphql/resolver/TransactionLinkResolver.test.ts @@ -1,15 +1,13 @@ -/* eslint-disable @typescript-eslint/no-unsafe-call */ /* eslint-disable @typescript-eslint/no-unsafe-member-access */ /* eslint-disable @typescript-eslint/no-unsafe-assignment */ /* eslint-disable @typescript-eslint/restrict-template-expressions */ -/* eslint-disable @typescript-eslint/no-explicit-any */ -/* eslint-disable @typescript-eslint/explicit-module-boundary-types */ -/* eslint-disable @typescript-eslint/no-unsafe-argument */ +import { Connection } from '@dbTools/typeorm' import { ContributionLink as DbContributionLink } from '@entity/ContributionLink' import { Event as DbEvent } from '@entity/Event' import { Transaction } from '@entity/Transaction' import { User } from '@entity/User' import { UserContact } from '@entity/UserContact' +import { ApolloServerTestClient } from 'apollo-server-testing' import { Decimal } from 'decimal.js-light' import { GraphQLError } from 'graphql' @@ -44,8 +42,14 @@ import { transactionLinkCode } from './TransactionLinkResolver' jest.mock('@/util/TRANSACTIONS_LOCK') TRANSACTIONS_LOCK.acquire = jest.fn().mockResolvedValue(jest.fn()) -let mutate: any, query: any, con: any -let testEnv: any +let mutate: ApolloServerTestClient['mutate'], + query: ApolloServerTestClient['query'], + con: Connection +let testEnv: { + mutate: ApolloServerTestClient['mutate'] + query: ApolloServerTestClient['query'] + con: Connection +} let user: User diff --git a/backend/src/graphql/resolver/TransactionResolver.test.ts b/backend/src/graphql/resolver/TransactionResolver.test.ts index 5b16a37ab..4cf7746bc 100644 --- a/backend/src/graphql/resolver/TransactionResolver.test.ts +++ b/backend/src/graphql/resolver/TransactionResolver.test.ts @@ -1,12 +1,11 @@ -/* eslint-disable @typescript-eslint/no-unsafe-call */ +/* eslint-disable @typescript-eslint/no-explicit-any */ /* eslint-disable @typescript-eslint/no-unsafe-member-access */ /* eslint-disable @typescript-eslint/no-unsafe-assignment */ -/* eslint-disable @typescript-eslint/no-explicit-any */ -/* eslint-disable @typescript-eslint/explicit-module-boundary-types */ -/* eslint-disable @typescript-eslint/no-unsafe-argument */ +import { Connection } from '@dbTools/typeorm' import { Event as DbEvent } from '@entity/Event' import { Transaction } from '@entity/Transaction' import { User } from '@entity/User' +import { ApolloServerTestClient } from 'apollo-server-testing' import { Decimal } from 'decimal.js-light' import { GraphQLError } from 'graphql' @@ -26,13 +25,16 @@ import { garrickOllivander } from '@/seeds/users/garrick-ollivander' import { peterLustig } from '@/seeds/users/peter-lustig' import { stephenHawking } from '@/seeds/users/stephen-hawking' -let mutate: any, query: any, con: any -let testEnv: any +let mutate: ApolloServerTestClient['mutate'], con: Connection +let testEnv: { + mutate: ApolloServerTestClient['mutate'] + query: ApolloServerTestClient['query'] + con: Connection +} beforeAll(async () => { testEnv = await testEnvironment(logger) mutate = testEnv.mutate - query = testEnv.query con = testEnv.con await cleanDB() }) @@ -273,7 +275,7 @@ describe('send coins', () => { }) // login as admin - await query({ mutation: login, variables: peterData }) + await mutate({ mutation: login, variables: peterData }) // confirm the contribution await mutate({ @@ -282,7 +284,7 @@ describe('send coins', () => { }) // login as bob again - await query({ mutation: login, variables: bobData }) + await mutate({ mutation: login, variables: bobData }) }) afterAll(async () => { diff --git a/backend/src/graphql/resolver/UserResolver.test.ts b/backend/src/graphql/resolver/UserResolver.test.ts index 89f26a502..889e5749f 100644 --- a/backend/src/graphql/resolver/UserResolver.test.ts +++ b/backend/src/graphql/resolver/UserResolver.test.ts @@ -3,12 +3,13 @@ /* eslint-disable @typescript-eslint/no-unsafe-assignment */ /* eslint-disable @typescript-eslint/no-unsafe-return */ /* eslint-disable @typescript-eslint/no-explicit-any */ -/* eslint-disable @typescript-eslint/explicit-module-boundary-types */ /* eslint-disable @typescript-eslint/no-unsafe-argument */ +import { Connection } from '@dbTools/typeorm' import { Event as DbEvent } from '@entity/Event' import { TransactionLink } from '@entity/TransactionLink' import { User } from '@entity/User' import { UserContact } from '@entity/UserContact' +import { ApolloServerTestClient } from 'apollo-server-testing' import { GraphQLError } from 'graphql' import { v4 as uuidv4, validate as validateUUID, version as versionUUID } from 'uuid' @@ -87,8 +88,14 @@ jest.mock('@/apis/KlicktippController', () => { let admin: User let user: User -let mutate: any, query: any, con: any -let testEnv: any +let mutate: ApolloServerTestClient['mutate'], + query: ApolloServerTestClient['query'], + con: Connection +let testEnv: { + mutate: ApolloServerTestClient['mutate'] + query: ApolloServerTestClient['query'] + con: Connection +} beforeAll(async () => { testEnv = await testEnvironment(logger, localization) @@ -235,7 +242,7 @@ describe('UserResolver', () => { }) describe('user already exists', () => { - let mutation: User + let mutation: any beforeAll(async () => { mutation = await mutate({ mutation: createUser, variables }) }) @@ -637,7 +644,7 @@ describe('UserResolver', () => { publisherId: 1234, } - let result: User + let result: any afterAll(async () => { await cleanDB() diff --git a/backend/src/graphql/resolver/semaphore.test.ts b/backend/src/graphql/resolver/semaphore.test.ts index f4d87f467..eb4052e1f 100644 --- a/backend/src/graphql/resolver/semaphore.test.ts +++ b/backend/src/graphql/resolver/semaphore.test.ts @@ -1,9 +1,8 @@ /* eslint-disable @typescript-eslint/no-unsafe-member-access */ /* eslint-disable @typescript-eslint/no-unsafe-assignment */ -/* eslint-disable @typescript-eslint/no-unsafe-call */ /* eslint-disable @typescript-eslint/restrict-template-expressions */ -/* eslint-disable @typescript-eslint/no-explicit-any */ -/* eslint-disable @typescript-eslint/no-unsafe-argument */ +import { Connection } from '@dbTools/typeorm' +import { ApolloServerTestClient } from 'apollo-server-testing' import { Decimal } from 'decimal.js-light' import { cleanDB, testEnvironment, contributionDateFormatter } from '@test/helpers' @@ -23,8 +22,12 @@ import { bibiBloxberg } from '@/seeds/users/bibi-bloxberg' import { bobBaumeister } from '@/seeds/users/bob-baumeister' import { peterLustig } from '@/seeds/users/peter-lustig' -let mutate: any, con: any -let testEnv: any +let mutate: ApolloServerTestClient['mutate'], con: Connection +let testEnv: { + mutate: ApolloServerTestClient['mutate'] + query: ApolloServerTestClient['query'] + con: Connection +} beforeAll(async () => { testEnv = await testEnvironment() diff --git a/backend/src/graphql/resolver/util/creations.test.ts b/backend/src/graphql/resolver/util/creations.test.ts index 0b05099c8..25d8a45c2 100644 --- a/backend/src/graphql/resolver/util/creations.test.ts +++ b/backend/src/graphql/resolver/util/creations.test.ts @@ -1,11 +1,7 @@ -/* eslint-disable @typescript-eslint/no-unsafe-call */ -/* eslint-disable @typescript-eslint/no-unsafe-member-access */ -/* eslint-disable @typescript-eslint/no-unsafe-assignment */ -/* eslint-disable @typescript-eslint/no-explicit-any */ -/* eslint-disable @typescript-eslint/explicit-module-boundary-types */ -/* eslint-disable @typescript-eslint/no-unsafe-argument */ +import { Connection } from '@dbTools/typeorm' import { Contribution } from '@entity/Contribution' import { User } from '@entity/User' +import { ApolloServerTestClient } from 'apollo-server-testing' import { testEnvironment, cleanDB, contributionDateFormatter } from '@test/helpers' @@ -16,8 +12,12 @@ import { peterLustig } from '@/seeds/users/peter-lustig' import { getUserCreation } from './creations' -let mutate: any, con: any -let testEnv: any +let mutate: ApolloServerTestClient['mutate'], con: Connection +let testEnv: { + mutate: ApolloServerTestClient['mutate'] + query: ApolloServerTestClient['query'] + con: Connection +} beforeAll(async () => { testEnv = await testEnvironment() From 56dbcd4f589ad7f7ddd92e9d4c2b3aac3c88368b Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Wed, 5 Apr 2023 05:46:38 +0200 Subject: [PATCH 05/19] various more typesafety --- backend/src/graphql/directive/isAuthorized.ts | 10 +++------- .../graphql/resolver/ContributionResolver.ts | 7 +++---- backend/src/index.ts | 1 - backend/src/seeds/factory/creation.ts | 4 ---- backend/src/seeds/index.ts | 13 ++++--------- backend/src/server/context.ts | 1 + backend/src/server/plugins.ts | 1 - backend/test/helpers.ts | 19 +++++++------------ backend/test/testSetup.ts | 6 ++---- 9 files changed, 20 insertions(+), 42 deletions(-) diff --git a/backend/src/graphql/directive/isAuthorized.ts b/backend/src/graphql/directive/isAuthorized.ts index d659b3f1c..9cddc76ac 100644 --- a/backend/src/graphql/directive/isAuthorized.ts +++ b/backend/src/graphql/directive/isAuthorized.ts @@ -1,8 +1,3 @@ -/* eslint-disable @typescript-eslint/no-unsafe-member-access */ -/* eslint-disable @typescript-eslint/no-unsafe-call */ -/* eslint-disable @typescript-eslint/no-explicit-any */ -/* eslint-disable @typescript-eslint/no-unsafe-argument */ - import { User } from '@entity/User' import { AuthChecker } from 'type-graphql' @@ -10,9 +5,10 @@ import { INALIENABLE_RIGHTS } from '@/auth/INALIENABLE_RIGHTS' import { decode, encode } from '@/auth/JWT' import { RIGHTS } from '@/auth/RIGHTS' import { ROLE_UNAUTHORIZED, ROLE_USER, ROLE_ADMIN } from '@/auth/ROLES' +import { Context } from '@/server/context' import LogError from '@/server/LogError' -const isAuthorized: AuthChecker = async ({ context }, rights) => { +const isAuthorized: AuthChecker = async ({ context }, rights) => { context.role = ROLE_UNAUTHORIZED // unauthorized user // is rights an inalienable right? @@ -47,7 +43,7 @@ const isAuthorized: AuthChecker = async ({ context }, rights) => { } // check for correct rights - const missingRights = (rights).filter((right) => !context.role.hasRight(right)) + const missingRights = (rights).filter((right) => !context.role?.hasRight(right)) if (missingRights.length !== 0) { throw new LogError('401 Unauthorized') } diff --git a/backend/src/graphql/resolver/ContributionResolver.ts b/backend/src/graphql/resolver/ContributionResolver.ts index 5969eaef2..a4a68f584 100644 --- a/backend/src/graphql/resolver/ContributionResolver.ts +++ b/backend/src/graphql/resolver/ContributionResolver.ts @@ -1,4 +1,3 @@ -/* eslint-disable @typescript-eslint/restrict-template-expressions */ import { IsNull, getConnection } from '@dbTools/typeorm' import { Contribution as DbContribution } from '@entity/Contribution' import { ContributionMessage } from '@entity/ContributionMessage' @@ -229,11 +228,11 @@ export class ContributionResolver { contributionMessage.createdAt = contributionToUpdate.updatedAt ? contributionToUpdate.updatedAt : contributionToUpdate.createdAt - const changeMessage = `${contributionToUpdate.contributionDate} + const changeMessage = `${contributionToUpdate.contributionDate.toString()} --- ${contributionToUpdate.memo} --- - ${contributionToUpdate.amount}` + ${contributionToUpdate.amount.toString()}` contributionMessage.message = changeMessage contributionMessage.isModerator = false contributionMessage.userId = user.id @@ -259,7 +258,7 @@ export class ContributionResolver { @Ctx() context: Context, ): Promise { logger.info( - `adminCreateContribution(email=${email}, amount=${amount}, memo=${memo}, creationDate=${creationDate})`, + `adminCreateContribution(email=${email}, amount=${amount.toString()}, memo=${memo}, creationDate=${creationDate})`, ) const clientTimezoneOffset = getClientTimezoneOffset(context) if (!isValidDateString(creationDate)) { diff --git a/backend/src/index.ts b/backend/src/index.ts index 72b627820..3631deca8 100644 --- a/backend/src/index.ts +++ b/backend/src/index.ts @@ -1,4 +1,3 @@ -/* eslint-disable @typescript-eslint/no-explicit-any */ import CONFIG from './config' import { startValidateCommunities } from './federation/validateCommunities' import createServer from './server/createServer' diff --git a/backend/src/seeds/factory/creation.ts b/backend/src/seeds/factory/creation.ts index 6a3aaa3e7..5b4c56c57 100644 --- a/backend/src/seeds/factory/creation.ts +++ b/backend/src/seeds/factory/creation.ts @@ -2,9 +2,6 @@ /* eslint-disable @typescript-eslint/no-unsafe-assignment */ /* eslint-disable @typescript-eslint/no-unsafe-member-access */ /* eslint-disable @typescript-eslint/unbound-method */ -/* eslint-disable @typescript-eslint/no-explicit-any */ -/* eslint-disable @typescript-eslint/explicit-module-boundary-types */ - import { Contribution } from '@entity/Contribution' import { Transaction } from '@entity/Transaction' import { ApolloServerTestClient } from 'apollo-server-testing' @@ -12,7 +9,6 @@ import { ApolloServerTestClient } from 'apollo-server-testing' import { findUserByEmail } from '@/graphql/resolver/UserResolver' import { CreationInterface } from '@/seeds/creation/CreationInterface' import { login, createContribution, confirmContribution } from '@/seeds/graphql/mutations' -// import CONFIG from '@/config/index' export const nMonthsBefore = (date: Date, months = 1): string => { return new Date(date.getFullYear(), date.getMonth() - months, 1).toISOString() diff --git a/backend/src/seeds/index.ts b/backend/src/seeds/index.ts index d1960eea9..df6bf768c 100644 --- a/backend/src/seeds/index.ts +++ b/backend/src/seeds/index.ts @@ -1,10 +1,3 @@ -/* eslint-disable @typescript-eslint/no-unsafe-return */ -/* eslint-disable @typescript-eslint/no-unsafe-member-access */ -/* eslint-disable @typescript-eslint/no-unsafe-assignment */ -/* eslint-disable @typescript-eslint/no-unsafe-call */ -/* eslint-disable @typescript-eslint/no-explicit-any */ -/* eslint-disable @typescript-eslint/explicit-module-boundary-types */ - import { entities } from '@entity/index' import { createTestClient } from 'apollo-server-testing' import { name, internet, datatype } from 'faker' @@ -43,10 +36,12 @@ export const cleanDB = async () => { } } -const resetEntity = async (entity: any) => { +const [entityTypes] = entities + +const resetEntity = async (entity: typeof entityTypes) => { const items = await entity.find({ withDeleted: true }) if (items.length > 0) { - const ids = items.map((i: any) => i.id) + const ids = items.map((i) => i.id) await entity.delete(ids) } } diff --git a/backend/src/server/context.ts b/backend/src/server/context.ts index f0e63daea..af5047348 100644 --- a/backend/src/server/context.ts +++ b/backend/src/server/context.ts @@ -13,6 +13,7 @@ export interface Context { role?: Role user?: dbUser clientTimezoneOffset?: number + gradidoID?: string // hack to use less DB calls for Balance Resolver lastTransaction?: dbTransaction transactionCount?: number diff --git a/backend/src/server/plugins.ts b/backend/src/server/plugins.ts index d113cb4b7..067810cf8 100644 --- a/backend/src/server/plugins.ts +++ b/backend/src/server/plugins.ts @@ -5,7 +5,6 @@ /* eslint-disable @typescript-eslint/no-unsafe-return */ /* eslint-disable @typescript-eslint/no-explicit-any */ /* eslint-disable @typescript-eslint/explicit-module-boundary-types */ - import clonedeep from 'lodash.clonedeep' const setHeadersPlugin = { diff --git a/backend/test/helpers.ts b/backend/test/helpers.ts index cd86573fc..4944fddc1 100644 --- a/backend/test/helpers.ts +++ b/backend/test/helpers.ts @@ -1,20 +1,13 @@ -/* eslint-disable @typescript-eslint/no-unsafe-assignment */ -/* eslint-disable @typescript-eslint/no-unsafe-return */ -/* eslint-disable @typescript-eslint/no-unsafe-call */ -/* eslint-disable @typescript-eslint/no-unsafe-member-access */ /* eslint-disable @typescript-eslint/unbound-method */ -/* eslint-disable @typescript-eslint/no-explicit-any */ -/* eslint-disable @typescript-eslint/explicit-module-boundary-types */ -/* eslint-disable @typescript-eslint/no-unsafe-argument */ - import { entities } from '@entity/index' import { createTestClient } from 'apollo-server-testing' +import { Context } from '@/server/context' import createServer from '@/server/createServer' import { i18n, logger } from './testSetup' -export const headerPushMock = jest.fn((t) => { +export const headerPushMock = jest.fn(([t]: Context['setHeaders']) => { context.token = t.value }) @@ -34,7 +27,7 @@ export const cleanDB = async () => { } } -export const testEnvironment = async (testLogger: any = logger, testI18n: any = i18n) => { +export const testEnvironment = async (testLogger = logger, testI18n = i18n) => { const server = await createServer(context, testLogger, testI18n) const con = server.con const testClient = createTestClient(server.apollo) @@ -43,10 +36,12 @@ export const testEnvironment = async (testLogger: any = logger, testI18n: any = return { mutate, query, con } } -export const resetEntity = async (entity: any) => { +const [entityTypes] = entities + +export const resetEntity = async (entity: typeof entityTypes) => { const items = await entity.find({ withDeleted: true }) if (items.length > 0) { - const ids = items.map((i: any) => i.id) + const ids = items.map((i) => i.id) await entity.delete(ids) } } diff --git a/backend/test/testSetup.ts b/backend/test/testSetup.ts index 4e8a67e3f..2c8afee32 100644 --- a/backend/test/testSetup.ts +++ b/backend/test/testSetup.ts @@ -1,5 +1,3 @@ -/* eslint-disable @typescript-eslint/no-unsafe-assignment */ -/* eslint-disable @typescript-eslint/no-unsafe-return */ import CONFIG from '@/config' import { i18n } from '@/server/localization' import { backendLogger as logger } from '@/server/logger' @@ -10,7 +8,7 @@ CONFIG.EMAIL_TEST_MODUS = false jest.setTimeout(1000000) jest.mock('@/server/logger', () => { - const originalModule = jest.requireActual('@/server/logger') + const originalModule = jest.requireActual('@/server/logger') return { __esModule: true, ...originalModule, @@ -27,7 +25,7 @@ jest.mock('@/server/logger', () => { }) jest.mock('@/server/localization', () => { - const originalModule = jest.requireActual('@/server/localization') + const originalModule = jest.requireActual('@/server/localization') return { __esModule: true, ...originalModule, From 51900af67d26dbde0464877491d3017a12580f04 Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Tue, 2 May 2023 11:39:37 +0200 Subject: [PATCH 06/19] updated docu based on new findings regarding yarn output to tmp folder --- deployment/bare_metal/setup.md | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/deployment/bare_metal/setup.md b/deployment/bare_metal/setup.md index b1204b1b3..da3688eed 100644 --- a/deployment/bare_metal/setup.md +++ b/deployment/bare_metal/setup.md @@ -196,6 +196,27 @@ Use it as pattern to do all steps manually in your terminal shell. Follow the commands in `./install.sh` as installation pattern. +## Define Cronjob To Compensate Yarn Output In `/tmp` + +`yarn` creates output in `/tmp` directory. This output is generated whenever `yarn start` is called. THis is especially problematic on staging systems where instable versions are automatically deployed which can lead to a ever resatrting service, hence generating alot of yarn output. + +To solve this you can install the following hourly cron using `crontab` as `gradido` user.he `gradido` user. + +Run: + +```bash +crontab -e +``` + +This opens the crontab in edit-mode and insert the following entry: + +```bash +0 * * * * find /tmp -name "yarn--*" -exec rm -r {} \; > /dev/null + +``` + +For production systems this is not need by default since the yarn output is deleted when `start.sh` is executed. If the service runs stable and does not restart frequently the yarn output to the tmp folder scales with the amount of services running. + ## Define Cronjob To start backup script automatically At least at production stage we need a daily backup of our database. This can be done by adding a cronjob From 5eade026c1ee4f30b1137d2e4d027d6243e400fa Mon Sep 17 00:00:00 2001 From: mahula Date: Tue, 2 May 2023 17:00:35 +0200 Subject: [PATCH 07/19] move mariadb test jobs to separate workflow file --- .github/file-filters.yml | 3 +++ .github/workflows/test.yml | 26 ----------------------- .github/workflows/test_mariadb.yml | 33 ++++++++++++++++++++++++++++++ 3 files changed, 36 insertions(+), 26 deletions(-) create mode 100644 .github/workflows/test_mariadb.yml diff --git a/.github/file-filters.yml b/.github/file-filters.yml index 6690cdb9d..02ea2709e 100644 --- a/.github/file-filters.yml +++ b/.github/file-filters.yml @@ -42,5 +42,8 @@ federation: &federation frontend: &frontend - 'frontend/**/*' +mariadb: &mariadb + - 'mariadb/**/*' + nginx: &nginx - 'nginx/**/*' \ No newline at end of file diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 0fcedb4ce..d2e83d8e9 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -55,32 +55,6 @@ jobs: name: docker-database-test_up path: /tmp/database_up.tar - ############################################################################## - # JOB: DOCKER BUILD TEST MARIADB ############################################# - ############################################################################## - build_test_mariadb: - name: Docker Build Test - MariaDB - runs-on: ubuntu-latest - #needs: [nothing] - steps: - ########################################################################## - # CHECKOUT CODE ########################################################## - ########################################################################## - - name: Checkout code - uses: actions/checkout@v3 - ########################################################################## - # BUILD MARIADB DOCKER IMAGE ############################################# - ########################################################################## - - name: mariadb | Build `test` image - run: | - docker build --target mariadb_server -t "gradido/mariadb:test" -f ./mariadb/Dockerfile ./ - docker save "gradido/mariadb:test" > /tmp/mariadb.tar - - name: Upload Artifact - uses: actions/upload-artifact@v3 - with: - name: docker-mariadb-test - path: /tmp/mariadb.tar - ############################################################################## # JOB: LINT BACKEND ########################################################## ############################################################################## diff --git a/.github/workflows/test_mariadb.yml b/.github/workflows/test_mariadb.yml new file mode 100644 index 000000000..ea260e5db --- /dev/null +++ b/.github/workflows/test_mariadb.yml @@ -0,0 +1,33 @@ +name: Gradido MariaDB Test CI + +on: push + +jobs: + files-changed: + name: Detect File Changes - MariaDB + runs-on: ubuntu-latest + outputs: + docker-compose: ${{ steps.changes.outputs.docker-compose }} + mariadb: ${{ steps.changes.outputs.mariadb }} + steps: + - uses: actions/checkout@v3.3.0 + + - name: Check for frontend file changes + uses: dorny/paths-filter@v2.11.1 + id: changes + with: + token: ${{ github.token }} + filters: .github/file-filters.yml + list-files: shell + + build_test: + if: needs.files-changed.outputs.mariadb == 'true' + name: Docker Build Test - MariaDB + needs: files-changed + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v3 + - name: MariaDB | Build 'test' image + run: | + docker build --target mariadb_server -t "gradido/mariadb:test" -f ./mariadb/Dockerfile ./ From 583b2f5d8f3be067e7e2674904359c886e0a8ba0 Mon Sep 17 00:00:00 2001 From: mahula Date: Tue, 2 May 2023 17:00:35 +0200 Subject: [PATCH 08/19] move mariadb test jobs to separate workflow file --- .github/workflows/test_mariadb.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/test_mariadb.yml b/.github/workflows/test_mariadb.yml index ea260e5db..585ede680 100644 --- a/.github/workflows/test_mariadb.yml +++ b/.github/workflows/test_mariadb.yml @@ -7,7 +7,6 @@ jobs: name: Detect File Changes - MariaDB runs-on: ubuntu-latest outputs: - docker-compose: ${{ steps.changes.outputs.docker-compose }} mariadb: ${{ steps.changes.outputs.mariadb }} steps: - uses: actions/checkout@v3.3.0 From 5c7a0df7ff3caf08cb45736c46682bcf98479f85 Mon Sep 17 00:00:00 2001 From: mahula Date: Tue, 2 May 2023 17:00:35 +0200 Subject: [PATCH 09/19] move mariadb test jobs to separate workflow file --- .github/workflows/test_mariadb.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/test_mariadb.yml b/.github/workflows/test_mariadb.yml index 585ede680..925884cf5 100644 --- a/.github/workflows/test_mariadb.yml +++ b/.github/workflows/test_mariadb.yml @@ -27,6 +27,7 @@ jobs: steps: - name: Checkout code uses: actions/checkout@v3 + - name: MariaDB | Build 'test' image run: | docker build --target mariadb_server -t "gradido/mariadb:test" -f ./mariadb/Dockerfile ./ From 069215adf59f0e55e7098655b34510ad2c393c00 Mon Sep 17 00:00:00 2001 From: mahula Date: Tue, 2 May 2023 17:43:05 +0200 Subject: [PATCH 10/19] move database test jobs to separate workflow file --- .github/workflows/test.yml | 66 +---------------------------- .github/workflows/test_database.yml | 65 ++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+), 65 deletions(-) create mode 100644 .github/workflows/test_database.yml diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index d2e83d8e9..1b245fa2b 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -29,32 +29,6 @@ jobs: name: docker-backend-test path: /tmp/backend.tar - ############################################################################## - # JOB: DOCKER BUILD TEST DATABASE UP ######################################### - ############################################################################## - build_test_database_up: - name: Docker Build Test - Database up - runs-on: ubuntu-latest - #needs: [nothing] - steps: - ########################################################################## - # CHECKOUT CODE ########################################################## - ########################################################################## - - name: Checkout code - uses: actions/checkout@v3 - ########################################################################## - # DATABASE UP ############################################################ - ########################################################################## - - name: Database | Build `test_up` image - run: | - docker build --target test_up -t "gradido/database:test_up" database/ - docker save "gradido/database:test_up" > /tmp/database_up.tar - - name: Upload Artifact - uses: actions/upload-artifact@v3 - with: - name: docker-database-test_up - path: /tmp/database_up.tar - ############################################################################## # JOB: LINT BACKEND ########################################################## ############################################################################## @@ -91,23 +65,7 @@ jobs: - name: Backend | Locales run: cd backend && yarn && yarn locales - ############################################################################## - # JOB: LINT DATABASE UP ###################################################### - ############################################################################## - lint_database_up: - name: Lint - Database Up - runs-on: ubuntu-latest - steps: - ########################################################################## - # CHECKOUT CODE ########################################################## - ########################################################################## - - name: Checkout code - uses: actions/checkout@v3 - ########################################################################## - # LINT DATABASE ########################################################## - ########################################################################## - - name: Database | Lint - run: cd database && yarn && yarn run lint + ############################################################################## # JOB: UNIT TEST BACKEND #################################################### @@ -145,25 +103,3 @@ jobs: - name: backend Unit tests | test run: cd database && yarn && yarn build && cd ../backend && yarn && yarn test - ########################################################################## - # DATABASE MIGRATION TEST UP + RESET ##################################### - ########################################################################## - database_migration_test: - name: Database Migration Test - Up + Reset - runs-on: ubuntu-latest - #needs: [nothing] - steps: - ########################################################################## - # CHECKOUT CODE ########################################################## - ########################################################################## - - name: Checkout code - uses: actions/checkout@v3 - ########################################################################## - # DOCKER COMPOSE DATABASE UP + RESET ##################################### - ########################################################################## - - name: database | docker-compose - run: docker-compose -f docker-compose.yml up --detach mariadb - - name: database | up - run: docker-compose -f docker-compose.yml run -T database yarn up - - name: database | reset - run: docker-compose -f docker-compose.yml run -T database yarn reset diff --git a/.github/workflows/test_database.yml b/.github/workflows/test_database.yml new file mode 100644 index 000000000..d39fe5972 --- /dev/null +++ b/.github/workflows/test_database.yml @@ -0,0 +1,65 @@ +name: Gradido Database Test CI + +on: push + +jobs: + files-changed: + name: Detect File Changes - Database + runs-on: ubuntu-latest + outputs: + database: ${{ steps.changes.outputs.database }} + docker-compose: ${{ steps.changes.outputs.docker-compose }} + mariadb: ${{ steps.changes.outputs.mariadb }} + steps: + - uses: actions/checkout@v3.3.0 + + - name: Check for frontend file changes + uses: dorny/paths-filter@v2.11.1 + id: changes + with: + token: ${{ github.token }} + filters: .github/file-filters.yml + list-files: shell + + build: + if: needs.files-changed.outputs.database == 'true' + name: Docker Build Test - Database up + needs: files-changed + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Database | Build 'test_up' image + run: | + docker build --target test_up -t "gradido/database:test_up" database/ + + database_migration_test: + if: needs.files-changed.outputs.database == 'true' || needs.files-changed.outputs.docker-compose == 'true' || needs.files-changed.outputs.mariadb == 'true' + name: Database Migration Test - Up + Reset + needs: files-changed + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Database | docker-compose + run: docker-compose -f docker-compose.yml up --detach mariadb + + - name: Database | up + run: docker-compose -f docker-compose.yml run -T database yarn up + + - name: Database | reset + run: docker-compose -f docker-compose.yml run -T database yarn reset + + lint: + if: needs.files-changed.outputs.database == 'true' + name: Lint - Database Up + needs: files-changed + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Database | Lint + run: cd database && yarn && yarn run lint \ No newline at end of file From 98a02de50acc90c021d49548e333ffe09916f663 Mon Sep 17 00:00:00 2001 From: mahula Date: Tue, 2 May 2023 20:31:49 +0200 Subject: [PATCH 11/19] move backend test jobs to separate workflow file --- .github/file-filters.yml | 3 + .github/workflows/test.yml | 105 ----------------------------- .github/workflows/test_backend.yml | 81 ++++++++++++++++++++++ 3 files changed, 84 insertions(+), 105 deletions(-) delete mode 100644 .github/workflows/test.yml create mode 100644 .github/workflows/test_backend.yml diff --git a/.github/file-filters.yml b/.github/file-filters.yml index 02ea2709e..f0d38b75b 100644 --- a/.github/file-filters.yml +++ b/.github/file-filters.yml @@ -30,6 +30,9 @@ admin: &admin - 'admin/**/*' +backend: &backend + - 'backend/**/*' + dht_node: &dht_node - 'dht-node/**/*' diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml deleted file mode 100644 index 1b245fa2b..000000000 --- a/.github/workflows/test.yml +++ /dev/null @@ -1,105 +0,0 @@ -name: gradido test CI - -on: push - -jobs: - ############################################################################## - # JOB: DOCKER BUILD TEST BACKEND ############################################# - ############################################################################## - build_test_backend: - name: Docker Build Test - Backend - runs-on: ubuntu-latest - #needs: [nothing] - steps: - ########################################################################## - # CHECKOUT CODE ########################################################## - ########################################################################## - - name: Checkout code - uses: actions/checkout@v3 - ########################################################################## - # BACKEND ################################################################ - ########################################################################## - - name: Backend | Build `test` image - run: | - docker build -f ./backend/Dockerfile --target test -t "gradido/backend:test" . - docker save "gradido/backend:test" > /tmp/backend.tar - - name: Upload Artifact - uses: actions/upload-artifact@v3 - with: - name: docker-backend-test - path: /tmp/backend.tar - - ############################################################################## - # JOB: LINT BACKEND ########################################################## - ############################################################################## - lint_backend: - name: Lint - Backend - runs-on: ubuntu-latest - steps: - ########################################################################## - # CHECKOUT CODE ########################################################## - ########################################################################## - - name: Checkout code - uses: actions/checkout@v3 - ########################################################################## - # LINT BACKEND ########################################################### - ########################################################################## - - name: backend | Lint - run: cd database && yarn && cd ../backend && yarn && yarn run lint - - ############################################################################## - # JOB: LOCALES BACKEND ####################################################### - ############################################################################## - locales_backend: - name: Locales - Backend - runs-on: ubuntu-latest - steps: - ########################################################################## - # CHECKOUT CODE ########################################################## - ########################################################################## - - name: Checkout code - uses: actions/checkout@v3 - ########################################################################## - # LOCALES BACKEND ##################################################### - ########################################################################## - - name: Backend | Locales - run: cd backend && yarn && yarn locales - - - - ############################################################################## - # JOB: UNIT TEST BACKEND #################################################### - ############################################################################## - unit_test_backend: - name: Unit tests - Backend - runs-on: ubuntu-latest - needs: [build_test_mariadb] - steps: - ########################################################################## - # CHECKOUT CODE ########################################################## - ########################################################################## - - name: Checkout code - uses: actions/checkout@v3 - ########################################################################## - # DOWNLOAD DOCKER IMAGES ################################################# - ########################################################################## - - name: Download Docker Image (Mariadb) - uses: actions/download-artifact@v3 - with: - name: docker-mariadb-test - path: /tmp - - name: Load Docker Image - run: docker load < /tmp/mariadb.tar - ########################################################################## - # UNIT TESTS BACKEND ##################################################### - ########################################################################## - - name: backend | docker-compose mariadb - run: docker-compose -f docker-compose.yml -f docker-compose.test.yml up --detach --no-deps mariadb - - name: Sleep for 30 seconds - run: sleep 30s - shell: bash - - name: backend | docker-compose database - run: docker-compose -f docker-compose.yml -f docker-compose.test.yml up --detach --no-deps database - - name: backend Unit tests | test - run: cd database && yarn && yarn build && cd ../backend && yarn && yarn test - diff --git a/.github/workflows/test_backend.yml b/.github/workflows/test_backend.yml new file mode 100644 index 000000000..b517c5186 --- /dev/null +++ b/.github/workflows/test_backend.yml @@ -0,0 +1,81 @@ +name: Gradido Backend Test CI + +on: push + +jobs: + files-changed: + name: Detect File Changes - Backend + runs-on: ubuntu-latest + outputs: + backend: ${{ steps.changes.outputs.backend }} + database: ${{ steps.changes.outputs.database }} + docker-compose: ${{ steps.changes.outputs.docker-compose }} + mariadb: ${{ steps.changes.outputs.mariadb }} + steps: + - uses: actions/checkout@v3.3.0 + + - name: Check for frontend file changes + uses: dorny/paths-filter@v2.11.1 + id: changes + with: + token: ${{ github.token }} + filters: .github/file-filters.yml + list-files: shell + + build_test: + if: needs.files-changed.outputs.backend == 'true' + name: Docker Build Test - Backend + needs: files-changed + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Backend | Build 'test' image + run: docker build -f ./backend/Dockerfile --target test -t "gradido/backend:test" . + + unit_test: + if: needs.files-changed.outputs.backend == 'true' || needs.files-changed.outputs.database == 'true' || needs.files-changed.outputs.docker-compose == 'true' || needs.files-changed.outputs.mariadb == 'true' + name: Unit tests - Backend + needs: files-changed + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Backend | docker-compose mariadb + run: docker-compose -f docker-compose.yml -f docker-compose.test.yml up --detach --no-deps mariadb + + - name: Sleep for 30 seconds + run: sleep 30s + shell: bash + + - name: Backend | docker-compose database + run: docker-compose -f docker-compose.yml -f docker-compose.test.yml up --detach --no-deps database + + - name: Backend | Unit tests + run: cd database && yarn && yarn build && cd ../backend && yarn && yarn test + + lint: + if: needs.files-changed.outputs.backend == 'true' + name: Lint - Backend + needs: files-changed + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Backend | Lint + run: cd database && yarn && cd ../backend && yarn && yarn run lint + + locales: + if: needs.files-changed.outputs.backend == 'true' + name: Locales - Backend + needs: files-changed + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Backend | Locales + run: cd backend && yarn && yarn locales \ No newline at end of file From bd4ea0bade627df51f206e6e3e9fecaa4140cc75 Mon Sep 17 00:00:00 2001 From: mahula Date: Tue, 2 May 2023 20:41:44 +0200 Subject: [PATCH 12/19] clean up --- .github/workflows/test_database.yml | 3 +-- .github/workflows/test_mariadb.yml | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/.github/workflows/test_database.yml b/.github/workflows/test_database.yml index d39fe5972..0444a0538 100644 --- a/.github/workflows/test_database.yml +++ b/.github/workflows/test_database.yml @@ -31,8 +31,7 @@ jobs: uses: actions/checkout@v3 - name: Database | Build 'test_up' image - run: | - docker build --target test_up -t "gradido/database:test_up" database/ + run: docker build --target test_up -t "gradido/database:test_up" database/ database_migration_test: if: needs.files-changed.outputs.database == 'true' || needs.files-changed.outputs.docker-compose == 'true' || needs.files-changed.outputs.mariadb == 'true' diff --git a/.github/workflows/test_mariadb.yml b/.github/workflows/test_mariadb.yml index 925884cf5..fe101bc48 100644 --- a/.github/workflows/test_mariadb.yml +++ b/.github/workflows/test_mariadb.yml @@ -29,5 +29,4 @@ jobs: uses: actions/checkout@v3 - name: MariaDB | Build 'test' image - run: | - docker build --target mariadb_server -t "gradido/mariadb:test" -f ./mariadb/Dockerfile ./ + run: docker build --target mariadb_server -t "gradido/mariadb:test" -f ./mariadb/Dockerfile ./ From fd61eb84fed8ee78133ac267ec8c6108aeadd16b Mon Sep 17 00:00:00 2001 From: mahula Date: Tue, 2 May 2023 21:38:44 +0200 Subject: [PATCH 13/19] add check for mariadb and database changes to dht node and federation workflow --- .github/workflows/test_dht_node.yml | 3 ++- .github/workflows/test_federation.yml | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test_dht_node.yml b/.github/workflows/test_dht_node.yml index bb24f2d2f..b63d1fc0d 100644 --- a/.github/workflows/test_dht_node.yml +++ b/.github/workflows/test_dht_node.yml @@ -7,6 +7,7 @@ jobs: name: Detect File Changes - DHT Node runs-on: ubuntu-latest outputs: + database: ${{ steps.changes.outputs.database }} dht_node: ${{ steps.changes.outputs.dht_node }} docker-compose: ${{ steps.changes.outputs.docker-compose }} steps: @@ -54,7 +55,7 @@ jobs: unit_test: name: Unit Tests - DHT Node - if: needs.files-changed.outputs.dht_node == 'true' || needs.files-changed.outputs.docker-compose == 'true' + if: needs.files-changed.outputs.database == 'true' || needs.files-changed.outputs.dht_node == 'true' || needs.files-changed.outputs.docker-compose == 'true' || needs.files-changed.outputs.mariadb == 'true' needs: [files-changed, build] runs-on: ubuntu-latest steps: diff --git a/.github/workflows/test_federation.yml b/.github/workflows/test_federation.yml index 5fd714b00..92ccd95d2 100644 --- a/.github/workflows/test_federation.yml +++ b/.github/workflows/test_federation.yml @@ -54,7 +54,7 @@ jobs: unit_test: name: Unit Tests - Federation - if: needs.files-changed.outputs.docker-compose == 'true' || needs.files-changed.outputs.federation == 'true' + if: needs.files-changed.outputs.database == 'true' || needs.files-changed.outputs.docker-compose == 'true' || needs.files-changed.outputs.federation == 'true' || needs.files-changed.outputs.mariadb == 'true' needs: [files-changed, build] runs-on: ubuntu-latest steps: From 0c820fb53bef2098cd39c08fc668d74f6abb3ab1 Mon Sep 17 00:00:00 2001 From: mahula Date: Tue, 2 May 2023 21:55:41 +0200 Subject: [PATCH 14/19] clean up mariadb Dockerfile fo check workflow changes --- mariadb/Dockerfile | 5 ----- 1 file changed, 5 deletions(-) diff --git a/mariadb/Dockerfile b/mariadb/Dockerfile index 07d2ba368..d3d5937d0 100644 --- a/mariadb/Dockerfile +++ b/mariadb/Dockerfile @@ -2,8 +2,3 @@ # mariadb server ######################################################################################################### FROM mariadb/server:10.5 as mariadb_server - -# ENV DOCKER_WORKDIR="/docker-entrypoint-initdb.d" - -# RUN mkdir -p ${DOCKER_WORKDIR} -# WORKDIR ${DOCKER_WORKDIR} From 1241f00ede40de1949b6dc10fbe890ef88e57b55 Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Wed, 3 May 2023 10:16:37 +0200 Subject: [PATCH 15/19] fixed typos --- deployment/bare_metal/setup.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deployment/bare_metal/setup.md b/deployment/bare_metal/setup.md index da3688eed..325082e80 100644 --- a/deployment/bare_metal/setup.md +++ b/deployment/bare_metal/setup.md @@ -198,7 +198,7 @@ Follow the commands in `./install.sh` as installation pattern. ## Define Cronjob To Compensate Yarn Output In `/tmp` -`yarn` creates output in `/tmp` directory. This output is generated whenever `yarn start` is called. THis is especially problematic on staging systems where instable versions are automatically deployed which can lead to a ever resatrting service, hence generating alot of yarn output. +`yarn` creates output in `/tmp` directory. This output is generated whenever `yarn start` is called. This is especially problematic on staging systems where instable versions are automatically deployed which can lead to an ever restarting, hence generating a lot of yarn output. To solve this you can install the following hourly cron using `crontab` as `gradido` user.he `gradido` user. From 7cb11af5993febefeba7764c4eacdb0a24b94cf3 Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Wed, 3 May 2023 10:17:25 +0200 Subject: [PATCH 16/19] fix typo --- deployment/bare_metal/setup.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deployment/bare_metal/setup.md b/deployment/bare_metal/setup.md index 325082e80..881c79bec 100644 --- a/deployment/bare_metal/setup.md +++ b/deployment/bare_metal/setup.md @@ -200,7 +200,7 @@ Follow the commands in `./install.sh` as installation pattern. `yarn` creates output in `/tmp` directory. This output is generated whenever `yarn start` is called. This is especially problematic on staging systems where instable versions are automatically deployed which can lead to an ever restarting, hence generating a lot of yarn output. -To solve this you can install the following hourly cron using `crontab` as `gradido` user.he `gradido` user. +To solve this you can install the following hourly cron using `crontab` as `gradido` user. Run: From bf3cbfa87587d2946df1702cefce6ff585f3053c Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Wed, 3 May 2023 10:19:01 +0200 Subject: [PATCH 17/19] typo --- deployment/bare_metal/setup.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deployment/bare_metal/setup.md b/deployment/bare_metal/setup.md index 881c79bec..9cbc4e2e3 100644 --- a/deployment/bare_metal/setup.md +++ b/deployment/bare_metal/setup.md @@ -215,7 +215,7 @@ This opens the crontab in edit-mode and insert the following entry: ``` -For production systems this is not need by default since the yarn output is deleted when `start.sh` is executed. If the service runs stable and does not restart frequently the yarn output to the tmp folder scales with the amount of services running. +For production systems this is not needed by default since the yarn output is deleted when `start.sh` is executed. If the service runs stable and does not restart frequently, the yarn output to the tmp folder scales with the amount of services running. ## Define Cronjob To start backup script automatically From 9b9c0ea8cbc578bd15d802e1ec1ae1490891be39 Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Wed, 3 May 2023 12:37:29 +0200 Subject: [PATCH 18/19] merge conflict --- backend/src/graphql/directive/isAuthorized.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/src/graphql/directive/isAuthorized.ts b/backend/src/graphql/directive/isAuthorized.ts index 504e8d27b..b8595a2bd 100644 --- a/backend/src/graphql/directive/isAuthorized.ts +++ b/backend/src/graphql/directive/isAuthorized.ts @@ -8,7 +8,7 @@ import { ROLE_UNAUTHORIZED, ROLE_USER, ROLE_ADMIN } from '@/auth/ROLES' import { Context } from '@/server/context' import { LogError } from '@/server/LogError' -const isAuthorized: AuthChecker = async ({ context }, rights) => { +export const isAuthorized: AuthChecker = async ({ context }, rights) => { context.role = ROLE_UNAUTHORIZED // unauthorized user // is rights an inalienable right? From 8c76de3ee51e4f52ea27d2da3e651b4b983f1d6f Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Wed, 3 May 2023 13:07:54 +0200 Subject: [PATCH 19/19] try fixing auth tests by reverting header token change --- backend/test/helpers.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/backend/test/helpers.ts b/backend/test/helpers.ts index 07601227c..d42db959f 100644 --- a/backend/test/helpers.ts +++ b/backend/test/helpers.ts @@ -2,12 +2,12 @@ import { entities } from '@entity/index' import { createTestClient } from 'apollo-server-testing' -import { Context } from '@/server/context' import { createServer } from '@/server/createServer' import { i18n, logger } from './testSetup' -export const headerPushMock = jest.fn(([t]: Context['setHeaders']) => { +export const headerPushMock = jest.fn((t) => { + // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access context.token = t.value })