CreateStoreTest.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. namespace Tests\Services\StoreService;
  3. use App\OracleDOCASNHeader;
  4. use App\Services\StoreService;
  5. use Carbon\Carbon;
  6. use Illuminate\Support\Facades\DB;
  7. use Tests\TestCase;
  8. class CreateStoreTest extends TestCase
  9. {
  10. /** @var StoreService $service */
  11. public $service;
  12. public $asnHeaders;
  13. public $stores;
  14. public function setUp(): void
  15. {
  16. parent::setUp(); // TODO: Change the autogenerated stub
  17. $dataInterval = intval(data_get(config('sync'), 'asn_sync.interval')) * 60 + 5;
  18. $startDate = \Illuminate\Support\Carbon::now()->subSeconds($dataInterval);
  19. $this->service=app(StoreService::class);
  20. $this->asnHeaders=OracleDOCASNHeader::query()
  21. ->with(['asnType', 'asnStatus', 'asnDetails' => function ($query) {
  22. $query->with(['lineStatus', 'qualityStatus','basSku']);
  23. }])
  24. ->where('addTime', '>=', $startDate)
  25. ->get();
  26. }
  27. public function testCreateStore(){
  28. if (!$this->asnHeaders) return null;
  29. $this->stores=$this->service->createStore($this->asnHeaders);
  30. $this->assertNotEmpty($this->stores);
  31. }
  32. public function tearDown(): void
  33. {
  34. $storeIds=[];
  35. foreach ($this->stores as $store){
  36. array_push($storeIds,$store->id);
  37. }
  38. DB::table('stores')->whereIn('asn_code',data_get($this->asnHeaders,'*.asnno'))->delete();
  39. DB::table('store_items')->whereIn('store_id',$storeIds)->delete();
  40. parent::tearDown(); // TODO: Change the autogenerated stub
  41. }
  42. }