mirror of
https://github.com/Ocelot-Social-Community/Ocelot-Social.git
synced 2025-12-13 07:46:06 +00:00
Implement showDonations in the database
- Add to backend tests.
This commit is contained in:
parent
a48355f8bc
commit
d40dd94868
@ -197,6 +197,7 @@ Factory.define('comment')
|
|||||||
|
|
||||||
Factory.define('donations')
|
Factory.define('donations')
|
||||||
.attr('id', uuid)
|
.attr('id', uuid)
|
||||||
|
.attr('showDonations', true)
|
||||||
.attr('goal', 15000)
|
.attr('goal', 15000)
|
||||||
.attr('progress', 0)
|
.attr('progress', 0)
|
||||||
.after((buildObject, options) => {
|
.after((buildObject, options) => {
|
||||||
|
|||||||
@ -2,6 +2,7 @@ import { v4 as uuid } from 'uuid'
|
|||||||
|
|
||||||
export default {
|
export default {
|
||||||
id: { type: 'string', primary: true, default: uuid },
|
id: { type: 'string', primary: true, default: uuid },
|
||||||
|
showDonations: { type: 'boolean' },
|
||||||
goal: { type: 'number' },
|
goal: { type: 'number' },
|
||||||
progress: { type: 'number' },
|
progress: { type: 'number' },
|
||||||
createdAt: { type: 'string', isoDate: true, default: () => new Date().toISOString() },
|
createdAt: { type: 'string', isoDate: true, default: () => new Date().toISOString() },
|
||||||
|
|||||||
@ -9,9 +9,10 @@ const instance = getNeode()
|
|||||||
const driver = getDriver()
|
const driver = getDriver()
|
||||||
|
|
||||||
const updateDonationsMutation = gql`
|
const updateDonationsMutation = gql`
|
||||||
mutation($goal: Int, $progress: Int) {
|
mutation($showDonations: Boolean, $goal: Int, $progress: Int) {
|
||||||
UpdateDonations(goal: $goal, progress: $progress) {
|
UpdateDonations(showDonations: $showDonations, goal: $goal, progress: $progress) {
|
||||||
id
|
id
|
||||||
|
showDonations
|
||||||
goal
|
goal
|
||||||
progress
|
progress
|
||||||
createdAt
|
createdAt
|
||||||
@ -23,6 +24,7 @@ const donationsQuery = gql`
|
|||||||
query {
|
query {
|
||||||
Donations {
|
Donations {
|
||||||
id
|
id
|
||||||
|
showDonations
|
||||||
goal
|
goal
|
||||||
progress
|
progress
|
||||||
}
|
}
|
||||||
@ -64,20 +66,20 @@ describe('donations', () => {
|
|||||||
errors: [{ message: 'Not Authorised!' }],
|
errors: [{ message: 'Not Authorised!' }],
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
})
|
||||||
|
|
||||||
describe('authenticated', () => {
|
describe('authenticated', () => {
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
currentUser = await Factory.build('user', {
|
currentUser = await Factory.build('user', {
|
||||||
id: 'normal-user',
|
id: 'normal-user',
|
||||||
role: 'user',
|
role: 'user',
|
||||||
})
|
|
||||||
authenticatedUser = await currentUser.toJson()
|
|
||||||
})
|
})
|
||||||
|
authenticatedUser = await currentUser.toJson()
|
||||||
|
})
|
||||||
|
|
||||||
it('returns the current Donations info', async () => {
|
it('returns the current Donations info', async () => {
|
||||||
await expect(query({ query: donationsQuery, variables })).resolves.toMatchObject({
|
await expect(query({ query: donationsQuery, variables })).resolves.toMatchObject({
|
||||||
data: { Donations: [{ goal: 15000, progress: 0 }] },
|
data: { Donations: [{ showDonations: true, goal: 15000, progress: 0 }] },
|
||||||
})
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@ -85,7 +87,7 @@ describe('donations', () => {
|
|||||||
|
|
||||||
describe('update donations', () => {
|
describe('update donations', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
variables = { goal: 20000, progress: 3000 }
|
variables = { showDonations: false, goal: 20000, progress: 3000 }
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('unauthenticated', () => {
|
describe('unauthenticated', () => {
|
||||||
@ -97,75 +99,75 @@ describe('donations', () => {
|
|||||||
errors: [{ message: 'Not Authorised!' }],
|
errors: [{ message: 'Not Authorised!' }],
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
})
|
||||||
|
|
||||||
describe('authenticated', () => {
|
describe('authenticated', () => {
|
||||||
describe('as a normal user', () => {
|
describe('as a normal user', () => {
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
currentUser = await Factory.build('user', {
|
currentUser = await Factory.build('user', {
|
||||||
id: 'normal-user',
|
id: 'normal-user',
|
||||||
role: 'user',
|
role: 'user',
|
||||||
})
|
|
||||||
authenticatedUser = await currentUser.toJson()
|
|
||||||
})
|
})
|
||||||
|
authenticatedUser = await currentUser.toJson()
|
||||||
|
})
|
||||||
|
|
||||||
it('throws authorization error', async () => {
|
it('throws authorization error', async () => {
|
||||||
await expect(
|
await expect(
|
||||||
mutate({ mutation: updateDonationsMutation, variables }),
|
mutate({ mutation: updateDonationsMutation, variables }),
|
||||||
).resolves.toMatchObject({
|
).resolves.toMatchObject({
|
||||||
data: { UpdateDonations: null },
|
data: { UpdateDonations: null },
|
||||||
errors: [{ message: 'Not Authorised!' }],
|
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', () => {
|
it('updates the updatedAt attribute', async () => {
|
||||||
beforeEach(async () => {
|
newlyCreatedDonations = await newlyCreatedDonations.toJson()
|
||||||
currentUser = await Factory.build('user', {
|
const {
|
||||||
id: 'moderator',
|
data: { UpdateDonations },
|
||||||
role: 'moderator',
|
} = await mutate({ mutation: updateDonationsMutation, variables })
|
||||||
})
|
expect(newlyCreatedDonations.updatedAt).toBeTruthy()
|
||||||
authenticatedUser = await currentUser.toJson()
|
expect(Date.parse(newlyCreatedDonations.updatedAt)).toEqual(expect.any(Number))
|
||||||
})
|
expect(UpdateDonations.updatedAt).toBeTruthy()
|
||||||
|
expect(Date.parse(UpdateDonations.updatedAt)).toEqual(expect.any(Number))
|
||||||
it('throws authorization error', async () => {
|
expect(newlyCreatedDonations.updatedAt).not.toEqual(UpdateDonations.updatedAt)
|
||||||
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)
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@ -1,7 +1,8 @@
|
|||||||
type Donations {
|
type Donations {
|
||||||
id: ID!
|
id: ID!
|
||||||
goal: Int!
|
showDonations: Boolean! # Wolle make it required in the schema
|
||||||
progress: Int!
|
goal: Int! # Wolle make it required in the schema
|
||||||
|
progress: Int! # Wolle make it required in the schema
|
||||||
createdAt: String
|
createdAt: String
|
||||||
updatedAt: String
|
updatedAt: String
|
||||||
}
|
}
|
||||||
@ -11,5 +12,5 @@ type Query {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Mutation {
|
type Mutation {
|
||||||
UpdateDonations(goal: Int, progress: Int): Donations
|
UpdateDonations(showDonations: Boolean, goal: Int, progress: Int): Donations
|
||||||
}
|
}
|
||||||
@ -48,7 +48,7 @@ export default {
|
|||||||
},
|
},
|
||||||
update({ Donations }) {
|
update({ Donations }) {
|
||||||
if (!Donations[0]) return
|
if (!Donations[0]) return
|
||||||
const { goal, progress } = Donations[0]
|
const { goal, progress } = Donations[0] // Wolle showDonations
|
||||||
this.goal = goal
|
this.goal = goal
|
||||||
this.progress = progress
|
this.progress = progress
|
||||||
},
|
},
|
||||||
|
|||||||
@ -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
|
export const DONATIONS_SHOW_INFO = true
|
||||||
|
|||||||
@ -1 +1 @@
|
|||||||
export const NEWSFEED_SHOW_INFO_LEFT_LANE = true
|
export const NEWSFEED_SHOW_INFO_LEFT_LANE = true // Wolle
|
||||||
|
|||||||
@ -4,6 +4,7 @@ export const DonationsQuery = () => gql`
|
|||||||
query {
|
query {
|
||||||
Donations {
|
Donations {
|
||||||
id
|
id
|
||||||
|
showDonations
|
||||||
goal
|
goal
|
||||||
progress
|
progress
|
||||||
}
|
}
|
||||||
@ -12,9 +13,10 @@ export const DonationsQuery = () => gql`
|
|||||||
|
|
||||||
export const UpdateDonations = () => {
|
export const UpdateDonations = () => {
|
||||||
return gql`
|
return gql`
|
||||||
mutation($goal: Int, $progress: Int) {
|
mutation($showDonations: Boolean, $goal: Int, $progress: Int) {
|
||||||
UpdateDonations(goal: $goal, progress: $progress) {
|
UpdateDonations(showDonations: $showDonations, goal: $goal, progress: $progress) {
|
||||||
id
|
id
|
||||||
|
showDonations
|
||||||
goal
|
goal
|
||||||
progress
|
progress
|
||||||
updatedAt
|
updatedAt
|
||||||
|
|||||||
@ -29,12 +29,8 @@
|
|||||||
icon="money"
|
icon="money"
|
||||||
:disabled="!showDonations"
|
:disabled="!showDonations"
|
||||||
/>
|
/>
|
||||||
<base-button
|
<base-button class="donations-info-button" filled type="submit">
|
||||||
class="donations-info-button"
|
<!-- Wolle :disabled="formData.showDonations === null || !formData.goal || !formData.progress" -->
|
||||||
filled
|
|
||||||
type="submit"
|
|
||||||
:disabled="!formData.goal || !formData.progress"
|
|
||||||
>
|
|
||||||
{{ $t('actions.save') }}
|
{{ $t('actions.save') }}
|
||||||
</base-button>
|
</base-button>
|
||||||
</ds-form>
|
</ds-form>
|
||||||
@ -59,11 +55,13 @@ export default {
|
|||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
submit() {
|
submit() {
|
||||||
|
const { showDonations } = this
|
||||||
const { goal, progress } = this.formData
|
const { goal, progress } = this.formData
|
||||||
this.$apollo
|
this.$apollo
|
||||||
.mutate({
|
.mutate({
|
||||||
mutation: UpdateDonations(),
|
mutation: UpdateDonations(),
|
||||||
variables: {
|
variables: {
|
||||||
|
showDonations,
|
||||||
goal: parseInt(goal),
|
goal: parseInt(goal),
|
||||||
progress: parseInt(progress),
|
progress: parseInt(progress),
|
||||||
},
|
},
|
||||||
@ -81,7 +79,8 @@ export default {
|
|||||||
},
|
},
|
||||||
update({ Donations }) {
|
update({ Donations }) {
|
||||||
if (!Donations[0]) return
|
if (!Donations[0]) return
|
||||||
const { goal, progress } = Donations[0]
|
const { showDonations, goal, progress } = Donations[0]
|
||||||
|
this.showDonations = showDonations
|
||||||
this.formData = {
|
this.formData = {
|
||||||
goal,
|
goal,
|
||||||
progress,
|
progress,
|
||||||
|
|||||||
@ -90,8 +90,8 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { DONATIONS_SHOW_INFO } from '~/constants/donations'
|
import { DONATIONS_SHOW_INFO } from '~/constants/donations' // Wolle
|
||||||
import { NEWSFEED_SHOW_INFO_LEFT_LANE } from '~/constants/newsfeed'
|
import { NEWSFEED_SHOW_INFO_LEFT_LANE } from '~/constants/newsfeed' // Wolle
|
||||||
import postListActions from '~/mixins/postListActions'
|
import postListActions from '~/mixins/postListActions'
|
||||||
import DonationInfo from '~/components/DonationInfo/DonationInfo.vue'
|
import DonationInfo from '~/components/DonationInfo/DonationInfo.vue'
|
||||||
import HashtagsFilter from '~/components/HashtagsFilter/HashtagsFilter.vue'
|
import HashtagsFilter from '~/components/HashtagsFilter/HashtagsFilter.vue'
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user