matchMethod(RequestMethod::GET) ->reply(200) ->withBody($json); $client = TestClientFactory::createClient($mock->getClient()); $response = $client->integration->get('mg-fbmessenger'); self::assertModelEqualsToResponse($json, $response); } public function testMgTransportEdit(): void { $json = <<<'EOF' { "success": true, "info": { "mgTransport": { "endpointUrl": "https://mg-s1.retailcrm.pro", "token": "token" } } } EOF; $module = new IntegrationModule(); $module->integrations = new Integrations(); $module->integrations->mgTransport = new TransportConfiguration(); $module->code = 'mg-fbmessenger'; $module->clientId = 'e029f3dd545147c6428d12d9524f33b806e9310947430773c6c82719e4c41904'; $module->integrationCode = 'mg-fbmessenger'; $module->name = 'Facebook Messenger'; $module->logo = 'https://mg-tp-fbm-s1.retailcrm.pro/static/fbmessenger_logo.svg'; $module->baseUrl = 'https://mg-tp-fbm-s1.retailcrm.pro/'; $module->actions = ['activity' => '/actions/activity']; $module->accountUrl = 'https://mg-tp-fbm-s1.retailcrm.pro/settings/clientId'; $module->integrations->mgTransport->webhookUrl = 'https://mg-tp-fbm-s1.retailcrm.pro/webhook/'; $request = new IntegrationModulesEditRequest($module); $mock = static::createApiMockBuilder('integration-modules/mg-fbmessenger/edit'); $mock->matchMethod(RequestMethod::POST) ->matchBody(static::encodeForm($request)) ->reply(200) ->withBody($json); $client = TestClientFactory::createClient($mock->getClient()); $response = $client->integration->edit('mg-fbmessenger', $request); self::assertModelEqualsToResponse($json, $response); } public function testPaymentEdit(): void { $json = <<<'EOF' { "success": true, "info": [] } EOF; $module = new IntegrationModule(); $module->integrations = new Integrations(); $module->integrations->payment = new PaymentConfiguration(); $module->integrations->payment->actions = new Actions(); $module->code = 'test-payment-integration'; $module->clientId = 'test-payment-integration'; $module->integrationCode = 'test-payment-integration'; $module->name = 'Test Payment Integration'; $module->baseUrl = 'https://example.com'; $module->accountUrl = 'https://example.com'; $module->integrations->payment->shops = [ new Shop('moysklad', 'МойСклад', true), new Shop('aliexpress', 'AliExpress', true), ]; $module->integrations->payment->currencies = [Currency::USD, Currency::EUR, Currency::RUB]; $module->integrations->payment->invoiceTypes = ['link']; $module->integrations->payment->actions->create = 'payment/create'; $module->integrations->payment->actions->approve = 'payment/approve'; $module->integrations->payment->actions->cancel = 'payment/cancel'; $module->integrations->payment->actions->refund = 'payment/refund'; $request = new IntegrationModulesEditRequest($module); $mock = static::createApiMockBuilder('integration-modules/test-payment-integration/edit'); $mock->matchMethod(RequestMethod::POST) ->matchBody(static::encodeForm($request)) ->reply(200) ->withBody($json); $client = TestClientFactory::createClient($mock->getClient()); $response = $client->integration->edit('test-payment-integration', $request); self::assertModelEqualsToResponse($json, $response); } public function testDeliveryEdit(): void { $json = <<<'EOF' { "success": true, "info": { "billingInfo": { "price": 2, "priceWithDiscount": 1, "currency": { "name": "Рубль", "shortName": "руб.", "code": "RUB" }, "billingType": "fixed" }, "deliveryType": { "id": 1, "code": "ozon-integration-10" } } } EOF; $module = new IntegrationModule(); $module->clientId = '34fa3509-92f3-4faf-87d5-2efbd88cb4cb'; $module->name = 'Ozon seller'; $module->code = 'ozon-integration-10'; $module->integrationCode = 'ozon-integration'; $module->logo = 'https://localhost/images/logo.svg'; $module->accountUrl = 'https://localhost/login'; $module->baseUrl = 'https://localhost'; $module->active = true; $module->actions = [ 'activity' => '/api/callback/v1/activity' ]; $module->availableCountries = ['RU']; $deliveryConfiguration = new DeliveryConfiguration(); $deliveryConfiguration->actions = [ 'get' => '/api/callback/v1/get', 'print' => '/api/callback/v1/print' ]; $deliveryConfiguration->payerType = ['receiver']; $deliveryConfiguration->platePrintLimit = 20; $deliveryConfiguration->rateDeliveryCost = true; $deliveryConfiguration->allowPackages = false; $deliveryConfiguration->codAvailable = false; $deliveryConfiguration->plateList = $this->createPlateList(); $integrations = new Integrations(); $integrations->delivery = $deliveryConfiguration; $module->integrations = $integrations; $request = new IntegrationModulesEditRequest($module); $mock = static::createApiMockBuilder('integration-modules/ozon-integration-10/edit'); $mock->matchMethod(RequestMethod::POST) ->matchBody(static::encodeForm($request)) ->reply(200) ->withBody($json); $client = TestClientFactory::createClient($mock->getClient()); $response = $client->integration->edit('ozon-integration-10', $request); self::assertModelEqualsToResponse($json, $response); } /** * @return Plate[] */ private function createPlateList(): array { $plateList = []; $plates = [ [ 'type' => 'order', 'code' => 'sticker', 'label' => 'Наклейка OZON', ], [ 'type' => 'order', 'code' => 'act', 'label' => 'Акт OZON', ], ]; foreach ($plates as $plate) { $plateModel = new Plate(); $plateModel->code = $plate['code']; $plateModel->type = $plate['type']; $plateModel->label = $plate['label']; $plateList[] = $plateModel; } return $plateList; } }