From c7aa32ef6d6b9f3f8dcb39be9993036d9049a76a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BE=9D=E7=91=AA=E8=B2=93?= Date: Fri, 6 Mar 2026 08:14:07 +0800 Subject: [PATCH] Guard baseResponse.data access when baseLogId is falsy in getAllTrace Co-Authored-By: Claude Opus 4.6 --- src/stores/allMapData.js | 6 ++++-- tests/stores/allMapData.test.js | 14 ++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/stores/allMapData.js b/src/stores/allMapData.js index 27eb08f..673bfa8 100644 --- a/src/stores/allMapData.js +++ b/src/stores/allMapData.js @@ -165,8 +165,10 @@ export default defineStore('allMapDataStore', { let baseResponse; const response = await this.$axios.get(api); this.allTrace = response.data; - if(baseLogId) baseResponse = await this.$axios.get(baseApi); - this.allBaseTrace = baseResponse.data; + if(baseLogId) { + baseResponse = await this.$axios.get(baseApi); + this.allBaseTrace = baseResponse.data; + } } catch(error) { apiError(error, 'Failed to load the Trace.'); } diff --git a/tests/stores/allMapData.test.js b/tests/stores/allMapData.test.js index bc2c3de..300cc77 100644 --- a/tests/stores/allMapData.test.js +++ b/tests/stores/allMapData.test.js @@ -191,6 +191,20 @@ describe('allMapDataStore', () => { }); }); + describe('getAllTrace', () => { + it('does not crash when baseLogId is falsy', async () => { + store.logId = 1; + store.baseLogId = null; + mockAxios.get.mockResolvedValue({ data: [{ id: 1 }] }); + + await store.getAllTrace(); + + expect(store.allTrace).toEqual([{ id: 1 }]); + // allBaseTrace should not be set when baseLogId is falsy + expect(store.allBaseTrace).toEqual([]); + }); + }); + describe('getters', () => { it('traces getter sorts by id', () => { store.allTrace = [