|
|
@@ -4,6 +4,8 @@ namespace Tests\Unit\Customer;
|
|
|
|
|
|
use App\Feature;
|
|
|
use App\Services\FeatureService;
|
|
|
+use Illuminate\Support\Str;
|
|
|
+use Ramsey\Uuid\Uuid;
|
|
|
use Tests\TestCase;
|
|
|
|
|
|
class FeatureServiceTest extends TestCase
|
|
|
@@ -17,59 +19,19 @@ class FeatureServiceTest extends TestCase
|
|
|
parent::setUp();
|
|
|
$this->service = app(FeatureService::class);
|
|
|
$this->data = [
|
|
|
- [
|
|
|
- "type" => "商品名称",
|
|
|
- "logic" => "包含",
|
|
|
- "describe"=>"衣服",
|
|
|
- ],[
|
|
|
- "type" => "订单类型",
|
|
|
- "logic" => "不包含",
|
|
|
- "describe"=>"创建",
|
|
|
- ],[
|
|
|
- "type" => "承运商",
|
|
|
- "logic" => "等于",
|
|
|
- "describe"=>"顺丰",
|
|
|
- ],[
|
|
|
- "type" => "店铺类型",
|
|
|
- "logic" => "不包含",
|
|
|
- "describe"=>"日用品",
|
|
|
- ],[
|
|
|
- "type" => "商品名称",
|
|
|
- "logic" => "不包含",
|
|
|
- "describe"=>"鞋子",
|
|
|
- ],[
|
|
|
- "type" => "订单类型",
|
|
|
- "logic" => "包含",
|
|
|
- "describe"=>"取消",
|
|
|
- ],[
|
|
|
- "type" => "商品名称",
|
|
|
- "logic" => "包含",
|
|
|
- "describe"=>"测试",
|
|
|
- ],[
|
|
|
- "type" => "订单类型",
|
|
|
- "logic" => "不包含",
|
|
|
- "describe"=>"实际",
|
|
|
- ],[
|
|
|
- "type" => "店铺类型",
|
|
|
- "logic" => "等于",
|
|
|
- "describe"=>"测试",
|
|
|
- ]
|
|
|
+ "models" => factory(Feature::class,3)->create()->toArray(),
|
|
|
];
|
|
|
}
|
|
|
|
|
|
public function testGetMapArray(){
|
|
|
- factory(Feature::class,3)->create();
|
|
|
$models = $this->service->getMapArray();
|
|
|
$this->assertGreaterThanOrEqual(3,count($models));
|
|
|
}
|
|
|
public function testTranslationFeature(){
|
|
|
- $model1 = factory(Feature::class)->create($this->data[0]);
|
|
|
- $model2 = factory(Feature::class)->create($this->data[1]);
|
|
|
- $model3 = factory(Feature::class)->create($this->data[2]);
|
|
|
- $str = $model1->id."&(".$model2->id."|".$model3->id.")";
|
|
|
+ $str = $this->data["models"][0]["id"]."&(".$this->data["models"][1]["id"]."|".$this->data["models"][2]["id"].")";
|
|
|
$result = $this->service->translationFeature($str);
|
|
|
$this->assertEquals(3,count($result));
|
|
|
- $this->assertEquals("订单类型",$result[1]["type"]);
|
|
|
+ $this->assertEquals($this->data["models"][1]["type"],$result[1]["type"]);
|
|
|
$this->assertEquals(false,$result[0]["strategyGroupStartSign"]);
|
|
|
$this->assertEquals(true,$result[1]["strategyGroupStartSign"]);
|
|
|
$this->assertEquals("并且",$result[1]["calculation"]);
|
|
|
@@ -77,34 +39,32 @@ class FeatureServiceTest extends TestCase
|
|
|
$this->assertEquals("或",$result[2]["calculation"]);
|
|
|
}
|
|
|
public function testAnalysisFeature(){
|
|
|
- $model1 = factory(Feature::class)->create($this->data[4]);
|
|
|
- $model2 = factory(Feature::class)->create($this->data[5]);
|
|
|
- $model3 = factory(Feature::class)->create($this->data[3]);
|
|
|
+ $models = $this->data["models"];
|
|
|
$params = [
|
|
|
[
|
|
|
"strategyGroupStartSign" => true,
|
|
|
"calculation" => "",
|
|
|
- "type"=>"商品名称",
|
|
|
- "logic"=>"不包含",
|
|
|
- "describe"=>"鞋子",
|
|
|
+ "type"=>$models[0]["type"],
|
|
|
+ "logic"=>$models[0]["logic"],
|
|
|
+ "describe"=>$models[0]["describe"],
|
|
|
"strategyGroupEndSign" => false,
|
|
|
],[
|
|
|
"strategyGroupStartSign" => false,
|
|
|
"calculation" => "并且",
|
|
|
- "type"=>"订单类型",
|
|
|
- "logic"=>"包含",
|
|
|
- "describe"=>"取消",
|
|
|
+ "type"=>$models[1]["type"],
|
|
|
+ "logic"=>$models[1]["logic"],
|
|
|
+ "describe"=>$models[1]["describe"],
|
|
|
"strategyGroupEndSign" => true,
|
|
|
],[
|
|
|
"strategyGroupStartSign" => false,
|
|
|
"calculation" => "或",
|
|
|
- "type"=>"店铺类型",
|
|
|
- "logic"=>"不包含",
|
|
|
- "describe"=>"日用品",
|
|
|
+ "type"=>$models[2]["type"],
|
|
|
+ "logic"=>$models[2]["logic"],
|
|
|
+ "describe"=>$models[2]["describe"],
|
|
|
"strategyGroupEndSign" => false,
|
|
|
]
|
|
|
];
|
|
|
- $expected = "(".$model1->id."&".$model2->id.")|".$model3->id;
|
|
|
+ $expected = "(".$models[0]["id"]."&".$models[1]["id"].")|".$models[2]["id"];
|
|
|
$result = $this->service->analysisFeature($params);
|
|
|
$this->assertIsArray($result);
|
|
|
$this->assertCount(2,$result);
|
|
|
@@ -112,9 +72,24 @@ class FeatureServiceTest extends TestCase
|
|
|
$this->assertEquals($expected,$result["feature"]);
|
|
|
}
|
|
|
public function testFormatFeature(){
|
|
|
- $model1 = factory(Feature::class)->make($this->data[0]);
|
|
|
- $model2 = factory(Feature::class)->make($this->data[1]);
|
|
|
- $model3 = factory(Feature::class)->make($this->data[2]);
|
|
|
+ $model1 = factory(Feature::class)->make([
|
|
|
+ "id" => 1,
|
|
|
+ "type"=>"商品名称",
|
|
|
+ "logic"=>"包含",
|
|
|
+ "describe"=>"衣服"
|
|
|
+ ]);
|
|
|
+ $model2 = factory(Feature::class)->make([
|
|
|
+ "id" => 2,
|
|
|
+ "type"=>"订单类型",
|
|
|
+ "logic"=>"不包含",
|
|
|
+ "describe"=>"创建"
|
|
|
+ ]);
|
|
|
+ $model3 = factory(Feature::class)->make([
|
|
|
+ "id"=>3,
|
|
|
+ "type"=>"承运商",
|
|
|
+ "logic"=>"等于",
|
|
|
+ "describe"=>"顺丰"
|
|
|
+ ]);
|
|
|
$features = [1=>$model1,2=>$model2,3=>$model3];
|
|
|
$result = $this->service->formatFeature($features,"1&(2|3)");
|
|
|
$expected = "商品名称 包含 衣服 并且 (订单类型 不包含 创建 或 承运商 等于 顺丰)";
|
|
|
@@ -125,22 +100,37 @@ class FeatureServiceTest extends TestCase
|
|
|
$this->assertEquals($expected,$result);
|
|
|
}
|
|
|
public function testMatchFeature(){
|
|
|
- $model1 = factory(Feature::class)->create($this->data[6]);
|
|
|
- $model2 = factory(Feature::class)->create($this->data[7]);
|
|
|
- $model3 = factory(Feature::class)->create($this->data[8]);
|
|
|
+ $model1 = factory(Feature::class)->create([
|
|
|
+ "type" => "商品名称",
|
|
|
+ "logic"=>"包含",
|
|
|
+ "describe"=>Uuid::uuid1(),
|
|
|
+ ]);
|
|
|
+ $model2 = factory(Feature::class)->create([
|
|
|
+ "type" => "订单类型",
|
|
|
+ "logic"=>"不包含",
|
|
|
+ "describe"=>Uuid::uuid1(),
|
|
|
+ ]);
|
|
|
+ $model3 = factory(Feature::class)->create([
|
|
|
+ "type" => "店铺类型",
|
|
|
+ "logic"=>"等于",
|
|
|
+ "describe"=>Uuid::uuid1(),
|
|
|
+ ]);
|
|
|
+ $this->data["models"][] = $model1->toArray();
|
|
|
+ $this->data["models"][] = $model2->toArray();
|
|
|
+ $this->data["models"][] = $model3->toArray();
|
|
|
$columnMapping = ["商品名称"=>"commodity","订单类型"=>"order","店铺类型"=>"shop"];
|
|
|
- $matchObject = ["commodity"=>"测试商品","order"=>"TEST","shop"=>"测试"];
|
|
|
+ $matchObject = ["commodity"=>Str::random(2).$model1->describe,"order"=>$model1->describe,"shop"=>$model3->describe];
|
|
|
$value = $model1->id."&(".$model2->id."&".$model3->id.")";
|
|
|
$result = $this->service->matchFeature($value,$columnMapping,$matchObject);
|
|
|
$this->assertEquals(true,$result);
|
|
|
- $matchObject = ["commodity"=>"测试商品","order"=>"实际","shop"=>"测试"];
|
|
|
+ $matchObject = ["commodity"=>$model1->describe.Str::random(2),"order"=>$model2->describe.Str::random(2),"shop"=>"1"];
|
|
|
$result = $this->service->matchFeature($value,$columnMapping,$matchObject);
|
|
|
$this->assertEquals(false,$result);
|
|
|
}
|
|
|
|
|
|
- public function testTruncate(){
|
|
|
- Feature::query()->truncate();
|
|
|
- $feature = Feature::query()->get();
|
|
|
- $this->assertCount(0,$feature);
|
|
|
+ public function tearDown(): void
|
|
|
+ {
|
|
|
+ Feature::destroy(array_column($this->data["models"],"id"));
|
|
|
+ parent::tearDown();
|
|
|
}
|
|
|
}
|