Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/Http/Controllers/AuthController.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public function showOnboarding(Request $request)

$top = User::withCount('appreciationsReceived')
->orderByDesc('appreciations_received_count')
->take(1)
->take(2)
->get(['id', 'name', 'username', 'image_path', 'institution', 'is_verified']);

$verified = User::where('is_verified', true)
Expand All @@ -120,7 +120,7 @@ public function showOnboarding(Request $request)

$random = User::whereNotIn('id', $excludedIds)
->inRandomOrder()
->take(2)
->take(1)
->get(['id', 'name', 'username', 'image_path', 'institution', 'is_verified']);

$suggestedContributors = $top->concat($verified)->concat($random)->values();
Expand Down
15 changes: 12 additions & 3 deletions resources/js/pages/auth/Onboarding.vue
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,17 @@ const flashError = computed(() => (page.props as any).flash?.error);

const currentStep = ref<1 | 2>(1);

const getInitialAppreciations = (suggested: Contributor[] = []): number[] => {
if (suggested.length === 0) {
return [];
}

const [first, ...rest] = suggested;
const randomRest = [...rest].sort(() => Math.random() - 0.5).slice(0, 2);

return [first, ...randomRest].map((c) => c.id);
};

const form = useForm<{
name: string;
username: string;
Expand All @@ -55,9 +66,7 @@ const form = useForm<{
school: '',
image: null,
receive_emails: true,
appreciations: (props.suggestedContributors || [])
.slice(0, 3)
.map((c) => c.id),
appreciations: getInitialAppreciations(props.suggestedContributors),
});

const previewUrl = ref<string | null>(null);
Expand Down
14 changes: 10 additions & 4 deletions tests/Feature/AuthenticationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -392,10 +392,15 @@
});

test('onboarding passes suggested contributors to the view according to algorithm', function () {
$topUser = User::factory()->create(['name' => 'Top Appreciator']);
$topUser1 = User::factory()->create(['name' => 'Top Appreciator 1']);
$topUser2 = User::factory()->create(['name' => 'Top Appreciator 2']);
$admirer = User::factory()->create();
UserAppreciation::create([
'user_id' => $topUser->id,
'user_id' => $topUser1->id,
'appreciator_id' => $admirer->id,
]);
UserAppreciation::create([
'user_id' => $topUser2->id,
'appreciator_id' => $admirer->id,
]);

Expand All @@ -415,8 +420,9 @@
$response->assertInertia(fn ($page) => $page
->component('auth/Onboarding')
->has('suggestedContributors', 4)
->where('suggestedContributors.0.id', $topUser->id)
->where('suggestedContributors.1.id', $verifiedUser->id)
->where('suggestedContributors.0.id', $topUser1->id)
->where('suggestedContributors.1.id', $topUser2->id)
->where('suggestedContributors.2.id', $verifiedUser->id)
);
});

Expand Down
Loading