Skip to content

Commit

Permalink
add command, test, fix container
Browse files Browse the repository at this point in the history
  • Loading branch information
salimkanoun committed Jun 11, 2024
1 parent fe682a7 commit 1d2b785
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ RUN apt-get update -qy && \
libpng-dev \
libmemcached-dev \
mariadb-client \
postgresql-client-13 && \
postgresql-client && \
apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

RUN pecl install pcov redis memcached
Expand Down
43 changes: 43 additions & 0 deletions GaelO2/app/Console/Commands/UpdateSupervisorUpload.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

namespace App\Console\Commands;

use App\Models\Study;
use Illuminate\Console\Command;

class UpdateSupervisorUpload extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'gaelo:update-supervisor-upload {studyName : the study name to update}';

/**
* The console command description.
*
* @var string
*/
protected $description = 'update allow supervisor upload for a study';

private Study $study;

/**
* Execute the console command.
*/
public function handle(Study $study)
{
$this->study = $study;
$studyName = $this->argument('studyName');
$studyEntity = $this->study->findOrFail($studyName);

if ($this->confirm('Warning : you are about to ' . ($studyEntity->allow_supervisor_upload_dicom ? 'disallow' : 'allow') . ' supervisor upload of dicom, are you sure to continue?')) {
$studyEntity->allow_supervisor_upload_dicom = !$studyEntity->allow_supervisor_upload_dicom;
$studyEntity->save();
$this->info('Updated');
} else {
$this->info('Aborted');
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

namespace Tests\Feature\TestUpdateSupervisorUploadCommand;

use App\Models\Study;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;

class UpdateSupervisorUploadCommandTest extends TestCase
{

use RefreshDatabase;
private Study $study;

protected function setUp(): void
{
parent::setUp();
$this->artisan('db:seed');
$this->study = Study::factory()->create();
}

public function testShouldProposeActivateUploadForSupervisor()
{
$studyName = $this->study->name;
$this->artisan('gaelo:update-supervisor-upload ' . $studyName)->expectsConfirmation('Warning : you are about to allow supervisor upload of dicom, are you sure to continue?', 'yes')
->expectsOutput('Updated');
$updatedStudy = Study::find($studyName);
$this->assertTrue($updatedStudy->allow_supervisor_upload_dicom);
}


public function testShouldProposeDeactivateUploadForSupervisor()
{
$this->study->allow_supervisor_upload_dicom = true;
$this->study->save();
$studyName = $this->study->name;
$this->artisan('gaelo:update-supervisor-upload ' . $studyName)->expectsConfirmation('Warning : you are about to disallow supervisor upload of dicom, are you sure to continue?', 'yes')
->expectsOutput('Updated');
$updatedStudy = Study::find($studyName);
$this->assertFalse($updatedStudy->allow_supervisor_upload_dicom);
}

public function testShouldAbortIfNoConfirmation()
{
$this->study->allow_supervisor_upload_dicom = true;
$this->study->save();
$studyName = $this->study->name;
$this->artisan('gaelo:update-supervisor-upload ' . $studyName)->expectsConfirmation('Warning : you are about to disallow supervisor upload of dicom, are you sure to continue?', 'no')
->expectsOutput('Aborted');
$updatedStudy = Study::find($studyName);
$this->assertTrue($updatedStudy->allow_supervisor_upload_dicom);
}
}

0 comments on commit 1d2b785

Please sign in to comment.