Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F120826752
DiscountsTest.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Authored By
Unknown
Size
2 KB
Referenced Files
None
Subscribers
None
DiscountsTest.php
View Options
<?php
namespace
Tests\Feature\Controller\Admin
;
use
App\Discount
;
use
Tests\TestCase
;
class
DiscountsTest
extends
TestCase
{
/**
* {@inheritDoc}
*/
public
function
setUp
():
void
{
parent
::
setUp
();
self
::
useAdminUrl
();
}
/**
* {@inheritDoc}
*/
public
function
tearDown
():
void
{
parent
::
tearDown
();
}
/**
* Test listing discounts (GET /api/v4/users/{user}/discounts)
*/
public
function
testuserDiscounts
():
void
{
$user
=
$this
->
getTestUser
(
'john@kolab.org'
);
$admin
=
$this
->
getTestUser
(
'jeroen@jeroen.jeroen'
);
// Non-admin user
$response
=
$this
->
actingAs
(
$user
)->
get
(
"api/v4/users/{$user->id}/discounts"
);
$response
->
assertStatus
(
403
);
// Admin user
$response
=
$this
->
actingAs
(
$admin
)->
get
(
"api/v4/users/{$user->id}/discounts"
);
$response
->
assertStatus
(
200
);
$json
=
$response
->
json
();
$discount_test
=
Discount
::
where
(
'code'
,
'TEST'
)->
first
();
$discount_free
=
Discount
::
where
(
'discount'
,
100
)->
first
();
$this
->
assertSame
(
3
,
$json
[
'count'
]);
$this
->
assertSame
(
$discount_test
->
id
,
$json
[
'list'
][
0
][
'id'
]);
$this
->
assertSame
(
$discount_test
->
discount
,
$json
[
'list'
][
0
][
'discount'
]);
$this
->
assertSame
(
$discount_test
->
code
,
$json
[
'list'
][
0
][
'code'
]);
$this
->
assertSame
(
$discount_test
->
description
,
$json
[
'list'
][
0
][
'description'
]);
$this
->
assertSame
(
'10% - Test voucher [TEST]'
,
$json
[
'list'
][
0
][
'label'
]);
$this
->
assertSame
(
$discount_free
->
id
,
$json
[
'list'
][
2
][
'id'
]);
$this
->
assertSame
(
$discount_free
->
discount
,
$json
[
'list'
][
2
][
'discount'
]);
$this
->
assertSame
(
$discount_free
->
code
,
$json
[
'list'
][
2
][
'code'
]);
$this
->
assertSame
(
$discount_free
->
description
,
$json
[
'list'
][
2
][
'description'
]);
$this
->
assertSame
(
'100% - Free Account'
,
$json
[
'list'
][
2
][
'label'
]);
// A user in another tenant
$user
=
$this
->
getTestUser
(
'user@sample-tenant.dev-local'
);
$response
=
$this
->
actingAs
(
$admin
)->
get
(
"api/v4/users/{$user->id}/discounts"
);
$response
->
assertStatus
(
200
);
$json
=
$response
->
json
();
$discount
=
Discount
::
withObjectTenantContext
(
$user
)->
where
(
'discount'
,
10
)->
first
();
$this
->
assertSame
(
1
,
$json
[
'count'
]);
$this
->
assertSame
(
$discount
->
id
,
$json
[
'list'
][
0
][
'id'
]);
$this
->
assertSame
(
$discount
->
discount
,
$json
[
'list'
][
0
][
'discount'
]);
$this
->
assertSame
(
$discount
->
code
,
$json
[
'list'
][
0
][
'code'
]);
$this
->
assertSame
(
$discount
->
description
,
$json
[
'list'
][
0
][
'description'
]);
$this
->
assertSame
(
'10% - '
.
$discount
->
description
,
$json
[
'list'
][
0
][
'label'
]);
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Fri, Apr 24, 11:00 AM (1 w, 4 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
18852410
Default Alt Text
DiscountsTest.php (2 KB)
Attached To
Mode
rK kolab
Attached
Detach File
Event Timeline