Fix design file metadata mapping in files store
Co-Authored-By: Codex <codex@openai.com>
This commit is contained in:
@@ -91,15 +91,16 @@ export const useFilesStore = defineStore('filesStore', {
|
|||||||
*/
|
*/
|
||||||
async fetchAllFiles() {
|
async fetchAllFiles() {
|
||||||
const api = '/api/files';
|
const api = '/api/files';
|
||||||
let icon = '';
|
|
||||||
let fileType = '';
|
|
||||||
let parentLog = '';
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await apiClient.get(api);
|
const response = await apiClient.get(api);
|
||||||
|
|
||||||
this.allEventFiles = response.data;
|
this.allEventFiles = response.data;
|
||||||
this.allEventFiles.forEach(o => {
|
this.allEventFiles.forEach(o => {
|
||||||
|
let icon = '';
|
||||||
|
let fileType = '';
|
||||||
|
let parentLog = o.name;
|
||||||
|
|
||||||
switch (o.type) {
|
switch (o.type) {
|
||||||
case 'log':
|
case 'log':
|
||||||
icon = 'work_history';
|
icon = 'work_history';
|
||||||
@@ -119,6 +120,8 @@ export const useFilesStore = defineStore('filesStore', {
|
|||||||
break;
|
break;
|
||||||
case 'design':
|
case 'design':
|
||||||
icon = 'shape_line';
|
icon = 'shape_line';
|
||||||
|
fileType = 'Design';
|
||||||
|
parentLog = o.name;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
o.icon = icon;
|
o.icon = icon;
|
||||||
|
|||||||
@@ -105,6 +105,33 @@ describe('filesStore', () => {
|
|||||||
mockGet.mockRejectedValue(new Error('Network error'));
|
mockGet.mockRejectedValue(new Error('Network error'));
|
||||||
await expect(store.fetchAllFiles()).resolves.toBeUndefined();
|
await expect(store.fetchAllFiles()).resolves.toBeUndefined();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('maps design files without leaking metadata from previous file items', async () => {
|
||||||
|
mockGet.mockResolvedValue({
|
||||||
|
data: [
|
||||||
|
{
|
||||||
|
type: 'log',
|
||||||
|
name: 'order-log',
|
||||||
|
owner: { name: 'Alice' },
|
||||||
|
updated_at: '2024-01-15T10:00:00Z',
|
||||||
|
accessed_at: null,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'design',
|
||||||
|
name: 'diagram-a',
|
||||||
|
owner: { name: 'Bob' },
|
||||||
|
updated_at: '2024-01-16T10:00:00Z',
|
||||||
|
accessed_at: null,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
await store.fetchAllFiles();
|
||||||
|
|
||||||
|
expect(store.allEventFiles[1].icon).toBe('shape_line');
|
||||||
|
expect(store.allEventFiles[1].fileType).toBe('Design');
|
||||||
|
expect(store.allEventFiles[1].parentLog).toBe('diagram-a');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('upload', () => {
|
describe('upload', () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user