mirror of
https://github.com/IT4Change/gradido.git
synced 2026-01-20 20:01:31 +00:00
Merge changes to deletePendingCreation branch.
This commit is contained in:
commit
e84f30c1fc
@ -241,7 +241,7 @@ export default {
|
||||
.then((result) => {
|
||||
this.$emit('update-user-data', this.item, result.data.createPendingCreation)
|
||||
this.$toasted.success(
|
||||
`Offene schöpfung (${this.value} GDD) für ${this.item.email} wurde gespeichert, liegen zur bestätigung bereit`,
|
||||
`Offene Schöpfung (${this.value} GDD) für ${this.item.email} wurde gespeichert und liegen zur Bestätigung bereit`,
|
||||
)
|
||||
this.$store.commit('openCreationsPlus', 1)
|
||||
this.submitObj = null
|
||||
|
||||
@ -3,14 +3,6 @@ import EditCreationFormular from './EditCreationFormular.vue'
|
||||
|
||||
const localVue = global.localVue
|
||||
|
||||
const apolloMock = jest.fn().mockResolvedValue({
|
||||
data: {
|
||||
verifyLogin: {
|
||||
name: 'success',
|
||||
id: 0,
|
||||
},
|
||||
},
|
||||
})
|
||||
const apolloMutateMock = jest.fn().mockResolvedValue({
|
||||
data: {
|
||||
updatePendingCreation: {
|
||||
@ -21,6 +13,7 @@ const apolloMutateMock = jest.fn().mockResolvedValue({
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
const stateCommitMock = jest.fn()
|
||||
|
||||
const mocks = {
|
||||
@ -35,7 +28,6 @@ const mocks = {
|
||||
}
|
||||
}),
|
||||
$apollo: {
|
||||
query: apolloMock,
|
||||
mutate: apolloMutateMock,
|
||||
},
|
||||
$store: {
|
||||
@ -71,23 +63,6 @@ describe('EditCreationFormular', () => {
|
||||
expect(wrapper.find('.component-edit-creation-formular').exists()).toBeTruthy()
|
||||
})
|
||||
|
||||
describe('server sends back moderator data', () => {
|
||||
it('called store commit with mocked data', () => {
|
||||
expect(stateCommitMock).toBeCalledWith('moderator', { name: 'success', id: 0 })
|
||||
})
|
||||
})
|
||||
|
||||
describe('server throws error for moderator data call', () => {
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks()
|
||||
apolloMock.mockRejectedValue({ message: 'Ouch!' })
|
||||
wrapper = Wrapper()
|
||||
})
|
||||
it('has called store commit with fake data', () => {
|
||||
expect(stateCommitMock).toBeCalledWith('moderator', { id: 0, name: 'Test Moderator' })
|
||||
})
|
||||
})
|
||||
|
||||
describe('radio buttons to selcet month', () => {
|
||||
it('has three radio buttons', () => {
|
||||
expect(wrapper.findAll('input[type="radio"]').length).toBe(3)
|
||||
|
||||
@ -124,7 +124,6 @@
|
||||
</template>
|
||||
<script>
|
||||
import { updatePendingCreation } from '../graphql/updatePendingCreation'
|
||||
import { verifyLogin } from '../graphql/verifyLogin'
|
||||
export default {
|
||||
name: 'EditCreationFormular',
|
||||
props: {
|
||||
@ -246,19 +245,8 @@ export default {
|
||||
this.value = 0
|
||||
})
|
||||
},
|
||||
searchModeratorData() {
|
||||
this.$apollo
|
||||
.query({ query: verifyLogin })
|
||||
.then((result) => {
|
||||
this.$store.commit('moderator', result.data.verifyLogin)
|
||||
})
|
||||
.catch(() => {
|
||||
this.$store.commit('moderator', { id: 0, name: 'Test Moderator' })
|
||||
})
|
||||
},
|
||||
},
|
||||
created() {
|
||||
this.searchModeratorData()
|
||||
if (this.pagetype === 'PageCreationConfirm' && this.creationUserData.date) {
|
||||
switch (this.$moment(this.creationUserData.date).format('MMMM')) {
|
||||
case this.currentMonth.short:
|
||||
|
||||
7
admin/src/graphql/deletePendingCreation.js
Normal file
7
admin/src/graphql/deletePendingCreation.js
Normal file
@ -0,0 +1,7 @@
|
||||
import gql from 'graphql-tag'
|
||||
|
||||
export const deletePendingCreation = gql`
|
||||
mutation ($id: Float!) {
|
||||
deletePendingCreation(id: $id)
|
||||
}
|
||||
`
|
||||
@ -4,19 +4,20 @@ import CONFIG from './config'
|
||||
|
||||
import Vue from 'vue'
|
||||
import VueApollo from 'vue-apollo'
|
||||
import Vuex from 'vuex'
|
||||
import VueI18n from 'vue-i18n'
|
||||
import i18n from './i18n'
|
||||
import { BootstrapVue, IconsPlugin } from 'bootstrap-vue'
|
||||
import moment from 'vue-moment'
|
||||
import store from './store/store'
|
||||
import router from './router/router'
|
||||
|
||||
jest.mock('vue')
|
||||
jest.mock('vue-apollo')
|
||||
jest.mock('vuex')
|
||||
jest.mock('vue-i18n')
|
||||
jest.mock('vue-moment')
|
||||
|
||||
const storeMock = jest.fn()
|
||||
Vuex.Store = storeMock
|
||||
jest.mock('./store/store')
|
||||
jest.mock('./i18n')
|
||||
jest.mock('./router/router')
|
||||
|
||||
jest.mock('apollo-boost', () => {
|
||||
return {
|
||||
@ -65,8 +66,12 @@ describe('main', () => {
|
||||
expect(Vue).toBeCalled()
|
||||
})
|
||||
|
||||
it('calls VueI18n', () => {
|
||||
expect(VueI18n).toBeCalled()
|
||||
it('calls i18n', () => {
|
||||
expect(Vue).toBeCalledWith(
|
||||
expect.objectContaining({
|
||||
i18n,
|
||||
}),
|
||||
)
|
||||
})
|
||||
|
||||
it('calls BootstrapVue', () => {
|
||||
@ -81,7 +86,92 @@ describe('main', () => {
|
||||
expect(Vue.use).toBeCalledWith(moment)
|
||||
})
|
||||
|
||||
it.skip('creates a store', () => {
|
||||
expect(storeMock).toBeCalled()
|
||||
it('creates a store', () => {
|
||||
expect(Vue).toBeCalledWith(
|
||||
expect.objectContaining({
|
||||
store,
|
||||
}),
|
||||
)
|
||||
})
|
||||
|
||||
it('creates a router', () => {
|
||||
expect(Vue).toBeCalledWith(
|
||||
expect.objectContaining({
|
||||
router,
|
||||
}),
|
||||
)
|
||||
})
|
||||
|
||||
describe('ApolloLink', () => {
|
||||
// mock store
|
||||
const storeDispatchMock = jest.fn()
|
||||
store.state = {
|
||||
token: 'some-token',
|
||||
}
|
||||
store.dispatch = storeDispatchMock
|
||||
|
||||
// mock i18n.t
|
||||
i18n.t = jest.fn((t) => t)
|
||||
|
||||
// mock apllo response
|
||||
const responseMock = {
|
||||
errors: [{ message: '403.13 - Client certificate revoked' }],
|
||||
}
|
||||
|
||||
// mock router
|
||||
const routerPushMock = jest.fn()
|
||||
router.push = routerPushMock
|
||||
router.currentRoute = {
|
||||
path: '/overview',
|
||||
}
|
||||
|
||||
// mock context
|
||||
const setContextMock = jest.fn()
|
||||
const getContextMock = jest.fn(() => {
|
||||
return {
|
||||
response: {
|
||||
headers: {
|
||||
get: jest.fn(),
|
||||
},
|
||||
},
|
||||
}
|
||||
})
|
||||
|
||||
// mock apollo link function params
|
||||
const operationMock = {
|
||||
setContext: setContextMock,
|
||||
getContext: getContextMock,
|
||||
}
|
||||
|
||||
const forwardMock = jest.fn(() => {
|
||||
return [responseMock]
|
||||
})
|
||||
|
||||
// get apollo link callback
|
||||
const middleware = ApolloLink.mock.calls[0][0]
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks()
|
||||
// run the callback with mocked params
|
||||
middleware(operationMock, forwardMock)
|
||||
})
|
||||
|
||||
it('sets authorization header', () => {
|
||||
expect(setContextMock).toBeCalledWith({
|
||||
headers: {
|
||||
Authorization: 'Bearer some-token',
|
||||
},
|
||||
})
|
||||
})
|
||||
|
||||
describe('apollo response is 403.13', () => {
|
||||
it.skip('dispatches logout', () => {
|
||||
expect(storeDispatchMock).toBeCalledWith('logout', null)
|
||||
})
|
||||
|
||||
it.skip('redirects to logout', () => {
|
||||
expect(routerPushMock).toBeCalledWith('/logout')
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@ -12,6 +12,7 @@
|
||||
<script>
|
||||
import UserTable from '../components/UserTable.vue'
|
||||
import { getPendingCreations } from '../graphql/getPendingCreations'
|
||||
import { deletePendingCreation } from '../graphql/deletePendingCreation'
|
||||
|
||||
export default {
|
||||
name: 'CreationConfirm',
|
||||
@ -57,11 +58,23 @@ export default {
|
||||
|
||||
findArr = this.confirmResult.find((arr) => arr.id === e.id)
|
||||
|
||||
index = this.confirmResult.indexOf(findArr)
|
||||
|
||||
this.confirmResult.splice(index, 1)
|
||||
|
||||
this.$store.commit('openCreationsMinus', 1)
|
||||
// console.log('findArr', findArr)
|
||||
this.$apollo
|
||||
.mutate({
|
||||
mutation: deletePendingCreation,
|
||||
variables: {
|
||||
id: findArr.id,
|
||||
},
|
||||
})
|
||||
.then((result) => {
|
||||
index = this.confirmResult.indexOf(findArr)
|
||||
this.confirmResult.splice(index, 1)
|
||||
this.$store.commit('openCreationsMinus', 1)
|
||||
this.$toasted.success('Pending Creation has been deleted')
|
||||
})
|
||||
.catch((error) => {
|
||||
this.$toasted.error(error.message)
|
||||
})
|
||||
}
|
||||
},
|
||||
getPendingCreations() {
|
||||
|
||||
@ -5,31 +5,31 @@ const localVue = global.localVue
|
||||
|
||||
const apolloQueryMock = jest.fn().mockResolvedValue({
|
||||
data: {
|
||||
searchUsers: [
|
||||
getPendingCreations: [
|
||||
{
|
||||
firstName: 'Bibi',
|
||||
lastName: 'Bloxberg',
|
||||
email: 'bibi@bloxberg.de',
|
||||
creation: [200, 400, 600],
|
||||
pending: true,
|
||||
},
|
||||
{
|
||||
pending: true,
|
||||
},
|
||||
{
|
||||
pending: true,
|
||||
},
|
||||
],
|
||||
},
|
||||
})
|
||||
|
||||
const toastErrorMock = jest.fn()
|
||||
const storeCommitMock = jest.fn()
|
||||
|
||||
const mocks = {
|
||||
$store: {
|
||||
state: {
|
||||
openCreations: 0,
|
||||
},
|
||||
commit: jest.fn(),
|
||||
},
|
||||
$apollo: {
|
||||
query: apolloQueryMock,
|
||||
},
|
||||
$toasted: {
|
||||
error: toastErrorMock,
|
||||
$store: {
|
||||
commit: storeCommitMock,
|
||||
state: {
|
||||
openCreations: 2,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
@ -45,8 +45,30 @@ describe('Overview', () => {
|
||||
wrapper = Wrapper()
|
||||
})
|
||||
|
||||
it('has a DIV element with the class.admin-overview', () => {
|
||||
expect(wrapper.find('div.admin-overview').exists()).toBeTruthy()
|
||||
it('calls getPendingCreations', () => {
|
||||
expect(apolloQueryMock).toBeCalled()
|
||||
})
|
||||
|
||||
it('commts three pending creations to store', () => {
|
||||
expect(storeCommitMock).toBeCalledWith('setOpenCreations', 3)
|
||||
})
|
||||
|
||||
describe('with open creations', () => {
|
||||
it('renders a link to confirm creations', () => {
|
||||
expect(wrapper.find('a[href="creation-confirm"]').text()).toContain('2')
|
||||
expect(wrapper.find('a[href="creation-confirm"]').exists()).toBeTruthy()
|
||||
})
|
||||
})
|
||||
|
||||
describe('without open creations', () => {
|
||||
beforeEach(() => {
|
||||
mocks.$store.state.openCreations = 0
|
||||
})
|
||||
|
||||
it('renders a link to confirm creations', () => {
|
||||
expect(wrapper.find('a[href="creation-confirm"]').text()).toContain('0')
|
||||
expect(wrapper.find('a[href="creation-confirm"]').exists()).toBeTruthy()
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@ -138,9 +138,8 @@ export class AdminResolver {
|
||||
@Mutation(() => Boolean)
|
||||
async deletePendingCreation(@Arg('id') id: number): Promise<boolean> {
|
||||
const pendingCreationRepository = getCustomRepository(PendingCreationRepository)
|
||||
const entity = await pendingCreationRepository.findOne(id)
|
||||
if (!entity) throw new Error('Not pending creation with this id.')
|
||||
const res = await pendingCreationRepository.manager.remove(entity)
|
||||
const entity = await pendingCreationRepository.findOneOrFail(id)
|
||||
const res = await pendingCreationRepository.delete(entity)
|
||||
return !!res
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user