Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MarvinOehlerkingCap committed Aug 2, 2024
1 parent ab93b58 commit 6ad3364
Show file tree
Hide file tree
Showing 29 changed files with 636 additions and 112 deletions.
6 changes: 5 additions & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,12 @@ const config = deepmerge(defaultPreset, {
"<rootDir>/src/layouts/**/*.{js,ts,vue}",
"<rootDir>/src/modules/**/*.{js,ts,vue}",
"<rootDir>/src/plugins/**/*.(js|ts)",
"<rootDir>/src/router/**/*.(js|ts)",
// "<rootDir>/src/router/guards/**/*.(js|ts)",
"<rootDir>/src/utils/**/*.(js|ts)",

// Exclude
"!<rootDir>/src/**/index.(js|ts)",
"!<rootDir>/src/plugins/vuetify.ts",
],
});

Expand Down
128 changes: 118 additions & 10 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"axios": "^1.7.2",
"dayjs": "^1.11.12",
"pinia": "^2.2.0",
"ts-node": "^10.9.2",
"universal-cookie": "^7.2.0",
"vue": "^3.4.34",
"vue-dompurify-html": "^5.1.0",
Expand Down Expand Up @@ -59,6 +60,7 @@
"sass-loader": "^13.3.3",
"ts-jest": "^27.1.5",
"typescript": "^4.9.5",
"vue-component-type-helpers": "^2.0.29",
"webpack-plugin-vuetify": "^2.0.1"
},
"engines": {
Expand Down
3 changes: 2 additions & 1 deletion src/locales/de.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export default {
test: "Transaltion test",
"error.generic": "Ein Fehler ist aufgetreten",
"error.load": "Fehler beim Laden der Daten.",
};
3 changes: 2 additions & 1 deletion src/locales/en.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export default {
test: "Transaltion test",
"error.generic": "An error has occurred",
"error.load": "Error while loading the data.",
};
3 changes: 2 additions & 1 deletion src/locales/es.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export default {
test: "Transaltion test",
"error.generic": "Se ha producido un error",
"error.load": "Error al cargar los datos.",
};
3 changes: 2 additions & 1 deletion src/locales/uk.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export default {
test: "Transaltion test",
"error.generic": "Виникла помилка",
"error.load": "Помилка під час завантаження даних.",
};
2 changes: 1 addition & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ app.use(VueDOMPurifyHTML, {
if (jwt) {
axios.defaults.headers.common["Authorization"] = "Bearer " + jwt;
try {
await useAuthStore().login(jwt);
await useAuthStore().login();
} catch (e) {
// eslint-disable-next-line no-console
console.error("### JWT invalid: ", e);
Expand Down
3 changes: 2 additions & 1 deletion src/modules/data/application-error/applicationError.store.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { defineStore } from "pinia";
import { Ref, ref } from "vue";
import { readonly, Ref, ref } from "vue";
import { ApplicationError } from "./applicationError";

export const useApplicationErrorStore = defineStore("applicationError", () => {
Expand All @@ -10,6 +10,7 @@ export const useApplicationErrorStore = defineStore("applicationError", () => {
};

return {
getError: readonly(error),
setError,
};
});
36 changes: 36 additions & 0 deletions src/modules/data/application-error/applicationError.store.unit.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { applicationErrorFactory } from "@@/tests/test-utils/factory";
import { createPinia, setActivePinia } from "pinia";
import { useApplicationErrorStore } from "./applicationError.store";

describe("EnvConfigStore", () => {
beforeEach(() => {
setActivePinia(createPinia());
});

afterEach(() => {
jest.clearAllMocks();
});

describe("setError", () => {
describe("when loading envs", () => {
const setup = () => {
const store = useApplicationErrorStore();

const error = applicationErrorFactory.build();

return {
store,
error,
};
};

it("should set the error", async () => {
const { store, error } = setup();

store.setError(error);

expect(store.getError).toEqual(error);
});
});
});
});
9 changes: 4 additions & 5 deletions src/modules/data/auth/auth.store.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,27 @@
import { MeApiFactory, MeApiInterface, MeResponse } from "@/serverApi/v3";
import { $axios } from "@/utils/api/api";
import { $axios } from "@/utils/api";
import { defineStore } from "pinia";
import { computed, ComputedRef, Ref, ref } from "vue";

export const useAuthStore = defineStore("auth", () => {
const me: Ref<MeResponse | null> = ref(null);
const accessToken: Ref<string | null> = ref(null);

const meApi = (): MeApiInterface => {
return MeApiFactory(undefined, "v3", $axios);
};

const login = async (jwt: string): Promise<void> => {
const login = async (): Promise<void> => {
const { data } = await meApi().meControllerMe();

me.value = data;
accessToken.value = jwt;
};

const isLoggedIn: ComputedRef<boolean> = computed(() => {
return true;
return me.value !== null;
});

return {
me,
login,
isLoggedIn,
};
Expand Down
Loading

0 comments on commit 6ad3364

Please sign in to comment.