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)
|
||||
}
|
||||
`
|
||||
|
||||
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', () => {
|
||||
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', () => {
|
||||
|
||||
@ -100,7 +100,11 @@ export default {
|
||||
this.$store.dispatch('logout')
|
||||
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) {
|
||||
this.pending = true
|
||||
@ -112,6 +116,7 @@ export default {
|
||||
firstPage: pagination.firstPage,
|
||||
items: pagination.items,
|
||||
},
|
||||
fetchPolicy: 'network-only',
|
||||
})
|
||||
.then((result) => {
|
||||
const {
|
||||
|
||||
@ -1,13 +1,8 @@
|
||||
import { mount } from '@vue/test-utils'
|
||||
import AccountOverview from './AccountOverview'
|
||||
import communityAPI from '../../apis/communityAPI.js'
|
||||
|
||||
jest.mock('../../apis/communityAPI.js')
|
||||
|
||||
const sendMock = jest.fn()
|
||||
sendMock.mockReturnValue({ success: true })
|
||||
|
||||
communityAPI.send = sendMock
|
||||
sendMock.mockResolvedValue('success')
|
||||
|
||||
const localVue = global.localVue
|
||||
|
||||
@ -27,6 +22,9 @@ describe('AccountOverview', () => {
|
||||
},
|
||||
},
|
||||
$n: jest.fn((n) => String(n)),
|
||||
$apollo: {
|
||||
query: sendMock,
|
||||
},
|
||||
}
|
||||
|
||||
const Wrapper = () => {
|
||||
@ -92,11 +90,16 @@ describe('AccountOverview', () => {
|
||||
})
|
||||
|
||||
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',
|
||||
amount: 23.45,
|
||||
memo: 'Make the best of it!',
|
||||
})
|
||||
},
|
||||
}),
|
||||
)
|
||||
})
|
||||
|
||||
it('emits update-balance', () => {
|
||||
@ -112,7 +115,7 @@ describe('AccountOverview', () => {
|
||||
describe('transaction is confirmed and server response is error', () => {
|
||||
beforeEach(async () => {
|
||||
jest.clearAllMocks()
|
||||
sendMock.mockReturnValue({ success: false, result: { message: 'receiver not found' } })
|
||||
sendMock.mockRejectedValue({ message: 'receiver not found' })
|
||||
await wrapper
|
||||
.findComponent({ name: 'TransactionConfirmation' })
|
||||
.vm.$emit('send-transaction')
|
||||
|
||||
@ -51,7 +51,7 @@ import GddTransactionListFooter from './AccountOverview/GddTransactionListFooter
|
||||
import TransactionForm from './AccountOverview/GddSend/TransactionForm.vue'
|
||||
import TransactionConfirmation from './AccountOverview/GddSend/TransactionConfirmation.vue'
|
||||
import TransactionResult from './AccountOverview/GddSend/TransactionResult.vue'
|
||||
import communityAPI from '../../apis/communityAPI.js'
|
||||
import { sendCoins } from '../../graphql/queries.js'
|
||||
|
||||
const EMPTY_TRANSACTION_DATA = {
|
||||
email: '',
|
||||
@ -104,14 +104,22 @@ export default {
|
||||
},
|
||||
async sendTransaction() {
|
||||
this.loading = true
|
||||
const result = await communityAPI.send(this.$store.state.sessionId, this.transactionData)
|
||||
if (result.success) {
|
||||
this.$apollo
|
||||
.query({
|
||||
query: sendCoins,
|
||||
variables: {
|
||||
sessionId: this.$store.state.sessionId,
|
||||
...this.transactionData,
|
||||
},
|
||||
})
|
||||
.then(() => {
|
||||
this.error = false
|
||||
this.$emit('update-balance', this.transactionData.amount)
|
||||
} else {
|
||||
this.errorResult = result.result.message
|
||||
})
|
||||
.catch((err) => {
|
||||
this.errorResult = err.message
|
||||
this.error = true
|
||||
}
|
||||
})
|
||||
this.currentTransactionStep = 2
|
||||
this.loading = false
|
||||
},
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user