CostsTest.php 1.99 KB
<?php

namespace Tests\Unit;

use App\Models\Account;
use App\Models\Tokens;
use App\Models\User;
use App\Service\Contract\API;
use App\Service\Costs;
use App\Service\Limits;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Illuminate\Support\Facades\Date;
use Tests\TestCase;
use Illuminate\Foundation\Testing\RefreshDatabase;

class CostsTest extends TestCase
{
    use RefreshDatabase;

    private $costs;
    private $request;

    protected function setUp(): void
    {
        parent::setUp();

        $this->costs = new Costs();
        $this->request = \App\Service\Requests\APIRequest::getInstance(API::YANDEX);
    }

    public function testGetCostCall(){
        $this->request->setService('AdExtensions');
        $this->request->setMethod('add');
        $limit = $this->costs->getCostCall($this->request);
        $this->assertEquals($limit, 5);

        $this->request->setService('AdGroups');
        $this->request->setMethod('update');
        $limit = $this->costs->getCostCall($this->request);
        $this->assertEquals($limit, 20);

        $this->request->setService('Keywords');
        $this->request->setMethod('get');
        $limit = $this->costs->getCostCall($this->request);
        $this->assertEquals($limit, 15);
    }

    public function testGetCostObject(){
        $this->request->setService('Keywords');
        $this->request->setMethod('get');
        $this->request->setParams(['FieldNames' => []]);
        $limit = $this->costs->getCostObject($this->request);
        $this->assertEquals($limit, 1/2000);

        $this->request->setService('Keywords');
        $this->request->setMethod('get');
        $this->request->setParams(['FieldNames' => ['Productivity']]);
        $limit = $this->costs->getCostObject($this->request);
        $this->assertEquals($limit, 3/2000);

        $this->request->setService('SmartAdTargets');
        $this->request->setMethod('get');
        $limit = $this->costs->getCostObject($this->request);
        $this->assertEquals($limit, 1);
    }

}