mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
Merge pull request #2791 from gradido/refactor-find-contribtiions
refactor(admin): admin list contributions for creation transaction list query
This commit is contained in:
commit
7fd6d947cc
@ -1,43 +1,75 @@
|
|||||||
import { mount } from '@vue/test-utils'
|
import { mount } from '@vue/test-utils'
|
||||||
import CreationTransactionList from './CreationTransactionList'
|
import CreationTransactionList from './CreationTransactionList'
|
||||||
import { toastErrorSpy } from '../../test/testSetup'
|
import { toastErrorSpy } from '../../test/testSetup'
|
||||||
|
import VueApollo from 'vue-apollo'
|
||||||
|
import { createMockClient } from 'mock-apollo-client'
|
||||||
|
import { adminListContributions } from '../graphql/adminListContributions'
|
||||||
|
|
||||||
|
const mockClient = createMockClient()
|
||||||
|
const apolloProvider = new VueApollo({
|
||||||
|
defaultClient: mockClient,
|
||||||
|
})
|
||||||
|
|
||||||
const localVue = global.localVue
|
const localVue = global.localVue
|
||||||
|
localVue.use(VueApollo)
|
||||||
|
|
||||||
const apolloQueryMock = jest.fn().mockResolvedValue({
|
const defaultData = () => {
|
||||||
data: {
|
return {
|
||||||
creationTransactionList: {
|
adminListContributions: {
|
||||||
contributionCount: 2,
|
contributionCount: 2,
|
||||||
contributionList: [
|
contributionList: [
|
||||||
{
|
{
|
||||||
id: 1,
|
id: 1,
|
||||||
amount: 5.8,
|
firstName: 'Bibi',
|
||||||
createdAt: '2022-09-21T11:09:51.000Z',
|
lastName: 'Bloxberg',
|
||||||
confirmedAt: null,
|
userId: 99,
|
||||||
contributionDate: '2022-08-01T00:00:00.000Z',
|
email: 'bibi@bloxberg.de',
|
||||||
memo: 'für deine Hilfe, Fräulein Rottenmeier',
|
amount: 500,
|
||||||
|
memo: 'Danke für alles',
|
||||||
|
date: new Date(),
|
||||||
|
moderator: 1,
|
||||||
state: 'PENDING',
|
state: 'PENDING',
|
||||||
|
creation: [500, 500, 500],
|
||||||
|
messagesCount: 0,
|
||||||
|
deniedBy: null,
|
||||||
|
deniedAt: null,
|
||||||
|
confirmedBy: null,
|
||||||
|
confirmedAt: null,
|
||||||
|
contributionDate: new Date(),
|
||||||
|
deletedBy: null,
|
||||||
|
deletedAt: null,
|
||||||
|
createdAt: new Date(),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 2,
|
id: 2,
|
||||||
amount: '47',
|
firstName: 'Räuber',
|
||||||
createdAt: '2022-09-21T11:09:28.000Z',
|
lastName: 'Hotzenplotz',
|
||||||
confirmedAt: '2022-09-21T11:09:28.000Z',
|
userId: 100,
|
||||||
contributionDate: '2022-08-01T00:00:00.000Z',
|
email: 'raeuber@hotzenplotz.de',
|
||||||
memo: 'für deine Hilfe, Frau Holle',
|
amount: 1000000,
|
||||||
state: 'CONFIRMED',
|
memo: 'Gut Ergattert',
|
||||||
|
date: new Date(),
|
||||||
|
moderator: 1,
|
||||||
|
state: 'PENDING',
|
||||||
|
creation: [500, 500, 500],
|
||||||
|
messagesCount: 0,
|
||||||
|
deniedBy: null,
|
||||||
|
deniedAt: null,
|
||||||
|
confirmedBy: null,
|
||||||
|
confirmedAt: new Date(),
|
||||||
|
contributionDate: new Date(),
|
||||||
|
deletedBy: null,
|
||||||
|
deletedAt: null,
|
||||||
|
createdAt: new Date(),
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
},
|
}
|
||||||
})
|
}
|
||||||
|
|
||||||
const mocks = {
|
const mocks = {
|
||||||
$d: jest.fn((t) => t),
|
$d: jest.fn((t) => t),
|
||||||
$t: jest.fn((t) => t),
|
$t: jest.fn((t) => t),
|
||||||
$apollo: {
|
|
||||||
query: apolloQueryMock,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const propsData = {
|
const propsData = {
|
||||||
@ -48,55 +80,53 @@ const propsData = {
|
|||||||
describe('CreationTransactionList', () => {
|
describe('CreationTransactionList', () => {
|
||||||
let wrapper
|
let wrapper
|
||||||
|
|
||||||
|
const adminListContributionsMock = jest.fn()
|
||||||
|
mockClient.setRequestHandler(
|
||||||
|
adminListContributions,
|
||||||
|
adminListContributionsMock
|
||||||
|
.mockRejectedValueOnce({ message: 'Ouch!' })
|
||||||
|
.mockResolvedValue({ data: defaultData() }),
|
||||||
|
)
|
||||||
|
|
||||||
const Wrapper = () => {
|
const Wrapper = () => {
|
||||||
return mount(CreationTransactionList, { localVue, mocks, propsData })
|
return mount(CreationTransactionList, { localVue, mocks, propsData, apolloProvider })
|
||||||
}
|
}
|
||||||
|
|
||||||
describe('mount', () => {
|
describe('mount', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
|
jest.clearAllMocks()
|
||||||
wrapper = Wrapper()
|
wrapper = Wrapper()
|
||||||
})
|
})
|
||||||
|
|
||||||
it('sends query to Apollo when created', () => {
|
describe('server error', () => {
|
||||||
expect(apolloQueryMock).toBeCalledWith(
|
|
||||||
expect.objectContaining({
|
|
||||||
variables: {
|
|
||||||
currentPage: 1,
|
|
||||||
pageSize: 10,
|
|
||||||
order: 'DESC',
|
|
||||||
userId: 1,
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
it('has two values for the transaction', () => {
|
|
||||||
expect(wrapper.find('tbody').findAll('tr').length).toBe(2)
|
|
||||||
})
|
|
||||||
|
|
||||||
describe('query transaction with error', () => {
|
|
||||||
beforeEach(() => {
|
|
||||||
apolloQueryMock.mockRejectedValue({ message: 'OUCH!' })
|
|
||||||
wrapper = Wrapper()
|
|
||||||
})
|
|
||||||
|
|
||||||
it('calls the API', () => {
|
|
||||||
expect(apolloQueryMock).toBeCalled()
|
|
||||||
})
|
|
||||||
|
|
||||||
it('toast error', () => {
|
it('toast error', () => {
|
||||||
expect(toastErrorSpy).toBeCalledWith('OUCH!')
|
expect(toastErrorSpy).toBeCalledWith('Ouch!')
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('watch currentPage', () => {
|
describe('sever success', () => {
|
||||||
beforeEach(async () => {
|
it('sends query to Apollo when created', () => {
|
||||||
jest.clearAllMocks()
|
expect(adminListContributionsMock).toBeCalledWith({
|
||||||
await wrapper.setData({ currentPage: 2 })
|
currentPage: 1,
|
||||||
|
pageSize: 10,
|
||||||
|
order: 'DESC',
|
||||||
|
userId: 1,
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it('returns the string in normal order if reversed property is not true', () => {
|
it('has two values for the transaction', () => {
|
||||||
expect(wrapper.vm.currentPage).toBe(2)
|
expect(wrapper.find('tbody').findAll('tr').length).toBe(2)
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('watch currentPage', () => {
|
||||||
|
beforeEach(async () => {
|
||||||
|
jest.clearAllMocks()
|
||||||
|
await wrapper.setData({ currentPage: 2 })
|
||||||
|
})
|
||||||
|
|
||||||
|
it('returns the string in normal order if reversed property is not true', () => {
|
||||||
|
expect(wrapper.vm.currentPage).toBe(2)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@ -42,7 +42,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
<script>
|
<script>
|
||||||
import { creationTransactionList } from '../graphql/creationTransactionList'
|
import { adminListContributions } from '../graphql/adminListContributions'
|
||||||
export default {
|
export default {
|
||||||
name: 'CreationTransactionList',
|
name: 'CreationTransactionList',
|
||||||
props: {
|
props: {
|
||||||
@ -92,33 +92,26 @@ export default {
|
|||||||
],
|
],
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
apollo: {
|
||||||
getTransactions() {
|
AdminListContributions: {
|
||||||
this.$apollo
|
query() {
|
||||||
.query({
|
return adminListContributions
|
||||||
query: creationTransactionList,
|
},
|
||||||
variables: {
|
variables() {
|
||||||
currentPage: this.currentPage,
|
return {
|
||||||
pageSize: this.perPage,
|
currentPage: this.currentPage,
|
||||||
order: 'DESC',
|
pageSize: this.perPage,
|
||||||
userId: parseInt(this.userId),
|
order: 'DESC',
|
||||||
},
|
userId: parseInt(this.userId),
|
||||||
})
|
}
|
||||||
.then((result) => {
|
},
|
||||||
this.rows = result.data.creationTransactionList.contributionCount
|
update({ adminListContributions }) {
|
||||||
this.items = result.data.creationTransactionList.contributionList
|
this.rows = adminListContributions.contributionCount
|
||||||
})
|
this.items = adminListContributions.contributionList
|
||||||
.catch((error) => {
|
},
|
||||||
this.toastError(error.message)
|
error({ message }) {
|
||||||
})
|
this.toastError(message)
|
||||||
},
|
},
|
||||||
},
|
|
||||||
created() {
|
|
||||||
this.getTransactions()
|
|
||||||
},
|
|
||||||
watch: {
|
|
||||||
currentPage() {
|
|
||||||
this.getTransactions()
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,17 +1,19 @@
|
|||||||
import gql from 'graphql-tag'
|
import gql from 'graphql-tag'
|
||||||
|
|
||||||
export const adminListAllContributions = gql`
|
export const adminListContributions = gql`
|
||||||
query (
|
query (
|
||||||
$currentPage: Int = 1
|
$currentPage: Int = 1
|
||||||
$pageSize: Int = 25
|
$pageSize: Int = 25
|
||||||
$order: Order = DESC
|
$order: Order = DESC
|
||||||
$statusFilter: [ContributionStatus!]
|
$statusFilter: [ContributionStatus!]
|
||||||
|
$userId: Int
|
||||||
) {
|
) {
|
||||||
adminListAllContributions(
|
adminListContributions(
|
||||||
currentPage: $currentPage
|
currentPage: $currentPage
|
||||||
pageSize: $pageSize
|
pageSize: $pageSize
|
||||||
order: $order
|
order: $order
|
||||||
statusFilter: $statusFilter
|
statusFilter: $statusFilter
|
||||||
|
userId: $userId
|
||||||
) {
|
) {
|
||||||
contributionCount
|
contributionCount
|
||||||
contributionList {
|
contributionList {
|
||||||
@ -1,23 +0,0 @@
|
|||||||
import gql from 'graphql-tag'
|
|
||||||
|
|
||||||
export const creationTransactionList = gql`
|
|
||||||
query ($currentPage: Int = 1, $pageSize: Int = 25, $order: Order = DESC, $userId: Int!) {
|
|
||||||
creationTransactionList(
|
|
||||||
currentPage: $currentPage
|
|
||||||
pageSize: $pageSize
|
|
||||||
order: $order
|
|
||||||
userId: $userId
|
|
||||||
) {
|
|
||||||
contributionCount
|
|
||||||
contributionList {
|
|
||||||
id
|
|
||||||
amount
|
|
||||||
createdAt
|
|
||||||
confirmedAt
|
|
||||||
contributionDate
|
|
||||||
memo
|
|
||||||
state
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
`
|
|
||||||
@ -2,7 +2,7 @@ import { mount } from '@vue/test-utils'
|
|||||||
import CreationConfirm from './CreationConfirm'
|
import CreationConfirm from './CreationConfirm'
|
||||||
import { adminDeleteContribution } from '../graphql/adminDeleteContribution'
|
import { adminDeleteContribution } from '../graphql/adminDeleteContribution'
|
||||||
import { denyContribution } from '../graphql/denyContribution'
|
import { denyContribution } from '../graphql/denyContribution'
|
||||||
import { adminListAllContributions } from '../graphql/adminListAllContributions'
|
import { adminListContributions } from '../graphql/adminListContributions'
|
||||||
import { confirmContribution } from '../graphql/confirmContribution'
|
import { confirmContribution } from '../graphql/confirmContribution'
|
||||||
import { toastErrorSpy, toastSuccessSpy } from '../../test/testSetup'
|
import { toastErrorSpy, toastSuccessSpy } from '../../test/testSetup'
|
||||||
import VueApollo from 'vue-apollo'
|
import VueApollo from 'vue-apollo'
|
||||||
@ -38,7 +38,7 @@ const mocks = {
|
|||||||
|
|
||||||
const defaultData = () => {
|
const defaultData = () => {
|
||||||
return {
|
return {
|
||||||
adminListAllContributions: {
|
adminListContributions: {
|
||||||
contributionCount: 2,
|
contributionCount: 2,
|
||||||
contributionList: [
|
contributionList: [
|
||||||
{
|
{
|
||||||
@ -92,14 +92,14 @@ const defaultData = () => {
|
|||||||
|
|
||||||
describe('CreationConfirm', () => {
|
describe('CreationConfirm', () => {
|
||||||
let wrapper
|
let wrapper
|
||||||
const adminListAllContributionsMock = jest.fn()
|
const adminListContributionsMock = jest.fn()
|
||||||
const adminDeleteContributionMock = jest.fn()
|
const adminDeleteContributionMock = jest.fn()
|
||||||
const adminDenyContributionMock = jest.fn()
|
const adminDenyContributionMock = jest.fn()
|
||||||
const confirmContributionMock = jest.fn()
|
const confirmContributionMock = jest.fn()
|
||||||
|
|
||||||
mockClient.setRequestHandler(
|
mockClient.setRequestHandler(
|
||||||
adminListAllContributions,
|
adminListContributions,
|
||||||
adminListAllContributionsMock
|
adminListContributionsMock
|
||||||
.mockRejectedValueOnce({ message: 'Ouch!' })
|
.mockRejectedValueOnce({ message: 'Ouch!' })
|
||||||
.mockResolvedValue({ data: defaultData() }),
|
.mockResolvedValue({ data: defaultData() }),
|
||||||
)
|
)
|
||||||
@ -337,7 +337,7 @@ describe('CreationConfirm', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('refetches contributions with proper filter', () => {
|
it('refetches contributions with proper filter', () => {
|
||||||
expect(adminListAllContributionsMock).toBeCalledWith({
|
expect(adminListContributionsMock).toBeCalledWith({
|
||||||
currentPage: 1,
|
currentPage: 1,
|
||||||
order: 'DESC',
|
order: 'DESC',
|
||||||
pageSize: 25,
|
pageSize: 25,
|
||||||
@ -352,7 +352,7 @@ describe('CreationConfirm', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('refetches contributions with proper filter', () => {
|
it('refetches contributions with proper filter', () => {
|
||||||
expect(adminListAllContributionsMock).toBeCalledWith({
|
expect(adminListContributionsMock).toBeCalledWith({
|
||||||
currentPage: 1,
|
currentPage: 1,
|
||||||
order: 'DESC',
|
order: 'DESC',
|
||||||
pageSize: 25,
|
pageSize: 25,
|
||||||
@ -368,7 +368,7 @@ describe('CreationConfirm', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('refetches contributions with proper filter', () => {
|
it('refetches contributions with proper filter', () => {
|
||||||
expect(adminListAllContributionsMock).toBeCalledWith({
|
expect(adminListContributionsMock).toBeCalledWith({
|
||||||
currentPage: 1,
|
currentPage: 1,
|
||||||
order: 'DESC',
|
order: 'DESC',
|
||||||
pageSize: 25,
|
pageSize: 25,
|
||||||
@ -384,7 +384,7 @@ describe('CreationConfirm', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('refetches contributions with proper filter', () => {
|
it('refetches contributions with proper filter', () => {
|
||||||
expect(adminListAllContributionsMock).toBeCalledWith({
|
expect(adminListContributionsMock).toBeCalledWith({
|
||||||
currentPage: 1,
|
currentPage: 1,
|
||||||
order: 'DESC',
|
order: 'DESC',
|
||||||
pageSize: 25,
|
pageSize: 25,
|
||||||
@ -400,7 +400,7 @@ describe('CreationConfirm', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('refetches contributions with proper filter', () => {
|
it('refetches contributions with proper filter', () => {
|
||||||
expect(adminListAllContributionsMock).toBeCalledWith({
|
expect(adminListContributionsMock).toBeCalledWith({
|
||||||
currentPage: 1,
|
currentPage: 1,
|
||||||
order: 'DESC',
|
order: 'DESC',
|
||||||
pageSize: 25,
|
pageSize: 25,
|
||||||
|
|||||||
@ -85,7 +85,7 @@
|
|||||||
<script>
|
<script>
|
||||||
import Overlay from '../components/Overlay'
|
import Overlay from '../components/Overlay'
|
||||||
import OpenCreationsTable from '../components/Tables/OpenCreationsTable'
|
import OpenCreationsTable from '../components/Tables/OpenCreationsTable'
|
||||||
import { adminListAllContributions } from '../graphql/adminListAllContributions'
|
import { adminListContributions } from '../graphql/adminListContributions'
|
||||||
import { adminDeleteContribution } from '../graphql/adminDeleteContribution'
|
import { adminDeleteContribution } from '../graphql/adminDeleteContribution'
|
||||||
import { confirmContribution } from '../graphql/confirmContribution'
|
import { confirmContribution } from '../graphql/confirmContribution'
|
||||||
import { denyContribution } from '../graphql/denyContribution'
|
import { denyContribution } from '../graphql/denyContribution'
|
||||||
@ -397,7 +397,7 @@ export default {
|
|||||||
apollo: {
|
apollo: {
|
||||||
ListAllContributions: {
|
ListAllContributions: {
|
||||||
query() {
|
query() {
|
||||||
return adminListAllContributions
|
return adminListContributions
|
||||||
},
|
},
|
||||||
variables() {
|
variables() {
|
||||||
return {
|
return {
|
||||||
@ -407,11 +407,11 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
fetchPolicy: 'no-cache',
|
fetchPolicy: 'no-cache',
|
||||||
update({ adminListAllContributions }) {
|
update({ adminListContributions }) {
|
||||||
this.rows = adminListAllContributions.contributionCount
|
this.rows = adminListContributions.contributionCount
|
||||||
this.items = adminListAllContributions.contributionList
|
this.items = adminListContributions.contributionList
|
||||||
if (this.statusFilter === FILTER_TAB_MAP[0]) {
|
if (this.statusFilter === FILTER_TAB_MAP[0]) {
|
||||||
this.$store.commit('setOpenCreations', adminListAllContributions.contributionCount)
|
this.$store.commit('setOpenCreations', adminListContributions.contributionCount)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
error({ message }) {
|
error({ message }) {
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
import { mount } from '@vue/test-utils'
|
import { mount } from '@vue/test-utils'
|
||||||
import Overview from './Overview'
|
import Overview from './Overview'
|
||||||
import { adminListAllContributions } from '../graphql/adminListAllContributions'
|
import { adminListContributions } from '../graphql/adminListContributions'
|
||||||
import VueApollo from 'vue-apollo'
|
import VueApollo from 'vue-apollo'
|
||||||
import { createMockClient } from 'mock-apollo-client'
|
import { createMockClient } from 'mock-apollo-client'
|
||||||
import { toastErrorSpy } from '../../test/testSetup'
|
import { toastErrorSpy } from '../../test/testSetup'
|
||||||
@ -30,7 +30,7 @@ const mocks = {
|
|||||||
|
|
||||||
const defaultData = () => {
|
const defaultData = () => {
|
||||||
return {
|
return {
|
||||||
adminListAllContributions: {
|
adminListContributions: {
|
||||||
contributionCount: 2,
|
contributionCount: 2,
|
||||||
contributionList: [
|
contributionList: [
|
||||||
{
|
{
|
||||||
@ -84,11 +84,11 @@ const defaultData = () => {
|
|||||||
|
|
||||||
describe('Overview', () => {
|
describe('Overview', () => {
|
||||||
let wrapper
|
let wrapper
|
||||||
const adminListAllContributionsMock = jest.fn()
|
const adminListContributionsMock = jest.fn()
|
||||||
|
|
||||||
mockClient.setRequestHandler(
|
mockClient.setRequestHandler(
|
||||||
adminListAllContributions,
|
adminListContributions,
|
||||||
adminListAllContributionsMock
|
adminListContributionsMock
|
||||||
.mockRejectedValueOnce({ message: 'Ouch!' })
|
.mockRejectedValueOnce({ message: 'Ouch!' })
|
||||||
.mockResolvedValue({ data: defaultData() }),
|
.mockResolvedValue({ data: defaultData() }),
|
||||||
)
|
)
|
||||||
@ -109,8 +109,8 @@ describe('Overview', () => {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it('calls the adminListAllContributions query', () => {
|
it('calls the adminListContributions query', () => {
|
||||||
expect(adminListAllContributionsMock).toBeCalledWith({
|
expect(adminListContributionsMock).toBeCalledWith({
|
||||||
currentPage: 1,
|
currentPage: 1,
|
||||||
order: 'DESC',
|
order: 'DESC',
|
||||||
pageSize: 25,
|
pageSize: 25,
|
||||||
|
|||||||
@ -31,7 +31,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
<script>
|
<script>
|
||||||
import { adminListAllContributions } from '../graphql/adminListAllContributions'
|
import { adminListContributions } from '../graphql/adminListContributions'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'overview',
|
name: 'overview',
|
||||||
@ -43,7 +43,7 @@ export default {
|
|||||||
apollo: {
|
apollo: {
|
||||||
AllContributions: {
|
AllContributions: {
|
||||||
query() {
|
query() {
|
||||||
return adminListAllContributions
|
return adminListContributions
|
||||||
},
|
},
|
||||||
variables() {
|
variables() {
|
||||||
// may be at some point we need a pagination here
|
// may be at some point we need a pagination here
|
||||||
@ -51,8 +51,8 @@ export default {
|
|||||||
statusFilter: this.statusFilter,
|
statusFilter: this.statusFilter,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
update({ adminListAllContributions }) {
|
update({ adminListContributions }) {
|
||||||
this.$store.commit('setOpenCreations', adminListAllContributions.contributionCount)
|
this.$store.commit('setOpenCreations', adminListContributions.contributionCount)
|
||||||
},
|
},
|
||||||
error({ message }) {
|
error({ message }) {
|
||||||
this.toastError(message)
|
this.toastError(message)
|
||||||
|
|||||||
@ -6,7 +6,7 @@ module.exports = {
|
|||||||
collectCoverageFrom: ['src/**/*.ts', '!**/node_modules/**', '!src/seeds/**', '!build/**'],
|
collectCoverageFrom: ['src/**/*.ts', '!**/node_modules/**', '!src/seeds/**', '!build/**'],
|
||||||
coverageThreshold: {
|
coverageThreshold: {
|
||||||
global: {
|
global: {
|
||||||
lines: 80,
|
lines: 81,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
setupFiles: ['<rootDir>/test/testSetup.ts'],
|
setupFiles: ['<rootDir>/test/testSetup.ts'],
|
||||||
|
|||||||
@ -43,10 +43,9 @@ export enum RIGHTS {
|
|||||||
ADMIN_CREATE_CONTRIBUTION = 'ADMIN_CREATE_CONTRIBUTION',
|
ADMIN_CREATE_CONTRIBUTION = 'ADMIN_CREATE_CONTRIBUTION',
|
||||||
ADMIN_UPDATE_CONTRIBUTION = 'ADMIN_UPDATE_CONTRIBUTION',
|
ADMIN_UPDATE_CONTRIBUTION = 'ADMIN_UPDATE_CONTRIBUTION',
|
||||||
ADMIN_DELETE_CONTRIBUTION = 'ADMIN_DELETE_CONTRIBUTION',
|
ADMIN_DELETE_CONTRIBUTION = 'ADMIN_DELETE_CONTRIBUTION',
|
||||||
LIST_UNCONFIRMED_CONTRIBUTIONS = 'LIST_UNCONFIRMED_CONTRIBUTIONS',
|
ADMIN_LIST_CONTRIBUTIONS = 'ADMIN_LIST_CONTRIBUTIONS',
|
||||||
CONFIRM_CONTRIBUTION = 'CONFIRM_CONTRIBUTION',
|
CONFIRM_CONTRIBUTION = 'CONFIRM_CONTRIBUTION',
|
||||||
SEND_ACTIVATION_EMAIL = 'SEND_ACTIVATION_EMAIL',
|
SEND_ACTIVATION_EMAIL = 'SEND_ACTIVATION_EMAIL',
|
||||||
CREATION_TRANSACTION_LIST = 'CREATION_TRANSACTION_LIST',
|
|
||||||
LIST_TRANSACTION_LINKS_ADMIN = 'LIST_TRANSACTION_LINKS_ADMIN',
|
LIST_TRANSACTION_LINKS_ADMIN = 'LIST_TRANSACTION_LINKS_ADMIN',
|
||||||
CREATE_CONTRIBUTION_LINK = 'CREATE_CONTRIBUTION_LINK',
|
CREATE_CONTRIBUTION_LINK = 'CREATE_CONTRIBUTION_LINK',
|
||||||
DELETE_CONTRIBUTION_LINK = 'DELETE_CONTRIBUTION_LINK',
|
DELETE_CONTRIBUTION_LINK = 'DELETE_CONTRIBUTION_LINK',
|
||||||
|
|||||||
@ -27,7 +27,7 @@ import {
|
|||||||
import {
|
import {
|
||||||
listAllContributions,
|
listAllContributions,
|
||||||
listContributions,
|
listContributions,
|
||||||
adminListAllContributions,
|
adminListContributions,
|
||||||
} from '@/seeds/graphql/queries'
|
} from '@/seeds/graphql/queries'
|
||||||
import {
|
import {
|
||||||
sendContributionConfirmedEmail,
|
sendContributionConfirmedEmail,
|
||||||
@ -2669,12 +2669,12 @@ describe('ContributionResolver', () => {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('adminListAllContribution', () => {
|
describe('adminListContributions', () => {
|
||||||
describe('unauthenticated', () => {
|
describe('unauthenticated', () => {
|
||||||
it('returns an error', async () => {
|
it('returns an error', async () => {
|
||||||
await expect(
|
await expect(
|
||||||
query({
|
query({
|
||||||
query: adminListAllContributions,
|
query: adminListContributions,
|
||||||
}),
|
}),
|
||||||
).resolves.toEqual(
|
).resolves.toEqual(
|
||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
@ -2699,7 +2699,7 @@ describe('ContributionResolver', () => {
|
|||||||
it('returns an error', async () => {
|
it('returns an error', async () => {
|
||||||
await expect(
|
await expect(
|
||||||
query({
|
query({
|
||||||
query: adminListAllContributions,
|
query: adminListContributions,
|
||||||
}),
|
}),
|
||||||
).resolves.toEqual(
|
).resolves.toEqual(
|
||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
@ -2723,9 +2723,9 @@ describe('ContributionResolver', () => {
|
|||||||
|
|
||||||
it('returns 17 creations in total', async () => {
|
it('returns 17 creations in total', async () => {
|
||||||
const {
|
const {
|
||||||
data: { adminListAllContributions: contributionListObject },
|
data: { adminListContributions: contributionListObject },
|
||||||
}: { data: { adminListAllContributions: ContributionListResult } } = await query({
|
}: { data: { adminListContributions: ContributionListResult } } = await query({
|
||||||
query: adminListAllContributions,
|
query: adminListContributions,
|
||||||
})
|
})
|
||||||
expect(contributionListObject.contributionList).toHaveLength(17)
|
expect(contributionListObject.contributionList).toHaveLength(17)
|
||||||
expect(contributionListObject).toMatchObject({
|
expect(contributionListObject).toMatchObject({
|
||||||
@ -2890,9 +2890,9 @@ describe('ContributionResolver', () => {
|
|||||||
|
|
||||||
it('returns two pending creations with page size set to 2', async () => {
|
it('returns two pending creations with page size set to 2', async () => {
|
||||||
const {
|
const {
|
||||||
data: { adminListAllContributions: contributionListObject },
|
data: { adminListContributions: contributionListObject },
|
||||||
}: { data: { adminListAllContributions: ContributionListResult } } = await query({
|
}: { data: { adminListContributions: ContributionListResult } } = await query({
|
||||||
query: adminListAllContributions,
|
query: adminListContributions,
|
||||||
variables: {
|
variables: {
|
||||||
currentPage: 1,
|
currentPage: 1,
|
||||||
pageSize: 2,
|
pageSize: 2,
|
||||||
|
|||||||
@ -136,15 +136,15 @@ export class ContributionResolver {
|
|||||||
): Promise<ContributionListResult> {
|
): Promise<ContributionListResult> {
|
||||||
const user = getUser(context)
|
const user = getUser(context)
|
||||||
|
|
||||||
const [dbContributions, count] = await findContributions(
|
const [dbContributions, count] = await findContributions({
|
||||||
order,
|
order,
|
||||||
currentPage,
|
currentPage,
|
||||||
pageSize,
|
pageSize,
|
||||||
true,
|
withDeleted: true,
|
||||||
['messages'],
|
relations: ['messages'],
|
||||||
user.id,
|
userId: user.id,
|
||||||
statusFilter,
|
statusFilter,
|
||||||
)
|
})
|
||||||
return new ContributionListResult(
|
return new ContributionListResult(
|
||||||
count,
|
count,
|
||||||
dbContributions.map((contribution) => new Contribution(contribution, user)),
|
dbContributions.map((contribution) => new Contribution(contribution, user)),
|
||||||
@ -159,15 +159,13 @@ export class ContributionResolver {
|
|||||||
@Arg('statusFilter', () => [ContributionStatus], { nullable: true })
|
@Arg('statusFilter', () => [ContributionStatus], { nullable: true })
|
||||||
statusFilter?: ContributionStatus[] | null,
|
statusFilter?: ContributionStatus[] | null,
|
||||||
): Promise<ContributionListResult> {
|
): Promise<ContributionListResult> {
|
||||||
const [dbContributions, count] = await findContributions(
|
const [dbContributions, count] = await findContributions({
|
||||||
order,
|
order,
|
||||||
currentPage,
|
currentPage,
|
||||||
pageSize,
|
pageSize,
|
||||||
false,
|
relations: ['user'],
|
||||||
['user'],
|
|
||||||
undefined,
|
|
||||||
statusFilter,
|
statusFilter,
|
||||||
)
|
})
|
||||||
|
|
||||||
return new ContributionListResult(
|
return new ContributionListResult(
|
||||||
count,
|
count,
|
||||||
@ -384,23 +382,25 @@ export class ContributionResolver {
|
|||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
@Authorized([RIGHTS.LIST_UNCONFIRMED_CONTRIBUTIONS])
|
@Authorized([RIGHTS.ADMIN_LIST_CONTRIBUTIONS])
|
||||||
@Query(() => ContributionListResult) // [UnconfirmedContribution]
|
@Query(() => ContributionListResult)
|
||||||
async adminListAllContributions(
|
async adminListContributions(
|
||||||
@Args()
|
@Args()
|
||||||
{ currentPage = 1, pageSize = 3, order = Order.DESC }: Paginated,
|
{ currentPage = 1, pageSize = 3, order = Order.DESC }: Paginated,
|
||||||
@Arg('statusFilter', () => [ContributionStatus], { nullable: true })
|
@Arg('statusFilter', () => [ContributionStatus], { nullable: true })
|
||||||
statusFilter?: ContributionStatus[] | null,
|
statusFilter?: ContributionStatus[] | null,
|
||||||
|
@Arg('userId', () => Int, { nullable: true })
|
||||||
|
userId?: number | null,
|
||||||
): Promise<ContributionListResult> {
|
): Promise<ContributionListResult> {
|
||||||
const [dbContributions, count] = await findContributions(
|
const [dbContributions, count] = await findContributions({
|
||||||
order,
|
order,
|
||||||
currentPage,
|
currentPage,
|
||||||
pageSize,
|
pageSize,
|
||||||
true,
|
withDeleted: true,
|
||||||
['user', 'messages'],
|
userId,
|
||||||
undefined,
|
relations: ['user', 'messages'],
|
||||||
statusFilter,
|
statusFilter,
|
||||||
)
|
})
|
||||||
|
|
||||||
return new ContributionListResult(
|
return new ContributionListResult(
|
||||||
count,
|
count,
|
||||||
@ -562,33 +562,6 @@ export class ContributionResolver {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
@Authorized([RIGHTS.CREATION_TRANSACTION_LIST])
|
|
||||||
@Query(() => ContributionListResult)
|
|
||||||
async creationTransactionList(
|
|
||||||
@Args()
|
|
||||||
{ currentPage = 1, pageSize = 25, order = Order.DESC }: Paginated,
|
|
||||||
@Arg('userId', () => Int) userId: number,
|
|
||||||
): Promise<ContributionListResult> {
|
|
||||||
const offset = (currentPage - 1) * pageSize
|
|
||||||
const [contributionResult, count] = await getConnection()
|
|
||||||
.createQueryBuilder()
|
|
||||||
.select('c')
|
|
||||||
.from(DbContribution, 'c')
|
|
||||||
.leftJoinAndSelect('c.user', 'u')
|
|
||||||
.where(`user_id = ${userId}`)
|
|
||||||
.withDeleted()
|
|
||||||
.limit(pageSize)
|
|
||||||
.offset(offset)
|
|
||||||
.orderBy('c.created_at', order)
|
|
||||||
.getManyAndCount()
|
|
||||||
|
|
||||||
return new ContributionListResult(
|
|
||||||
count,
|
|
||||||
contributionResult.map((contribution) => new Contribution(contribution, contribution.user)),
|
|
||||||
)
|
|
||||||
// return userTransactions.map((t) => new Transaction(t, new User(user), communityUser))
|
|
||||||
}
|
|
||||||
|
|
||||||
@Authorized([RIGHTS.OPEN_CREATIONS])
|
@Authorized([RIGHTS.OPEN_CREATIONS])
|
||||||
@Query(() => [OpenCreation])
|
@Query(() => [OpenCreation])
|
||||||
async openCreations(@Ctx() context: Context): Promise<OpenCreation[]> {
|
async openCreations(@Ctx() context: Context): Promise<OpenCreation[]> {
|
||||||
|
|||||||
@ -3,21 +3,30 @@ import { Order } from '@enum/Order'
|
|||||||
import { Contribution as DbContribution } from '@entity/Contribution'
|
import { Contribution as DbContribution } from '@entity/Contribution'
|
||||||
import { In } from '@dbTools/typeorm'
|
import { In } from '@dbTools/typeorm'
|
||||||
|
|
||||||
|
interface FindContributionsOptions {
|
||||||
|
order: Order
|
||||||
|
currentPage: number
|
||||||
|
pageSize: number
|
||||||
|
withDeleted?: boolean
|
||||||
|
relations?: string[]
|
||||||
|
userId?: number | null
|
||||||
|
statusFilter?: ContributionStatus[] | null
|
||||||
|
}
|
||||||
|
|
||||||
export const findContributions = async (
|
export const findContributions = async (
|
||||||
order: Order,
|
options: FindContributionsOptions,
|
||||||
currentPage: number,
|
): Promise<[DbContribution[], number]> => {
|
||||||
pageSize: number,
|
const { order, currentPage, pageSize, withDeleted, relations, userId, statusFilter } = {
|
||||||
withDeleted: boolean,
|
withDeleted: false,
|
||||||
relations: string[],
|
relations: [],
|
||||||
userId?: number,
|
...options,
|
||||||
statusFilter?: ContributionStatus[] | null,
|
}
|
||||||
): Promise<[DbContribution[], number]> =>
|
return DbContribution.findAndCount({
|
||||||
DbContribution.findAndCount({
|
|
||||||
where: {
|
where: {
|
||||||
...(statusFilter && statusFilter.length && { contributionStatus: In(statusFilter) }),
|
...(statusFilter && statusFilter.length && { contributionStatus: In(statusFilter) }),
|
||||||
...(userId && { userId }),
|
...(userId && { userId }),
|
||||||
},
|
},
|
||||||
withDeleted: withDeleted,
|
withDeleted,
|
||||||
order: {
|
order: {
|
||||||
createdAt: order,
|
createdAt: order,
|
||||||
id: order,
|
id: order,
|
||||||
@ -26,3 +35,4 @@ export const findContributions = async (
|
|||||||
skip: (currentPage - 1) * pageSize,
|
skip: (currentPage - 1) * pageSize,
|
||||||
take: pageSize,
|
take: pageSize,
|
||||||
})
|
})
|
||||||
|
}
|
||||||
|
|||||||
@ -220,18 +220,20 @@ query ($currentPage: Int = 1, $pageSize: Int = 5, $order: Order = DESC, $statusF
|
|||||||
`
|
`
|
||||||
// from admin interface
|
// from admin interface
|
||||||
|
|
||||||
export const adminListAllContributions = gql`
|
export const adminListContributions = gql`
|
||||||
query (
|
query (
|
||||||
$currentPage: Int = 1
|
$currentPage: Int = 1
|
||||||
$pageSize: Int = 25
|
$pageSize: Int = 25
|
||||||
$order: Order = DESC
|
$order: Order = DESC
|
||||||
$statusFilter: [ContributionStatus!]
|
$statusFilter: [ContributionStatus!]
|
||||||
|
$userId: Int
|
||||||
) {
|
) {
|
||||||
adminListAllContributions(
|
adminListContributions(
|
||||||
currentPage: $currentPage
|
currentPage: $currentPage
|
||||||
pageSize: $pageSize
|
pageSize: $pageSize
|
||||||
order: $order
|
order: $order
|
||||||
statusFilter: $statusFilter
|
statusFilter: $statusFilter
|
||||||
|
userId: $userId
|
||||||
) {
|
) {
|
||||||
contributionCount
|
contributionCount
|
||||||
contributionList {
|
contributionList {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user