Skip to content

Commit

Permalink
Revert "Don't set the empty string as we display it on the scoreboard"
Browse files Browse the repository at this point in the history
This reverts commit 9974cec.

A better fix was applied in: #2567, the values is now properly validated
and we fail if the property is not set. Added another case for this
specific case of an empty name.
  • Loading branch information
vmcj committed Jun 4, 2024
1 parent c5988a0 commit e1f78ca
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
4 changes: 2 additions & 2 deletions webapp/src/Service/ImportExportService.php
Original file line number Diff line number Diff line change
Expand Up @@ -984,8 +984,8 @@ public function importTeamsJson(array $data, ?string &$message = null, ?array &$
'icpcid' => $team['icpc_id'] ?? null,
'label' => $team['label'] ?? null,
'categoryid' => $team['group_ids'][0] ?? null,
'name' => $team['name'] ?? null,
'display_name' => $team['display_name'] ?? null,
'name' => $team['name'] ?? '',
'display_name' => $team['display_name'] ?? '',
'publicdescription' => $team['public_description'] ?? $team['members'] ?? '',
'location' => $team['location']['description'] ?? null,
],
Expand Down
38 changes: 38 additions & 0 deletions webapp/tests/Unit/Service/ImportExportServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -858,6 +858,44 @@ public function testImportTeamsJsonError(): void
self::assertEquals($preCount, $postCount);
}

public function testImportTeamsJsonErrorEmptyString(): void
{
$teamsData = <<<EOF
[{
"id": "11",
"icpc_id": "447047",
"label": "team1",
"name": "",
"group_ids": ["24"],
"organization_id": "INST-42",
"location": {"description": "AUD 10"}
}, {
"id": "12",
"icpc_id": "447837",
"group_ids": ["25"],
"name": "Pleading not FAUlty",
"organization_id": "INST-43"
}]
EOF;
$em = static::getContainer()->get(EntityManagerInterface::class);
$preCount = $em->getRepository(Team::class)->count([]);

$fileName = tempnam(static::getContainer()->get(DOMJudgeService::class)->getDomjudgeTmpDir(), 'teams-json');
file_put_contents($fileName, $teamsData);
$file = new UploadedFile($fileName, 'teams.json');
/** @var ImportExportService $importExportService */
$importExportService = static::getContainer()->get(ImportExportService::class);
$importCount = $importExportService->importJson('teams', $file, $message);
// Remove the file, we don't need it anymore.
unlink($fileName);

self::assertMatchesRegularExpression('/name: This value should not be blank./', $message);
self::assertEquals(0, $importCount);

$postCount = $em->getRepository(Team::class)->count([]);
self::assertEquals($preCount, $postCount);
}

public function testImportGroupsTsv(): void
{
// Example from the manual
Expand Down

0 comments on commit e1f78ca

Please sign in to comment.