Merge branch 'master' into 2077-copy-text-after-transaction-link-creation

This commit is contained in:
mahula 2022-07-27 12:33:49 +02:00 committed by GitHub
commit e17e1b43f5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 262 additions and 94 deletions

View File

@ -28,7 +28,7 @@ const propsData = {
amount: 210,
memo: 'Aktives Grundeinkommen für Januar 2022',
date: '2022-01-01T00:00:00.000Z',
moderator: 1,
moderator: null,
creation: [790, 1000, 1000],
__typename: 'PendingCreation',
},
@ -66,7 +66,7 @@ const propsData = {
},
},
{ key: 'moderator', label: 'moderator' },
{ key: 'edit_creation', label: 'edit' },
{ key: 'editCreation', label: 'edit' },
{ key: 'confirm', label: 'save' },
],
toggleDetails: false,
@ -113,6 +113,10 @@ describe('OpenCreationsTable', () => {
expect(wrapper.findAll('tr').at(1).find('.bi-pencil-square').exists()).toBe(true)
})
it('has no button.bi-pencil-square for user contribution ', () => {
expect(wrapper.findAll('tr').at(2).find('.bi-pencil-square').exists()).toBe(false)
})
describe('show edit details', () => {
beforeEach(async () => {
await wrapper.findAll('tr').at(1).find('.bi-pencil-square').trigger('click')

View File

@ -11,8 +11,14 @@
<b-icon icon="x" variant="light"></b-icon>
</b-button>
</template>
<template #cell(edit_creation)="row">
<b-button variant="info" size="md" @click="rowToggleDetails(row, 0)" class="mr-2">
<template #cell(editCreation)="row">
<b-button
v-if="row.item.moderator"
variant="info"
size="md"
@click="rowToggleDetails(row, 0)"
class="mr-2"
>
<b-icon :icon="row.detailsShowing ? 'x' : 'pencil-square'" aria-label="Help"></b-icon>
</b-button>
</template>

View File

@ -35,6 +35,7 @@
"creation_form": {
"creation_failed": "Ausstehende Schöpfung für {email} konnte nicht erzeugt werden.",
"creation_for": "Aktives Grundeinkommen für",
"deleteNow": "Möchtest du diesen Beitrag zur Gemeinschaft wirklich löschen?",
"enter_text": "Text eintragen",
"form": "Schöpfungsformular",
"min_characters": "Mindestens 10 Zeichen eingeben",

View File

@ -35,6 +35,7 @@
"creation_form": {
"creation_failed": "Could not create pending creation for {email}",
"creation_for": "Active Basic Income for",
"deleteNow": "Do you really want to delete this contribution to the community?",
"enter_text": "Enter text",
"form": "Creation form",
"min_characters": "Enter at least 10 characters",

View File

@ -18,7 +18,7 @@ const apolloQueryMock = jest.fn().mockResolvedValue({
amount: 500,
memo: 'Danke für alles',
date: new Date(),
moderator: 0,
moderator: 2,
},
{
id: 2,
@ -28,7 +28,7 @@ const apolloQueryMock = jest.fn().mockResolvedValue({
amount: 1000000,
memo: 'Gut Ergattert',
date: new Date(),
moderator: 0,
moderator: 2,
},
],
},
@ -80,28 +80,54 @@ describe('CreationConfirm', () => {
})
describe('remove creation with success', () => {
beforeEach(async () => {
await wrapper.findAll('tr').at(1).findAll('button').at(0).trigger('click')
})
let spy
it('calls the adminDeleteContribution mutation', () => {
expect(apolloMutateMock).toBeCalledWith({
mutation: adminDeleteContribution,
variables: { id: 1 },
describe('admin confirms deletion', () => {
beforeEach(async () => {
spy = jest.spyOn(wrapper.vm.$bvModal, 'msgBoxConfirm')
spy.mockImplementation(() => Promise.resolve('some value'))
await wrapper.findAll('tr').at(1).findAll('button').at(0).trigger('click')
})
it('opens a modal', () => {
expect(spy).toBeCalled()
})
it('calls the adminDeleteContribution mutation', () => {
expect(apolloMutateMock).toBeCalledWith({
mutation: adminDeleteContribution,
variables: { id: 1 },
})
})
it('commits openCreationsMinus to store', () => {
expect(storeCommitMock).toBeCalledWith('openCreationsMinus', 1)
})
it('toasts a success message', () => {
expect(toastSuccessSpy).toBeCalledWith('creation_form.toasted_delete')
})
})
it('commits openCreationsMinus to store', () => {
expect(storeCommitMock).toBeCalledWith('openCreationsMinus', 1)
})
describe('admin cancels deletion', () => {
beforeEach(async () => {
spy = jest.spyOn(wrapper.vm.$bvModal, 'msgBoxConfirm')
spy.mockImplementation(() => Promise.resolve(false))
await wrapper.findAll('tr').at(1).findAll('button').at(0).trigger('click')
})
it('toasts a success message', () => {
expect(toastSuccessSpy).toBeCalledWith('creation_form.toasted_delete')
it('does not call the adminDeleteContribution mutation', () => {
expect(apolloMutateMock).not.toBeCalled()
})
})
})
describe('remove creation with error', () => {
let spy
beforeEach(async () => {
spy = jest.spyOn(wrapper.vm.$bvModal, 'msgBoxConfirm')
spy.mockImplementation(() => Promise.resolve('some value'))
apolloMutateMock.mockRejectedValue({ message: 'Ouchhh!' })
await wrapper.findAll('tr').at(1).findAll('button').at(0).trigger('click')
})

View File

@ -34,20 +34,23 @@ export default {
},
methods: {
removeCreation(item) {
this.$apollo
.mutate({
mutation: adminDeleteContribution,
variables: {
id: item.id,
},
})
.then((result) => {
this.updatePendingCreations(item.id)
this.toastSuccess(this.$t('creation_form.toasted_delete'))
})
.catch((error) => {
this.toastError(error.message)
})
this.$bvModal.msgBoxConfirm(this.$t('creation_form.deleteNow')).then(async (value) => {
if (value)
await this.$apollo
.mutate({
mutation: adminDeleteContribution,
variables: {
id: item.id,
},
})
.then((result) => {
this.updatePendingCreations(item.id)
this.toastSuccess(this.$t('creation_form.toasted_delete'))
})
.catch((error) => {
this.toastError(error.message)
})
})
},
confirmCreation() {
this.$apollo
@ -114,7 +117,7 @@ export default {
},
},
{ key: 'moderator', label: this.$t('moderator') },
{ key: 'edit_creation', label: this.$t('edit') },
{ key: 'editCreation', label: this.$t('edit') },
{ key: 'confirm', label: this.$t('save') },
]
},

View File

@ -10,7 +10,7 @@ Decimal.set({
})
const constants = {
DB_VERSION: '0043-add_event_protocol_table',
DB_VERSION: '0044-insert_missing_contributions',
DECAY_START_TIME: new Date('2021-05-13 17:46:31-0000'), // GMT+0
LOG4JS_CONFIG: 'log4js-config.json',
// default log level on production should be info

View File

@ -35,12 +35,17 @@ export const creationFactory = async (
if (creation.confirmed) {
await mutate({ mutation: confirmContribution, variables: { id: pendingCreation.id } })
const confirmedCreation = await Contribution.findOneOrFail({ id: pendingCreation.id })
if (creation.moveCreationDate) {
const transaction = await Transaction.findOneOrFail({
where: { userId: user.id, creationDate: new Date(creation.creationDate) },
order: { balanceDate: 'DESC' },
})
if (transaction.decay.equals(0) && transaction.creationDate) {
confirmedCreation.contributionDate = new Date(
nMonthsBefore(transaction.creationDate, creation.moveCreationDate),
)
transaction.creationDate = new Date(
nMonthsBefore(transaction.creationDate, creation.moveCreationDate),
)
@ -48,6 +53,7 @@ export const creationFactory = async (
nMonthsBefore(transaction.balanceDate, creation.moveCreationDate),
)
await transaction.save()
await confirmedCreation.save()
}
}
} else {

View File

@ -0,0 +1,34 @@
/* MIGRATION TO INSERT contributions for all transactions with type creation that do not have a contribution yet */
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
/* eslint-disable @typescript-eslint/no-explicit-any */
export async function upgrade(queryFn: (query: string, values?: any[]) => Promise<Array<any>>) {
await queryFn(
`INSERT INTO gradido_community.contributions
(user_id, created_at, contribution_date, memo, amount, moderator_id, confirmed_by, confirmed_at, transaction_id)
SELECT
user_id,
balance_date,
creation_date AS contribution_date,
memo,
amount,
20 AS moderator_id,
502 AS confirmed_by,
balance_date AS confirmed_at,
id
FROM
gradido_community.transactions
WHERE
type_id = 1
AND NOT EXISTS(
SELECT * FROM gradido_community.contributions
WHERE gradido_community.contributions.transaction_id = gradido_community.transactions.id);`,
)
}
export async function downgrade(queryFn: (query: string, values?: any[]) => Promise<Array<any>>) {
await queryFn(
'DELETE FROM `contributions` WHERE `contributions`.`moderator_id` = 20 AND `contributions`.`confirmed_by` = 502 AND `contributions`.`created_at` = `contributions`.`confirmed_at`;',
)
}

View File

@ -23,6 +23,9 @@ describe('ContributionForm', () => {
creation: ['1000', '1000', '1000'],
},
},
$i18n: {
locale: 'en',
},
}
const Wrapper = () => {
@ -42,8 +45,70 @@ describe('ContributionForm', () => {
expect(wrapper.find('div.contribution-form').exists()).toBe(true)
})
it('is submit button disable of true', () => {
expect(wrapper.find('button[type="submit"]').attributes('disabled')).toBe('disabled')
describe('empty form data', () => {
describe('buttons', () => {
it('has reset enabled', () => {
expect(wrapper.find('button[type="reset"]').attributes('disabled')).toBeFalsy()
})
it('has submit disabled', () => {
expect(wrapper.find('button[type="submit"]').attributes('disabled')).toBe('disabled')
})
})
})
describe('set contrubtion', () => {
describe('fill in form data', () => {
const now = new Date().toISOString()
beforeEach(async () => {
await wrapper.setData({
form: {
id: null,
date: now,
memo: 'Mein Beitrag zur Gemeinschaft für diesen Monat ...',
amount: '200',
},
})
})
describe('buttons', () => {
it('has reset enabled', () => {
expect(wrapper.find('button[type="reset"]').attributes('disabled')).toBeFalsy()
})
it('has submit enabled', () => {
expect(wrapper.find('button[type="submit"]').attributes('disabled')).toBeFalsy()
})
})
})
})
describe('update contrubtion', () => {
describe('fill in form data and "id"', () => {
const now = new Date().toISOString()
beforeEach(async () => {
await wrapper.setData({
form: {
id: 2,
date: now,
memo: 'Mein Beitrag zur Gemeinschaft für diesen Monat ...',
amount: '200',
},
})
})
describe('buttons', () => {
it('has reset enabled', () => {
expect(wrapper.find('button[type="reset"]').attributes('disabled')).toBeFalsy()
})
it('has submit enabled', () => {
expect(wrapper.find('button[type="submit"]').attributes('disabled')).toBeFalsy()
})
})
})
})
})
})

View File

@ -18,32 +18,38 @@
id="contribution-date"
v-model="form.date"
size="lg"
:locale="$i18n.locale"
:max="maximalDate"
:min="minimalDate"
class="mb-4"
reset-value=""
:label-no-date-selected="$t('contribution.noDateSelected')"
required
></b-form-datepicker>
<label class="mt-3">{{ $t('contribution.activity') }}</label>
<b-form-textarea
id="contribution-memo"
v-model="form.memo"
rows="3"
max-rows="6"
required
:minlength="minlength"
:maxlength="maxlength"
></b-form-textarea>
<div
v-show="form.memo.length > 0"
class="text-right"
:class="form.memo.length < minlength ? 'text-danger' : 'text-success'"
>
{{ form.memo.length }}
<span v-if="form.memo.length < minlength">{{ $t('math.lower') }} {{ minlength }}</span>
<span v-else>{{ $t('math.divide') }} {{ maxlength }}</span>
</div>
<template #nav-prev-year><span></span></template>
<template #nav-next-year><span></span></template>
</b-form-datepicker>
<validation-provider
:rules="{
required: true,
min: minlength,
max: maxlength,
}"
:name="$t('form.message')"
v-slot="{ errors }"
>
<label class="mt-3">{{ $t('contribution.activity') }}</label>
<b-form-textarea
id="contribution-memo"
v-model="form.memo"
rows="3"
max-rows="6"
required
></b-form-textarea>
<b-col v-if="errors">
<span v-for="error in errors" class="errors" :key="error">{{ error }}</span>
</b-col>
</validation-provider>
<label class="mt-3">{{ $t('form.amount') }}</label>
<b-input-group size="lg" prepend="GDD" append=".00">
<b-form-input
@ -68,13 +74,13 @@
</div>
<b-row class="mt-3">
<b-col>
<b-button type="button" variant="light" @click.prevent="reset">
{{ $t('form.reset') }}
<b-button class="test-cancel" type="reset" variant="secondary" @click="reset">
{{ $t('form.cancel') }}
</b-button>
</b-col>
<b-col class="text-right">
<b-button class="test-submit" type="submit" variant="primary" :disabled="disabled">
{{ value.id ? $t('form.edit') : $t('contribution.submit') }}
{{ form.id ? $t('form.change') : $t('contribution.submit') }}
</b-button>
</b-col>
</b-row>
@ -90,16 +96,15 @@ export default {
},
data() {
return {
minlength: 50,
minlength: 5,
maxlength: 255,
maximalDate: new Date(),
form: this.value,
id: this.value.id,
form: this.value, // includes 'id'
}
},
methods: {
submit() {
if (this.value.id) {
if (this.form.id) {
this.$emit('update-contribution', this.form)
} else {
this.$emit('set-contribution', this.form)
@ -108,9 +113,10 @@ export default {
},
reset() {
this.$refs.form.reset()
this.form.id = null
this.form.date = ''
this.id = null
this.form.memo = ''
this.form.amount = ''
},
},
computed: {
@ -153,16 +159,21 @@ export default {
},
maxGddLastMonth() {
// When edited, the amount is added back on top of the amount
return this.value.id && !this.isThisMonth
return this.form.id && !this.isThisMonth
? parseInt(this.$store.state.creation[1]) + parseInt(this.updateAmount)
: this.$store.state.creation[1]
},
maxGddThisMonth() {
// When edited, the amount is added back on top of the amount
return this.value.id && this.isThisMonth
return this.form.id && this.isThisMonth
? parseInt(this.$store.state.creation[2]) + parseInt(this.updateAmount)
: this.$store.state.creation[2]
},
},
}
</script>
<style>
span.errors {
color: red;
}
</style>

View File

@ -13,6 +13,7 @@ describe('ContributionListItem', () => {
const propsData = {
id: 1,
createdAt: '26/07/2022',
contributionDate: '07/06/2022',
memo: 'Ich habe 10 Stunden die Elbwiesen von Müll befreit.',
amount: '200',
@ -84,21 +85,9 @@ describe('ContributionListItem', () => {
})
})
describe('contribution date', () => {
it('is contributionDate by default', () => {
expect(wrapper.vm.date).toBe(wrapper.vm.contributionDate)
})
it('is deletedAt when deletedAt is present', async () => {
const now = new Date().toISOString()
await wrapper.setProps({ deletedAt: now })
expect(wrapper.vm.date).toBe(now)
})
it('is confirmedAt at when confirmedAt is present', async () => {
const now = new Date().toISOString()
await wrapper.setProps({ confirmedAt: now })
expect(wrapper.vm.date).toBe(now)
describe('date', () => {
it('is equal to createdAt', () => {
expect(wrapper.vm.date).toBe(wrapper.vm.createdAt)
})
})

View File

@ -11,6 +11,12 @@
{{ $t('math.minus') }}
<div class="mx-2">{{ $d(new Date(date), 'short') }}</div>
</div>
<div class="mr-2">
<span>{{ $t('contribution.date') }}</span>
<span>
{{ $d(new Date(contributionDate), 'monthAndYear') }}
</span>
</div>
<div class="mr-2">{{ memo }}</div>
<div v-if="type === 'pending' && !firstName" class="d-flex flex-row-reverse">
<div
@ -91,9 +97,10 @@ export default {
return 'primary'
},
date() {
if (this.deletedAt) return this.deletedAt
if (this.confirmedAt) return this.confirmedAt
return this.contributionDate
// if (this.deletedAt) return this.deletedAt
// if (this.confirmedAt) return this.confirmedAt
// return this.contributionDate
return this.createdAt
},
},
methods: {

View File

@ -26,7 +26,7 @@
"community": "Gemeinschaft",
"continue-to-registration": "Weiter zur Registrierung",
"current-community": "Aktuelle Gemeinschaft",
"myContributions": "Meine Beiträge",
"myContributions": "Meine Beiträge zum Gemeinwohl",
"other-communities": "Weitere Gemeinschaften",
"submitContribution": "Beitrag einreichen",
"switch-to-this-community": "zu dieser Gemeinschaft wechseln"
@ -36,11 +36,12 @@
"alert": {
"communityNoteList": "Hier findest du alle eingereichten und bestätigten Beiträge von allen Mitgliedern aus dieser Gemeinschaft.",
"confirm": "bestätigt",
"myContributionNoteList": "Hier findest du chronologisch aufgelistet alle deine eingereichten Beiträge. Es gibt drei Darstellungsarten. Du kannst deine Beiträge, welche noch nicht bestätigt wurden, jederzeit bearbeiten.",
"myContributionNoteList": "Eingereichte Beiträge, die noch nicht bestätigt wurden, kannst du jederzeit bearbeiten oder löschen.",
"myContributionNoteSupport": "Es wird bald an dieser Stelle die Möglichkeit geben das ein Dialog zwischen Moderatoren und dir stattfinden kann. Solltest du jetzt Probleme haben bitte nimm Kontakt mit dem Support auf.",
"pending": "Eingereicht und wartet auf Bestätigung",
"rejected": "abgelehnt"
},
"date": "Beitrag für:",
"delete": "Beitrag löschen! Bist du sicher?",
"deleted": "Der Beitrag wurde gelöscht! Wird aber sichtbar bleiben.",
"formText": {
@ -105,12 +106,12 @@
"amount": "Betrag",
"at": "am",
"cancel": "Abbrechen",
"change": "Ändern",
"check_now": "Jetzt prüfen",
"close": "Schließen",
"current_balance": "Aktueller Kontostand",
"date": "Datum",
"description": "Beschreibung",
"edit": "Bearbeiten",
"email": "E-Mail",
"firstname": "Vorname",
"from": "Von",
@ -203,10 +204,8 @@
"login": "Anmeldung",
"math": {
"aprox": "~",
"divide": "/",
"equal": "=",
"exclaim": "!",
"lower": "<",
"minus": "",
"pipe": "|"
},

View File

@ -26,7 +26,7 @@
"community": "Community",
"continue-to-registration": "Continue to registration",
"current-community": "Current community",
"myContributions": "My contributions",
"myContributions": "My contributions to the common good",
"other-communities": "Other communities",
"submitContribution": "Submit contribution",
"switch-to-this-community": "Switch to this community"
@ -36,11 +36,12 @@
"alert": {
"communityNoteList": "Here you will find all submitted and confirmed contributions from all members of this community.",
"confirm": "confirmed",
"myContributionNoteList": "Here you will find a chronological list of all your submitted contributions. There are three display types. There are three ways of displaying your posts. You can edit your contributions, which have not yet been confirmed, at any time.",
"myContributionNoteList": "You can edit or delete entries that have not yet been confirmed at any time.",
"myContributionNoteSupport": "Soon there will be the possibility for a dialogue between moderators and you. If you have any problems now, please contact the support.",
"pending": "Submitted and waiting for confirmation",
"rejected": "deleted"
},
"date": "Contribution for:",
"delete": "Delete Contribution! Are you sure?",
"deleted": "The contribution has been deleted! But it will remain visible.",
"formText": {
@ -105,12 +106,12 @@
"amount": "Amount",
"at": "at",
"cancel": "Cancel",
"change": "Change",
"check_now": "Check now",
"close": "Close",
"current_balance": "Current Balance",
"date": "Date",
"description": "Description",
"edit": "Edit",
"email": "Email",
"firstname": "Firstname",
"from": "from",
@ -203,10 +204,8 @@
"login": "Login",
"math": {
"aprox": "~",
"divide": "/",
"equal": "=",
"exclaim": "!",
"lower": "<",
"minus": "",
"pipe": "|"
},

View File

@ -26,6 +26,9 @@ describe('Community', () => {
creation: ['1000', '1000', '1000'],
},
},
$i18n: {
locale: 'en',
},
}
const Wrapper = () => {
@ -190,6 +193,13 @@ describe('Community', () => {
fetchPolicy: 'network-only',
})
})
it('set all data to the default values)', () => {
expect(wrapper.vm.form.id).toBe(null)
expect(wrapper.vm.form.date).toBe('')
expect(wrapper.vm.form.memo).toBe('')
expect(wrapper.vm.form.amount).toBe('')
})
})
describe('with error', () => {
@ -270,6 +280,13 @@ describe('Community', () => {
fetchPolicy: 'network-only',
})
})
it('set all data to the default values)', () => {
expect(wrapper.vm.form.id).toBe(null)
expect(wrapper.vm.form.date).toBe('')
expect(wrapper.vm.form.memo).toBe('')
expect(wrapper.vm.form.amount).toBe('')
})
})
describe('with error', () => {
@ -376,7 +393,7 @@ describe('Community', () => {
})
})
it('sets the form date to the new values', () => {
it('sets the form data to the new values', () => {
expect(wrapper.vm.form.id).toBe(2)
expect(wrapper.vm.form.date).toBe(now)
expect(wrapper.vm.form.memo).toBe('Mein Beitrag zur Gemeinschaft für diesen Monat ...')