added it_get_user_data test

This commit is contained in:
Peter Papp
2021-03-03 09:39:56 +01:00
parent b38f04533c
commit b1c15bb6a7
3 changed files with 94 additions and 22 deletions

View File

@@ -18,6 +18,7 @@ class UserResource extends JsonResource
*/
public function toArray($request)
{
// TODO: zrefaktorovat
return [
'data' => [
'id' => (string)$this->id,
@@ -27,9 +28,7 @@ class UserResource extends JsonResource
'subscription' => $this->subscribed('main'),
'incomplete_payment' => $this->hasIncompletePayment('main') ? route('cashier.payment', $this->subscription('main')->latestPayment()->id) : null,
'stripe_customer' => is_null($this->stripe_id) ? false : true,
'name' => $this->name,
'email' => env('APP_DEMO') ? obfuscate_email($this->email) : $this->email,
'avatar' => $this->avatar,
'role' => $this->role,
'created_at_formatted' => format_date($this->created_at, '%d. %B. %Y'),
'created_at' => $this->created_at,
@@ -39,16 +38,18 @@ class UserResource extends JsonResource
'relationships' => [
'settings' => [
'data' => [
'id' => (string)$this->settings->id,
'id' => $this->settings->user_id,
'type' => 'settings',
'attributes' => [
'billing_name' => $this->settings->billing_name,
'billing_address' => $this->settings->billing_address,
'billing_state' => $this->settings->billing_state,
'billing_city' => $this->settings->billing_city,
'billing_postal_code' => $this->settings->billing_postal_code,
'billing_country' => $this->settings->billing_country,
'billing_phone_number' => $this->settings->billing_phone_number,
'avatar' => $this->settings->avatar,
'billing_name' => $this->settings->name,
'billing_address' => $this->settings->address,
'billing_state' => $this->settings->state,
'billing_city' => $this->settings->city,
'billing_postal_code' => $this->settings->postal_code,
'billing_country' => $this->settings->country,
'billing_phone_number' => $this->settings->phone_number,
'timezone' => $this->settings->timezone
]
]
],
@@ -77,15 +78,6 @@ class UserResource extends JsonResource
],
],
],
'timezone' => [
'data' => [
'id' => '1',
'type' => 'timezone',
'attributes' => [
'timezone' =>$this->settings->timezone
],
]
],
]
];
}

View File

@@ -42,8 +42,6 @@ class RouteServiceProvider extends ServiceProvider
{
$this->mapApiRoutes();
$this->mapWebRoutes();
$this->mapAdminApiRoutes();
$this->mapSetupWizardApiRoutes();
@@ -51,6 +49,8 @@ class RouteServiceProvider extends ServiceProvider
$this->mapUserApiRoutes();
$this->mapMaintenanceRoutes();
$this->mapWebRoutes();
}
/**

View File

@@ -79,10 +79,90 @@ class UserAccountTest extends TestCase
->image('fake-image.jpg');
$this->patchJson('/api/user/relationships/settings', [
'avatar' => $avatar,
'avatar' => $avatar,
])->assertStatus(204);
Storage::disk('local')
->assertExists($user->settings->avatar);
}
/**
* @test
*/
public function it_get_user_data()
{
$user = User::factory(User::class)
->create();
Sanctum::actingAs($user);
$this->getJson('/api/user')
->assertStatus(200)
->assertExactJson([
"data" => [
"id" => (string) $user->id,
"type" => "user",
"attributes" => [
"storage_capacity" => "5",
"subscription" => false,
"incomplete_payment" => null,
"stripe_customer" => false,
"email" => $user->email,
"role" => $user->role,
"created_at_formatted" => format_date($user->created_at, '%d. %B. %Y'),
"created_at" => $user->created_at->toJson(),
"updated_at" => $user->updated_at->toJson(),
]
],
"relationships" => [
"settings" => [
"data" => [
"id" => (string) $user->id,
"type" => "settings",
"attributes" => [
'avatar' => $user->settings->avatar,
'billing_name' => $user->settings->name,
'billing_address' => $user->settings->address,
'billing_state' => $user->settings->state,
'billing_city' => $user->settings->city,
'billing_postal_code' => $user->settings->postal_code,
'billing_country' => $user->settings->country,
'billing_phone_number' => $user->settings->phone_number,
'timezone' => $user->settings->timezone
]
]
],
"storage" => [
"data" => [
"id" => "1",
"type" => "storage",
"attributes" => [
"used" => 0,
"used_formatted" => "0.00%",
"capacity" => "5",
"capacity_formatted" => "5GB",
]
]
],
"favourites" => [
"data" => [
"id" => "1",
"type" => "folders_favourite",
"attributes" => [
"folders" => []
]
]
],
"tree" => [
"data" => [
"id" => "1",
"type" => "folders_tree",
"attributes" => [
"folders" => [],
]
]
],
]
]);
}
}