Skip to content

Commit 4d1d2c2

Browse files
committed
chore: update profile tests
1 parent a3e1e88 commit 4d1d2c2

File tree

13 files changed

+244
-163
lines changed

13 files changed

+244
-163
lines changed

app/Http/Controllers/Auth/RegisteredUserController.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,17 @@ final class RegisteredUserController extends Controller
2626
public function store(Request $request): RedirectResponse
2727
{
2828
$request->validate([
29-
'name' => 'required|string|max:255',
29+
'first_name' => 'required|string|max:255',
30+
'last_name' => 'required|string|max:255',
3031
'email' => 'required|string|lowercase|email|max:255|unique:'.User::class,
3132
'password' => ['required', 'confirmed', Rules\Password::defaults()],
3233
]);
3334

3435
/** @var string $password */
3536
$password = $request->password;
3637
$user = User::create([
37-
'name' => $request->name,
38+
'first_name' => $request->first_name,
39+
'last_name' => $request->last_name,
3840
'email' => $request->email,
3941
'password' => Hash::make($password),
4042
]);

app/Http/Requests/Settings/ProfileUpdateRequest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ final class ProfileUpdateRequest extends FormRequest
1919
public function rules(): array
2020
{
2121
return [
22-
'name' => ['required', 'string', 'max:255'],
22+
'first_name' => ['required', 'string', 'max:255'],
23+
'last_name' => ['required', 'string', 'max:255'],
2324
'email' => [
2425
'required',
2526
'string',

bin/ci

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ fi
8080

8181
info "Running frontend CI checks..."
8282

83-
npm run check
83+
npm run lint
8484

8585
info "Building assets..."
8686

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@
8787
"test:ci": "vendor/bin/pest --mutate --min=100 --parallel --ci",
8888
"test": [
8989
"@php artisan config:clear --ansi",
90-
"vendor/bin/pest"
90+
"@test:unit"
9191
],
9292
"test:all": [
9393
"@test",
@@ -114,7 +114,7 @@
114114
"@lint",
115115
"@fmt:test",
116116
"@refactor:test",
117-
"@test",
117+
"@test:all",
118118
"@typos"
119119
],
120120
"transform": "php artisan typescript:transform --format",

phpunit.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
<testsuite name="Feature">
1212
<directory>tests/Feature</directory>
1313
</testsuite>
14+
<testsuite name="Arch">
15+
<directory suffix="ArchTest.php">tests</directory>
16+
</testsuite>
1417
</testsuites>
1518
<source>
1619
<include>

resources/js/pages/auth/Register.vue

Lines changed: 38 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<script setup lang="ts">
1+
<script lang="ts" setup>
22
import { Head, useForm } from "@inertiajs/vue3";
33
import { LoaderCircle } from "lucide-vue-next";
44
import InputError from "@/components/InputError.vue";
@@ -9,7 +9,8 @@ import { Label } from "@/components/ui/label";
99
import AuthBase from "@/layouts/AuthLayout.vue";
1010
1111
const form = useForm({
12-
name: "",
12+
first_name: "",
13+
last_name: "",
1314
email: "",
1415
password: "",
1516
password_confirmation: "",
@@ -23,20 +24,44 @@ function submit() {
2324
</script>
2425

2526
<template>
26-
<AuthBase title="Create an account" description="Enter your details below to create your account">
27+
<AuthBase description="Enter your details below to create your account" title="Create an account">
2728
<Head title="Register" />
2829

2930
<form class="flex flex-col gap-6" @submit.prevent="submit">
3031
<div class="grid gap-6">
3132
<div class="grid gap-2">
32-
<Label for="name">Name</Label>
33-
<Input id="name" v-model="form.name" type="text" required autofocus :tabindex="1" autocomplete="name" placeholder="Full name" />
34-
<InputError :message="form.errors.name" />
33+
<Label for="first_name">First name</Label>
34+
<Input
35+
id="first_name" v-model="form.first_name"
36+
:tabindex="1"
37+
autocomplete="first_name"
38+
autofocus
39+
placeholder="First name"
40+
required type="text"
41+
/>
42+
<InputError :message="form.errors.first_name" />
43+
</div>
44+
45+
<div class="grid gap-2">
46+
<Label for="last_name">Last name</Label>
47+
<Input
48+
id="last_name" v-model="form.last_name"
49+
:tabindex="1"
50+
autocomplete="last_name"
51+
autofocus
52+
placeholder="Last name"
53+
required type="text"
54+
/>
55+
<InputError :message="form.errors.last_name" />
3556
</div>
3657

3758
<div class="grid gap-2">
3859
<Label for="email">Email address</Label>
39-
<Input id="email" v-model="form.email" type="email" required :tabindex="2" autocomplete="email" placeholder="[email protected]" />
60+
<Input
61+
id="email" v-model="form.email" :tabindex="2" autocomplete="email"
62+
placeholder="[email protected]" required
63+
type="email"
64+
/>
4065
<InputError :message="form.errors.email" />
4166
</div>
4267

@@ -45,11 +70,11 @@ function submit() {
4570
<Input
4671
id="password"
4772
v-model="form.password"
48-
type="password"
49-
required
5073
:tabindex="3"
5174
autocomplete="new-password"
5275
placeholder="Password"
76+
required
77+
type="password"
5378
/>
5479
<InputError :message="form.errors.password" />
5580
</div>
@@ -59,24 +84,24 @@ function submit() {
5984
<Input
6085
id="password_confirmation"
6186
v-model="form.password_confirmation"
62-
type="password"
63-
required
6487
:tabindex="4"
6588
autocomplete="new-password"
6689
placeholder="Confirm password"
90+
required
91+
type="password"
6792
/>
6893
<InputError :message="form.errors.password_confirmation" />
6994
</div>
7095

71-
<Button type="submit" class="mt-2 w-full" tabindex="5" :disabled="form.processing">
96+
<Button :disabled="form.processing" class="mt-2 w-full" tabindex="5" type="submit">
7297
<LoaderCircle v-if="form.processing" class="h-4 w-4 animate-spin" />
7398
Create account
7499
</Button>
75100
</div>
76101

77102
<div class="text-muted-foreground text-center text-sm">
78103
Already have an account?
79-
<TextLink :href="route('login')" class="underline underline-offset-4" :tabindex="6">
104+
<TextLink :href="route('login')" :tabindex="6" class="underline underline-offset-4">
80105
Log in
81106
</TextLink>
82107
</div>

resources/js/pages/settings/Profile.vue

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ const page = usePage<SharedData>();
2929
const user = page.props.auth.user as App.Data.UserData;
3030
3131
const form = useForm({
32-
name: user.fullName,
32+
first_name: user.firstName,
33+
last_name: user.lastName,
3334
email: user.email,
3435
});
3536
@@ -49,14 +50,32 @@ function submit() {
4950
<HeadingSmall description="Update your name and email address" title="Profile information" />
5051

5152
<form class="space-y-6" @submit.prevent="submit">
52-
<div class="grid gap-2">
53-
<Label for="name">Name</Label>
54-
<Input
55-
id="name" v-model="form.name" autocomplete="name" class="mt-1 block w-full"
56-
placeholder="Full name"
57-
required
58-
/>
59-
<InputError :message="form.errors.name" class="mt-2" />
53+
<div class="grid grid-cols-2 gap-6">
54+
<div class="grid gap-2">
55+
<Label for="first_name">First name</Label>
56+
<Input
57+
id="first_name"
58+
v-model="form.first_name"
59+
autocomplete="first_name"
60+
class="mt-1 block w-full"
61+
placeholder="First name"
62+
required
63+
/>
64+
<InputError :message="form.errors.first_name" class="mt-2" />
65+
</div>
66+
67+
<div class="grid gap-2">
68+
<Label for="last_name">Last name</Label>
69+
<Input
70+
id="name"
71+
v-model="form.last_name"
72+
autocomplete="last_name"
73+
class="mt-1 block w-full"
74+
placeholder="Last name"
75+
required
76+
/>
77+
<InputError :message="form.errors.last_name" class="mt-2" />
78+
</div>
6079
</div>
6180

6281
<div class="grid gap-2">

tests/ArchTest.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Tests;
6+
7+
use Illuminate\Contracts\Validation\ValidationRule;
8+
9+
arch()->preset()->laravel();
10+
11+
arch('Rules should be suffixed with rule', fn (): \Pest\Arch\Contracts\ArchExpectation => expect('App\Http\Rules')
12+
->classes()
13+
->toBeFinal()
14+
->toHaveSuffix('Rule')
15+
->toImplement(ValidationRule::class));
16+
17+
arch('All test files are strictly typed')
18+
->expect('Tests\\')
19+
->toUseStrictTypes();
20+
21+
arch('All enums are string backed')
22+
->expect('App\\Enums\\')
23+
->toBeStringBackedEnums();
24+
25+
arch('All value objects are immutable')
26+
->expect('App\\ValueObjects\\')
27+
->toBeReadonly()
28+
->and('App\\ValueObjects')
29+
->toBeFinal();
30+
31+
arch('All contracts are interfaces')
32+
->expect('App\\Contracts\\')
33+
->toBeInterfaces();

tests/Feature/Auth/RegistrationTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212

1313
it('allows new users to register', function (): void {
1414
$response = $this->post('/register', [
15-
'name' => 'Test User',
15+
'first_name' => 'Test',
16+
'last_name' => 'User',
1617
'email' => '[email protected]',
1718
'password' => 'password',
1819
'password_confirmation' => 'password',

tests/Feature/DashboardTest.php

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,17 @@
66

77
use App\Models\User;
88

9-
it('redirects guests to the login page', function (): void {
10-
$response = $this->get('/dashboard');
11-
$response->assertRedirect('/login');
12-
});
9+
describe('Dashboard', function (): void {
10+
it('redirects guests to the login page', function (): void {
11+
$response = $this->get('/dashboard');
12+
$response->assertRedirect('/login');
13+
});
1314

14-
it('allows authenticated users to visit the dashboard', function (): void {
15-
$user = User::factory()->create();
16-
$this->actingAs($user);
15+
it('allows authenticated users to visit the dashboard', function (): void {
16+
$user = User::factory()->create();
17+
$this->actingAs($user);
1718

18-
$response = $this->get('/dashboard');
19-
$response->assertStatus(200);
19+
$response = $this->get('/dashboard');
20+
$response->assertStatus(200);
21+
});
2022
});

0 commit comments

Comments
 (0)