Skip to content

Commit

Permalink
Merge pull request #1296 from seatplus/feature/onboarding
Browse files Browse the repository at this point in the history
Feature/onboarding
herpaderpaldent authored Oct 16, 2022
2 parents 46f6075 + 0e0a231 commit 6876480
Showing 14 changed files with 888 additions and 2 deletions.
1 change: 1 addition & 0 deletions config/web.config.php
Original file line number Diff line number Diff line change
@@ -27,4 +27,5 @@
return [
'EVE_CLIENT_ID' => env('EVE_CLIENT_ID'),
'EVE_CLIENT_SECRET' => env('EVE_CLIENT_SECRET'),
'ONBOARDING' => env('ONBOARDING', false),
];
43 changes: 43 additions & 0 deletions database/migrations/2022_10_19_221652_create_onboardings_table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

/*
* MIT License
*
* Copyright (c) 2019, 2020, 2021 Felix Huber
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{

public function up()
{
Schema::create('onboardings', function (Blueprint $table) {
$table->id();
$table->foreignId('user_id')->constrained('users')->onDelete('cascade');
$table->timestamps();
});
}

};
13 changes: 13 additions & 0 deletions resources/js/Functions/useResolveId.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import axios from "axios";
import {ref} from "vue";

export function useResolveId(id) {

let result = ref()

axios.get(route('resolve.id', id))
.then((response) => result.value = response.data)
.catch(error => console.log(error))

return result
}
182 changes: 182 additions & 0 deletions resources/js/Pages/Onboarding/AddCharacters.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
<template>
<div class="bg-gray-100">
<div class="mx-auto max-w-7xl px-4 sm:py-24 sm:px-6 lg:px-8">
<div class="relative bg-gray-50 shadow-xl">
<h2 class="sr-only">
Add Characters
</h2>

<div class="grid grid-cols-1 lg:grid-cols-3">
<!-- Contact information -->
<div class="relative overflow-hidden bg-indigo-700 py-10 px-6 sm:px-10 xl:p-12">
<div
class="pointer-events-none absolute inset-0 sm:hidden"
aria-hidden="true"
>
<svg
class="absolute inset-0 h-full w-full"
width="343"
height="388"
viewBox="0 0 343 388"
fill="none"
preserveAspectRatio="xMidYMid slice"
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M-99 461.107L608.107-246l707.103 707.107-707.103 707.103L-99 461.107z"
fill="url(#linear1)"
fill-opacity=".1"
/>
<defs>
<linearGradient
id="linear1"
x1="254.553"
y1="107.554"
x2="961.66"
y2="814.66"
gradientUnits="userSpaceOnUse"
>
<stop stop-color="#fff" />
<stop
offset="1"
stop-color="#fff"
stop-opacity="0"
/>
</linearGradient>
</defs>
</svg>
</div>
<div
class="pointer-events-none absolute top-0 right-0 bottom-0 hidden w-1/2 sm:block lg:hidden"
aria-hidden="true"
>
<svg
class="absolute inset-0 h-full w-full"
width="359"
height="339"
viewBox="0 0 359 339"
fill="none"
preserveAspectRatio="xMidYMid slice"
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M-161 382.107L546.107-325l707.103 707.107-707.103 707.103L-161 382.107z"
fill="url(#linear2)"
fill-opacity=".1"
/>
<defs>
<linearGradient
id="linear2"
x1="192.553"
y1="28.553"
x2="899.66"
y2="735.66"
gradientUnits="userSpaceOnUse"
>
<stop stop-color="#fff" />
<stop
offset="1"
stop-color="#fff"
stop-opacity="0"
/>
</linearGradient>
</defs>
</svg>
</div>
<div
class="pointer-events-none absolute top-0 right-0 bottom-0 hidden w-1/2 lg:block"
aria-hidden="true"
>
<svg
class="absolute inset-0 h-full w-full"
width="160"
height="678"
viewBox="0 0 160 678"
fill="none"
preserveAspectRatio="xMidYMid slice"
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M-161 679.107L546.107-28l707.103 707.107-707.103 707.103L-161 679.107z"
fill="url(#linear3)"
fill-opacity=".1"
/>
<defs>
<linearGradient
id="linear3"
x1="192.553"
y1="325.553"
x2="899.66"
y2="1032.66"
gradientUnits="userSpaceOnUse"
>
<stop stop-color="#fff" />
<stop
offset="1"
stop-color="#fff"
stop-opacity="0"
/>
</linearGradient>
</defs>
</svg>
</div>
<h3 class="text-lg font-medium text-white">
Add Characters
</h3>
<p class="mt-6 max-w-3xl text-base text-indigo-50">
Please add all characters you want to track. You can add more later.
</p>
</div>

<!-- Contact form -->
<div class="flex flex-col justify-between py-10 px-6 sm:px-10 lg:col-span-2 xl:p-12">
<div class="grid grid-cols-1 gap-4 sm:grid-cols-2">
<a
type="button"
:href="route('auth.eve')"
class="flex p-2 lg:col-span-2 border-2 border-dashed border-gray-300 hover:border-gray-400 focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:ring-offset-2 rounded-lg"
>
<div class="mb-4 shrink-0 sm:mb-0 mr-4 self-center">
<div>
<UserPlusIcon
class="h-10 w-10 rounded-full text-gray-900"
aria-hidden="true"
/>
</div>
</div>
<div class="flex flex-col justify-center">
<h3 class="text-lg leading-6 font-medium text-gray-900">
Add another character
</h3>
</div>
</a>
<EntityByIdBlock
v-for="character in characters"
:id="character.character_id"
:key="character.id"
:entity="character"
/>
</div>

<div class="sm:flex sm:justify-end">
<slot />
</div>
</div>
</div>
</div>
</div>
</div>
</template>

<script setup>
import EntityByIdBlock from "@/Shared/Layout/Eve/EntityByIdBlock.vue";
import { UserPlusIcon } from "@heroicons/vue/24/outline";
const props = defineProps({
characters: {
type: Array,
required: true,
},
});
</script>
132 changes: 132 additions & 0 deletions resources/js/Pages/Onboarding/Index.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
<template>
<div class="absolute min-h-full min-w-full bg-gray-100 px-4 py-16 sm:px-6 sm:py-24 md:grid md:place-items-center lg:px-8">
<main class="mx-auto flex w-full max-w-7xl flex-grow flex-col justify-center px-4 sm:px-6 lg:px-8">
<div class="flex flex-shrink-0 justify-center">
<a
href="/"
class="inline-flex"
>
<span class="sr-only">Seat Plus</span>
<img
class="h-12 w-auto"
src="/img/seat_plus_logo.svg"
alt="Seat Plus"
>
</a>
</div>
<div>
<Introduction
v-if="step === 1"
:main-character-id="mainCharacterId"
>
<Link
class="block w-full rounded-md border border-transparent bg-white py-3 px-5 text-center text-base font-medium text-indigo-700 shadow-md hover:bg-gray-50 sm:inline-block sm:w-auto"
:href="nextUrl"
>
Next
</Link>
</Introduction>
<OnboardingEnlistment
v-if="step === 2"
:main-character-id="mainCharacterId"
:enlistments="user_enlistments"
>
<Link
as="button"
:href="nextUrl"
class="mt-2 inline-flex w-full items-center justify-center rounded-md border border-transparent bg-indigo-600 px-6 py-3 text-base font-medium text-white shadow-sm hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:ring-offset-2 sm:w-auto"
>
Next
</Link>
</OnboardingEnlistment>
<AddCharacters
v-if="step === 3"
:characters="characters"
>
<Link
:key="character_enlistments.length"
as="button"
:method="character_enlistments.length > 0 ? 'get' : 'post'"
:href="nextUrl"
class="mt-2 inline-flex w-full items-center justify-center rounded-md border border-transparent bg-indigo-600 px-6 py-3 text-base font-medium text-white shadow-sm hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:ring-offset-2 sm:w-auto"
>
{{ character_enlistments.length > 0 ? 'Next' : 'Finish' }}
</Link>
</AddCharacters>
<OnboardingEnlistment
v-if="step === 4"
:main-character-id="mainCharacterId"
:enlistments="character_enlistments"
>
<Link
as="button"
:href="nextUrl"
method="post"
class="mt-2 inline-flex w-full items-center justify-center rounded-md border border-transparent bg-indigo-600 px-6 py-3 text-base font-medium text-white shadow-sm hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:ring-offset-2 sm:w-auto"
>
Finish
</Link>
</OnboardingEnlistment>
</div>
</main>
</div>
</template>


<script>
export default {
layout: null,
}
</script>

<script setup>
import { computed } from "vue";
import { Link } from "@inertiajs/inertia-vue3";
import OnboardingEnlistment from "@/Pages/Onboarding/OnboardingEnlistment.vue";
import Introduction from "@/Pages/Onboarding/Introduction.vue";
import AddCharacters from "@/Pages/Onboarding/AddCharacters.vue";
const props = defineProps({
enlistments: {
required: true,
type: Array
},
characters: {
required: true,
type: Array
},
mainCharacterId: {
required: true,
type: Number
},
step: {
required: true,
type: Number
}
})
const user_enlistments = computed(() => {
return props.enlistments.filter(enlistment => enlistment.type === 'user')
})
const character_enlistments = computed(() => {
return props.enlistments.filter(enlistment => enlistment.type === 'character')
})
const nextUrl = computed(() => {
let route_name = route().current()
if(props.step === 1) {
return route(route_name, {step: user_enlistments.value.length > 0 ? 2 : 3})
}
if(props.step > 1) {
return route(route_name, {step: props.step + 1})
}
})
</script>

129 changes: 129 additions & 0 deletions resources/js/Pages/Onboarding/Introduction.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
<template>
<div class="relative py-16">
<div class="mx-auto max-w-7xl bg-indigo-600 lg:bg-transparent lg:px-8">
<div class="lg:grid lg:grid-cols-12">
<div class="relative z-10 lg:col-span-4 lg:col-start-1 lg:row-start-1 lg:bg-transparent lg:py-16">
<div
class="absolute inset-x-0 h-1/2 bg-gray-100 lg:hidden"
aria-hidden="true"
/>
<div class="mx-auto max-w-md px-4 sm:max-w-3xl sm:px-6 lg:max-w-none lg:p-0">
<div class="aspect-w-10 aspect-h-6 sm:aspect-w-2 sm:aspect-h-1 lg:aspect-w-1">
<img
class="rounded-3xl object-cover object-center shadow-2xl"
:src="`https://images.evetech.net/characters/${mainCharacterId}/portrait?size=512`"
:alt="resolvedObject?.name"
>
</div>
</div>
</div>

<div class="relative bg-indigo-600 lg:col-span-10 lg:col-start-3 lg:row-start-1 lg:grid lg:grid-cols-10 lg:items-center lg:rounded-3xl">
<div
class="absolute inset-0 hidden overflow-hidden rounded-3xl lg:block"
aria-hidden="true"
>
<svg
class="absolute bottom-full left-full translate-y-1/3 -translate-x-2/3 transform xl:bottom-auto xl:top-0 xl:translate-y-0"
width="404"
height="384"
fill="none"
viewBox="0 0 404 384"
aria-hidden="true"
>
<defs>
<pattern
id="64e643ad-2176-4f86-b3d7-f2c5da3b6a6d"
x="0"
y="0"
width="20"
height="20"
patternUnits="userSpaceOnUse"
>
<rect
x="0"
y="0"
width="4"
height="4"
class="text-indigo-500"
fill="currentColor"
/>
</pattern>
</defs>
<rect
width="404"
height="384"
fill="url(#64e643ad-2176-4f86-b3d7-f2c5da3b6a6d)"
/>
</svg>
<svg
class="absolute top-full -translate-y-1/3 -translate-x-1/3 transform xl:-translate-y-1/2"
width="404"
height="384"
fill="none"
viewBox="0 0 404 384"
aria-hidden="true"
>
<defs>
<pattern
id="64e643ad-2176-4f86-b3d7-f2c5da3b6a6d"
x="0"
y="0"
width="20"
height="20"
patternUnits="userSpaceOnUse"
>
<rect
x="0"
y="0"
width="4"
height="4"
class="text-indigo-500"
fill="currentColor"
/>
</pattern>
</defs>
<rect
width="404"
height="384"
fill="url(#64e643ad-2176-4f86-b3d7-f2c5da3b6a6d)"
/>
</svg>
</div>
<div class="relative mx-auto max-w-md space-y-6 py-12 px-4 sm:max-w-3xl sm:py-16 sm:px-6 lg:col-span-6 lg:col-start-4 lg:max-w-none lg:p-0">
<h2
id="join-heading"
class="text-3xl font-bold tracking-tight text-white"
>
Welcome {{ resolvedObject?.name }}
</h2>
<p class="text-lg text-white">
This is the first step of the onboarding process. If this instance has an open enlistment you can join it and then add additional characters
</p>
<slot />
</div>
</div>
</div>
</div>
</div>
</template>

<script setup>
import {useResolveId} from "@/Functions/useResolveId.js";
const props = defineProps({
mainCharacterId: {
type: Number,
required: true
}
})
const resolvedObject = useResolveId(props.mainCharacterId)
</script>

<style scoped>
</style>
162 changes: 162 additions & 0 deletions resources/js/Pages/Onboarding/OnboardingEnlistment.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
<template>
<div class="bg-gray-100">
<div class="mx-auto max-w-7xl px-4 sm:py-24 sm:px-6 lg:px-8">
<div class="relative bg-gray-50 shadow-xl">
<h2 class="sr-only">
Job Postings
</h2>

<div class="grid grid-cols-1 lg:grid-cols-3">
<!-- Contact information -->
<div class="relative overflow-hidden bg-indigo-700 py-10 px-6 sm:px-10 xl:p-12">
<div
class="pointer-events-none absolute inset-0 sm:hidden"
aria-hidden="true"
>
<svg
class="absolute inset-0 h-full w-full"
width="343"
height="388"
viewBox="0 0 343 388"
fill="none"
preserveAspectRatio="xMidYMid slice"
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M-99 461.107L608.107-246l707.103 707.107-707.103 707.103L-99 461.107z"
fill="url(#linear1)"
fill-opacity=".1"
/>
<defs>
<linearGradient
id="linear1"
x1="254.553"
y1="107.554"
x2="961.66"
y2="814.66"
gradientUnits="userSpaceOnUse"
>
<stop stop-color="#fff" />
<stop
offset="1"
stop-color="#fff"
stop-opacity="0"
/>
</linearGradient>
</defs>
</svg>
</div>
<div
class="pointer-events-none absolute top-0 right-0 bottom-0 hidden w-1/2 sm:block lg:hidden"
aria-hidden="true"
>
<svg
class="absolute inset-0 h-full w-full"
width="359"
height="339"
viewBox="0 0 359 339"
fill="none"
preserveAspectRatio="xMidYMid slice"
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M-161 382.107L546.107-325l707.103 707.107-707.103 707.103L-161 382.107z"
fill="url(#linear2)"
fill-opacity=".1"
/>
<defs>
<linearGradient
id="linear2"
x1="192.553"
y1="28.553"
x2="899.66"
y2="735.66"
gradientUnits="userSpaceOnUse"
>
<stop stop-color="#fff" />
<stop
offset="1"
stop-color="#fff"
stop-opacity="0"
/>
</linearGradient>
</defs>
</svg>
</div>
<div
class="pointer-events-none absolute top-0 right-0 bottom-0 hidden w-1/2 lg:block"
aria-hidden="true"
>
<svg
class="absolute inset-0 h-full w-full"
width="160"
height="678"
viewBox="0 0 160 678"
fill="none"
preserveAspectRatio="xMidYMid slice"
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M-161 679.107L546.107-28l707.103 707.107-707.103 707.103L-161 679.107z"
fill="url(#linear3)"
fill-opacity=".1"
/>
<defs>
<linearGradient
id="linear3"
x1="192.553"
y1="325.553"
x2="899.66"
y2="1032.66"
gradientUnits="userSpaceOnUse"
>
<stop stop-color="#fff" />
<stop
offset="1"
stop-color="#fff"
stop-opacity="0"
/>
</linearGradient>
</defs>
</svg>
</div>
<h3 class="text-lg font-medium text-white">
Job Postings
</h3>
<p class="mt-6 max-w-3xl text-base text-indigo-50">
The following corporations are open for new recruits. These job listings do have two kind of characteristics: either 'character' or 'user' and it's defined by a senior recruiter of that corporation. For an enlistment with character type, this means you are able to apply with single characters of yours and sso-scope requirements are only enforced per applied character. If an enlistment is of user type, upon application each and every character that belongs to your user account must fulfill the set sso-scope requirements of the recruiting corporation.
</p>
</div>

<!-- Contact form -->
<div class="flex flex-col justify-between py-10 px-6 sm:px-10 lg:col-span-2 xl:p-12">
<div class="grid grid-cols-1 gap-4 sm:grid-cols-2">
<Enlistment
v-for="enlistment in enlistments"
:key="enlistment.corporation_id"
:enlistment="enlistment"
/>
</div>

<div class="sm:flex sm:justify-end">
<slot />
</div>
</div>
</div>
</div>
</div>
</div>
</template>

<script setup>
import Enlistment from "@/Pages/Dashboard/Enlistment.vue";
defineProps({
enlistments: {
type: Array,
required: true,
},
})
</script>
9 changes: 9 additions & 0 deletions routes/Routes/Onboarding/Onboarding.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

use Seatplus\Web\Http\Controllers\Onboarding\OnboardingController;

Route::controller(OnboardingController::class)
->group(function () {
Route::get('/', 'index')->name('onboarding');
Route::post('/', 'complete')->name('onboarding.complete');
});
8 changes: 7 additions & 1 deletion routes/routes.php
Original file line number Diff line number Diff line change
@@ -29,10 +29,11 @@
use Seatplus\Web\Http\Controllers\HomeController;
use Seatplus\Web\Http\Controllers\Shared\StopImpersonateController;
use Seatplus\Web\Http\Middleware\CheckRequiredScopes;
use Seatplus\Web\Http\Middleware\OnboardingMiddleware;

Route::middleware('web')
->group(function () {
Route::middleware(['auth', CheckRequiredScopes::class])
Route::middleware(['auth', CheckRequiredScopes::class, OnboardingMiddleware::class])
->group(function () {
Route::get('/home', [HomeController::class, 'home'])->name('home');
Route::get('/enlistments', [HomeController::class, 'getEnlistments'])->name('list.open.enlistments');
@@ -72,6 +73,11 @@
include __DIR__ . '/Routes/Corporation/MemberCompliance.php';
});

Route::prefix('onboarding')
->group(function () {
include __DIR__ . '/Routes/Onboarding/Onboarding.php';
});

Route::prefix('acl')
->middleware(['acl-permission:view access control'])
->group(function () {
40 changes: 40 additions & 0 deletions src/Http/Controllers/Onboarding/OnboardingController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

namespace Seatplus\Web\Http\Controllers\Onboarding;

use Illuminate\Http\Request;
use Seatplus\Auth\Models\User;
use Seatplus\Web\Http\Controllers\Controller;
use Seatplus\Web\Models\Onboarding;
use Seatplus\Web\Models\Recruitment\Enlistment;

class OnboardingController extends Controller
{
public function index(Request $request)
{
throw_unless(config('web.config.ONBOARDING'), 'Onboarding is disabled');

$user = User::query()
->with('character_users')
->firstWhere('id', auth()->user()->getAuthIdentifier());

return inertia('Onboarding/Index', [
'step' => intval($request->query('step', 1)),
'characters' => $user->character_users,
'mainCharacterId' => $user->main_character_id,
'enlistments' => Enlistment::query()
->with(['corporation' => ['alliance']])
->get(),
]);
}

public function complete()
{
// create onboarding record
Onboarding::query()->create([
'user_id' => auth()->user()->getAuthIdentifier(),
]);

return redirect()->route('home');
}
}
45 changes: 45 additions & 0 deletions src/Http/Middleware/OnboardingMiddleware.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

namespace Seatplus\Web\Http\Middleware;

use Closure;
use Illuminate\Http\Request;
use Seatplus\Auth\Models\User;
use Seatplus\Web\Models\Onboarding;

class OnboardingMiddleware
{
private $user;

public function handle(Request $request, Closure $next)
{
// if onboarding is disabled, skip middleware
if (! config('web.config.ONBOARDING')) {
return $next($request);
}

$this->setUser($request);

// if user has been created longer then an hour ago don't bother with onboarding
if ($this->getUser()->created_at->diffInMinutes(now()) >= 60) {
return $next($request);
}

// if user has completed onboarding don't bother with onboarding
if (Onboarding::firstWhere('user_id', $this->getUser()->getAuthIdentifier())) {
return $next($request);
}

return redirect()->route('onboarding');
}

private function setUser(Request $request): void
{
$this->user = $request->user();
}

private function getUser(): User
{
return $this->user;
}
}
1 change: 0 additions & 1 deletion src/Http/Resources/UserRessource.php
Original file line number Diff line number Diff line change
@@ -42,7 +42,6 @@ public function toArray($request)
'id' => $this->id,
'main_character' => $this->main_character,
'characters' => $this->characters
//->reject(fn($character) => $character->character_id === $this->main_character_id)
->map(fn ($character) => [
'character_id' => $character->character_id,
'name' => $character->name,
48 changes: 48 additions & 0 deletions src/Models/Onboarding.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

/*
* MIT License
*
* Copyright (c) 2019, 2020, 2021 Felix Huber
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

namespace Seatplus\Web\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Seatplus\Auth\Models\User;

class Onboarding extends Model
{
use HasFactory;

/**
* The attributes that aren't mass assignable.
*
* @var array
*/
protected $guarded = [];

public function user()
{
return $this->belongsTo(User::class, 'user_id', 'id');
}
}
77 changes: 77 additions & 0 deletions tests/Integration/OnboardingLifeCycleTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?php

use function Pest\Laravel\actingAs;
use Seatplus\Web\Models\Onboarding;

it('throws error when turned off and navigated to onboarding if turned off', function () {
config()->set('web.config.ONBOARDING', false);

actingAs($this->test_user);

$response = $this->get(route('onboarding'))->assertStatus(500);
});

it('redirects to onboarding if turned on', function () {
config()->set('web.config.ONBOARDING', true);

actingAs($this->test_user);

expect($this->test_user->created_at->diffInMinutes(now()))->not()->toBeGreaterThan(60);

$response = $this->get(route('home'))
->assertRedirect(route('onboarding'));
});

it('does not redirect to onboarding if user has been created longer then an hour ago', function () {
config()->set('web.config.ONBOARDING', true);

$this->test_user->created_at = now()->subHour();

$this->test_user->save();

actingAs($this->test_user);

$this->get(route('home'))
->assertOk();
});

it('does not redirect to onboarding if user has completed onboarding', function () {
config()->set('web.config.ONBOARDING', true);

actingAs($this->test_user);

Onboarding::create([
'user_id' => $this->test_user->getAuthIdentifier(),
]);

$this->get(route('home'))
->assertOk();
});

it('shows onboarding page', function () {
config()->set('web.config.ONBOARDING', true);

actingAs($this->test_user);

$this->withoutMiddleware(\Seatplus\Web\Http\Middleware\OnboardingMiddleware::class);

$response = $this->get(route('onboarding'));

$response->assertOk()
->assertInertia(fn (\Inertia\Testing\AssertableInertia $page) => $page->component('Onboarding/Index'));
});

it('completes onboarding', function () {
config()->set('web.config.ONBOARDING', true);

actingAs($this->test_user);

$this->withoutMiddleware(\Seatplus\Web\Http\Middleware\OnboardingMiddleware::class);

expect(Onboarding::all())->toBeEmpty();

$this->post(route('onboarding.complete'))
->assertRedirect(route('home'));

expect(Onboarding::firstWhere('user_id', $this->test_user->getAuthIdentifier()))->toBeInstanceOf(Onboarding::class);
});

0 comments on commit 6876480

Please sign in to comment.