diff --git a/frontend/src/graphql/queries.js b/frontend/src/graphql/queries.js index a941ed61e..632a63bf3 100644 --- a/frontend/src/graphql/queries.js +++ b/frontend/src/graphql/queries.js @@ -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) + } +` diff --git a/frontend/src/views/Layout/DashboardLayout_gdd.spec.js b/frontend/src/views/Layout/DashboardLayout_gdd.spec.js index 6e19b28a2..bfa11d9ec 100644 --- a/frontend/src/views/Layout/DashboardLayout_gdd.spec.js +++ b/frontend/src/views/Layout/DashboardLayout_gdd.spec.js @@ -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', () => { diff --git a/frontend/src/views/Layout/DashboardLayout_gdd.vue b/frontend/src/views/Layout/DashboardLayout_gdd.vue index dc4b60991..8c272cb0d 100755 --- a/frontend/src/views/Layout/DashboardLayout_gdd.vue +++ b/frontend/src/views/Layout/DashboardLayout_gdd.vue @@ -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 { diff --git a/frontend/src/views/Pages/AccountOverview.spec.js b/frontend/src/views/Pages/AccountOverview.spec.js index 8d47cdb27..b890f1471 100644 --- a/frontend/src/views/Pages/AccountOverview.spec.js +++ b/frontend/src/views/Pages/AccountOverview.spec.js @@ -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, { - email: 'user@example.org', - amount: 23.45, - memo: 'Make the best of it!', - }) + 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') diff --git a/frontend/src/views/Pages/AccountOverview.vue b/frontend/src/views/Pages/AccountOverview.vue index 54bcf2bdd..6574fb6aa 100644 --- a/frontend/src/views/Pages/AccountOverview.vue +++ b/frontend/src/views/Pages/AccountOverview.vue @@ -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.error = false - this.$emit('update-balance', this.transactionData.amount) - } else { - this.errorResult = result.result.message - this.error = true - } + this.$apollo + .query({ + query: sendCoins, + variables: { + sessionId: this.$store.state.sessionId, + ...this.transactionData, + }, + }) + .then(() => { + this.error = false + this.$emit('update-balance', this.transactionData.amount) + }) + .catch((err) => { + this.errorResult = err.message + this.error = true + }) this.currentTransactionStep = 2 this.loading = false },