diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 00a599e95..7e07cc8d3 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -399,7 +399,7 @@ jobs: report_name: Coverage Frontend type: lcov result_path: ./coverage/lcov.info - min_coverage: 86 + min_coverage: 87 token: ${{ github.token }} ############################################################################## diff --git a/README.md b/README.md index ead54701c..ce8e84df0 100644 --- a/README.md +++ b/README.md @@ -69,6 +69,22 @@ We are currently restructuring the service to reduce dependencies and unify busi Once you have `docker-compose` up and running, you can open [http://localhost/vue](http://localhost/vue) and create yourself a new wallet account. +## How to release + +A release is tagged on Github by its version number and published as github release. This is done automatically when a new version is defined in the [package.json](./package.json) and merged into master - furthermore we set all our sub-package-versions to the same version as the main package.json version to make version management as simple as possible. +Each release is accompanied with release notes automatically generated from the git log which is available as [CHANGELOG.md](./CHANGELOG.md). + +To generate the Changelog and set a new Version you should use the following commands in the main folder +```bash +git fetch --all +yarn release +``` + +The first command `git fetch --all` will make sure you have all tags previously defined which is required to generate a correct changelog. The second command `yarn release` will execute the changelog tool and set version numbers in the main package and sub-packages. It is required to do `yarn install` before you can use this command. +After generating a new version you should commit the changes. This will be the CHANGELOG.md and several package.json files. This commit will be omitted in the changelog. + +Note: The Changelog will be regenerated with all tags on release on the external builder tool, but will not be checked in there. The Changelog on the github release will therefore always be correct, on the repo it might be incorrect due to missing tags when executing the `yarn release` command. + ## Troubleshooting | Problem | Issue | Solution | Description | diff --git a/admin/src/pages/CreationConfirm.spec.js b/admin/src/pages/CreationConfirm.spec.js index 86f90231b..90db3a93f 100644 --- a/admin/src/pages/CreationConfirm.spec.js +++ b/admin/src/pages/CreationConfirm.spec.js @@ -1,14 +1,17 @@ import { mount } from '@vue/test-utils' import CreationConfirm from './CreationConfirm.vue' +import { deletePendingCreation } from '../graphql/deletePendingCreation' const localVue = global.localVue const storeCommitMock = jest.fn() const toastedErrorMock = jest.fn() +const toastedSuccessMock = jest.fn() const apolloQueryMock = jest.fn().mockResolvedValue({ data: { getPendingCreations: [ { + id: 1, firstName: 'Bibi', lastName: 'Bloxberg', email: 'bibi@bloxberg.de', @@ -18,6 +21,7 @@ const apolloQueryMock = jest.fn().mockResolvedValue({ moderator: 0, }, { + id: 2, firstName: 'Räuber', lastName: 'Hotzenplotz', email: 'raeuber@hotzenplotz.de', @@ -30,15 +34,19 @@ const apolloQueryMock = jest.fn().mockResolvedValue({ }, }) +const apolloMutateMock = jest.fn().mockResolvedValue({}) + const mocks = { $store: { commit: storeCommitMock, }, $apollo: { query: apolloQueryMock, + mutate: apolloMutateMock, }, $toasted: { error: toastedErrorMock, + success: toastedSuccessMock, }, $moment: jest.fn((value) => { return { @@ -73,6 +81,68 @@ describe('CreationConfirm', () => { }) }) + describe('confirm creation delete with success', () => { + beforeEach(async () => { + apolloQueryMock.mockResolvedValue({ + data: { + getPendingCreations: [ + { + id: 1, + firstName: 'Bibi', + lastName: 'Bloxberg', + email: 'bibi@bloxberg.de', + amount: 500, + memo: 'Danke für alles', + date: new Date(), + moderator: 0, + }, + { + id: 2, + firstName: 'Räuber', + lastName: 'Hotzenplotz', + email: 'raeuber@hotzenplotz.de', + amount: 1000000, + memo: 'Gut Ergatert', + date: new Date(), + moderator: 0, + }, + ], + }, + }) + await wrapper + .findComponent({ name: 'UserTable' }) + .vm.$emit('remove-confirm-result', { id: 1 }, 'remove') + }) + + it('calls the deletePendingCreation mutation', () => { + expect(apolloMutateMock).toBeCalledWith({ + mutation: deletePendingCreation, + variables: { id: 1 }, + }) + }) + + it('commits openCreationsMinus to store', () => { + expect(storeCommitMock).toBeCalledWith('openCreationsMinus', 1) + }) + + it('toasts a success message', () => { + expect(toastedSuccessMock).toBeCalledWith('Pending Creation has been deleted') + }) + }) + + describe('confirm creation delete with error', () => { + beforeEach(async () => { + apolloMutateMock.mockRejectedValue({ message: 'Ouchhh!' }) + await wrapper + .findComponent({ name: 'UserTable' }) + .vm.$emit('remove-confirm-result', { id: 1 }, 'remove') + }) + + it('toasts an error message', () => { + expect(toastedErrorMock).toBeCalledWith('Ouchhh!') + }) + }) + describe('server response is error', () => { beforeEach(() => { jest.clearAllMocks() @@ -86,17 +156,5 @@ describe('CreationConfirm', () => { expect(toastedErrorMock).toBeCalledWith('Ouch!') }) }) - - describe('confirm creation', () => { - beforeEach(async () => { - await wrapper - .findComponent({ name: 'UserTable' }) - .vm.$emit('remove-confirm-result', 1, 'remove') - }) - - it('commits openCreationsMinus to store', () => { - expect(storeCommitMock).toBeCalledWith('openCreationsMinus', 1) - }) - }) }) }) diff --git a/admin/src/pages/CreationConfirm.vue b/admin/src/pages/CreationConfirm.vue index d8094ca69..42ff6da50 100644 --- a/admin/src/pages/CreationConfirm.vue +++ b/admin/src/pages/CreationConfirm.vue @@ -49,16 +49,11 @@ export default { confirmResult: [], } }, - methods: { removeConfirmResult(e, event) { if (event === 'remove') { let index = 0 - let findArr = {} - - findArr = this.confirmResult.find((arr) => arr.id === e.id) - - // console.log('findArr', findArr) + const findArr = this.confirmResult.find((arr) => arr.id === e.id) this.$apollo .mutate({ mutation: deletePendingCreation, diff --git a/frontend/src/routes/guards.js b/frontend/src/routes/guards.js index 0788cb9d8..1838fa0fc 100644 --- a/frontend/src/routes/guards.js +++ b/frontend/src/routes/guards.js @@ -15,12 +15,19 @@ const addNavigationGuards = (router, store, apollo) => { router.beforeEach(async (to, from, next) => { if (to.path === '/authenticate' && to.query.token) { store.commit('token', to.query.token) - const result = await apollo.query({ - query: verifyLogin, - fetchPolicy: 'network-only', - }) - store.dispatch('login', result.data.verifyLogin) - next({ path: '/overview' }) + await apollo + .query({ + query: verifyLogin, + fetchPolicy: 'network-only', + }) + .then((result) => { + store.dispatch('login', result.data.verifyLogin) + next({ path: '/overview' }) + }) + .catch(() => { + store.dispatch('logout') + next() + }) } else { next() } diff --git a/frontend/src/routes/guards.test.js b/frontend/src/routes/guards.test.js index f271c5427..fa9f60f56 100644 --- a/frontend/src/routes/guards.test.js +++ b/frontend/src/routes/guards.test.js @@ -2,15 +2,28 @@ import addNavigationGuards from './guards' import router from './router' const storeCommitMock = jest.fn() +const storeDispatchMock = jest.fn() +const apolloQueryMock = jest.fn().mockResolvedValue({ + data: { + verifyLogin: { + firstName: 'Peter', + }, + }, +}) const store = { commit: storeCommitMock, state: { token: null, }, + dispatch: storeDispatchMock, } -addNavigationGuards(router, store) +const apollo = { + query: apolloQueryMock, +} + +addNavigationGuards(router, store, apollo) describe('navigation guards', () => { beforeEach(() => { @@ -29,6 +42,46 @@ describe('navigation guards', () => { }) }) + describe('authenticate', () => { + const navGuard = router.beforeHooks[1] + const next = jest.fn() + + describe('with valid token', () => { + beforeEach(() => { + navGuard({ path: '/authenticate', query: { token: 'valid-token' } }, {}, next) + }) + + it('commts the token to the store', () => { + expect(storeCommitMock).toBeCalledWith('token', 'valid-token') + }) + + it('calls verifyLogin', () => { + expect(apolloQueryMock).toBeCalled() + }) + + it('commits login to the store', () => { + expect(storeDispatchMock).toBeCalledWith('login', { firstName: 'Peter' }) + }) + }) + + describe('with valid token and server error', () => { + beforeEach(() => { + apolloQueryMock.mockRejectedValue({ + message: 'Ouch!', + }) + navGuard({ path: '/authenticate', query: { token: 'valid-token' } }, {}, next) + }) + + it('dispatches logout to store', () => { + expect(storeDispatchMock).toBeCalledWith('logout') + }) + + it('calls next', () => { + expect(next).toBeCalledWith() + }) + }) + }) + describe('authorization', () => { const navGuard = router.beforeHooks[2] const next = jest.fn() diff --git a/scripts/release.sh b/scripts/release.sh index d18c4948c..0b70e76ad 100755 --- a/scripts/release.sh +++ b/scripts/release.sh @@ -6,6 +6,7 @@ PROJECT_DIR="${SCRIPT_DIR}/../" FRONTEND_DIR="${PROJECT_DIR}/frontend/" BACKEND_DIR="${PROJECT_DIR}/backend/" DATABASE_DIR="${PROJECT_DIR}/database/" +ADMIN_DIR="${PROJECT_DIR}/admin/" # navigate to project directory cd ${PROJECT_DIR} @@ -23,6 +24,8 @@ cd ${BACKEND_DIR} yarn version --no-git-tag-version --no-commit-hooks --no-commit --new-version ${VERSION} cd ${DATABASE_DIR} yarn version --no-git-tag-version --no-commit-hooks --no-commit --new-version ${VERSION} +cd ${ADMIN_DIR} +yarn version --no-git-tag-version --no-commit-hooks --no-commit --new-version ${VERSION} # generate changelog cd ${PROJECT_DIR}