| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233 |
- <?php
- namespace Tests\Feature;
- use App\Jobs\LogisticZopSync;
- use App\Order;
- use App\OrderPackage;
- use Illuminate\Database\Eloquent\Model;
- use Illuminate\Foundation\Testing\RefreshDatabase;
- use Illuminate\Foundation\Testing\WithFaker;
- use Tests\TestCase;
- class LogisticZopSyncTest extends TestCase
- {
- protected $order;
- /**
- * A basic feature test example.
- *
- * @return void
- */
- // public function testExample()
- // {
- // LogisticZopSync::dispatch('73228022760994');
- // }
- protected function setUp(): void
- {
- parent::setUp(); // TODO: Change the autogenerated stub
- }
- protected function tearDown(): void
- {
- OrderPackage::query()->where('logistic_number', '000000111')->delete();
- $this->order && $this->order->delete();
- parent::tearDown(); // TODO: Change the autogenerated stub
- }
- public function test_get()
- {
- LogisticZopSync::dispatch('75806876414856');
- }
- /**
- * @test
- */
- public function transformRoutes疑似库内丢件Test()
- {
- $order = factory(Order::class)->create(['province' => '上海']);
- $this->order = $order;
- factory(OrderPackage::class)->create(['logistic_number' => '000000111', 'sent_at' => now()->subHours(5),'order_id' => $order->id]);
- $logisticZopSync = new LogisticZopSync('000000111');
- $data[] = [
- 'routes' => [
- ],
- "logisticNum" => "000000111",
- ];
- $result = $logisticZopSync->transformRoutes($data);
- $this->assertEquals('疑似库内丢件', $result[0]['exception_type']);
- }
- /**
- * @test
- */
- public function transformRoutes中转异常Test()
- {
- $order = factory(Order::class)->create(['province' => '上海']);
- $this->order = $order;
- factory(OrderPackage::class)->create(['logistic_number' => '000000111', 'sent_at' => now()->subHours(5), 'order_id' => $order->id]);
- $logisticZopSync = new LogisticZopSync('000000111');
- $data[] = [
- 'routes' => [
- json_decode($this->itemScanDate25hBefore()),
- ],
- "logisticNum" => "000000111",
- ];
- $result = $logisticZopSync->transformRoutes($data);
- $this->assertEquals('中转异常', $result[0]['exception_type']);
- }
- /**
- * @test
- */
- public function transformRoutes疑似丢件Test()
- {
- $order = factory(Order::class)->create(['province' => '上海']);
- $this->order = $order;
- factory(OrderPackage::class)->create(['logistic_number' => '000000111', 'sent_at' => now()->subHours(5), 'order_id' => $order->id]);
- $logisticZopSync = new LogisticZopSync('000000111');
- $data[] = [
- 'routes' => [
- json_decode($this->itemScanDate73hBefore()),
- ],
- "logisticNum" => "000000111",
- ];
- $result = $logisticZopSync->transformRoutes($data);
- $this->assertEquals('疑似丢件', $result[0]['exception_type']);
- }
- /**
- * @test
- */
- public function transformRoutes派送异常Test()
- {
- $order = factory(Order::class)->create(['province' => '上海']);
- $this->order = $order;
- factory(OrderPackage::class)->create(['logistic_number' => '000000111', 'sent_at' => now()->subHours(5), 'order_id' => $order->id]);
- $logisticZopSync = new LogisticZopSync('000000111');
- $data[] = [
- 'routes' => [
- json_decode($this->itemScanDate49hBefore()),
- ],
- "logisticNum" => "000000111",
- ];
- $result = $logisticZopSync->transformRoutes($data);
- $this->assertEquals('派件异常', $result[0]['exception_type']);
- }
- /**
- * @return false|string
- */
- private function itemScanDate25hBefore()
- {
- return json_encode([
- 'country' => 'China',
- 'signMan' => null,
- 'operateUserPhone' => '17717571635',
- 'weight' => null,
- 'billCode' => null,
- 'operateUserCode' => '02141',
- 'preOrNextSite' => null,
- 'scanDate' => now()->subHours(25)->getTimestamp() * 1000,
- 'scanSite' => [
- 'isCenter' => 'F',
- 'code' => '02141',
- 'isTransfer' => 0,
- 'phone' => '60664064',
- 'city' => '""',
- 'name' => '九亭',
- 'siteId' => '2745',
- 'id' => '2745',
- 'prov' => '上海',
- ],
- 'extend' => "{'optReasonEn':'Parcel scanned by site'}",
- 'operateUser' => '笔记本',
- 'scanType' => '收件',
- ]);
- }
- /**
- * @return false|string
- */
- private function itemScanDate73hBefore()
- {
- return json_encode([
- 'country' => 'China',
- 'signMan' => null,
- 'operateUserPhone' => '17717571635',
- 'weight' => null,
- 'billCode' => null,
- 'operateUserCode' => '02141',
- 'preOrNextSite' => null,
- 'scanDate' => now()->subHours(73)->getTimestamp() * 1000,
- 'scanSite' => [
- 'isCenter' => 'F',
- 'code' => '02141',
- 'isTransfer' => 0,
- 'phone' => '60664064',
- 'city' => '""',
- 'name' => '九亭',
- 'siteId' => '2745',
- 'id' => '2745',
- 'prov' => '上海',
- ],
- 'extend' => "{'optReasonEn':'Parcel scanned by site'}",
- 'operateUser' => '笔记本',
- 'scanType' => '收件',
- ]);
- }
- /**
- * @return false|string
- */
- private function itemScanDate49hBefore()
- {
- return json_encode([
- 'country' => 'China',
- 'signMan' => null,
- 'operateUserPhone' => '17717571635',
- 'weight' => null,
- 'billCode' => null,
- 'operateUserCode' => '02141',
- 'preOrNextSite' => null,
- 'scanDate' => now()->subHours(49)->getTimestamp() * 1000,
- 'scanSite' => [
- 'isCenter' => 'F',
- 'code' => '02141',
- 'isTransfer' => 0,
- 'phone' => '60664064',
- 'city' => '""',
- 'name' => '九亭',
- 'siteId' => '2745',
- 'id' => '2745',
- 'prov' => '上海',
- ],
- 'extend' => "{'optReasonEn':'Parcel scanned by site'}",
- 'operateUser' => '笔记本',
- 'scanType' => '派件',
- ]);
- }
- /**
- * @return false|string
- */
- private function item2()
- {
- return json_encode([]);
- }
- /**
- * @test
- */
- public function arr_test()
- {
- $data = [];
- $data['aa'] = "vbbb";
- dd(array_key_exists('aa',$data));
- }
- }
|