mirror of
https://github.com/IT4Change/Ocelot-Social.git
synced 2025-12-13 07:45:56 +00:00
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:
commit
6dfe0ce7af
@ -1,5 +1,5 @@
|
|||||||
FROM node:12.13.0-alpine as build
|
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
|
EXPOSE 3000
|
||||||
CMD ["yarn", "run", "start"]
|
CMD ["yarn", "run", "start"]
|
||||||
|
|||||||
@ -2,26 +2,43 @@ import { mount, createLocalVue } from '@vue/test-utils'
|
|||||||
import Styleguide from '@human-connection/styleguide'
|
import Styleguide from '@human-connection/styleguide'
|
||||||
import VTooltip from 'v-tooltip'
|
import VTooltip from 'v-tooltip'
|
||||||
import LocaleSwitch from './LocaleSwitch.vue'
|
import LocaleSwitch from './LocaleSwitch.vue'
|
||||||
|
import Vuex from 'vuex'
|
||||||
|
|
||||||
const localVue = createLocalVue()
|
const localVue = createLocalVue()
|
||||||
|
|
||||||
localVue.use(Styleguide)
|
localVue.use(Styleguide)
|
||||||
localVue.use(VTooltip)
|
localVue.use(VTooltip)
|
||||||
|
localVue.use(Vuex)
|
||||||
|
|
||||||
describe('LocaleSwitch.vue', () => {
|
describe('LocaleSwitch.vue', () => {
|
||||||
let wrapper
|
let wrapper, mocks, computed, deutschLanguageItem, getters
|
||||||
let mocks
|
|
||||||
let computed
|
|
||||||
let deutschLanguageItem
|
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
mocks = {
|
mocks = {
|
||||||
$i18n: {
|
$i18n: {
|
||||||
locale: () => 'de',
|
locale: () => 'en',
|
||||||
set: jest.fn(),
|
set: jest.fn(locale => locale),
|
||||||
},
|
},
|
||||||
$t: jest.fn(),
|
$t: jest.fn(),
|
||||||
|
$toast: {
|
||||||
|
success: jest.fn(a => a),
|
||||||
|
error: jest.fn(a => a),
|
||||||
|
},
|
||||||
setPlaceholderText: jest.fn(),
|
setPlaceholderText: jest.fn(),
|
||||||
|
$apollo: {
|
||||||
|
mutate: jest
|
||||||
|
.fn()
|
||||||
|
.mockResolvedValueOnce({
|
||||||
|
data: {
|
||||||
|
UpdateUser: {
|
||||||
|
locale: 'de',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
.mockRejectedValueOnce({
|
||||||
|
message: 'Please log in!',
|
||||||
|
}),
|
||||||
|
},
|
||||||
}
|
}
|
||||||
computed = {
|
computed = {
|
||||||
current: () => {
|
current: () => {
|
||||||
@ -40,12 +57,21 @@ describe('LocaleSwitch.vue', () => {
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
getters = {
|
||||||
|
'auth/user': () => {
|
||||||
|
return { id: 'u35' }
|
||||||
|
},
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('mount', () => {
|
|
||||||
const Wrapper = () => {
|
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(() => {
|
beforeEach(() => {
|
||||||
wrapper = Wrapper()
|
wrapper = Wrapper()
|
||||||
wrapper.find('.locale-menu').trigger('click')
|
wrapper.find('.locale-menu').trigger('click')
|
||||||
@ -53,8 +79,30 @@ describe('LocaleSwitch.vue', () => {
|
|||||||
deutschLanguageItem.trigger('click')
|
deutschLanguageItem.trigger('click')
|
||||||
})
|
})
|
||||||
|
|
||||||
it("changes a user's locale", () => {
|
it("sets a user's locale", () => {
|
||||||
expect(mocks.$i18n.set).toHaveBeenCalledTimes(1)
|
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()
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@ -33,12 +33,12 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
import gql from 'graphql-tag'
|
||||||
import Dropdown from '~/components/Dropdown'
|
import Dropdown from '~/components/Dropdown'
|
||||||
import find from 'lodash/find'
|
import find from 'lodash/find'
|
||||||
import orderBy from 'lodash/orderBy'
|
import orderBy from 'lodash/orderBy'
|
||||||
import locales from '~/locales'
|
import locales from '~/locales'
|
||||||
import { mapGetters, mapMutations } from 'vuex'
|
import { mapGetters, mapMutations } from 'vuex'
|
||||||
import { localeMutation } from '~/graphql/User.js'
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
components: {
|
components: {
|
||||||
@ -84,9 +84,17 @@ export default {
|
|||||||
setCurrentUser: 'auth/SET_USER',
|
setCurrentUser: 'auth/SET_USER',
|
||||||
}),
|
}),
|
||||||
async updateUserLocale() {
|
async updateUserLocale() {
|
||||||
|
if (!this.currentUser || !this.currentUser.id) return null
|
||||||
try {
|
try {
|
||||||
await this.$apollo.mutate({
|
await this.$apollo.mutate({
|
||||||
mutation: localeMutation(),
|
mutation: gql`
|
||||||
|
mutation($id: ID!, $locale: String) {
|
||||||
|
UpdateUser(id: $id, locale: $locale) {
|
||||||
|
id
|
||||||
|
locale
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`,
|
||||||
variables: {
|
variables: {
|
||||||
id: this.currentUser.id,
|
id: this.currentUser.id,
|
||||||
locale: this.$i18n.locale(),
|
locale: this.$i18n.locale(),
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user