Skip to content

Commit

Permalink
fix: return user to settings page after changing settings (resolves #…
Browse files Browse the repository at this point in the history
…2272) (#2345)

* fix: return user to settings page after changing settings

* test: update to expect settings.show as the redirect
  • Loading branch information
jobara authored Nov 4, 2024
1 parent 3f4256c commit 603f981
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 20 deletions.
14 changes: 7 additions & 7 deletions app/Http/Controllers/SettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ public function updateAccessNeeds(UpdateAccessNeedsRequest $request): RedirectRe
return redirect(localized_route('engagements.confirm-access-needs', ['engagement' => $data['return_to_engagement']]));
}

return redirect(localized_route('settings.edit-access-needs'));
return redirect(localized_route('settings.show'));
}

public function editCommunicationAndConsultationPreferences(): View
Expand Down Expand Up @@ -216,7 +216,7 @@ public function updateCommunicationAndConsultationPreferences(UpdateCommunicatio

flash(__('Your communication and consultation preferences have been updated.'), 'success|'.__('Your communication and consultation preferences have been updated.', [], 'en'));

return redirect(localized_route('settings.edit-communication-and-consultation-preferences'));
return redirect(localized_route('settings.show'));
}

public function editLanguagePreferences(): View
Expand Down Expand Up @@ -256,7 +256,7 @@ public function updateLanguagePreferences(UpdateLanguagePreferencesRequest $requ

flash(__('Your language preferences have been updated.'), 'success|'.__('Your language preferences have been updated.', [], 'en'));

return redirect(localized_route('settings.edit-language-preferences'));
return redirect(localized_route('settings.show'));
}

public function editPaymentInformation(): View
Expand Down Expand Up @@ -287,7 +287,7 @@ public function updatePaymentInformation(UpdatePaymentInformationRequest $reques

flash(__('Your payment information has been updated.'), 'success|'.__('Your payment information has been updated.', [], 'en'));

return redirect(localized_route('settings.edit-payment-information'));
return redirect(localized_route('settings.show'));
}

public function editAreasOfInterest(): View
Expand All @@ -313,7 +313,7 @@ public function updateAreasOfInterest(UpdateAreasOfInterestRequest $request): Re

flash(__('Your areas of interest have been updated.'), 'success|'.__('Your areas of interest have been updated.', [], 'en'));

return redirect(localized_route('settings.edit-areas-of-interest'));
return redirect(localized_route('settings.show'));
}

public function editWebsiteAccessibilityPreferences(): View
Expand All @@ -336,7 +336,7 @@ public function updateWebsiteAccessibilityPreferences(UpdateWebsiteAccessibility

Cookie::queue('theme', $data['theme']);

return redirect(localized_route('settings.edit-website-accessibility-preferences'));
return redirect(localized_route('settings.show'));
}

public function editNotificationPreferences(): View
Expand Down Expand Up @@ -385,7 +385,7 @@ public function updateNotificationPreferences(UpdateNotificationPreferencesReque

flash(__('Your notification preferences have been updated.'), 'success|'.__('Your notification preferences have been updated.', [], 'en'));

return redirect(localized_route('settings.edit-notification-preferences'));
return redirect(localized_route('settings.show'));
}

public function editRolesAndPermissions(): View
Expand Down
26 changes: 13 additions & 13 deletions tests/Feature/UserSettingsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
'additional_needs_or_concerns' => $additionalNeeds->id,
])
->assertSessionHasNoErrors()
->assertRedirect(localized_route('settings.edit-access-needs'));
->assertRedirect(localized_route('settings.show'));

$individual = $individual->fresh();
expect($individual->accessSupports->pluck('id')->toArray())->toContain($additionalNeeds->id);
Expand Down Expand Up @@ -83,7 +83,7 @@
'other_access_need' => $otherAccessNeed,
])
->assertSessionHasNoErrors()
->assertRedirect(localized_route('settings.edit-access-needs'));
->assertRedirect(localized_route('settings.show'));

$individual = $individual->fresh();
expect($individual->other_access_need)->toBe($otherAccessNeed);
Expand All @@ -96,7 +96,7 @@
'other' => false,
])
->assertSessionHasNoErrors()
->assertRedirect(localized_route('settings.edit-access-needs'));
->assertRedirect(localized_route('settings.show'));

$individual = $individual->fresh();
expect($individual->other_access_need)->toBe('');
Expand Down Expand Up @@ -150,7 +150,7 @@
'consulting_methods' => ['survey'],
])
->assertSessionHasNoErrors()
->assertRedirect(localized_route('settings.edit-communication-and-consultation-preferences'));
->assertRedirect(localized_route('settings.show'));

expect($user->fresh()->email_verified_at)->toBeNull();

Expand Down Expand Up @@ -183,7 +183,7 @@
'consulting_methods' => ['survey'],
])
->assertSessionHasNoErrors()
->assertRedirect(localized_route('settings.edit-communication-and-consultation-preferences'));
->assertRedirect(localized_route('settings.show'));

$user = $user->fresh();

Expand Down Expand Up @@ -214,7 +214,7 @@
'working_languages' => ['asl', 'en'],
])
->assertSessionHasNoErrors()
->assertRedirect(localized_route('settings.edit-language-preferences'));
->assertRedirect(localized_route('settings.show'));

expect($user->locale)->toEqual('asl');
expect($user->individual->first_language)->toEqual('asl');
Expand All @@ -228,7 +228,7 @@
'locale' => 'lsq',
])
->assertSessionHasNoErrors()
->assertRedirect(localized_route('settings.edit-language-preferences'));
->assertRedirect(localized_route('settings.show'));

expect($newUser->locale)->toEqual('lsq');
});
Expand All @@ -246,7 +246,7 @@
'other_payment_type' => 'Square',
])
->assertSessionHasNoErrors()
->assertRedirect(localized_route('settings.edit-payment-information'));
->assertRedirect(localized_route('settings.show'));

expect($user->individual->other_payment_type)->toEqual('Square');

Expand All @@ -255,7 +255,7 @@
'other_payment_type' => 'Square',
])
->assertSessionHasNoErrors()
->assertRedirect(localized_route('settings.edit-payment-information'));
->assertRedirect(localized_route('settings.show'));

expect($user->individual->fresh()->paymentTypes)->toHaveCount(1);
});
Expand Down Expand Up @@ -312,7 +312,7 @@

actingAs($user)->put(localized_route('settings.update-areas-of-interest'), [])
->assertSessionHasNoErrors()
->assertRedirect(localized_route('settings.edit-areas-of-interest'));
->assertRedirect(localized_route('settings.show'));
});

test('other users cannot edit areas of interest', function () {
Expand All @@ -338,7 +338,7 @@
'theme' => 'dark',
'text_to_speech' => false,
])
->assertRedirect(localized_route('settings.edit-website-accessibility-preferences'))
->assertRedirect(localized_route('settings.show'))
->assertPlainCookie('theme', 'dark');
});

Expand All @@ -357,7 +357,7 @@
'preferred_notification_method' => 'email',
])
->assertSessionHasNoErrors()
->assertRedirect(localized_route('settings.edit-notification-preferences'));
->assertRedirect(localized_route('settings.show'));

$user = User::factory()->create(['context' => 'organization']);
Organization::factory()
Expand All @@ -371,7 +371,7 @@
'preferred_notification_method' => 'email',
])
->assertSessionHasNoErrors()
->assertRedirect(localized_route('settings.edit-notification-preferences'));
->assertRedirect(localized_route('settings.show'));
});

test('other users cannot edit notification preferences', function () {
Expand Down

0 comments on commit 603f981

Please sign in to comment.