diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 42b8c526e..1e8d53acc 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -344,7 +344,7 @@ jobs: report_name: Coverage Frontend type: lcov result_path: ./coverage/lcov.info - min_coverage: 83 + min_coverage: 85 token: ${{ github.token }} ############################################################################## @@ -353,7 +353,7 @@ jobs: unit_test_backend: name: Unit tests - Backend runs-on: ubuntu-latest - needs: [build_test_backend] + needs: [build_test_backend,build_test_mariadb] steps: ########################################################################## # CHECKOUT CODE ########################################################## @@ -363,6 +363,13 @@ jobs: ########################################################################## # DOWNLOAD DOCKER IMAGES ################################################# ########################################################################## + - name: Download Docker Image (Mariadb) + uses: actions/download-artifact@v2 + with: + name: docker-mariadb-test + path: /tmp + - name: Load Docker Image + run: docker load < /tmp/mariadb.tar - name: Download Docker Image (Backend) uses: actions/download-artifact@v2 with: @@ -373,10 +380,11 @@ jobs: ########################################################################## # UNIT TESTS BACKEND ##################################################### ########################################################################## - - name: backend | Unit tests - run: | - docker run -v ~/coverage:/app/coverage --rm gradido/backend:test yarn run test - cp -r ~/coverage ./coverage + - name: backend | docker-compose + run: docker-compose -f docker-compose.yml -f docker-compose.test.yml up --detach --no-deps mariadb database + - name: backend Unit tests | test + run: cd database && yarn && cd ../backend && yarn && yarn test + # run: docker-compose -f docker-compose.yml -f docker-compose.test.yml exec -T backend yarn test ########################################################################## # COVERAGE CHECK BACKEND ################################################# ########################################################################## @@ -385,8 +393,8 @@ jobs: with: report_name: Coverage Backend type: lcov - result_path: ./coverage/lcov.info - min_coverage: 1 + result_path: ./backend/coverage/lcov.info + min_coverage: 45 token: ${{ github.token }} ############################################################################## diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 000000000..a6dc06683 --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,7 @@ +{ + "recommendations": [ + "streetsidesoftware.code-spell-checker", + "dbaeumer.vscode-eslint", + "esbenp.prettier-vscode" + ] +} \ No newline at end of file diff --git a/README.md b/README.md index fe6f2e7f3..ead54701c 100644 --- a/README.md +++ b/README.md @@ -8,33 +8,73 @@ The Gradido model can create global prosperity and peace The Corona crisis has fundamentally changed our world within a very short time. The dominant financial system threatens to fail around the globe, followed by mass insolvencies, record unemployment and abject poverty. Only with a sustainable new monetary system can humanity master these challenges of the 21st century. The Gradido Academy for Bionic Economy has developed such a system. +Find out more about the Project on its [Website](https://gradido.net/). It is offering vast resources about the idea. The remaining document will discuss the gradido software only. ## Software requirements -Currently we only support `docker` as environment to run all services, since many different programming languages and frameworks are used. +Currently we only support `docker` install instructions to run all services, since many different programming languages and frameworks are used. -- [docker](https://www.docker.com/) +- [docker](https://www.docker.com/) +- [docker-compose] + +### For Arch Linux +Install the required packages: +```bash +sudo pacman -S docker +sudo pacman -S docker-compose +``` + +Add group `docker` and then your user to it in order to allow you to run docker without sudo +```bash +sudo groupadd docker # may already exist `groupadd: group 'docker' already exists` +sudo usermod -aG docker $USER +groups # verify you have the group (requires relog) +``` + +Start the docker service: +```bash +sudo systemctrl start docker +``` ## How to run? -1. Clone the repo and pull all submodules - +### 1. Clone Sources +Clone the repo and pull all submodules ```bash git clone git@github.com:gradido/gradido.git git submodule update --recursive --init ``` -2. Run docker compose - 1. Run docker compose for the debug build +### 2. Run docker-compose +Run docker-compose to bring up the development environment +```bash +docker-compose up +``` +### Additional Build options +If you want to build for production you can do this aswell: +```bash +docker-compose -f docker-compose.yml up +``` - ```bash - docker-compose up - ``` +## Services defined in this package - 2. Or run docker compose in production build +- [frontend](./frontend) Wallet frontend +- [backend](./backend) GraphQL & Business logic backend +- [mariadb](./mariadb) Database backend +- [login_server](./login_server) User credential storage & business logic backend +- [community_server](./community_server/) Business logic backend - ```bash - docker-compose -f docker-compose.yml up - ``` +We are currently restructuring the service to reduce dependencies and unify business logic into one place. Furthermore the databases defined for each service will be unified into one. + +### Open the wallet + +Once you have `docker-compose` up and running, you can open [http://localhost/vue](http://localhost/vue) and create yourself a new wallet account. + +## Troubleshooting + +| Problem | Issue | Solution | Description | +| ------- | ----- | -------- | ----------- | +| docker-compose raises database connection errors | [#1062](https://github.com/gradido/gradido/issues/1062) | End `ctrl+c` and restart the `docker-compose up` after a successful build | Several Database connection related errors occur in the docker-compose log. | +| Wallet page is empty | [#1063](https://github.com/gradido/gradido/issues/1063) | Accept Cookies and Local Storage in your Browser | The page stays empty when navigating to [http://localhost/vue](http://localhost/vue) | ## Useful Links diff --git a/backend/Dockerfile b/backend/Dockerfile index 8331f5983..035841c17 100644 --- a/backend/Dockerfile +++ b/backend/Dockerfile @@ -85,7 +85,7 @@ RUN cd ../database && yarn run build FROM build as test # Run command -CMD /bin/sh -c "yarn run dev" +CMD /bin/sh -c "yarn run start" ################################################################################## # PRODUCTION (Does contain only "binary"- and static-files to reduce image size) # diff --git a/backend/package.json b/backend/package.json index 9da51cb7f..be183913a 100644 --- a/backend/package.json +++ b/backend/package.json @@ -13,11 +13,12 @@ "start": "node build/index.js", "dev": "nodemon -w src --ext ts --exec ts-node src/index.ts", "lint": "eslint . --ext .js,.ts", - "test": "jest --coverage" + "test": "jest --runInBand --coverage " }, "dependencies": { "@types/jest": "^27.0.2", "apollo-server-express": "^2.25.2", + "apollo-server-testing": "^2.25.2", "axios": "^0.21.1", "class-validator": "^0.13.1", "cors": "^2.8.5", diff --git a/backend/src/graphql/resolver/CommunityResolver.test.ts b/backend/src/graphql/resolver/CommunityResolver.test.ts new file mode 100644 index 000000000..20a06c2b8 --- /dev/null +++ b/backend/src/graphql/resolver/CommunityResolver.test.ts @@ -0,0 +1,123 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ +/* eslint-disable @typescript-eslint/explicit-module-boundary-types */ + +import { createTestClient } from 'apollo-server-testing' +import createServer from '../../server/createServer' +import CONFIG from '../../config' + +jest.mock('../../config') + +let query: any + +// to do: We need a setup for the tests that closes the connection +let con: any + +beforeAll(async () => { + const server = await createServer({}) + con = server.con + query = createTestClient(server.apollo).query +}) + +afterAll(async () => { + await con.close() +}) + +describe('CommunityResolver', () => { + const getCommunityInfoQuery = ` + query { + getCommunityInfo { + name + description + url + registerUrl + } + } + ` + + const communities = ` + query { + communities { + id + name + url + description + registerUrl + } + } + ` + + describe('getCommunityInfo', () => { + it('returns the default values', async () => { + expect(query({ query: getCommunityInfoQuery })).resolves.toMatchObject({ + data: { + getCommunityInfo: { + name: 'Gradido Entwicklung', + description: 'Die lokale Entwicklungsumgebung von Gradido.', + url: 'http://localhost/vue/', + registerUrl: 'http://localhost/vue/register', + }, + }, + }) + }) + }) + + describe('communities', () => { + describe('PRODUCTION = false', () => { + beforeEach(() => { + CONFIG.PRODUCTION = false + }) + + it('returns three communities', async () => { + expect(query({ query: communities })).resolves.toMatchObject({ + data: { + communities: [ + { + id: 1, + name: 'Gradido Entwicklung', + description: 'Die lokale Entwicklungsumgebung von Gradido.', + url: 'http://localhost/vue/', + registerUrl: 'http://localhost/vue/register-community', + }, + { + id: 2, + name: 'Gradido Staging', + description: 'Der Testserver der Gradido-Akademie.', + url: 'https://stage1.gradido.net/vue/', + registerUrl: 'https://stage1.gradido.net/vue/register-community', + }, + { + id: 3, + name: 'Gradido-Akademie', + description: 'Freies Institut für Wirtschaftsbionik.', + url: 'https://gradido.net', + registerUrl: 'https://gdd1.gradido.com/vue/register-community', + }, + ], + }, + }) + }) + }) + + describe('PRODUCTION = true', () => { + beforeEach(() => { + CONFIG.PRODUCTION = true + }) + + it('returns one community', async () => { + expect(query({ query: communities })).resolves.toMatchObject({ + data: { + communities: [ + { + id: 3, + name: 'Gradido-Akademie', + description: 'Freies Institut für Wirtschaftsbionik.', + url: 'https://gradido.net', + registerUrl: 'https://gdd1.gradido.com/vue/register-community', + }, + ], + }, + }) + }) + }) + }) +}) diff --git a/backend/src/graphql/schema.ts b/backend/src/graphql/schema.ts index 0a570ae82..02caf2784 100644 --- a/backend/src/graphql/schema.ts +++ b/backend/src/graphql/schema.ts @@ -6,7 +6,7 @@ import isAuthorized from './directive/isAuthorized' const schema = async (): Promise => { return buildSchema({ - resolvers: [path.join(__dirname, 'resolver', `*.{js,ts}`)], + resolvers: [path.join(__dirname, 'resolver', `!(*.test).{js,ts}`)], authChecker: isAuthorized, }) } diff --git a/backend/src/index.ts b/backend/src/index.ts index 65f899b26..a2e533e34 100644 --- a/backend/src/index.ts +++ b/backend/src/index.ts @@ -1,64 +1,14 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ -import 'reflect-metadata' -import 'module-alias/register' -import express from 'express' -import { ApolloServer } from 'apollo-server-express' +import createServer from './server/createServer' // config import CONFIG from './config' -// database -import connection from './typeorm/connection' -import getDBVersion from './typeorm/getDBVersion' - -// server -import cors from './server/cors' -import context from './server/context' -import plugins from './server/plugins' - -// graphql -import schema from './graphql/schema' - -// TODO implement -// import queryComplexity, { simpleEstimator, fieldConfigEstimator } from "graphql-query-complexity"; - -const DB_VERSION = '0004-login_server_data' - async function main() { - // open mysql connection - const con = await connection() - if (!con || !con.isConnected) { - throw new Error(`Couldn't open connection to database`) - } + const { app } = await createServer() - // check for correct database version - const dbVersion = await getDBVersion() - if (!dbVersion || dbVersion.indexOf(DB_VERSION) === -1) { - throw new Error( - `Wrong database version - the backend requires '${DB_VERSION}' but found '${ - dbVersion || 'None' - }'`, - ) - } - - // Express Server - const server = express() - - // cors - server.use(cors) - - // Apollo Server - const apollo = new ApolloServer({ - schema: await schema(), - playground: CONFIG.GRAPHIQL, - context, - plugins, - }) - apollo.applyMiddleware({ app: server }) - - // Start Server - server.listen(CONFIG.PORT, () => { + app.listen(CONFIG.PORT, () => { // eslint-disable-next-line no-console console.log(`Server is running at http://localhost:${CONFIG.PORT}`) if (CONFIG.GRAPHIQL) { diff --git a/backend/src/server/createServer.ts b/backend/src/server/createServer.ts new file mode 100644 index 000000000..4350483ff --- /dev/null +++ b/backend/src/server/createServer.ts @@ -0,0 +1,64 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ +/* eslint-disable @typescript-eslint/explicit-module-boundary-types */ + +import 'reflect-metadata' +import 'module-alias/register' + +import { ApolloServer } from 'apollo-server-express' +import express from 'express' + +// database +import connection from '../typeorm/connection' +import getDBVersion from '../typeorm/getDBVersion' + +// server +import cors from './cors' +import serverContext from './context' +import plugins from './plugins' + +// config +import CONFIG from '../config' + +// graphql +import schema from '../graphql/schema' + +// TODO implement +// import queryComplexity, { simpleEstimator, fieldConfigEstimator } from "graphql-query-complexity"; + +const DB_VERSION = '0004-login_server_data' + +const createServer = async (context: any = serverContext): Promise => { + // open mysql connection + const con = await connection() + if (!con || !con.isConnected) { + throw new Error(`Couldn't open connection to database`) + } + + // check for correct database version + const dbVersion = await getDBVersion() + if (!dbVersion || dbVersion.indexOf(DB_VERSION) === -1) { + throw new Error( + `Wrong database version - the backend requires '${DB_VERSION}' but found '${ + dbVersion || 'None' + }'`, + ) + } + + // Express Server + const app = express() + + // cors + app.use(cors) + + // Apollo Server + const apollo = new ApolloServer({ + schema: await schema(), + playground: CONFIG.GRAPHIQL, + context, + plugins, + }) + apollo.applyMiddleware({ app }) + return { apollo, app, con } +} + +export default createServer diff --git a/backend/yarn.lock b/backend/yarn.lock index 75b998c17..51a8e5997 100644 --- a/backend/yarn.lock +++ b/backend/yarn.lock @@ -1328,6 +1328,13 @@ apollo-server-plugin-base@^0.13.0: dependencies: apollo-server-types "^0.9.0" +apollo-server-testing@^2.25.2: + version "2.25.2" + resolved "https://registry.yarnpkg.com/apollo-server-testing/-/apollo-server-testing-2.25.2.tgz#0043e98b1a03720352e94b409215fb4782ae2e50" + integrity sha512-HjQV9wPbi/ZqpRbyyhNwCbaDnfjDM0hTRec5TOoOjurEZ/vh4hTPHwGkDZx3kbcWowhGxe2qoHM6KANSB/SxuA== + dependencies: + apollo-server-core "^2.25.2" + apollo-server-types@^0.9.0: version "0.9.0" resolved "https://registry.npmjs.org/apollo-server-types/-/apollo-server-types-0.9.0.tgz" diff --git a/docker-compose.test.yml b/docker-compose.test.yml index 73da574d2..e7b0e9849 100644 --- a/docker-compose.test.yml +++ b/docker-compose.test.yml @@ -2,6 +2,26 @@ version: "3.4" services: + ######################################################## + # BACKEND ############################################## + ######################################################## + backend: + image: gradido/backend:test + build: + target: test + networks: + - external-net + - internal-net + environment: + - NODE_ENV="test" + - DB_HOST=mariadb + + ######################################################## + # DATABASE ############################################# + ######################################################## + database: + restart: always # this is very dangerous, but worth a test for the delayed mariadb startup at first run + ######################################################### ## MARIADB ############################################## ######################################################### @@ -15,10 +35,11 @@ services: - MARIADB_USER=root networks: - internal-net + - external-net ports: - 3306:3306 volumes: - - db_test_vol:/var/lib/mysql + - db_test_vol:/var/lib/mysql ######################################################### ## LOGIN SERVER ######################################### diff --git a/docu/Gradido-Admin.epgz b/docu/Gradido-Admin.epgz new file mode 100644 index 000000000..9c00dc445 Binary files /dev/null and b/docu/Gradido-Admin.epgz differ diff --git a/docu/graphics/gradido_admin.png b/docu/graphics/gradido_admin.png new file mode 100644 index 000000000..855cf903e Binary files /dev/null and b/docu/graphics/gradido_admin.png differ diff --git a/docu/graphics/userdetails.png b/docu/graphics/userdetails.png new file mode 100644 index 000000000..b31ff3e63 Binary files /dev/null and b/docu/graphics/userdetails.png differ diff --git a/frontend/jest.config.js b/frontend/jest.config.js index dc44ca43e..774aa6bf9 100644 --- a/frontend/jest.config.js +++ b/frontend/jest.config.js @@ -9,8 +9,9 @@ module.exports = { ], // coverageReporters: ['lcov', 'text'], moduleNameMapper: { - '^@/(.*)$': '/src/$1', '\\.(css|less)$': 'identity-obj-proxy', + '\\.(scss)$': '/src/assets/mocks/styleMock.js', + '^@/(.*)$': '/src/$1', }, transform: { '^.+\\.vue$': 'vue-jest', diff --git a/frontend/src/assets/mocks/styleMock.js b/frontend/src/assets/mocks/styleMock.js new file mode 100644 index 000000000..4ba52ba2c --- /dev/null +++ b/frontend/src/assets/mocks/styleMock.js @@ -0,0 +1 @@ +module.exports = {} diff --git a/frontend/src/plugins/dashboard-plugin.test.js b/frontend/src/plugins/dashboard-plugin.test.js new file mode 100644 index 000000000..3792ad2c4 --- /dev/null +++ b/frontend/src/plugins/dashboard-plugin.test.js @@ -0,0 +1,25 @@ +import dashboardPlugin from './dashboard-plugin.js' +import Vue from 'vue' + +import GlobalComponents from './globalComponents' +import GlobalDirectives from './globalDirectives' + +jest.mock('./globalComponents') +jest.mock('./globalDirectives') + +jest.mock('vue') + +const vueUseMock = jest.fn() +Vue.use = vueUseMock + +describe('dashboard plugin', () => { + dashboardPlugin.install(Vue) + + it('installs the global components', () => { + expect(vueUseMock).toBeCalledWith(GlobalComponents) + }) + + it('installs the global directives', () => { + expect(vueUseMock).toBeCalledWith(GlobalDirectives) + }) +}) diff --git a/login_server/src/cpp/controller/User.cpp b/login_server/src/cpp/controller/User.cpp index e54832427..a1cd4011f 100644 --- a/login_server/src/cpp/controller/User.cpp +++ b/login_server/src/cpp/controller/User.cpp @@ -69,7 +69,7 @@ namespace controller { using namespace Poco::Data::Keywords; Poco::Data::Statement select(session); - select << "SELECT id, first_name, last_name, email, username, description, pubkey, created, email_checked, disabled, group_id FROM " << db->getTableName(); + select << "SELECT id, first_name, last_name, email, username, description, pubkey, created, email_checked, disabled, group_id, publisher_id FROM " << db->getTableName(); select << " where email_checked = 0 "; select, into(resultFromDB); if (searchString != "") { diff --git a/login_server/src/cpsp/CheckTransaction.cpsp b/login_server/src/cpsp/CheckTransaction.cpsp index d866384b7..f0c56c100 100644 --- a/login_server/src/cpsp/CheckTransaction.cpsp +++ b/login_server/src/cpsp/CheckTransaction.cpsp @@ -74,7 +74,8 @@ enum PageState { { //mSession->finalizeTransaction(false, true); // - if(!transaction.isNull() && transaction->getModel()->getUserId() == user_model->getID()) + if(!transaction.isNull() && + (transaction_body->isCreation() || transaction->getModel()->getUserId() == user_model->getID())) { if(pt->removeTask(transaction)) { transaction->deleteFromDB(); @@ -150,7 +151,7 @@ enum PageState { transaction_body = transaction->getTransactionBody(); // user can only delete there own transactions // TODO: Auto timeout for community transactions - if(transaction->getModel()->getUserId() == user_model->getID()) { + if(transaction_body->isCreation() || transaction->getModel()->getUserId() == user_model->getID()) { transaction_removeable = true; } } @@ -338,20 +339,19 @@ enum PageState { <%= gettext("Transaktion unterzeichnen") %> <% } %> + <% if(transaction_removeable) { %> - <% } else { %> - <% } %> <% } %> -<%@ include file="include/footer_chr.cpsp" %> \ No newline at end of file +<%@ include file="include/footer_chr.cpsp" %>