Bug: Add account scoping in CTA (#754)

This commit is contained in:
Pranav Raj S 2020-04-23 12:21:45 +05:30 committed by GitHub
parent 645d53db1c
commit 7d41b7a5dc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 56 additions and 10 deletions

View file

@ -40,10 +40,10 @@
<script>
import { mapGetters } from 'vuex';
import adminMixin from '../../../mixins/isAdmin';
import { frontendURL } from '../../../helper/URLHelper';
import accountMixin from '../../../mixins/account';
export default {
mixins: [adminMixin],
mixins: [accountMixin, adminMixin],
computed: {
...mapGetters({
@ -60,7 +60,7 @@ export default {
return this.$t('CONVERSATION.LOADING_CONVERSATIONS');
},
newInboxURL() {
return frontendURL('settings/inboxes/new');
return this.addAccountScoping('settings/inboxes/new');
},
},
};

View file

@ -0,0 +1,14 @@
import auth from '../api/auth';
export default {
computed: {
accountId() {
return auth.getCurrentUser().account_id;
},
},
methods: {
addAccountScoping(url) {
return `/app/accounts/${this.accountId}/${url}`;
},
},
};

View file

@ -0,0 +1,35 @@
import { createWrapper } from '@vue/test-utils';
import accountMixin from '../account';
import Vue from 'vue';
jest.mock('../../api/auth', () => ({
getCurrentUser: () => ({ account_id: 1 }),
}));
describe('accountMixin', () => {
test('set accountId properly', () => {
const Component = {
render() {},
title: 'TestComponent',
mixins: [accountMixin],
};
const Constructor = Vue.extend(Component);
const vm = new Constructor().$mount();
const wrapper = createWrapper(vm);
expect(wrapper.vm.accountId).toBe(1);
});
test('returns current url', () => {
const Component = {
render() {},
title: 'TestComponent',
mixins: [accountMixin],
};
const Constructor = Vue.extend(Component);
const vm = new Constructor().$mount();
const wrapper = createWrapper(vm);
expect(wrapper.vm.addAccountScoping('settings/inboxes/new')).toBe(
'/app/accounts/1/settings/inboxes/new'
);
});
});

View file

@ -7,7 +7,7 @@
{{ $t('INBOX_MGMT.LIST.404') }}
<router-link
v-if="isAdmin()"
:to="frontendURL('settings/inboxes/new')"
:to="addAccountScoping('settings/inboxes/new')"
>
{{ $t('SETTINGS.INBOXES.NEW_INBOX') }}
</router-link>
@ -51,9 +51,7 @@
<td>
<div class="button-wrapper">
<router-link
:to="
`/app/accounts/${accountId}/settings/inboxes/${item.id}`
"
:to="addAccountScoping(`settings/inboxes/${item.id}`)"
>
<woot-submit-button
v-if="isAdmin()"
@ -107,15 +105,15 @@ import { mapGetters } from 'vuex';
import Settings from './Settings';
import DeleteInbox from './DeleteInbox';
import adminMixin from '../../../../mixins/isAdmin';
import { frontendURL } from '../../../../helper/URLHelper';
import auth from '../../../../api/auth';
import accountMixin from '../../../../mixins/account';
export default {
components: {
Settings,
DeleteInbox,
},
mixins: [adminMixin],
mixins: [adminMixin, accountMixin],
data() {
return {
loading: {},
@ -184,7 +182,6 @@ export default {
this.showDeletePopup = false;
this.selectedInbox = {};
},
frontendURL,
},
};
</script>