Skip to content

Commit

Permalink
log error when receiving invalid workpackage data
Browse files Browse the repository at this point in the history
Signed-off-by: Artur Neumann <artur@jankaritech.com>
  • Loading branch information
individual-it committed Mar 17, 2022
1 parent a3c12e8 commit c205b92
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 6 deletions.
15 changes: 10 additions & 5 deletions src/components/tab/SearchInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,17 @@ export default {
},
async processWorkPackages(workPackages) {
for (let workPackage of workPackages) {
workPackage = await workpackageHelper.getAdditionalMetaData(workPackage)
const selectedIdFound = this.selectedId.some(el => el.id === workPackage.id)
const workpackageIdFound = this.searchResults.some(el => el.id === workPackage.id)
if (!workpackageIdFound && !selectedIdFound) {
this.searchResults.push(workPackage)
try {
workPackage = await workpackageHelper.getAdditionalMetaData(workPackage)
const selectedIdFound = this.selectedId.some(el => el.id === workPackage.id)
const workpackageIdFound = this.searchResults.some(el => el.id === workPackage.id)
if (!workpackageIdFound && !selectedIdFound) {
this.searchResults.push(workPackage)
}
} catch (e) {
console.error('could not process workpackage data')
}
}
},
},
Expand Down
20 changes: 19 additions & 1 deletion tests/jest/components/tab/SearchInput.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,24 @@ describe('SearchInput.vue tests', () => {
)
axiosSpy.mockRestore()
})
it('should log an error on invalid payload', async () => {
const axiosSpy = jest.spyOn(axios, 'get')
.mockImplementationOnce(() => Promise.resolve({
status: 200,
data: [{
id: 123,
}],
}))
const consoleMock = jest.spyOn(console, 'error')
.mockImplementationOnce(() => {})
wrapper = mountSearchInput()
const inputField = wrapper.find(inputSelector)
await inputField.setValue('orga')
await localVue.nextTick()
expect(consoleMock).toHaveBeenCalledWith('could not process workpackage data')
consoleMock.mockRestore()
axiosSpy.mockRestore()
})
})

describe('search list', () => {
Expand Down Expand Up @@ -212,7 +230,7 @@ describe('SearchInput.vue tests', () => {
})
})

function mountSearchInput(fileInfo = null) {
function mountSearchInput(fileInfo = { }) {
return mount(SearchInput, {
localVue,
mocks: {
Expand Down

0 comments on commit c205b92

Please sign in to comment.