Skip to content

Commit 2545988

Browse files
committed
Improved code coverage
1 parent cedd79b commit 2545988

7 files changed

+83
-7
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
@isTest(isParallel=true)
2+
public class QuizEditorControllerTest {
3+
@isTest
4+
static void setSessionQuestions_fails_when_no_session_id() {
5+
try {
6+
QuizEditorController.setSessionQuestions(null, new List<Id>());
7+
// expect to fail
8+
System.assert(false);
9+
} catch (AuraHandledException e) {
10+
System.assert(true);
11+
}
12+
}
13+
14+
@isTest
15+
static void setSessionQuestions_fails_when_no_questions() {
16+
try {
17+
QuizEditorController.setSessionQuestions(
18+
'a043N000000pLrVQAU',
19+
null
20+
);
21+
// expect to fail
22+
System.assert(false);
23+
} catch (AuraHandledException e) {
24+
System.assert(true);
25+
}
26+
}
27+
28+
@isTest
29+
static void getSessionQuestions_fails_when_no_session_id() {
30+
try {
31+
QuizEditorController.getSessionQuestions(null);
32+
// expect to fail
33+
System.assert(false);
34+
} catch (AuraHandledException e) {
35+
System.assert(true);
36+
}
37+
}
38+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
3+
<apiVersion>48.0</apiVersion>
4+
<status>Active</status>
5+
</ApexClass>

src/test/default/classes/QuizPlayerServiceTest.cls

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,21 @@
11
@isTest(isParallel=true)
22
public class QuizPlayerServiceTest {
33
@isTest
4-
static void onlyPlayerRanksOne() {
4+
static void getFromName_works() {
5+
List<Quiz_Player__c> players = QuizSessionTestFactory.createQuizPlayers(
6+
1
7+
);
8+
9+
QuizPlayerService playerService = new QuizPlayerService();
10+
Quiz_Player__c player = playerService.getFromName(
11+
QuizSessionTestFactory.PLAYER_NAME_PREFIX + '0'
12+
);
13+
14+
System.assertEquals(players[0].Id, player.Id);
15+
}
16+
17+
@isTest
18+
static void assignRanking_works_with_one_player() {
519
QuizSessionTestFactory.createQuizPlayers(1);
620

721
QuizPlayerService playerService = new QuizPlayerService();
@@ -16,7 +30,7 @@ public class QuizPlayerServiceTest {
1630
}
1731

1832
@isTest
19-
static void twoPlayersSameScoreBothRankOne() {
33+
static void assignRanking_works_with_two_player_same_score() {
2034
Quiz_Player__c player1 = QuizSessionTestFactory.createQuizPlayerWithScore(
2135
'one',
2236
100
@@ -46,7 +60,7 @@ public class QuizPlayerServiceTest {
4660
}
4761

4862
@isTest
49-
static void twoPlayersDifferentScoreDifferentRanking() {
63+
static void assignRanking_works_with_two_player_different_score() {
5064
Quiz_Player__c player1 = QuizSessionTestFactory.createQuizPlayerWithScore(
5165
'one',
5266
100
@@ -76,7 +90,7 @@ public class QuizPlayerServiceTest {
7690
}
7791

7892
@isTest
79-
static void threePlayersMixedRanking() {
93+
static void assignRanking_works_with_three_players() {
8094
Quiz_Player__c player1 = QuizSessionTestFactory.createQuizPlayerWithScore(
8195
'one',
8296
100

src/test/default/classes/QuizPlayerStatsRestResourceTest.cls

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public class QuizPlayerStatsRestResourceTest {
2626
}
2727

2828
@isTest
29-
static void getPlayerStats_failsWhenMissingPlayerId() {
29+
static void getPlayerStats_fails_whenMissingPlayerId() {
3030
RestRequest request = new RestRequest();
3131
request.requestUri = '/services/apexrest/quiz/player/stats';
3232

@@ -46,7 +46,7 @@ public class QuizPlayerStatsRestResourceTest {
4646
}
4747

4848
@isTest
49-
static void getPlayerStats_failsWhenUnknownPlayerId() {
49+
static void getPlayerStats_fails_whenUnknownPlayerId() {
5050
RestRequest request = new RestRequest();
5151
request.requestUri = '/services/apexrest/quiz/player/stats';
5252
request.params.put(
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
@isTest(isParallel=true)
2+
public class QuizQuestionServiceTest {
3+
@isTest
4+
static void getQuestions_works() {
5+
QuizQuestionService service = new QuizQuestionService();
6+
Quiz_Question__c question = QuizSessionTestFactory.createQuizQuestion();
7+
8+
List<Quiz_Question__c> questions = service.getQuestions();
9+
10+
System.assertEquals(1, questions.size());
11+
System.assertEquals(question.Id, questions[0].Id);
12+
}
13+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
3+
<apiVersion>48.0</apiVersion>
4+
<status>Active</status>
5+
</ApexClass>

src/test/default/classes/QuizSessionTestFactory.cls

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
@isTest
22
public class QuizSessionTestFactory {
3+
public static final String PLAYER_NAME_PREFIX = 'player';
34
private static final String PHASE_REGISTRATION = QuizSessionService.Phase.Registration.name();
45

56
public static Quiz_Session__c createQuizSession() {
@@ -43,7 +44,7 @@ public class QuizSessionTestFactory {
4344
public static List<Quiz_Player__c> createQuizPlayers(Integer playerCount) {
4445
List<Quiz_Player__c> players = new List<Quiz_Player__c>();
4546
for (Integer i = 0; i < playerCount; i++) {
46-
players.add(new Quiz_Player__c(Name = 'player' + i));
47+
players.add(new Quiz_Player__c(Name = PLAYER_NAME_PREFIX + i));
4748
}
4849
insert players;
4950
return players;

0 commit comments

Comments
 (0)