From d4b8b9f8fb95c36069cd6934cec66b690b8a1501 Mon Sep 17 00:00:00 2001 From: Andrew Newton Date: Thu, 10 Oct 2024 16:06:50 +0100 Subject: [PATCH] fix: Two methods in DataGovUkExport did not call new parent uploadToS3 method. (#378) --- .../Domain/CommandHandler/DataGovUkExport.php | 8 ++++++ .../CommandHandler/DataGovUkExportTest.php | 25 +++++++++++++------ 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/app/api/module/Cli/src/Domain/CommandHandler/DataGovUkExport.php b/app/api/module/Cli/src/Domain/CommandHandler/DataGovUkExport.php index b824ef7756..3a37e6736e 100644 --- a/app/api/module/Cli/src/Domain/CommandHandler/DataGovUkExport.php +++ b/app/api/module/Cli/src/Domain/CommandHandler/DataGovUkExport.php @@ -104,6 +104,12 @@ private function processPsvOperatorList() ['id' => $document->getId('document')], $document->getId('document') ); + + $tempFilePath = tempnam(sys_get_temp_dir(), 'psv_operator_list_'); + file_put_contents($tempFilePath, $csvContent); + $this->uploadToS3($tempFilePath); + unlink($tempFilePath); + $email = $this->handleSideEffect($emailQueue); $this->result->merge($email); @@ -135,6 +141,8 @@ private function processInternationalGoodsList() $document->getId('document') ); + $this->uploadToS3($csvContent); + $email = $this->handleSideEffect($emailQueue); $this->result->merge($email); diff --git a/app/api/test/module/Cli/src/Domain/CommandHandler/DataGovUkExportTest.php b/app/api/test/module/Cli/src/Domain/CommandHandler/DataGovUkExportTest.php index 387ed89f79..42e4b8487b 100644 --- a/app/api/test/module/Cli/src/Domain/CommandHandler/DataGovUkExportTest.php +++ b/app/api/test/module/Cli/src/Domain/CommandHandler/DataGovUkExportTest.php @@ -180,15 +180,22 @@ public function testInternationalGoods() ] ); + $this->mockS3client->shouldAllowMockingMethod('putObject'); + $this->mockS3client->shouldReceive('putObject') + ->once() + ->andReturn([]); + $actual = $this->sut->handleCommand($cmd); $date = new DateTime('now'); - $expectedFile = $this->tmpPath . '/' . $fileName . '_' . + + $expectedFileName = $fileName . '_' . $date->format(DataGovUkExport::FILE_DATETIME_FORMAT) . '.csv'; + $expectedFilePath = $this->tmpPath . '/' . $expectedFileName; $expectMsg = 'Fetching data for international goods list' . - 'Creating CSV file: ' . $expectedFile; + 'Creating CSV file: ' . $expectedFilePath . 'Uploaded file to S3: '.$expectedFileName; $this->assertEquals( $expectMsg, @@ -294,16 +301,20 @@ public function testPsvOperatorListOk() ] ); + $this->mockS3client->shouldAllowMockingMethod('putObject'); + $this->mockS3client->shouldReceive('putObject') + ->once() + ->andReturn([]); + $actual = $this->sut->handleCommand($cmd); $expectMsg = 'Fetching data from DB for PSV Operators' . - 'create csv file content'; + 'create csv file contentUploaded file to S3: psv_operator_list_'; - static::assertEquals( - $expectMsg, - implode('', $actual->toArray()['messages']) - ); + $actualMsg = implode('', $actual->toArray()['messages']); + + static::assertStringStartsWith($expectMsg, $actualMsg); } public function testOperatorLicenceOk()