Skip to content

Commit

Permalink
allow empty response from OpenProject
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 15, 2022
1 parent fcc17e3 commit a7b8611
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
11 changes: 7 additions & 4 deletions src/views/ProjectsTab.vue
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,15 @@ export default {
const url = generateUrl('/apps/integration_openproject/work-packages?fileId=' + fileId)
try {
const response = await axios.get(url, req)
if (!Array.isArray(response.data) || response.data.length < 1) {
if (!Array.isArray(response.data)) {
this.state = 'failed-fetching-workpackages'
} else {
for (let workPackage of response.data) {
workPackage = await workpackageHelper.getAdditionalMetaData(workPackage)
this.workpackages.push(workPackage)
// empty data means there are no workpackages linked
if (response.data.length > 0) {
for (let workPackage of response.data) {
workPackage = await workpackageHelper.getAdditionalMetaData(workPackage)
this.workpackages.push(workPackage)
}
}
this.state = 'ok'
}
Expand Down
9 changes: 7 additions & 2 deletions tests/jest/views/ProjectsTab.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ describe('ProjectsTab.vue Test', () => {
expect(wrapper.vm.state).toBe(cases.AppState)
})
it.each([
[],
null,
'string',
undefined,
Expand Down Expand Up @@ -168,7 +167,7 @@ describe('ProjectsTab.vue Test', () => {
project: { },
},
}],
])('sets "failed-fetching-workpackages" state on invalid responses', async (testCase) => {
])('sets the "failed-fetching-workpackages" state on invalid responses', async (testCase) => {
axios.get
.mockImplementationOnce(() => Promise.resolve({
status: 200,
Expand All @@ -179,6 +178,12 @@ describe('ProjectsTab.vue Test', () => {
await wrapper.vm.update({ id: 123 })
expect(wrapper.vm.state).toBe('failed-fetching-workpackages')
})
it('sets the "ok" state on empty response', async () => {
axios.get
.mockImplementation(() => Promise.resolve({ status: 200, data: [] }))
await wrapper.vm.update({ id: 123 })
expect(wrapper.vm.state).toBe('ok')
})
it.each([
{ statusColor: { color: '#A5D8FF' }, typeColor: { color: '#00B0F0' } },
{ statusColor: { }, typeColor: { } },
Expand Down

0 comments on commit a7b8611

Please sign in to comment.