Merge pull request #2025 from Human-Connection/fix_maintenance_dockerfile

fix: Don't attempt to save locale if not authenticated
This commit is contained in:
mattwr18 2019-10-24 14:22:08 +02:00 committed by GitHub
commit 6dfe0ce7af
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 70 additions and 14 deletions

View File

@ -1,5 +1,5 @@
FROM node:12.13.0-alpine as build
LABEL Description="Web Frontend of the Social Network Human-Connection.org" Vendor="Human-Connection gGmbH" Version="0.0.1" Maintainer="Human-Connection gGmbH (developer@human-connection.org)"
LABEL Description="Maintenance page of the Social Network Human-Connection.org" Vendor="Human-Connection gGmbH" Version="0.0.1" Maintainer="Human-Connection gGmbH (developer@human-connection.org)"
EXPOSE 3000
CMD ["yarn", "run", "start"]

View File

@ -2,26 +2,43 @@ import { mount, createLocalVue } from '@vue/test-utils'
import Styleguide from '@human-connection/styleguide'
import VTooltip from 'v-tooltip'
import LocaleSwitch from './LocaleSwitch.vue'
import Vuex from 'vuex'
const localVue = createLocalVue()
localVue.use(Styleguide)
localVue.use(VTooltip)
localVue.use(Vuex)
describe('LocaleSwitch.vue', () => {
let wrapper
let mocks
let computed
let deutschLanguageItem
let wrapper, mocks, computed, deutschLanguageItem, getters
beforeEach(() => {
mocks = {
$i18n: {
locale: () => 'de',
set: jest.fn(),
locale: () => 'en',
set: jest.fn(locale => locale),
},
$t: jest.fn(),
$toast: {
success: jest.fn(a => a),
error: jest.fn(a => a),
},
setPlaceholderText: jest.fn(),
$apollo: {
mutate: jest
.fn()
.mockResolvedValueOnce({
data: {
UpdateUser: {
locale: 'de',
},
},
})
.mockRejectedValueOnce({
message: 'Please log in!',
}),
},
}
computed = {
current: () => {
@ -40,12 +57,21 @@ describe('LocaleSwitch.vue', () => {
]
},
}
getters = {
'auth/user': () => {
return { id: 'u35' }
},
}
})
describe('mount', () => {
const Wrapper = () => {
return mount(LocaleSwitch, { mocks, localVue, computed })
const store = new Vuex.Store({
getters,
})
return mount(LocaleSwitch, { mocks, localVue, computed, store })
}
describe('with current user', () => {
beforeEach(() => {
wrapper = Wrapper()
wrapper.find('.locale-menu').trigger('click')
@ -53,8 +79,30 @@ describe('LocaleSwitch.vue', () => {
deutschLanguageItem.trigger('click')
})
it("changes a user's locale", () => {
it("sets a user's locale", () => {
expect(mocks.$i18n.set).toHaveBeenCalledTimes(1)
})
it("updates the user's locale in the database", () => {
expect(mocks.$apollo.mutate).toHaveBeenCalledTimes(1)
})
})
describe('no current user', () => {
beforeEach(() => {
getters = {
'auth/user': () => {
return null
},
}
wrapper = Wrapper()
wrapper.find('.locale-menu').trigger('click')
deutschLanguageItem = wrapper.findAll('li').at(1)
deutschLanguageItem.trigger('click')
})
it('does not send a UpdateUser mutation', () => {
expect(mocks.$apollo.mutate).not.toHaveBeenCalled()
})
})
})

View File

@ -33,12 +33,12 @@
</template>
<script>
import gql from 'graphql-tag'
import Dropdown from '~/components/Dropdown'
import find from 'lodash/find'
import orderBy from 'lodash/orderBy'
import locales from '~/locales'
import { mapGetters, mapMutations } from 'vuex'
import { localeMutation } from '~/graphql/User.js'
export default {
components: {
@ -84,9 +84,17 @@ export default {
setCurrentUser: 'auth/SET_USER',
}),
async updateUserLocale() {
if (!this.currentUser || !this.currentUser.id) return null
try {
await this.$apollo.mutate({
mutation: localeMutation(),
mutation: gql`
mutation($id: ID!, $locale: String) {
UpdateUser(id: $id, locale: $locale) {
id
locale
}
}
`,
variables: {
id: this.currentUser.id,
locale: this.$i18n.locale(),