|
1 | 1 | <?php
|
2 | 2 |
|
3 | 3 | use Coderflex\LaravelCsv\Http\Livewire\CsvImporter;
|
| 4 | +use Coderflex\LaravelCsv\Jobs\ImportCsv; |
4 | 5 | use Coderflex\LaravelCsv\Models\Import;
|
5 | 6 | use Coderflex\LaravelCsv\Tests\Models\Customer;
|
| 7 | +use Illuminate\Bus\PendingBatch; |
6 | 8 | use Illuminate\Http\UploadedFile;
|
| 9 | +use Illuminate\Support\Facades\Bus; |
7 | 10 | use Illuminate\Support\Facades\Storage;
|
8 | 11 | use function Pest\Livewire\livewire;
|
9 | 12 |
|
|
220 | 223 | ->assertHasErrors(['columnsToMap.name', 'columnsToMap.email']);
|
221 | 224 | });
|
222 | 225 |
|
223 |
| -it('creates a new import records', function () { |
| 226 | +it('ensures the imports is batched', function () { |
224 | 227 | Storage::fake('documents');
|
| 228 | + Bus::fake(); |
| 229 | + |
| 230 | + $columnsToMap = [ |
| 231 | + 'id', |
| 232 | + 'first_name', |
| 233 | + 'last_name', |
| 234 | + 'email', |
| 235 | + ]; |
225 | 236 |
|
226 | 237 | $file = UploadedFile::fake()
|
227 | 238 | ->createWithContent(
|
|
233 | 244 |
|
234 | 245 | livewire(CsvImporter::class, [
|
235 | 246 | 'model' => $model,
|
| 247 | + 'columnsToMap' => $columnsToMap, |
236 | 248 | ])
|
237 | 249 | ->set('file', $file)
|
| 250 | + ->set('columnsToMap', [ |
| 251 | + 'id' => 'id', |
| 252 | + 'fist_name' => 'fist_name', |
| 253 | + 'last_name' => 'last_name', |
| 254 | + 'email' => 'email', |
| 255 | + ]) |
238 | 256 | ->call('import')
|
239 | 257 | ->assertHasNoErrors();
|
240 | 258 |
|
| 259 | + Bus::assertBatched(function (PendingBatch $batch) { |
| 260 | + return $batch->name == 'import-csv' && |
| 261 | + $batch->jobs->count() === 100; |
| 262 | + }); |
| 263 | + |
241 | 264 | $this->assertEquals(Import::count(), 1);
|
242 | 265 | $this->assertEquals(Import::forModel(Customer::class)->count(), 1);
|
243 | 266 | });
|
0 commit comments