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 a6031dad
authored
May 12, 2021
by
Vladislav
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of
https://gitlab.veeble.ru/pismenov/yourroomads
2 parents
9c40e9d5
645a5632
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
106 additions
and
6 deletions
app/Console/Commands/LoadUpdatedCampaigns.php
app/Service/Requests/Direct/GetDictionaries.php
database/migrations/2021_05_11_084828_create_campaigns_table.php
tests/Unit/GetDictionariesTest.php
app/Console/Commands/LoadUpdatedCampaigns.php
View file @
a6031da
...
@@ -46,8 +46,9 @@ class LoadUpdatedCampaigns extends Command
...
@@ -46,8 +46,9 @@ class LoadUpdatedCampaigns extends Command
public
function
handle
()
public
function
handle
()
{
{
$campaigns
=
Campaigns
::
forUpdated
()
->
get
();
$campaigns
=
Campaigns
::
forUpdated
()
->
get
();
if
(
!
$campaigns
)
if
(
!
$campaigns
->
count
()){
return
;
return
;
}
$token
=
Tokens
::
where
(
'type'
,
Tokens
::
MAIN
)
->
first
();
$token
=
Tokens
::
where
(
'type'
,
Tokens
::
MAIN
)
->
first
();
if
(
!
$token
){
if
(
!
$token
){
...
...
app/Service/Requests/Direct/GetDictionaries.php
View file @
a6031da
...
@@ -11,10 +11,9 @@ class GetDictionaries extends DirectRequest
...
@@ -11,10 +11,9 @@ class GetDictionaries extends DirectRequest
{
{
protected
$next
;
protected
$next
;
function
call
(
$
next
=
null
,
$response
=
null
)
function
call
(
$
params
=
null
)
{
{
$this
->
next
=
$next
;
$this
->
requestPrepare
(
$params
);
$this
->
requestPrepare
(
$response
);
$process
=
new
ProcessCallLimitedAPI
(
$this
);
$process
=
new
ProcessCallLimitedAPI
(
$this
);
dispatch
(
$process
)
->
onQueue
(
'limits'
);
dispatch
(
$process
)
->
onQueue
(
'limits'
);
}
}
...
@@ -52,7 +51,7 @@ class GetDictionaries extends DirectRequest
...
@@ -52,7 +51,7 @@ class GetDictionaries extends DirectRequest
}
}
}
}
private
function
requestPrepare
(
$
response
)
private
function
requestPrepare
(
$
params
)
{
{
$this
->
setService
(
'dictionaries'
);
$this
->
setService
(
'dictionaries'
);
$this
->
setMethod
(
'get'
);
$this
->
setMethod
(
'get'
);
...
...
database/migrations/2021_05_11_084828_create_campaigns_table.php
View file @
a6031da
...
@@ -15,7 +15,7 @@ class CreateCampaignsTable extends Migration
...
@@ -15,7 +15,7 @@ class CreateCampaignsTable extends Migration
{
{
Schema
::
create
(
'campaigns'
,
function
(
Blueprint
$table
)
{
Schema
::
create
(
'campaigns'
,
function
(
Blueprint
$table
)
{
$table
->
id
();
$table
->
id
();
$table
->
bigInteger
(
'token'
);
$table
->
bigInteger
(
'token'
)
->
unsigned
()
;
$table
->
bigInteger
(
'external_id'
)
->
unique
();
$table
->
bigInteger
(
'external_id'
)
->
unique
();
$table
->
string
(
'name'
,
255
)
->
nullable
();
$table
->
string
(
'name'
,
255
)
->
nullable
();
$table
->
json
(
'time_targeting'
)
->
nullable
();
$table
->
json
(
'time_targeting'
)
->
nullable
();
...
...
tests/Unit/GetDictionariesTest.php
0 → 100644
View file @
a6031da
<?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