Skip to content

Commit

Permalink
CSCFAIRMETA-822: Fix cumulative state not updating correctly in v2 (#647
Browse files Browse the repository at this point in the history
)
  • Loading branch information
ismotee authored Dec 11, 2020
1 parent 10f1abf commit 72bb2d2
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 8 deletions.
10 changes: 7 additions & 3 deletions etsin_finder/frontend/__tests__/qvain.apiv2.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,11 @@ describe('Submit.exec()', () => {
beforeEach(() => {
handleSubmitToBackend.mockReturnValue(generateDefaultDatasetForPublish())
submitFunction = jest.fn(() => generalPostResponse)
mockQvain = createMockQvain()
mockQvain = createMockQvain({
original: {
identifier: 'some identifier',
},
})
Submit = new SubmitClass(mockQvain)
})

Expand Down Expand Up @@ -189,9 +193,9 @@ describe('Submit.exec()', () => {

test(`when newCumulativeState, calls editDataset with data from backend`, async () => {
mockQvain.newCumulativeState = 'new state'
axios.get.mockReturnValue(generalGetResponse)
axios.get.mockReturnValue(Promise.resolve(generalGetResponse))
await exec()
expect(mockQvain.editDataset).toHaveBeenCalledWith(generalGetResponse.data)
await expect(mockQvain.editDataset).toHaveBeenCalledWith(generalGetResponse.data)
})
})

Expand Down
8 changes: 4 additions & 4 deletions etsin_finder/frontend/js/stores/view/qvain/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ class Qvain extends Resources {
}

// load fields that won't be duplicated by template copy
@action loadStatusAndFileFields = async (dataset) => {
@action loadStatusAndFileFields = async dataset => {
this.deprecated = dataset.deprecated

// Load data catalog
Expand Down Expand Up @@ -246,9 +246,9 @@ class Qvain extends Resources {
r.download_url ? r.download_url.identifier : undefined,
r.use_category
? {
label: r.use_category.pref_label.en,
value: r.use_category.identifier,
}
label: r.use_category.pref_label.en,
value: r.use_category.identifier,
}
: undefined
)
)
Expand Down
14 changes: 13 additions & 1 deletion etsin_finder/frontend/js/stores/view/qvain/qvain.submit.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,19 @@ class Submit {
await this.updateFiles(data.identifier, fileActions, metadataActions)
setChanged(false)

if (fileActions || metadataActions || newCumulativeState) {
if (newCumulativeState != null) {
const obj = {
identifier: this.Qvain.original.identifier,
cumulative_state: this.Qvain.newCumulativeState,
}

const url = urls.v2.rpc.changeCumulativeState()
await axios.post(url, obj)
}

if (fileActions || metadataActions || newCumulativeState != null) {
// Files changed, get updated dataset

const url = urls.v2.dataset(data.identifier)
const updatedResponse = await axios.get(url)
await editDataset(updatedResponse.data)
Expand All @@ -145,6 +156,7 @@ class Submit {
this.setResponse(undefined)
if (!(error instanceof ValidationError)) {
console.error(error)
this.setResponse(error)
}
} finally {
this.setLoading(false)
Expand Down

0 comments on commit 72bb2d2

Please sign in to comment.