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

#3061: enhanced report endpoint/api with additional information about… #3074

Merged
merged 1 commit into from
Jan 7, 2025
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
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,15 @@ class SkillEventResult {
String projectId
String skillId
String name
int pointsEarned = 0
// earned on this request
int pointsEarned
// total points earned by this user for this skill
int totalPointsEarned
// total points defined by an admin for this skill
int totalPoints
// number of times skill needs to be performed in order to earn all of its points
int numOccurrencesToCompletion

boolean skillApplied = true
// only really applicable if it wasn't performed
String explanation = "Skill event was applied"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,9 @@ class SkillEventsTransactionalService {
savePerformedSkill(performedSkill)

res.pointsEarned = skillDefinition.pointIncrement
res.totalPointsEarned = ((int)numExistingSkills + 1) * skillDefinition.pointIncrement
res.totalPoints = skillDefinition.totalPoints
res.numOccurrencesToCompletion = (int)(skillDefinition.totalPoints / skillDefinition.pointIncrement)

List<CompletionItem> achievements = pointsAndAchievementsHandler.updatePointsAndAchievements(userId, skillDefinition, skillDate)
if (achievements) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/**
* Copyright 2024 SkillTree
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package skills.intTests

import skills.intTests.utils.DefaultIntSpec
import skills.intTests.utils.SkillsFactory
import skills.intTests.utils.SkillsService

class ReportSkillEndpointSpecs extends DefaultIntSpec {

def "skill points earned with multiple iterations for multiple users"() {
def proj = SkillsFactory.createProject(1)
def subj = SkillsFactory.createSubject(1, 1)
def skills = SkillsFactory.createSkills(10, 1, 1, 10, 3)
skills.each { it.pointIncrementInterval = 0 }
skillsService.createProjectAndSubjectAndSkills(proj, subj, skills)

List<String> userIds = getRandomUsers(3)
List<SkillsService> users = userIds.collect { userId -> createService(userId) }

when:
def user1Res1 = users[0].addSkill([projectId: proj.projectId, skillId: skills[0].skillId]).body
def user2Res1 = users[1].addSkill([projectId: proj.projectId, skillId: skills[0].skillId]).body
def user1Res2 = users[0].addSkill([projectId: proj.projectId, skillId: skills[0].skillId]).body
def user2Res2 = users[1].addSkill([projectId: proj.projectId, skillId: skills[0].skillId]).body
def user1Res3 = users[0].addSkill([projectId: proj.projectId, skillId: skills[0].skillId]).body
def user2Res3 = users[1].addSkill([projectId: proj.projectId, skillId: skills[0].skillId]).body

def user3Res1 = users[2].addSkill([projectId: proj.projectId, skillId: skills[0].skillId]).body
def user3Res2 = users[2].addSkill([projectId: proj.projectId, skillId: skills[0].skillId]).body
def user3Res3 = users[2].addSkill([projectId: proj.projectId, skillId: skills[0].skillId]).body


def checkUserRes = { def res, int totalPointsEarned, List<String> completedNames ->
assert res.skillApplied == true
assert res.totalPoints == 30
assert res.numOccurrencesToCompletion == 3
assert res.pointsEarned == 10
assert res.totalPointsEarned == totalPointsEarned
assert res.projectId == proj.projectId
assert res.name == skills[0].name
assert res.skillId == skills[0].skillId
assert res.explanation == "Skill event was applied"
if (completedNames) {
assert res.completed.name.sort() == completedNames.sort()
} else {
assert !res.completed
}

return true
}

then:
checkUserRes(user1Res1, 10, null)
checkUserRes(user1Res2, 20, null)
checkUserRes(user1Res3, 30, [skills[0].name, "OVERALL", subj.name])

checkUserRes(user2Res1, 10, null)
checkUserRes(user2Res2, 20, null)
checkUserRes(user2Res3, 30, [skills[0].name, "OVERALL", subj.name])

checkUserRes(user3Res1, 10, null)
checkUserRes(user3Res2, 20, null)
checkUserRes(user3Res3, 30, [skills[0].name, "OVERALL", subj.name])
}
}
Loading