Skip to content

Commit

Permalink
#2548 - added userCommunity to QuizDefSummaryResult
Browse files Browse the repository at this point in the history
  • Loading branch information
rmmayo committed Jan 17, 2025
1 parent f423ecc commit 746e294
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ class QuizDefSummaryResult {
String quizId
String name
QuizDefParent.QuizType type

Date created

Integer numQuestions
String userCommunity
}
Original file line number Diff line number Diff line change
Expand Up @@ -171,12 +171,15 @@ class QuizDefService {
QuizDefSummaryResult getQuizDefSummary(String quizId) {
assert quizId
QuizDefRepo.QuizDefSummaryRes dbRes = quizDefRepo.getQuizDefSummary(quizId)
UserInfo userInfo = userInfoService.currentUser
Boolean isCommunityMember = userCommunityService.isUserCommunityMember(userInfo.username);
return new QuizDefSummaryResult(
quizId: quizId,
name: dbRes.getName(),
created: dbRes.getCreated(),
type: QuizDefParent.QuizType.valueOf(dbRes.getQuizType()),
numQuestions: dbRes.getNumQuestions()
numQuestions: dbRes.getNumQuestions(),
userCommunity: isCommunityMember ? userCommunityService.getQuizUserCommunity(quizId) : null
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,18 +63,27 @@ class ConfigureCommunityForQuizSpecs extends DefaultIntSpec {
def q1CreatedRes = pristineDragonsUser.createQuizDef(q1)
def q2CreatedRes = pristineDragonsUser.createQuizDef(q2)
def quizDefsRes = pristineDragonsUser.getQuizDefs()
def quizSummaryRes1 = pristineDragonsUser.getQuizDefSummary(q1.quizId)
def quizSummaryRes2 = pristineDragonsUser.getQuizDefSummary(q2.quizId)

pristineDragonsUser.addQuizUserRole(q2.quizId, allDragonsUser.userName, RoleName.ROLE_QUIZ_ADMIN.toString())
def quizDefsRes_allDragonsUser = allDragonsUser.getQuizDefs()
def quizSummaryRes_allDragonsUser = allDragonsUser.getQuizDefSummary(q2.quizId)

then:
quizDefsRes.quizId == [q2.quizId, q1.quizId]
quizDefsRes.userCommunity == ['All Dragons', 'Divine Dragon']
quizSummaryRes1.quizId == q1.quizId
quizSummaryRes1.userCommunity == 'Divine Dragon'
quizSummaryRes2.quizId == q2.quizId
quizSummaryRes2.userCommunity == 'All Dragons'
q1CreatedRes.body.userCommunity == 'Divine Dragon'
q2CreatedRes.body.userCommunity == 'All Dragons'

quizDefsRes_allDragonsUser.quizId == [q2.quizId]
quizDefsRes_allDragonsUser.userCommunity == [null]
quizSummaryRes_allDragonsUser.quizId == q2.quizId
quizSummaryRes_allDragonsUser.userCommunity == null
}

def "community is null for a non-community user"() {
Expand All @@ -85,11 +94,17 @@ class ConfigureCommunityForQuizSpecs extends DefaultIntSpec {
def q1CreatedRes = skillsService.createQuizDef(q1)
def q2CreatedRes = skillsService.createQuizDef(q2)
def quizDefsRes = skillsService.getQuizDefs()
def quizSummaryRes1 = skillsService.getQuizDefSummary(q1.quizId)
def quizSummaryRes2 = skillsService.getQuizDefSummary(q2.quizId)
then:
quizDefsRes.quizId == [q2.quizId, q1.quizId]
quizDefsRes.userCommunity == [null, null]
q1CreatedRes.body.userCommunity == null
q2CreatedRes.body.userCommunity == null
quizSummaryRes1.quizId == q1.quizId
quizSummaryRes1.userCommunity == null
quizSummaryRes2.quizId == q2.quizId
quizSummaryRes2.userCommunity == null
}

def "only member of the community can enable quiz "() {
Expand Down

0 comments on commit 746e294

Please sign in to comment.