Made the community resolver work again & changes in frontend merged with 803-community-selection-page-of-registration-process

This commit is contained in:
elweyn 2021-10-05 10:13:28 +02:00
parent 5462e8b606
commit 06b7778f11
6 changed files with 53 additions and 23 deletions

View File

@ -1,7 +0,0 @@
{
"community": [
{"id": 1, "name": "Gradido Entwicklung", "url": "http://localhost:3000/vue/", "description":"Die lokale Entwicklungsumgebung von Gradido.", "registerUrl": "http://localhost:3000/vue/register"},
{"id": 2, "name": "Gradido Staging", "url": "https://stage1.gradido.net/vue/", "description":"Der Testserver der Gradido Akademie.", "registerUrl": "https://stage1.gradido.net/vue/register"},
{"id": 3, "name": "Gradido-Akademie", "url": "https://gdd1.gradido.com/vue/", "description":"Freies Institut für Wirtschaftsbionik.", "registerUrl": "https://gdd1.gradido.com/vue/register"}
]
}

View File

@ -106,13 +106,13 @@ export const checkEmailQuery = gql`
}
`
export const serverInformation = gql`
export const communityInfo = gql`
query {
serverInformation {
community {
name
description
}
getCommunityInfo {
name
description
registerUrl
url
}
}
`

View File

@ -43,7 +43,6 @@ export const actions = {
commit('lastName', data.lastName)
commit('description', data.description)
commit('newsletterState', data.klickTipp.newsletterState)
commit('community', data.community)
},
logout: ({ commit, state }) => {
commit('token', null)
@ -53,7 +52,6 @@ export const actions = {
commit('lastName', '')
commit('description', '')
commit('newsletterState', null)
commit('community', null)
localStorage.clear()
},
}

View File

@ -4,14 +4,20 @@ import Login from './Login'
const localVue = global.localVue
const loginQueryMock = jest.fn().mockResolvedValue({
const apolloQueryMock = jest.fn().mockResolvedValue({
data: {
login: 'token',
getCommunityInfo: {
name: 'test12',
description: 'test community 12',
url: 'http://test12.test12/',
registerUrl: 'http://test12.test12/vue/register',
},
},
})
const toastErrorMock = jest.fn()
const mockStoreDispach = jest.fn()
const mockStoreCommit = jest.fn()
const mockRouterPush = jest.fn()
const spinnerHideMock = jest.fn()
const spinnerMock = jest.fn(() => {
@ -30,6 +36,7 @@ describe('Login', () => {
$t: jest.fn((t) => t),
$store: {
dispatch: mockStoreDispach,
commit: mockStoreCommit,
state: {
community: {
name: 'Gradido Entwicklung',
@ -49,7 +56,7 @@ describe('Login', () => {
error: toastErrorMock,
},
$apollo: {
query: loginQueryMock,
query: apolloQueryMock,
},
}
@ -70,6 +77,15 @@ describe('Login', () => {
expect(wrapper.find('div.login-form').exists()).toBeTruthy()
})
it('calls the communityInfo', () => {
expect(mockStoreCommit).toBeCalledWith('community', {
name: 'test12',
description: 'test community 12',
url: 'http://test12.test12/',
registerUrl: 'http://test12.test12/vue/register',
})
})
describe('Login header', () => {
it('has a welcome message', () => {
expect(wrapper.find('div.header').text()).toBe('Gradido site.login.community')
@ -157,10 +173,15 @@ describe('Login', () => {
await flushPromises()
await wrapper.find('form').trigger('submit')
await flushPromises()
apolloQueryMock.mockResolvedValue({
data: {
login: 'token',
},
})
})
it('calls the API with the given data', () => {
expect(loginQueryMock).toBeCalledWith(
expect(apolloQueryMock).toBeCalledWith(
expect.objectContaining({
variables: {
email: 'user@example.org',
@ -190,7 +211,7 @@ describe('Login', () => {
describe('login fails', () => {
beforeEach(() => {
loginQueryMock.mockRejectedValue({
apolloQueryMock.mockRejectedValue({
message: 'Ouch!',
})
})

View File

@ -67,7 +67,7 @@
import CONFIG from '../../config'
import InputPassword from '../../components/Inputs/InputPassword'
import InputEmail from '../../components/Inputs/InputEmail'
import { login } from '../../graphql/queries'
import { login, communityInfo } from '../../graphql/queries'
export default {
name: 'login',
@ -112,6 +112,21 @@ export default {
this.$toasted.error(this.$t('error.no-account'))
})
},
async onCreated() {
this.$apollo
.query({
query: communityInfo,
})
.then((result) => {
this.$store.commit('community', result.data.getCommunityInfo)
})
.catch((error) => {
this.$toasted.error(error)
})
},
},
created() {
this.onCreated()
},
}
</script>

View File

@ -37,7 +37,7 @@
</small>
</b>
<br />
<b-button variant="outline-secondary" :href="community.url">
<b-button variant="outline-secondary" :href="community.registerUrl">
{{ $t('community.switch-to-this-community') }}
</b-button>
</b-card>
@ -51,7 +51,7 @@
</div>
</template>
<script>
import communities from '../../graphql/queries'
import { communities } from '../../graphql/queries'
export default {
name: 'registerSelectCommunity',
@ -69,11 +69,14 @@ export default {
this.$apollo
.query({
query: communities,
fetchPolicy: 'network-only',
})
.then((response) => {
console.log('got communities:', response.data.communities)
this.communities = response.data.communities
})
.catch((error) => {
console.log('Huston got a problem', error.message)
this.$toasted.error(error.message)
})
loader.hide()