diff --git a/backend/src/db/factories.js b/backend/src/db/factories.js index 717926413..07a0dacaa 100644 --- a/backend/src/db/factories.js +++ b/backend/src/db/factories.js @@ -197,6 +197,7 @@ Factory.define('comment') Factory.define('donations') .attr('id', uuid) + .attr('showDonations', true) .attr('goal', 15000) .attr('progress', 0) .after((buildObject, options) => { diff --git a/backend/src/models/Donations.js b/backend/src/models/Donations.js index 1409c85d4..1273a6f77 100644 --- a/backend/src/models/Donations.js +++ b/backend/src/models/Donations.js @@ -2,6 +2,7 @@ import { v4 as uuid } from 'uuid' export default { id: { type: 'string', primary: true, default: uuid }, + showDonations: { type: 'boolean' }, goal: { type: 'number' }, progress: { type: 'number' }, createdAt: { type: 'string', isoDate: true, default: () => new Date().toISOString() }, diff --git a/backend/src/schema/resolvers/donations.spec.js b/backend/src/schema/resolvers/donations.spec.js index ea5ee4e09..1cf46e50b 100644 --- a/backend/src/schema/resolvers/donations.spec.js +++ b/backend/src/schema/resolvers/donations.spec.js @@ -9,9 +9,10 @@ const instance = getNeode() const driver = getDriver() const updateDonationsMutation = gql` - mutation($goal: Int, $progress: Int) { - UpdateDonations(goal: $goal, progress: $progress) { + mutation($showDonations: Boolean, $goal: Int, $progress: Int) { + UpdateDonations(showDonations: $showDonations, goal: $goal, progress: $progress) { id + showDonations goal progress createdAt @@ -23,6 +24,7 @@ const donationsQuery = gql` query { Donations { id + showDonations goal progress } @@ -64,20 +66,20 @@ describe('donations', () => { errors: [{ message: 'Not Authorised!' }], }) }) + }) - describe('authenticated', () => { - beforeEach(async () => { - currentUser = await Factory.build('user', { - id: 'normal-user', - role: 'user', - }) - authenticatedUser = await currentUser.toJson() + describe('authenticated', () => { + beforeEach(async () => { + currentUser = await Factory.build('user', { + id: 'normal-user', + role: 'user', }) + authenticatedUser = await currentUser.toJson() + }) - it('returns the current Donations info', async () => { - await expect(query({ query: donationsQuery, variables })).resolves.toMatchObject({ - data: { Donations: [{ goal: 15000, progress: 0 }] }, - }) + it('returns the current Donations info', async () => { + await expect(query({ query: donationsQuery, variables })).resolves.toMatchObject({ + data: { Donations: [{ showDonations: true, goal: 15000, progress: 0 }] }, }) }) }) @@ -85,7 +87,7 @@ describe('donations', () => { describe('update donations', () => { beforeEach(() => { - variables = { goal: 20000, progress: 3000 } + variables = { showDonations: false, goal: 20000, progress: 3000 } }) describe('unauthenticated', () => { @@ -97,75 +99,75 @@ describe('donations', () => { errors: [{ message: 'Not Authorised!' }], }) }) + }) - describe('authenticated', () => { - describe('as a normal user', () => { - beforeEach(async () => { - currentUser = await Factory.build('user', { - id: 'normal-user', - role: 'user', - }) - authenticatedUser = await currentUser.toJson() + describe('authenticated', () => { + describe('as a normal user', () => { + beforeEach(async () => { + currentUser = await Factory.build('user', { + id: 'normal-user', + role: 'user', }) + authenticatedUser = await currentUser.toJson() + }) - it('throws authorization error', async () => { - await expect( - mutate({ mutation: updateDonationsMutation, variables }), - ).resolves.toMatchObject({ - data: { UpdateDonations: null }, - errors: [{ message: 'Not Authorised!' }], - }) + it('throws authorization error', async () => { + await expect( + mutate({ mutation: updateDonationsMutation, variables }), + ).resolves.toMatchObject({ + data: { UpdateDonations: null }, + errors: [{ message: 'Not Authorised!' }], + }) + }) + }) + + describe('as a moderator', () => { + beforeEach(async () => { + currentUser = await Factory.build('user', { + id: 'moderator', + role: 'moderator', + }) + authenticatedUser = await currentUser.toJson() + }) + + it('throws authorization error', async () => { + await expect( + mutate({ mutation: updateDonationsMutation, variables }), + ).resolves.toMatchObject({ + data: { UpdateDonations: null }, + errors: [{ message: 'Not Authorised!' }], + }) + }) + }) + + describe('as an admin', () => { + beforeEach(async () => { + currentUser = await Factory.build('user', { + id: 'admin', + role: 'admin', + }) + authenticatedUser = await currentUser.toJson() + }) + + it('updates Donations info', async () => { + await expect( + mutate({ mutation: updateDonationsMutation, variables }), + ).resolves.toMatchObject({ + data: { UpdateDonations: { showDonations: false, goal: 20000, progress: 3000 } }, + errors: undefined, }) }) - describe('as a moderator', () => { - beforeEach(async () => { - currentUser = await Factory.build('user', { - id: 'moderator', - role: 'moderator', - }) - authenticatedUser = await currentUser.toJson() - }) - - it('throws authorization error', async () => { - await expect( - mutate({ mutation: updateDonationsMutation, variables }), - ).resolves.toMatchObject({ - data: { UpdateDonations: null }, - errors: [{ message: 'Not Authorised!' }], - }) - }) - }) - - describe('as an admin', () => { - beforeEach(async () => { - currentUser = await Factory.build('user', { - id: 'admin', - role: 'admin', - }) - authenticatedUser = await currentUser.toJson() - }) - - it('updates Donations info', async () => { - await expect( - mutate({ mutation: updateDonationsMutation, variables }), - ).resolves.toMatchObject({ - data: { UpdateDonations: { goal: 20000, progress: 3000 } }, - errors: undefined, - }) - }) - - it('updates the updatedAt attribute', async () => { - newlyCreatedDonations = await newlyCreatedDonations.toJson() - const { - data: { UpdateDonations }, - } = await mutate({ mutation: updateDonationsMutation, variables }) - expect(newlyCreatedDonations.updatedAt).toBeTruthy() - expect(Date.parse(newlyCreatedDonations.updatedAt)).toEqual(expect.any(Number)) - expect(UpdateDonations.updatedAt).toBeTruthy() - expect(Date.parse(UpdateDonations.updatedAt)).toEqual(expect.any(Number)) - expect(newlyCreatedDonations.updatedAt).not.toEqual(UpdateDonations.updatedAt) - }) + it('updates the updatedAt attribute', async () => { + newlyCreatedDonations = await newlyCreatedDonations.toJson() + const { + data: { UpdateDonations }, + } = await mutate({ mutation: updateDonationsMutation, variables }) + expect(newlyCreatedDonations.updatedAt).toBeTruthy() + expect(Date.parse(newlyCreatedDonations.updatedAt)).toEqual(expect.any(Number)) + expect(UpdateDonations.updatedAt).toBeTruthy() + expect(Date.parse(UpdateDonations.updatedAt)).toEqual(expect.any(Number)) + expect(newlyCreatedDonations.updatedAt).not.toEqual(UpdateDonations.updatedAt) }) }) }) diff --git a/backend/src/schema/types/type/Donations.gql b/backend/src/schema/types/type/Donations.gql index 39cfe9b71..cf4531164 100644 --- a/backend/src/schema/types/type/Donations.gql +++ b/backend/src/schema/types/type/Donations.gql @@ -1,7 +1,8 @@ type Donations { id: ID! - goal: Int! - progress: Int! + showDonations: Boolean! # Wolle make it required in the schema + goal: Int! # Wolle make it required in the schema + progress: Int! # Wolle make it required in the schema createdAt: String updatedAt: String } @@ -11,5 +12,5 @@ type Query { } type Mutation { - UpdateDonations(goal: Int, progress: Int): Donations + UpdateDonations(showDonations: Boolean, goal: Int, progress: Int): Donations } \ No newline at end of file diff --git a/webapp/components/DonationInfo/DonationInfo.vue b/webapp/components/DonationInfo/DonationInfo.vue index 1234c67c4..f82b7b747 100644 --- a/webapp/components/DonationInfo/DonationInfo.vue +++ b/webapp/components/DonationInfo/DonationInfo.vue @@ -48,7 +48,7 @@ export default { }, update({ Donations }) { if (!Donations[0]) return - const { goal, progress } = Donations[0] + const { goal, progress } = Donations[0] // Wolle showDonations this.goal = goal this.progress = progress }, diff --git a/webapp/constants/donations.js b/webapp/constants/donations.js index e6cf2ecd6..63274d2b7 100644 --- a/webapp/constants/donations.js +++ b/webapp/constants/donations.js @@ -1,2 +1,2 @@ -export const DONATIONS_SHOW_MENU_BUTTON = true +export const DONATIONS_SHOW_MENU_BUTTON = true // Wolle export const DONATIONS_SHOW_INFO = true diff --git a/webapp/constants/newsfeed.js b/webapp/constants/newsfeed.js index a1f94e9e6..563d42135 100644 --- a/webapp/constants/newsfeed.js +++ b/webapp/constants/newsfeed.js @@ -1 +1 @@ -export const NEWSFEED_SHOW_INFO_LEFT_LANE = true +export const NEWSFEED_SHOW_INFO_LEFT_LANE = true // Wolle diff --git a/webapp/graphql/Donations.js b/webapp/graphql/Donations.js index cc2a6a783..e412ee4fa 100644 --- a/webapp/graphql/Donations.js +++ b/webapp/graphql/Donations.js @@ -4,6 +4,7 @@ export const DonationsQuery = () => gql` query { Donations { id + showDonations goal progress } @@ -12,9 +13,10 @@ export const DonationsQuery = () => gql` export const UpdateDonations = () => { return gql` - mutation($goal: Int, $progress: Int) { - UpdateDonations(goal: $goal, progress: $progress) { + mutation($showDonations: Boolean, $goal: Int, $progress: Int) { + UpdateDonations(showDonations: $showDonations, goal: $goal, progress: $progress) { id + showDonations goal progress updatedAt diff --git a/webapp/pages/admin/donations.vue b/webapp/pages/admin/donations.vue index 779513781..0646194dd 100644 --- a/webapp/pages/admin/donations.vue +++ b/webapp/pages/admin/donations.vue @@ -29,12 +29,8 @@ icon="money" :disabled="!showDonations" /> - + + {{ $t('actions.save') }} @@ -59,11 +55,13 @@ export default { }, methods: { submit() { + const { showDonations } = this const { goal, progress } = this.formData this.$apollo .mutate({ mutation: UpdateDonations(), variables: { + showDonations, goal: parseInt(goal), progress: parseInt(progress), }, @@ -81,7 +79,8 @@ export default { }, update({ Donations }) { if (!Donations[0]) return - const { goal, progress } = Donations[0] + const { showDonations, goal, progress } = Donations[0] + this.showDonations = showDonations this.formData = { goal, progress, diff --git a/webapp/pages/index.vue b/webapp/pages/index.vue index 29f80aba5..1db9e5639 100644 --- a/webapp/pages/index.vue +++ b/webapp/pages/index.vue @@ -90,8 +90,8 @@