Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/#712 #36

Merged
merged 3 commits into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions grails-app/services/au/org/ala/profile/OpusService.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ class OpusService extends BaseDataAccessService {
opus.markDirty('approvedLists')
}
opus.approvedLists.addAll(json.approvedLists)
} else {
opus.approvedLists.removeAll(opus.approvedLists)
}

if (json.featureLists) {
Expand All @@ -82,6 +84,8 @@ class OpusService extends BaseDataAccessService {
opus.markDirty('featureLists')
}
opus.featureLists.addAll(json.featureLists)
} else {
opus.featureLists.removeAll(opus.featureLists)
}
opus.featureListSectionName = json.featureListSectionName ? json.featureListSectionName : null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import au.org.ala.web.UserDetails
import grails.gorm.transactions.Rollback
import grails.gsp.PageRenderer
import grails.testing.mixin.integration.Integration
import net.sf.json.JSONObject
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.web.multipart.commons.CommonsMultipartFile

Expand Down Expand Up @@ -271,4 +272,92 @@ class OpusServiceSpec extends BaseIntegrationSpec {
1 * service.attachmentService.saveAttachment(_, _, _, _, _)
0 * service.attachmentService.deleteAttachment(_, _, _, _)
}
}

def "update opus for approved lists"() {
given:
Opus opus1 = new Opus(title: "opus1", dataResourceUid: "123", glossary: new Glossary(), approvedLists: ["dr123", "dr345"])

def opus2 = [
title : "opus1",
dataResourceUid : "123",
approvedLists : ["dr123"],
]


JSONObject json1 = new JSONObject(opus2)
save opus1

when:
Opus updateOpus = service.updateOpus(opus1.uuid, json1)

then:
updateOpus.approvedLists.size() == json1.approvedLists.size()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test when approved list and feature list is empty.

}

def "update opus for featured lists"() {
given:
Opus opus1 = new Opus(title: "opus1", dataResourceUid: "123", glossary: new Glossary(), featureLists: ["dr123", "dr345", "dr678"])

def opus2 = [
title : "opus1",
dataResourceUid : "123",
featureLists : ["dr345"],
]


JSONObject json1 = new JSONObject(opus2)
save opus1

when:
Opus updateOpus = service.updateOpus(opus1.uuid, json1)

then:
updateOpus.featureLists.size() == json1.featureLists.size()
}

def "update opus for approved lists and feature lists"() {
given:
Opus opus1 = new Opus(title: "opus1", dataResourceUid: "123", glossary: new Glossary(), approvedLists: ["dr123", "dr345"], featureLists: ["fl123","fl456","fl789"])

def opus2 = [
title : "opus1",
dataResourceUid : "123",
approvedLists : ["dr123"],
featureLists : ["fl123", "fl456"]
]


JSONObject json1 = new JSONObject(opus2)
save opus1

when:
Opus updateOpus = service.updateOpus(opus1.uuid, json1)

then:
updateOpus.approvedLists.size() == json1.approvedLists.size()
updateOpus.featureLists.size() == json1.featureLists.size()
}

def "update opus for approved lists and feature lists are empty"() {
given:
Opus opus1 = new Opus(title: "opus1", dataResourceUid: "123", glossary: new Glossary(), approvedLists: [], featureLists: [])

def opus2 = [
title : "opus1",
dataResourceUid : "123",
approvedLists : [],
featureLists : []
]


JSONObject json1 = new JSONObject(opus2)
save opus1

when:
Opus updateOpus = service.updateOpus(opus1.uuid, json1)

then:
updateOpus.approvedLists.size() == json1.approvedLists.size()
updateOpus.featureLists.size() == json1.featureLists.size()
}
}
Loading