Skip to content

Commit

Permalink
accepting xlsx and xls file formats (#24)
Browse files Browse the repository at this point in the history
Co-authored-by: dawid.miklas <[email protected]>
  • Loading branch information
dicani0 and dawid.miklas authored Jul 7, 2023
1 parent 33f793f commit 9c75a64
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/Http/Requests/ImportUsersFromCsvAPIRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public function authorize(): bool
public function rules(): array
{
return [
'file' => ['required', 'mimes:csv,txt'],
'file' => ['required', 'mimes:csv,txt,xlsx,xls'],
'return_url' => ['required', 'string'],
];
}
Expand Down
18 changes: 15 additions & 3 deletions tests/APIs/ImportUsersFromCsvTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,18 +67,30 @@ public function testAccessToImportUsersFromCSV(): void
Excel::assertImported('users.csv');
}

public function testUsersImport(): void
public function fileFormatProvider(): array
{
return [
'csv' => ['users.csv'],
'xlsx' => ['users.xlsx'],
'xls' => ['users.xls'],
];
}

/**
* @dataProvider fileFormatProvider
*/
public function testUsersImport(string $value): void
{
$importData = $this->prepareImportData();

$admin = $this->makeAdmin();
$response = $this->actingAs($admin, 'api')->postJson('/api/admin/csv/users', [
'file' => UploadedFile::fake()->create('users.csv'),
'file' => UploadedFile::fake()->create($value),
'return_url' => 'http://localhost/set-password',
]);
$response->assertOk();

Excel::assertImported('users.csv', function (UsersImport $import) use ($importData) {
Excel::assertImported($value, function (UsersImport $import) use ($importData) {
$import->collection($importData);
return true;
});
Expand Down

0 comments on commit 9c75a64

Please sign in to comment.