Merge branch 'dev' into 7306-warningCustomerUnpaid
gitea/salix-front/pipeline/pr-dev This commit looks good Details

This commit is contained in:
Carlos Satorres 2024-11-14 11:08:37 +00:00
commit 857136a866
6 changed files with 32 additions and 67 deletions

View File

@ -4,8 +4,9 @@ import { Router } from 'src/router';
import useNotify from 'src/composables/useNotify.js';
import { useStateQueryStore } from 'src/stores/useStateQueryStore';
let session, notify, stateQuery;
const session = useSession();
const { notify } = useNotify();
const stateQuery = useStateQueryStore();
const baseUrl = '/api/';
axios.defaults.baseURL = baseUrl;
@ -50,15 +51,9 @@ const onResponseError = (error) => {
return Promise.reject(error);
};
export function setupAxios() {
session = useSession();
notify = useNotify().notify;
stateQuery = useStateQueryStore();
axios.interceptors.request.use(onRequest, onRequestError);
axios.interceptors.response.use(onResponse, onResponseError);
axiosNoError.interceptors.request.use(onRequest);
axiosNoError.interceptors.response.use(onResponse);
}
axios.interceptors.request.use(onRequest, onRequestError);
axios.interceptors.response.use(onResponse, onResponseError);
axiosNoError.interceptors.request.use(onRequest);
axiosNoError.interceptors.response.use(onResponse);
export { onRequest, onResponseError, axiosNoError };

View File

@ -1,7 +1,6 @@
import { boot } from 'quasar/wrappers';
import qFormMixin from './qformMixin';
import keyShortcut from './keyShortcut';
import { setupAxios } from 'src/boot/axios';
import useNotify from 'src/composables/useNotify.js';
import { CanceledError } from 'axios';
@ -49,5 +48,4 @@ export default boot(({ app }) => {
notify(message ?? 'globals.error', 'negative', 'error');
};
setupAxios();
});

View File

@ -17,19 +17,12 @@ const config = reactive({
const type = Object.keys(config).find((key) => key in useAttrs()) || 'sip';
onBeforeMount(async () => {
let url;
let { channel } = config[type];
if (type === 'say-simple') {
url = (await axios.get('SaySimpleConfigs/findOne')).data.url;
if (!channel)
channel = (
await axios.get('SaySimpleCountries/findOne', {
params: {
filter: { fields: ['channel'], where: { countryFk: 0 } },
},
})
).data?.channel;
const { url, defaultChannel } = (await axios.get('SaySimpleConfigs/findOne'))
.data;
if (!channel) channel = defaultChannel;
config[
type

View File

@ -8,13 +8,9 @@ import useNotify from './useNotify';
import { useTokenConfig } from './useTokenConfig';
const TOKEN_MULTIMEDIA = 'tokenMultimedia';
const TOKEN = 'token';
let router;
export default {
setup() {
router = useRouter();
},
};
export function useSession() {
const router = useRouter();
const { notify } = useNotify();
let isCheckingToken = false;
let intervalId = null;

View File

@ -14,8 +14,8 @@ import { useUserConfig } from 'src/composables/useUserConfig';
import { useTokenConfig } from 'src/composables/useTokenConfig';
import { useAcl } from 'src/composables/useAcl';
let state, session;
const state = useState();
const session = useSession();
const { t, te } = i18n.global;
const createHistory = process.env.SERVER
@ -43,10 +43,8 @@ const Router = createRouter({
* with the Router instance.
*/
export { Router };
export default route((/* { store, ssrContext } */) => {
export default route(function (/* { store, ssrContext } */) {
Router.beforeEach(async (to, from, next) => {
state = useState();
session = useSession();
const { isLoggedIn } = session;
const outLayout = Router.options.routes[0].children.map((r) => r.name);
if (!isLoggedIn() && !outLayout.includes(to.name)) {

View File

@ -1,38 +1,23 @@
import { describe, it, expect, beforeEach, vi } from 'vitest';
import { setupAxios, onRequest, onResponseError } from 'src/boot/axios';
import { useSession } from 'src/composables/useSession';
import useNotify from 'src/composables/useNotify';
import { useStateQueryStore } from 'src/stores/useStateQueryStore';
import { Notify } from 'quasar';
import { onRequest, onResponseError } from 'src/boot/axios';
import { describe, expect, it, vi } from 'vitest';
vi.mock('src/composables/useSession');
vi.mock('src/composables/useNotify');
vi.mock('src/stores/useStateQueryStore');
vi.mock('src/composables/useSession', () => ({
useSession: () => ({
getToken: () => 'DEFAULT_TOKEN',
isLoggedIn: () => vi.fn(),
destroy: () => vi.fn(),
}),
}));
vi.mock('src/stores/useStateQueryStore', () => ({
useStateQueryStore: () => ({
add: () => vi.fn(),
remove: () => vi.fn(),
}),
}));
describe('Axios boot', () => {
let sessionMock, notifyMock, stateQueryMock;
beforeEach(() => {
sessionMock = {
getToken: vi.fn().mockReturnValue('DEFAULT_TOKEN'),
isLoggedIn: vi.fn().mockReturnValue(true),
destroy: vi.fn(),
};
notifyMock = {
notify: vi.fn(),
};
stateQueryMock = {
add: vi.fn(),
remove: vi.fn(),
};
useSession.mockReturnValue(sessionMock);
useNotify.mockReturnValue(notifyMock);
useStateQueryStore.mockReturnValue(stateQueryMock);
setupAxios();
});
describe('onRequest()', async () => {
it('should set the "Authorization" property on the headers', async () => {
const config = { headers: {} };