Guard baseResponse.data access when baseLogId is falsy in getAllTrace
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -165,8 +165,10 @@ export default defineStore('allMapDataStore', {
|
|||||||
let baseResponse;
|
let baseResponse;
|
||||||
const response = await this.$axios.get(api);
|
const response = await this.$axios.get(api);
|
||||||
this.allTrace = response.data;
|
this.allTrace = response.data;
|
||||||
if(baseLogId) baseResponse = await this.$axios.get(baseApi);
|
if(baseLogId) {
|
||||||
this.allBaseTrace = baseResponse.data;
|
baseResponse = await this.$axios.get(baseApi);
|
||||||
|
this.allBaseTrace = baseResponse.data;
|
||||||
|
}
|
||||||
} catch(error) {
|
} catch(error) {
|
||||||
apiError(error, 'Failed to load the Trace.');
|
apiError(error, 'Failed to load the Trace.');
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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', () => {
|
describe('getters', () => {
|
||||||
it('traces getter sorts by id', () => {
|
it('traces getter sorts by id', () => {
|
||||||
store.allTrace = [
|
store.allTrace = [
|
||||||
|
|||||||
Reference in New Issue
Block a user