Skip to content

Commit 6252044

Browse files
authored
fix: sponsor statistics assignment tweak (#516)
* fix: sponsor statistics assignment tweak Signed-off-by: romanetar <roman_ag@hotmail.com> * fix: sponsor statistics assignment tweak Signed-off-by: romanetar <roman_ag@hotmail.com> --------- Signed-off-by: romanetar <roman_ag@hotmail.com>
1 parent 349d81a commit 6252044

3 files changed

Lines changed: 40 additions & 8 deletions

File tree

app/Services/Model/Imp/SummitSponsorService.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1184,8 +1184,9 @@ public function updateSponsorServicesStatistics(Summit $summit, int $sponsor_id,
11841184

11851185
$statistics = $summit_sponsor->getSponsorServicesStatistics();
11861186
if (!$statistics) {
1187-
$statistics = new SponsorStatistics();
1188-
$statistics->setSponsor($summit_sponsor);
1187+
$statistics = SponsorServicesStatisticsFactory::build($payload);
1188+
$summit_sponsor->setSponsorServicesStatistics($statistics);
1189+
return $statistics;
11891190
}
11901191
return SponsorServicesStatisticsFactory::populate($statistics, $payload);
11911192
});

tests/InsertSummitTestData.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -913,12 +913,14 @@ protected static function insertSummitTestData(){
913913
}
914914
}
915915

916-
$statistics = new SponsorStatistics();
917-
$statistics->setFormsQty(random_int(1, 30));
918-
$statistics->setPurchasesQty(random_int(1, 30));
919-
$statistics->setPagesQty(random_int(1, 30));
920-
$statistics->setDocumentsQty(random_int(1, 30));
921-
$s->setSponsorServicesStatistics($statistics);
916+
if ($i % 2 == 0) {
917+
$statistics = new SponsorStatistics();
918+
$statistics->setFormsQty(random_int(1, 30));
919+
$statistics->setPurchasesQty(random_int(1, 30));
920+
$statistics->setPagesQty(random_int(1, 30));
921+
$statistics->setDocumentsQty(random_int(1, 30));
922+
$s->setSponsorServicesStatistics($statistics);
923+
}
922924

923925
self::$em->persist($s);
924926
self::$summit->addSummitSponsor($s);

tests/OAuth2SummitSponsorApiTest.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -878,4 +878,33 @@ public function testUpdatePartiallySponsorServicesStatistics(){
878878
$this->assertEquals($new_forms_qty, $statistics->forms_qty);
879879
$this->assertEquals($pages_qty, $statistics->pages_qty);
880880
}
881+
882+
public function testInsertPartiallySponsorServicesStatistics(){
883+
$params = [
884+
'id' => self::$summit->getId(),
885+
'sponsor_id' => self::$sponsors[1]->getId(),
886+
];
887+
888+
$new_forms_qty = 10;
889+
890+
$data = [
891+
'forms_qty' => $new_forms_qty
892+
];
893+
894+
$response = $this->action(
895+
"PUT",
896+
"OAuth2SummitSponsorApiController@updateSponsorServicesStatistics",
897+
$params,
898+
[],
899+
[],
900+
[],
901+
$this->getAuthHeaders(),
902+
json_encode($data)
903+
);
904+
905+
$content = $response->getContent();
906+
$this->assertResponseStatus(201);
907+
$statistics = json_decode($content);
908+
$this->assertEquals($new_forms_qty, $statistics->forms_qty);
909+
}
881910
}

0 commit comments

Comments
 (0)