|
23 | 23 | });
|
24 | 24 |
|
25 | 25 | it('renders import CSV component with model and file', function () {
|
26 |
| - Storage::fake(); |
27 |
| - |
28 |
| - $path = __DIR__.DIRECTORY_SEPARATOR.'stubs'.DIRECTORY_SEPARATOR.'customers.csv'; |
29 | 26 | $model = Customer::class;
|
30 | 27 |
|
31 | 28 | $file = UploadedFile::fake()
|
32 |
| - ->create('customers.csv', 10, 'csv'); |
| 29 | + ->createWithContent( |
| 30 | + 'customers.csv', |
| 31 | + file_get_contents('stubs/customers.csv', true) |
| 32 | + ); |
33 | 33 |
|
34 | 34 | livewire(CsvImporter::class, [
|
35 | 35 | 'model' => $model,
|
36 | 36 | ])
|
37 |
| - ->set('file', $path) |
| 37 | + ->set('file', $file) |
38 | 38 | ->assertSet('model', $model)
|
39 | 39 | ->assertSuccessful();
|
40 | 40 | });
|
41 | 41 |
|
42 | 42 | it('throws a validation error if the csv file empty', function () {
|
43 |
| - Storage::fake(); |
44 | 43 | $model = Customer::class;
|
45 | 44 |
|
46 | 45 | $file = UploadedFile::fake()
|
|
52 | 51 | livewire(CsvImporter::class, [
|
53 | 52 | 'model' => $model,
|
54 | 53 | ])
|
55 |
| - ->set('file', $file) |
56 |
| - ->assertSet('model', $model) |
57 |
| - ->assertHasErrors(['file']); |
| 54 | + ->set('file', $file) |
| 55 | + ->assertSet('model', $model) |
| 56 | + ->assertHasErrors(['file']); |
58 | 57 | });
|
59 | 58 |
|
60 | 59 | it('throws a validation error if the csv file has duplicate headers', function () {
|
61 |
| - Storage::fake(); |
62 |
| - |
63 | 60 | $model = Customer::class;
|
| 61 | + |
64 | 62 | $file = UploadedFile::fake()
|
65 | 63 | ->createWithContent(
|
66 | 64 | 'customers.csv',
|
|
70 | 68 | livewire(CsvImporter::class, [
|
71 | 69 | 'model' => $model,
|
72 | 70 | ])
|
73 |
| - ->set('file', $file) |
74 |
| - ->assertSet('model', $model) |
75 |
| - ->assertHasErrors(['file']); |
| 71 | + ->set('file', $file) |
| 72 | + ->assertSet('model', $model) |
| 73 | + ->assertHasErrors(['file']); |
76 | 74 | });
|
77 | 75 |
|
78 | 76 | it('transfers columnsToMap into an associative array', function () {
|
|
171 | 169 | ->assertSet('fileHeaders', [
|
172 | 170 | 'id', 'first_name', 'last_name', 'email', 'company', 'vip', 'birthday', 'created_at', 'updated_at',
|
173 | 171 | ])
|
174 |
| - ->assertSet('fileRowCount', 1000); |
| 172 | + ->assertSet('fileRowCount', 100); |
175 | 173 | });
|
176 | 174 |
|
177 | 175 | it('throws validation errors, if the file extension does not match', function () {
|
|
250 | 248 |
|
251 | 249 | Bus::assertBatched(function (PendingBatch $batch) {
|
252 | 250 | return $batch->name == 'import-csv' &&
|
253 |
| - $batch->jobs->count() === 100; |
| 251 | + $batch->jobs->count() === 10; |
254 | 252 | });
|
255 | 253 |
|
256 | 254 | $this->assertEquals(Import::count(), 1);
|
|
284 | 282 |
|
285 | 283 | $this->assertEquals(Import::count(), 1);
|
286 | 284 | $this->assertEquals($import->count(), 1);
|
287 |
| - $this->assertEquals(Customer::count(), 1000); |
288 |
| - $this->assertEquals($import->first()->processed_rows, 1000); |
| 285 | + $this->assertEquals(Customer::count(), 100); |
| 286 | + $this->assertEquals($import->first()->processed_rows, 100); |
289 | 287 | });
|
290 | 288 |
|
291 | 289 | it('toggles import button', function () {
|
|
0 commit comments