Skip to content

Commit

Permalink
fix: Cannot read properties of undefined (reading 'some') (#7278)
Browse files Browse the repository at this point in the history
  • Loading branch information
pranavrajs committed Jun 9, 2023
1 parent 7fd220c commit c8fac08
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
9 changes: 4 additions & 5 deletions app/javascript/dashboard/store/modules/conversations/index.js
Expand Up @@ -58,11 +58,10 @@ export const mutations = {
}
},
[types.SET_ALL_ATTACHMENTS](_state, { id, data }) {
if (data.length) {
const [chat] = _state.allConversations.filter(c => c.id === id);
Vue.set(chat, 'attachments', []);
chat.attachments.push(...data);
}
const [chat] = _state.allConversations.filter(c => c.id === id);
if (!chat) return;
Vue.set(chat, 'attachments', []);
chat.attachments.push(...data);
},
[types.SET_MISSING_MESSAGES](_state, { id, data }) {
const [chat] = _state.allConversations.filter(c => c.id === id);
Expand Down
Expand Up @@ -288,6 +288,14 @@ describe('#mutations', () => {
mutations[types.SET_ALL_ATTACHMENTS](state, { id: 1, data });
expect(state.allConversations[0].attachments).toEqual(data);
});
it('set attachments key even if the attachments are empty', () => {
const state = {
allConversations: [{ id: 1 }],
};
const data = [];
mutations[types.SET_ALL_ATTACHMENTS](state, { id: 1, data });
expect(state.allConversations[0].attachments).toEqual([]);
});
});

describe('#ADD_CONVERSATION_ATTACHMENTS', () => {
Expand Down

0 comments on commit c8fac08

Please sign in to comment.