FIX: Pass email correctly when resending activation email ()

Regressed as part of the refactoring in 7df4eab038. This commit also introduces a system spec for the activation flow.
This commit is contained in:
David Taylor 2023-10-02 13:00:29 +01:00 committed by GitHub
parent 5a904949b2
commit f314eaae55
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 60 additions and 21 deletions
app/assets/javascripts/discourse
spec

@ -1,4 +1,8 @@
<DModal @closeModal={{@closeModal}} @title={{i18n "log_in"}}> <DModal
@closeModal={{@closeModal}}
@title={{i18n "log_in"}}
class="not-activated-modal"
>
<:body> <:body>
{{html-safe (i18n "login.not_activated" sentTo=@model.sentTo)}} {{html-safe (i18n "login.not_activated" sentTo=@model.sentTo)}}
</:body> </:body>

@ -10,7 +10,7 @@ export default class NotActivated extends Component {
@action @action
sendActivationEmail() { sendActivationEmail() {
resendActivationEmail(this.username).then(() => { resendActivationEmail(this.args.model.currentEmail).then(() => {
this.modal.show(ActivationResent, { this.modal.show(ActivationResent, {
model: { currentEmail: this.args.model.currentEmail }, model: { currentEmail: this.args.model.currentEmail },
}); });

@ -1,19 +1,17 @@
(function () { (function () {
setTimeout(function () { const $activateButton = $("#activate-account-button");
const $activateButton = $("#activate-account-button"); $activateButton.on("click", function () {
$activateButton.on("click", function () { $activateButton.prop("disabled", true);
$activateButton.prop("disabled", true); const hpPath = document.getElementById("data-activate-account").dataset
const hpPath = document.getElementById("data-activate-account").dataset .path;
.path; $.ajax(hpPath)
$.ajax(hpPath) .then(function (hp) {
.then(function (hp) { $("#password_confirmation").val(hp.value);
$("#password_confirmation").val(hp.value); $("#challenge").val(hp.challenge.split("").reverse().join(""));
$("#challenge").val(hp.challenge.split("").reverse().join("")); $("#activate-account-form").submit();
$("#activate-account-form").submit(); })
}) .fail(function () {
.fail(function () { $activateButton.prop("disabled", false);
$activateButton.prop("disabled", false); });
}); });
});
}, 50);
})(); })();

@ -71,10 +71,10 @@ module Helpers
Guardian.stubs(new: guardian).with(user, anything) Guardian.stubs(new: guardian).with(user, anything)
end end
def wait_for(on_fail: nil, &blk) def wait_for(on_fail: nil, timeout: 1, &blk)
i = 0 i = 0
result = false result = false
while !result && i < 1000 while !result && i < timeout * 1000
result = blk.call result = blk.call
i += 1 i += 1
sleep 0.001 sleep 0.001

@ -0,0 +1,37 @@
# frozen_string_literal: true
describe "Account activation", type: :system do
fab!(:password) { "myverysecurepassword" }
fab!(:user) { Fabricate(:user, password: password, active: false) }
it "can resend activation email and activate account" do
Jobs.run_immediately!
visit "/"
find(".login-button").click
find("#login-account-name").fill_in with: user.email
find("#login-account-password").fill_in with: password
find("#login-button").click
not_activated_modal = find(".not-activated-modal")
expect(ActionMailer::Base.deliveries.count).to eq(0)
not_activated_modal.find("button.resend").click
wait_for(timeout: 5) { ActionMailer::Base.deliveries.count === 1 }
mail = ActionMailer::Base.deliveries.last
expect(mail.to).to contain_exactly(user.email)
activate_link = mail.body.to_s[%r{/u/activate-account/\S+}, 0]
visit activate_link
expect(user.reload.active).to eq(false)
find("#activate-account-button").click
wait_for(timeout: 5) { user.reload.active }
end
end