cleanup tests

This commit is contained in:
2024-05-17 18:52:38 +02:00
parent 314380097a
commit 719dc60027
3 changed files with 34 additions and 33 deletions

View File

@@ -3,42 +3,42 @@ import { ref } from 'vue'
import { useSort } from './sort' import { useSort } from './sort'
describe('useSort', () => { describe('useSort', () => {
const array = ref([{ key1: 'b', key2: 'a' }, { key1: 'a', key2: 'b' }]) const array = ref([{ key1: 'b', key2: 'a' }, { key1: 'a', key2: 'b' }])
test('Returns expected properties with default options', () => { test('Returns expected properties with default options', () => {
const { sortedArray, headerProps, showColumn } = useSort(array) const { sortedArray, headerProps, showColumn } = useSort(array)
expect(sortedArray).toBeDefined() expect(sortedArray).toBeDefined()
expect(headerProps).toBeDefined() expect(headerProps).toBeDefined()
expect(showColumn).toBeDefined() expect(showColumn).toBeDefined()
}) })
test('Returns expected properties with custom options', () => { test('Returns expected properties with custom options', () => {
const { sortedArray, headerProps, showColumn } = useSort(array, { defaultSortKey: 'key1', defaultSortDirection: 'asc' }) const { sortedArray, headerProps, showColumn } = useSort(array, { defaultSortKey: 'key1', defaultSortDirection: 'asc' })
expect(sortedArray.value[0].key1).toBe('a') expect(sortedArray.value[0].key1).toBe('a')
expect(headerProps.value.currentSortKey).toBe('key1') expect(headerProps.value.currentSortKey).toBe('key1')
expect(headerProps.value.sortDirection).toBe('asc') expect(headerProps.value.sortDirection).toBe('asc')
expect(showColumn('key1')).toBe(true) expect(showColumn('key1')).toBe(true)
}) })
test('Sorts array in ascending order', () => { test('Sorts array in ascending order', () => {
const { sortedArray, headerProps } = useSort(array, { defaultSortKey: 'key1', defaultSortDirection: 'asc' }) const { sortedArray, headerProps } = useSort(array, { defaultSortKey: 'key1', defaultSortDirection: 'asc' })
headerProps.value.onSort('key1', 'asc') headerProps.value.onSort('key1', 'asc')
expect(sortedArray.value[0].key1).toBe('a') expect(sortedArray.value[0].key1).toBe('a')
}) })
test('Sorts array in descending order', () => { test('Sorts array in descending order', () => {
const { sortedArray, headerProps } = useSort(array, { defaultSortKey: 'key1', defaultSortDirection: 'desc' }) const { sortedArray, headerProps } = useSort(array, { defaultSortKey: 'key1', defaultSortDirection: 'desc' })
headerProps.value.onSort('key1', 'desc') headerProps.value.onSort('key1', 'desc')
expect(sortedArray.value[0].key1).toBe('b') expect(sortedArray.value[0].key1).toBe('b')
}) })
test('Hides ignored columns', () => { test('Hides ignored columns', () => {
const { showColumn } = useSort(array, { ignoredColums: ['key1'] }) const { showColumn } = useSort(array, { ignoredColums: ['key1'] })
expect(showColumn('key1')).toBe(false) expect(showColumn('key1')).toBe(false)
}) })
}) })

View File

@@ -1,7 +1,7 @@
import { useAuthStore } from "@/auth"; import { useAuthStore } from "@/auth";
import { marbasAxiosInstance } from "@/service"; import { marbasAxiosInstance } from "@/service";
import { defineStore } from "pinia"; import { defineStore } from "pinia";
import { computed, onMounted, ref } from "vue"; import { computed, ref } from "vue";
export type AcquiredMarketItem = { export type AcquiredMarketItem = {
id: number; id: number;
@@ -60,9 +60,7 @@ export const useAcquiredItemStore = defineStore('market-acquisition', () => {
await marbasAxiosInstance.put(`${endpoint}/${item.id}`, item); await marbasAxiosInstance.put(`${endpoint}/${item.id}`, item);
}; };
onMounted(async () => { marbasAxiosInstance.get<AcquiredMarketItem[]>(endpoint).then(res => acquiredItems.value = res.data.filter(item => item.remaining > 0));
acquiredItems.value = (await marbasAxiosInstance.get<AcquiredMarketItem[]>(endpoint)).data.filter(item => item.remaining > 0);
});
return { items, addAcquiredItem, removeAcquiredItem }; return { items, addAcquiredItem, removeAcquiredItem };
}); });

View File

@@ -8,7 +8,10 @@ export const logResource = (a: AxiosInstance) => {
log.debug(`[${r.config.method?.toUpperCase()}] ${r.config.url}`); log.debug(`[${r.config.method?.toUpperCase()}] ${r.config.url}`);
return r; return r;
}, e => { }, e => {
log.error(`[${e.config.method?.toUpperCase()}] ${e.config.url} failed with ${e.response?.status} ${e.response?.statusText}`); if (e instanceof Error) {
log.error(e.message);
}
log.error(`[${e.config?.method?.toUpperCase()}] ${e.config?.url} failed with ${e.response?.status} ${e.response?.statusText}`);
return Promise.reject(e); return Promise.reject(e);
}); });
} }