diff --git a/.github/workflows/check-source-code.yml b/.github/workflows/check-source-code.yml index 53baa1aa..94da87fc 100644 --- a/.github/workflows/check-source-code.yml +++ b/.github/workflows/check-source-code.yml @@ -64,10 +64,10 @@ jobs: - name: Build source code run: npm run build - integration-tests: - name: Integration testing - needs: prepare-dependencies - runs-on: ubuntu-latest + # integration-tests: + # name: Integration testing + # needs: prepare-dependencies + # runs-on: ubuntu-latest # Disabled for now because when running in parallel, GitHub setups different # machines with different chrome-browsers installed. That causes Cypress errors # When trying to run in the cypress Docker container, there's no access to "sudo" @@ -87,35 +87,35 @@ jobs: # # see browsers tags here: https://hub.docker.com/r/cypress/browsers/tags # image: cypress/browsers:node-20.9.0-chrome-118.0.5993.88-1-ff-118.0.2-edge-118.0.2088.46-1 # options: --user 1001 - steps: - - name: Checkout repository and submodules - uses: actions/checkout@v2 - with: - submodules: recursive - token: ${{ secrets.REPOSITORIES_ACCESS_TOKEN }} - - uses: ./.github/actions/prepare-local-env - - name: Run Cypress e2e tests - uses: cypress-io/github-action@v6 - with: - start: npm run dev - wait-on: http://budget-tracker.com:8100 - install: false - config-file: cypress.config.ts - browser: chrome - quiet: true - record: true - # parallel: true - group: Cypress tests - env: - CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }} - # Recommended: pass the GitHub token lets this action correctly - # determine the unique run id necessary to re-run the checks - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - BASE_URL: http://budget-tracker.com:8100 - PORT: 8100 - HOST: budget-tracker.com - VITE_APP_API_HTTP: https://${{ secrets.API_HOST_PROD }} - VITE_APP_API_VER: ${{ secrets.VUE_APP_API_VER }} + # steps: + # - name: Checkout repository and submodules + # uses: actions/checkout@v2 + # with: + # submodules: recursive + # token: ${{ secrets.REPOSITORIES_ACCESS_TOKEN }} + # - uses: ./.github/actions/prepare-local-env + # - name: Run Cypress e2e tests + # uses: cypress-io/github-action@v6 + # with: + # start: npm run dev + # wait-on: http://budget-tracker.com:8100 + # install: false + # config-file: cypress.config.ts + # browser: chrome + # quiet: true + # record: true + # # parallel: true + # group: Cypress tests + # env: + # CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }} + # # Recommended: pass the GitHub token lets this action correctly + # # determine the unique run id necessary to re-run the checks + # GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + # BASE_URL: http://budget-tracker.com:8100 + # PORT: 8100 + # HOST: budget-tracker.com + # VITE_APP_API_HTTP: https://${{ secrets.API_HOST_PROD }} + # VITE_APP_API_VER: ${{ secrets.VUE_APP_API_VER }} docker-build: name: Build source code using Docker diff --git a/package-lock.json b/package-lock.json index 87f37331..97bf574c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -40,7 +40,7 @@ "@vue/eslint-config-typescript": "^12.0.0", "@vue/test-utils": "^2.4.2", "css-loader": "^6.8.1", - "cypress": "^13.5.1", + "cypress": "^13.6.2", "dotenv": "^16.3.1", "eslint": "^8.54.0", "eslint-friendly-formatter": "^4.0.1", @@ -8197,9 +8197,9 @@ "integrity": "sha512-I7K1Uu0MBPzaFKg4nI5Q7Vs2t+3gWWW648spaF+Rg7pI9ds18Ugn+lvg4SHczUdKlHI5LWBXyqfS8+DufyBsgQ==" }, "node_modules/cypress": { - "version": "13.5.1", - "resolved": "https://registry.npmjs.org/cypress/-/cypress-13.5.1.tgz", - "integrity": "sha512-yqLViT0D/lPI8Kkm7ciF/x/DCK/H/DnogdGyiTnQgX4OVR2aM30PtK+kvklTOD1u3TuItiD9wUQAF8EYWtyZug==", + "version": "13.6.2", + "resolved": "https://registry.npmjs.org/cypress/-/cypress-13.6.2.tgz", + "integrity": "sha512-TW3bGdPU4BrfvMQYv1z3oMqj71YI4AlgJgnrycicmPZAXtvywVFZW9DAToshO65D97rCWfG/kqMFsYB6Kp91gQ==", "dev": true, "hasInstallScript": true, "dependencies": { diff --git a/package.json b/package.json index e6566595..9658c1e0 100644 --- a/package.json +++ b/package.json @@ -57,7 +57,7 @@ "@vue/eslint-config-typescript": "^12.0.0", "@vue/test-utils": "^2.4.2", "css-loader": "^6.8.1", - "cypress": "^13.5.1", + "cypress": "^13.6.2", "dotenv": "^16.3.1", "eslint": "^8.54.0", "eslint-friendly-formatter": "^4.0.1", diff --git a/src/api/_api.ts b/src/api/_api.ts index ee7c298e..c9ec948a 100644 --- a/src/api/_api.ts +++ b/src/api/_api.ts @@ -1,4 +1,6 @@ import { API_ERROR_CODES, API_RESPONSE_STATUS } from 'shared-types'; +import { useAuthStore } from '@/stores'; +import { router } from '@/routes'; import { ApiBaseError } from '@/common/types'; import { useNotificationCenter, @@ -40,8 +42,6 @@ console.log('API_HTTP', API_HTTP); // eslint-disable-next-line no-console console.log('API_VER', API_VER); class ApiCaller { - logout: () => void; - authToken: string | null; _baseURL: string; @@ -183,15 +183,15 @@ class ApiCaller { }); throw new errors.NetworkError('Failed to fetch data from the server.'); - } else { - addNotification({ - id: 'unexpected-api-error', - text: 'Unexpected error.', - type: NotificationType.error, - }); - - throw new errors.UnexpectedError('Unexpected error.', {}); } + + addNotification({ + id: 'unexpected-api-error', + text: 'Unexpected error.', + type: NotificationType.error, + }); + + throw new errors.UnexpectedError('Unexpected error.', {}); } const { status, response }: { @@ -205,7 +205,8 @@ class ApiCaller { if (status === API_RESPONSE_STATUS.error) { if (response.code === API_ERROR_CODES.unauthorized) { - await this.logout(); + useAuthStore().logout(); + router.push('/'); addNotification({ id: 'authorization-error', @@ -235,17 +236,6 @@ class ApiCaller { return undefined; } - - setRequiredActions({ logout }) { - this.logout = logout; - } } export const api = new ApiCaller(); - -export function initApiCaller( - { logout }: - { logout: () => void }, -): void { - api.setRequiredActions({ logout }); -} diff --git a/src/main.ts b/src/main.ts index faffb38f..60822b75 100644 --- a/src/main.ts +++ b/src/main.ts @@ -2,9 +2,7 @@ import { createApp } from 'vue'; import { VueQueryPlugin } from '@tanstack/vue-query'; import { router } from '@/routes'; import { clickOutside, nodeResizeObserver } from '@/directives'; -import { initApiCaller } from '@/api'; import { store } from '@/stores/setup'; -import { useAuthStore } from '@/stores'; import { identifyCurrentTheme } from '@/common/utils'; import App from './app.vue'; import '@/styles/index.scss'; @@ -23,7 +21,3 @@ app.use(store); app.use(VueQueryPlugin); app.mount('#app'); - -initApiCaller({ - logout: useAuthStore().logout, -}); diff --git a/src/stores/categories/categories.ts b/src/stores/categories/categories.ts index ab8c797d..6b822411 100644 --- a/src/stores/categories/categories.ts +++ b/src/stores/categories/categories.ts @@ -4,6 +4,7 @@ import { CategoryModel } from 'shared-types'; import { loadSystemCategories } from '@/api'; import { type FormattedCategory } from '@/common/types'; import { useNotificationCenter } from '@/components/notification-center'; +import * as errors from '@/js/errors'; import { buildCategiesObjectGraph } from './helpers'; export const useCategoriesStore = defineStore('categories', () => { @@ -17,7 +18,9 @@ export const useCategoriesStore = defineStore('categories', () => { if (result?.length) categories.value = result; } catch (err) { - notificationStore.addErrorNotification('Cannot load categories'); + if (!(err instanceof errors.AuthError)) { + notificationStore.addErrorNotification('Cannot load categories'); + } } };