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 82fa1f1e
authored
Jun 09, 2021
by
Евгений
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Тесты
1 parent
6f86a701
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
100 additions
and
0 deletions
tests/Unit/UpdateCampaignsTest.php
tests/Unit/UpdateCampaignsTest.php
0 → 100644
View file @
82fa1f1
<?php
namespace
Tests\Unit
;
use
App\Jobs\ProcessCallLimitedAPI
;
use
App\Models\Account
;
use
App\Models\Campaigns
;
use
App\Models\Dictionary
;
use
App\Models\Pivots\DictionaryCampaign
;
use
App\Models\Tokens
;
use
App\Models\User
;
use
App\Service\Contract\API
;
use
App\Service\Requests\APIRequest
;
use
Carbon\Carbon
;
use
Illuminate\Support\Facades\Queue
;
use
Tests\TestCase
;
use
Illuminate\Foundation\Testing\RefreshDatabase
;
class
UpdateCampaignsTest
extends
TestCase
{
use
RefreshDatabase
;
private
$request
;
private
$user
;
private
$token_main
;
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_main
=
factory
(
Tokens
::
class
)
->
create
([
'type'
=>
Tokens
::
MAIN
,
'created_by'
=>
$this
->
user
->
id
,
]);
$this
->
token
=
factory
(
Tokens
::
class
)
->
create
([
'limit'
=>
20
,
'created_by'
=>
$this
->
user
->
getKey
()
]);
$this
->
request
=
APIRequest
::
getInstance
(
API
::
YANDEX
)
->
setToken
(
$this
->
token_main
)
->
getRequest
(
'Campaigns'
,
'update'
);
$this
->
campaign
=
factory
(
Campaigns
::
class
)
->
create
([
'manage'
=>
true
,
'token'
=>
$this
->
token_main
->
getKey
(),
]);
$this
->
dictionaries
=
factory
(
Dictionary
::
class
,
12
)
->
create
([
'token_id'
=>
$this
->
token
->
getKey
(),
'type'
=>
Dictionary
::
CITY
,
]);
$this
->
campaign
->
dictionaries
()
->
syncWithoutDetaching
(
$this
->
dictionaries
->
keyBy
(
Campaigns
::
getModel
()
->
getKeyName
())
->
transform
(
function
(
Dictionary
$dictionary
)
{
return
DictionaryCampaign
::
copyPropertyFromMain
(
$this
->
campaign
);
})
->
all
()
);
}
function
test_get_campaigns_for_update
(){
$dictionaryCampaign
=
DictionaryCampaign
::
first
();
$dictionaryCampaign
[
'external_id'
]
=
1
;
$data
[
'external_updated_at'
]
=
Carbon
::
now
();
if
(
$dictionaryCampaign
->
updated
)
{
$data
[
'updated_need'
]
=
Carbon
::
now
();
}
$dictionaryCampaign
->
update
(
$data
);
$tokens
=
Tokens
::
whereHas
(
'dictionaryCampaignsEnabledForExternalUpdatedNeedUpdated'
)
->
with
(
'dictionaryCampaignsEnabledForExternalUpdatedNeedUpdated.campaign'
)
->
where
(
'type'
,
'!='
,
Tokens
::
MAIN
)
->
get
();
Queue
::
fake
();
foreach
(
$tokens
as
$token
)
{
$this
->
assertEquals
(
$dictionaryCampaign
->
toArray
()[
'external_id'
],
$token
->
dictionaryCampaignsEnabledForExternalUpdatedNeedUpdated
->
toArray
()[
0
][
'external_id'
]);
$this
->
request
->
call
([
'dictionaryCampaigns'
=>
$token
->
dictionaryCampaignsEnabledForExternalUpdatedNeedUpdated
,
]);
Queue
::
assertPushed
(
ProcessCallLimitedAPI
::
class
);
}
}
}
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