Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
Письменов Дмитрий Иванович
/
yourroomads
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Settings
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 081c9b3b
authored
May 12, 2021
by
Евгений
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
доработка кампаний
Тесты загрузки регионов
1 parent
91e43e51
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
104 additions
and
5 deletions
app/Service/Requests/Direct/GetDictionaries.php
database/migrations/2021_05_11_084828_create_campaigns_table.php
tests/Unit/GetDictionariesTest.php
app/Service/Requests/Direct/GetDictionaries.php
View file @
081c9b3
...
...
@@ -11,10 +11,9 @@ class GetDictionaries extends DirectRequest
{
protected
$next
;
function
call
(
$
next
=
null
,
$response
=
null
)
function
call
(
$
params
=
null
)
{
$this
->
next
=
$next
;
$this
->
requestPrepare
(
$response
);
$this
->
requestPrepare
(
$params
);
$process
=
new
ProcessCallLimitedAPI
(
$this
);
dispatch
(
$process
)
->
onQueue
(
'limits'
);
}
...
...
@@ -52,7 +51,7 @@ class GetDictionaries extends DirectRequest
}
}
private
function
requestPrepare
(
$
response
)
private
function
requestPrepare
(
$
params
)
{
$this
->
setService
(
'dictionaries'
);
$this
->
setMethod
(
'get'
);
...
...
database/migrations/2021_05_11_084828_create_campaigns_table.php
View file @
081c9b3
...
...
@@ -15,7 +15,7 @@ class CreateCampaignsTable extends Migration
{
Schema
::
create
(
'campaigns'
,
function
(
Blueprint
$table
)
{
$table
->
id
();
$table
->
bigInteger
(
'token'
);
$table
->
bigInteger
(
'token'
)
->
unsigned
()
;
$table
->
bigInteger
(
'external_id'
)
->
unique
();
$table
->
string
(
'Name'
,
255
)
->
nullable
();
$table
->
json
(
'TimeTargeting'
)
->
nullable
();
...
...
tests/Unit/GetDictionariesTest.php
0 → 100644
View file @
081c9b3
<?php
namespace
Tests\Unit
;
use
App\Jobs\ProcessCallLimitedAPI
;
use
App\Models\Account
;
use
App\Models\Campaigns
;
use
App\Models\Dictionary
;
use
App\Models\Tokens
;
use
App\Models\User
;
use
App\Service\Contract\API
;
use
App\Service\Requests\APIRequest
;
use
Illuminate\Support\Facades\Queue
;
use
Tests\TestCase
;
use
Illuminate\Foundation\Testing\RefreshDatabase
;
class
GetDictionariesTest
extends
TestCase
{
use
RefreshDatabase
;
private
$request
;
protected
function
setUp
()
:
void
{
parent
::
setUp
();
$account
=
Account
::
create
([
'name'
=>
'Acme Corporation'
]);
$this
->
user
=
factory
(
User
::
class
)
->
create
([
'account_id'
=>
$account
->
id
,
'first_name'
=>
'John'
,
'last_name'
=>
'Doe'
,
'email'
=>
'johndoe@example.com'
,
'owner'
=>
true
,
]);
$this
->
token
=
factory
(
Tokens
::
class
)
->
create
([
'created_by'
=>
$this
->
user
->
id
]);
$this
->
request
=
APIRequest
::
getInstance
(
API
::
YANDEX
)
->
setToken
(
$this
->
token
)
->
getRequest
(
'dictionaries'
,
'get'
);
}
public
function
testCallApi
()
{
Queue
::
fake
();
Queue
::
assertNothingPushed
();
$this
->
request
->
call
();
Queue
::
assertPushed
(
ProcessCallLimitedAPI
::
class
);
}
public
function
testHandleApi
()
{
$this
->
request
->
handle
([
'result'
=>
[
'GeoRegions'
=>
[
[
'GeoRegionId'
=>
1
,
'GeoRegionName'
=>
'test'
,
'GeoRegionType'
=>
'World'
,
'ParentId'
=>
0
],
[
'GeoRegionId'
=>
2
,
'GeoRegionName'
=>
'test2'
,
'GeoRegionType'
=>
'City'
,
'ParentId'
=>
1
],
[
'GeoRegionId'
=>
3
,
'GeoRegionName'
=>
'test3'
,
'GeoRegionType'
=>
'Village'
,
'ParentId'
=>
2
],
]
]
]);
$this
->
assertEquals
(
3
,
Dictionary
::
all
()
->
count
());
$city
=
Dictionary
::
where
(
'region_id'
,
1
)
->
first
();
$this
->
assertEquals
(
$city
->
name
,
'test'
);
$this
->
assertEquals
(
$city
->
type
,
'World'
);
$this
->
assertEquals
(
$city
->
type
,
'World'
);
$city
=
Dictionary
::
where
(
'region_id'
,
2
)
->
first
();
$this
->
assertEquals
(
$city
->
name
,
'test2'
);
$this
->
assertEquals
(
$city
->
type
,
'City'
);
$this
->
assertEquals
(
$city
->
parent_id
,
1
);
$city
=
Dictionary
::
where
(
'region_id'
,
3
)
->
first
();
$this
->
assertEquals
(
$city
->
name
,
'test3'
);
$this
->
assertEquals
(
$city
->
type
,
'Village'
);
$this
->
assertEquals
(
$city
->
parent_id
,
2
);
}
}
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment