LogisticZopSyncTest.php 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. <?php
  2. namespace Tests\Feature;
  3. use App\Jobs\LogisticZopSync;
  4. use App\Order;
  5. use App\OrderPackage;
  6. use Illuminate\Database\Eloquent\Model;
  7. use Illuminate\Foundation\Testing\RefreshDatabase;
  8. use Illuminate\Foundation\Testing\WithFaker;
  9. use Tests\TestCase;
  10. class LogisticZopSyncTest extends TestCase
  11. {
  12. protected $order;
  13. /**
  14. * A basic feature test example.
  15. *
  16. * @return void
  17. */
  18. // public function testExample()
  19. // {
  20. // LogisticZopSync::dispatch('73228022760994');
  21. // }
  22. protected function setUp(): void
  23. {
  24. parent::setUp(); // TODO: Change the autogenerated stub
  25. OrderPackage::query()->where('logistic_number', '000000111')->delete();
  26. }
  27. protected function tearDown(): void
  28. {
  29. OrderPackage::query()->where('logistic_number', '000000111')->delete();
  30. $this->order && $this->order->delete();
  31. parent::tearDown(); // TODO: Change the autogenerated stub
  32. }
  33. /**
  34. * @test
  35. */
  36. public function transformRoutes疑似库内丢件Test()
  37. {
  38. factory(OrderPackage::class)->create(['logistic_number' => '000000111', 'sent_at' => now()->subHours(5)]);
  39. $logisticZopSync = new LogisticZopSync('000000111');
  40. $data[] = [
  41. 'routes' => [
  42. ],
  43. "logisticNum" => "000000111",
  44. ];
  45. $result = $logisticZopSync->transformRoutes($data);
  46. $this->assertEquals('疑似库内丢件', $result[0]['exception_type']);
  47. }
  48. /**
  49. * @test
  50. */
  51. public function transformRoutes中转异常Test()
  52. {
  53. $order = factory(Order::class)->create(['province' => '上海']);
  54. $this->order = $order;
  55. factory(OrderPackage::class)->create(['logistic_number' => '000000111', 'sent_at' => now()->subHours(5), 'order_id' => $order->id]);
  56. $logisticZopSync = new LogisticZopSync('000000111');
  57. $data[] = [
  58. 'routes' => [
  59. json_decode($this->itemScanDate25hBefore()),
  60. ],
  61. "logisticNum" => "000000111",
  62. ];
  63. $result = $logisticZopSync->transformRoutes($data);
  64. $this->assertEquals('中转异常', $result[0]['exception_type']);
  65. }
  66. /**
  67. * @test
  68. */
  69. public function transformRoutes疑似丢件Test()
  70. {
  71. $order = factory(Order::class)->create(['province' => '上海']);
  72. $this->order = $order;
  73. factory(OrderPackage::class)->create(['logistic_number' => '000000111', 'sent_at' => now()->subHours(5), 'order_id' => $order->id]);
  74. $logisticZopSync = new LogisticZopSync('000000111');
  75. $data[] = [
  76. 'routes' => [
  77. json_decode($this->itemScanDate73hBefore()),
  78. ],
  79. "logisticNum" => "000000111",
  80. ];
  81. $result = $logisticZopSync->transformRoutes($data);
  82. $this->assertEquals('疑似丢件', $result[0]['exception_type']);
  83. }
  84. /**
  85. * @test
  86. */
  87. public function transformRoutes派送异常Test()
  88. {
  89. $order = factory(Order::class)->create(['province' => '上海']);
  90. $this->order = $order;
  91. factory(OrderPackage::class)->create(['logistic_number' => '000000111', 'sent_at' => now()->subHours(5), 'order_id' => $order->id]);
  92. $logisticZopSync = new LogisticZopSync('000000111');
  93. $data[] = [
  94. 'routes' => [
  95. json_decode($this->itemScanDate49hBefore()),
  96. ],
  97. "logisticNum" => "000000111",
  98. ];
  99. $result = $logisticZopSync->transformRoutes($data);
  100. $this->assertEquals('派件异常', $result[0]['exception_type']);
  101. }
  102. /**
  103. * @return false|string
  104. */
  105. private function itemScanDate25hBefore()
  106. {
  107. return json_encode([
  108. 'country' => 'China',
  109. 'signMan' => null,
  110. 'operateUserPhone' => '17717571635',
  111. 'weight' => null,
  112. 'billCode' => null,
  113. 'operateUserCode' => '02141',
  114. 'preOrNextSite' => null,
  115. 'scanDate' => now()->subHours(25)->getTimestamp() * 1000,
  116. 'scanSite' => [
  117. 'isCenter' => 'F',
  118. 'code' => '02141',
  119. 'isTransfer' => 0,
  120. 'phone' => '60664064',
  121. 'city' => '""',
  122. 'name' => '九亭',
  123. 'siteId' => '2745',
  124. 'id' => '2745',
  125. 'prov' => '上海',
  126. ],
  127. 'extend' => "{'optReasonEn':'Parcel scanned by site'}",
  128. 'operateUser' => '笔记本',
  129. 'scanType' => '收件',
  130. ]);
  131. }
  132. /**
  133. * @return false|string
  134. */
  135. private function itemScanDate73hBefore()
  136. {
  137. return json_encode([
  138. 'country' => 'China',
  139. 'signMan' => null,
  140. 'operateUserPhone' => '17717571635',
  141. 'weight' => null,
  142. 'billCode' => null,
  143. 'operateUserCode' => '02141',
  144. 'preOrNextSite' => null,
  145. 'scanDate' => now()->subHours(73)->getTimestamp() * 1000,
  146. 'scanSite' => [
  147. 'isCenter' => 'F',
  148. 'code' => '02141',
  149. 'isTransfer' => 0,
  150. 'phone' => '60664064',
  151. 'city' => '""',
  152. 'name' => '九亭',
  153. 'siteId' => '2745',
  154. 'id' => '2745',
  155. 'prov' => '上海',
  156. ],
  157. 'extend' => "{'optReasonEn':'Parcel scanned by site'}",
  158. 'operateUser' => '笔记本',
  159. 'scanType' => '收件',
  160. ]);
  161. }
  162. /**
  163. * @return false|string
  164. */
  165. private function itemScanDate49hBefore()
  166. {
  167. return json_encode([
  168. 'country' => 'China',
  169. 'signMan' => null,
  170. 'operateUserPhone' => '17717571635',
  171. 'weight' => null,
  172. 'billCode' => null,
  173. 'operateUserCode' => '02141',
  174. 'preOrNextSite' => null,
  175. 'scanDate' => now()->subHours(49)->getTimestamp() * 1000,
  176. 'scanSite' => [
  177. 'isCenter' => 'F',
  178. 'code' => '02141',
  179. 'isTransfer' => 0,
  180. 'phone' => '60664064',
  181. 'city' => '""',
  182. 'name' => '九亭',
  183. 'siteId' => '2745',
  184. 'id' => '2745',
  185. 'prov' => '上海',
  186. ],
  187. 'extend' => "{'optReasonEn':'Parcel scanned by site'}",
  188. 'operateUser' => '笔记本',
  189. 'scanType' => '派件',
  190. ]);
  191. }
  192. /**
  193. * @return false|string
  194. */
  195. private function item2()
  196. {
  197. return json_encode([]);
  198. }
  199. }