#feature: update SQL generator
This commit is contained in:
@@ -0,0 +1,133 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Mockery;
|
||||
use Tests\TestCase;
|
||||
|
||||
class SqlGeneratorTest extends TestCase
|
||||
{
|
||||
public function test_check_production_countries_requires_production_codes(): void
|
||||
{
|
||||
$response = $this->postJson('/api/sql-generator/production-countries/check', []);
|
||||
|
||||
$response->assertStatus(422);
|
||||
$response->assertJson([
|
||||
'success' => false,
|
||||
'message' => '请求参数验证失败',
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_check_production_countries_returns_country_codes_from_crm(): void
|
||||
{
|
||||
$connection = Mockery::mock();
|
||||
DB::shouldReceive('connection')
|
||||
->times(2)
|
||||
->with('crmslave')
|
||||
->andReturn($connection);
|
||||
|
||||
$productionBuilder = Mockery::mock();
|
||||
$productionBuilder->shouldReceive('join')
|
||||
->once()
|
||||
->with('ea_production_cstm as epc', 'ep.id', '=', 'epc.id_c')
|
||||
->andReturnSelf();
|
||||
$productionBuilder->shouldReceive('where')
|
||||
->once()
|
||||
->with('ep.deleted', 0)
|
||||
->andReturnSelf();
|
||||
$productionBuilder->shouldReceive('whereIn')
|
||||
->once()
|
||||
->with('ep.name', ['M20260508006905'])
|
||||
->andReturnSelf();
|
||||
$productionBuilder->shouldReceive('select')
|
||||
->once()
|
||||
->with([
|
||||
'ep.name as production_code',
|
||||
'epc.ea_case_id_c',
|
||||
'epc.ea_businessorder_id_c',
|
||||
'epc.ea_salesorder_id_c',
|
||||
])
|
||||
->andReturnSelf();
|
||||
$productionBuilder->shouldReceive('get')
|
||||
->once()
|
||||
->andReturn(collect([
|
||||
(object) [
|
||||
'production_code' => 'M20260508006905',
|
||||
'ea_case_id_c' => '',
|
||||
'ea_businessorder_id_c' => '',
|
||||
'ea_salesorder_id_c' => 'sales-order-1',
|
||||
],
|
||||
]));
|
||||
|
||||
$salesOrderBuilder = Mockery::mock();
|
||||
$salesOrderBuilder->shouldReceive('join')
|
||||
->once()
|
||||
->with('accounts_ea_salesorder_1_c as aes1c', Mockery::type('Closure'))
|
||||
->andReturnSelf();
|
||||
$salesOrderBuilder->shouldReceive('join')
|
||||
->once()
|
||||
->with('accounts as a_base', 'a_base.id', '=', 'aes1c.accounts_ea_salesorder_1accounts_ida')
|
||||
->andReturnSelf();
|
||||
$salesOrderBuilder->shouldReceive('join')
|
||||
->once()
|
||||
->with('accounts_cstm as ac', 'ac.id_c', '=', 'aes1c.accounts_ea_salesorder_1accounts_ida')
|
||||
->andReturnSelf();
|
||||
$salesOrderBuilder->shouldReceive('where')
|
||||
->once()
|
||||
->with('es.deleted', 0)
|
||||
->andReturnSelf();
|
||||
$salesOrderBuilder->shouldReceive('where')
|
||||
->once()
|
||||
->with('a_base.deleted', 0)
|
||||
->andReturnSelf();
|
||||
$salesOrderBuilder->shouldReceive('whereIn')
|
||||
->once()
|
||||
->with('es.id', ['sales-order-1'])
|
||||
->andReturnSelf();
|
||||
$salesOrderBuilder->shouldReceive('whereNotNull')
|
||||
->once()
|
||||
->with('ac.country_c')
|
||||
->andReturnSelf();
|
||||
$salesOrderBuilder->shouldReceive('select')
|
||||
->once()
|
||||
->with([
|
||||
'es.id as entity_id',
|
||||
'ac.country_c as country',
|
||||
'ac.province_c as province',
|
||||
])
|
||||
->andReturnSelf();
|
||||
$salesOrderBuilder->shouldReceive('get')
|
||||
->once()
|
||||
->andReturn(collect([
|
||||
(object) [
|
||||
'entity_id' => 'sales-order-1',
|
||||
'country' => '840',
|
||||
'province' => '',
|
||||
],
|
||||
]));
|
||||
|
||||
$connection->shouldReceive('table')
|
||||
->once()
|
||||
->with('ea_production as ep')
|
||||
->andReturn($productionBuilder);
|
||||
$connection->shouldReceive('table')
|
||||
->once()
|
||||
->with('ea_salesorder as es')
|
||||
->andReturn($salesOrderBuilder);
|
||||
|
||||
$response = $this->postJson('/api/sql-generator/production-countries/check', [
|
||||
'production_codes' => ['M20260508006905'],
|
||||
]);
|
||||
|
||||
$response->assertStatus(200);
|
||||
$response->assertJson([
|
||||
'success' => true,
|
||||
'data' => [
|
||||
'production_countries' => [
|
||||
'M20260508006905' => ['US'],
|
||||
],
|
||||
],
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user