mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-24 02:14:21 -04:00
Accept migration over the API (#3356)
This commit is contained in:
parent
6ca0841626
commit
cf3bcb90be
@ -190,7 +190,11 @@ class MigrationController extends BaseController
|
||||
'migrations', $request->file('migration')->getClientOriginalName()
|
||||
);
|
||||
|
||||
// config('ninja.environment') - Returns 'selfhosted' instead of 'testing' while running with PhpUnit, which makes it run the migration file.
|
||||
if(!auth()->user()->company)
|
||||
return response()->json(['message' => 'Company doesn\'t exists.'], 402);
|
||||
|
||||
if($request->has('force'))
|
||||
$this->purgeCompany(auth()->user()->company);
|
||||
|
||||
if(app()->environment() !== 'testing') {
|
||||
StartMigration::dispatchNow($file, auth()->user(), auth()->user()->company);
|
||||
|
@ -23,8 +23,15 @@ class UploadMigrationFileRequest extends FormRequest
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'migration' => [], // TODO: Write mimes check for zip file.
|
||||
$rules = [
|
||||
'migration' => [],
|
||||
];
|
||||
|
||||
/** We'll skip mime validation while running tests. */
|
||||
if(app()->environment() !== 'testing') {
|
||||
$rules['migration'] = ['required', 'mimes:zip'];
|
||||
}
|
||||
|
||||
return $rules;
|
||||
}
|
||||
}
|
||||
|
@ -95,25 +95,25 @@ class MigrationTest extends TestCase
|
||||
|
||||
}
|
||||
|
||||
// public function testMigrationFileUpload()
|
||||
// {
|
||||
// $file = new UploadedFile(base_path('tests/Unit/Migration/migration.zip'), 'migration.zip');
|
||||
public function testMigrationFileUpload()
|
||||
{
|
||||
$file = new UploadedFile(base_path('tests/Unit/Migration/migration.zip'), 'migration.zip');
|
||||
|
||||
// $data = [
|
||||
// 'migration' => $file,
|
||||
// ];
|
||||
$data = [
|
||||
'migration' => $file,
|
||||
'force' => true,
|
||||
];
|
||||
|
||||
// $token = $this->company->tokens->first()->token;
|
||||
$token = $this->company->tokens->first()->token;
|
||||
|
||||
// $response = $this->withHeaders([
|
||||
// 'X-API-TOKEN' => $token,
|
||||
// 'X-API-SECRET' => config('ninja.api_secret'),
|
||||
// 'X-Requested-With' => 'XMLHttpRequest',
|
||||
// 'X-API-PASSWORD' => 'ALongAndBriliantPassword',
|
||||
// ])->post('/api/v1/migration/start', $data);
|
||||
|
||||
// $response->assertStatus(200);
|
||||
// $this->assertTrue(file_exists(base_path('storage/migrations/migration/migration.json')));
|
||||
// }
|
||||
$response = $this->withHeaders([
|
||||
'X-API-TOKEN' => $token,
|
||||
'X-API-SECRET' => config('ninja.api_secret'),
|
||||
'X-Requested-With' => 'XMLHttpRequest',
|
||||
'X-API-PASSWORD' => 'ALongAndBriliantPassword',
|
||||
])->post('/api/v1/migration/start', $data);
|
||||
|
||||
$response->assertStatus(200);
|
||||
$this->assertTrue(file_exists(base_path('storage/migrations/migration/migration.json')));
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user