mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
sendCoins with graphql
This commit is contained in:
parent
f0a325f332
commit
076d3edbd9
@ -101,3 +101,9 @@ export const resgisterUserQuery = gql`
|
|||||||
create(email: $email, firstName: $firstName, lastName: $lastName, password: $password)
|
create(email: $email, firstName: $firstName, lastName: $lastName, password: $password)
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
|
|
||||||
|
export const sendCoins = gql`
|
||||||
|
query($sessionId: Float!, $email: String!, $amount: Float!, $memo: String!) {
|
||||||
|
sendCoins(sessionId: $sessionId, email: $email, amount: $amount, memo: $memo)
|
||||||
|
}
|
||||||
|
`
|
||||||
|
|||||||
@ -143,6 +143,22 @@ describe('DashboardLayoutGdd', () => {
|
|||||||
it('redirects to login page', () => {
|
it('redirects to login page', () => {
|
||||||
expect(routerPushMock).toBeCalledWith('/login')
|
expect(routerPushMock).toBeCalledWith('/login')
|
||||||
})
|
})
|
||||||
|
|
||||||
|
describe('logout fails', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
apolloMock.mockRejectedValue({
|
||||||
|
message: 'error',
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
it('dispatches logout to store', () => {
|
||||||
|
expect(storeDispatchMock).toBeCalledWith('logout')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('redirects to login page', () => {
|
||||||
|
expect(routerPushMock).toBeCalledWith('/login')
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('update balance', () => {
|
describe('update balance', () => {
|
||||||
|
|||||||
@ -100,7 +100,11 @@ export default {
|
|||||||
this.$store.dispatch('logout')
|
this.$store.dispatch('logout')
|
||||||
this.$router.push('/login')
|
this.$router.push('/login')
|
||||||
})
|
})
|
||||||
// do we have to handle errors?
|
.catch(() => {
|
||||||
|
this.$sidebar.displaySidebar(false)
|
||||||
|
this.$store.dispatch('logout')
|
||||||
|
this.$router.push('/login')
|
||||||
|
})
|
||||||
},
|
},
|
||||||
async updateTransactions(pagination) {
|
async updateTransactions(pagination) {
|
||||||
this.pending = true
|
this.pending = true
|
||||||
@ -112,6 +116,7 @@ export default {
|
|||||||
firstPage: pagination.firstPage,
|
firstPage: pagination.firstPage,
|
||||||
items: pagination.items,
|
items: pagination.items,
|
||||||
},
|
},
|
||||||
|
fetchPolicy: 'network-only',
|
||||||
})
|
})
|
||||||
.then((result) => {
|
.then((result) => {
|
||||||
const {
|
const {
|
||||||
|
|||||||
@ -1,13 +1,8 @@
|
|||||||
import { mount } from '@vue/test-utils'
|
import { mount } from '@vue/test-utils'
|
||||||
import AccountOverview from './AccountOverview'
|
import AccountOverview from './AccountOverview'
|
||||||
import communityAPI from '../../apis/communityAPI.js'
|
|
||||||
|
|
||||||
jest.mock('../../apis/communityAPI.js')
|
|
||||||
|
|
||||||
const sendMock = jest.fn()
|
const sendMock = jest.fn()
|
||||||
sendMock.mockReturnValue({ success: true })
|
sendMock.mockResolvedValue('success')
|
||||||
|
|
||||||
communityAPI.send = sendMock
|
|
||||||
|
|
||||||
const localVue = global.localVue
|
const localVue = global.localVue
|
||||||
|
|
||||||
@ -27,6 +22,9 @@ describe('AccountOverview', () => {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
$n: jest.fn((n) => String(n)),
|
$n: jest.fn((n) => String(n)),
|
||||||
|
$apollo: {
|
||||||
|
query: sendMock,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
const Wrapper = () => {
|
const Wrapper = () => {
|
||||||
@ -92,11 +90,16 @@ describe('AccountOverview', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('calls the API when send-transaction is emitted', async () => {
|
it('calls the API when send-transaction is emitted', async () => {
|
||||||
expect(sendMock).toBeCalledWith(1, {
|
expect(sendMock).toBeCalledWith(
|
||||||
|
expect.objectContaining({
|
||||||
|
variables: {
|
||||||
|
sessionId: 1,
|
||||||
email: 'user@example.org',
|
email: 'user@example.org',
|
||||||
amount: 23.45,
|
amount: 23.45,
|
||||||
memo: 'Make the best of it!',
|
memo: 'Make the best of it!',
|
||||||
})
|
},
|
||||||
|
}),
|
||||||
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('emits update-balance', () => {
|
it('emits update-balance', () => {
|
||||||
@ -112,7 +115,7 @@ describe('AccountOverview', () => {
|
|||||||
describe('transaction is confirmed and server response is error', () => {
|
describe('transaction is confirmed and server response is error', () => {
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
jest.clearAllMocks()
|
jest.clearAllMocks()
|
||||||
sendMock.mockReturnValue({ success: false, result: { message: 'receiver not found' } })
|
sendMock.mockRejectedValue({ message: 'receiver not found' })
|
||||||
await wrapper
|
await wrapper
|
||||||
.findComponent({ name: 'TransactionConfirmation' })
|
.findComponent({ name: 'TransactionConfirmation' })
|
||||||
.vm.$emit('send-transaction')
|
.vm.$emit('send-transaction')
|
||||||
|
|||||||
@ -51,7 +51,7 @@ import GddTransactionListFooter from './AccountOverview/GddTransactionListFooter
|
|||||||
import TransactionForm from './AccountOverview/GddSend/TransactionForm.vue'
|
import TransactionForm from './AccountOverview/GddSend/TransactionForm.vue'
|
||||||
import TransactionConfirmation from './AccountOverview/GddSend/TransactionConfirmation.vue'
|
import TransactionConfirmation from './AccountOverview/GddSend/TransactionConfirmation.vue'
|
||||||
import TransactionResult from './AccountOverview/GddSend/TransactionResult.vue'
|
import TransactionResult from './AccountOverview/GddSend/TransactionResult.vue'
|
||||||
import communityAPI from '../../apis/communityAPI.js'
|
import { sendCoins } from '../../graphql/queries.js'
|
||||||
|
|
||||||
const EMPTY_TRANSACTION_DATA = {
|
const EMPTY_TRANSACTION_DATA = {
|
||||||
email: '',
|
email: '',
|
||||||
@ -104,14 +104,22 @@ export default {
|
|||||||
},
|
},
|
||||||
async sendTransaction() {
|
async sendTransaction() {
|
||||||
this.loading = true
|
this.loading = true
|
||||||
const result = await communityAPI.send(this.$store.state.sessionId, this.transactionData)
|
this.$apollo
|
||||||
if (result.success) {
|
.query({
|
||||||
|
query: sendCoins,
|
||||||
|
variables: {
|
||||||
|
sessionId: this.$store.state.sessionId,
|
||||||
|
...this.transactionData,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
.then(() => {
|
||||||
this.error = false
|
this.error = false
|
||||||
this.$emit('update-balance', this.transactionData.amount)
|
this.$emit('update-balance', this.transactionData.amount)
|
||||||
} else {
|
})
|
||||||
this.errorResult = result.result.message
|
.catch((err) => {
|
||||||
|
this.errorResult = err.message
|
||||||
this.error = true
|
this.error = true
|
||||||
}
|
})
|
||||||
this.currentTransactionStep = 2
|
this.currentTransactionStep = 2
|
||||||
this.loading = false
|
this.loading = false
|
||||||
},
|
},
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user