2016-11-08 14:29:50 -05:00
|
|
|
import { mapRoutes } from "discourse/mapping-router";
|
|
|
|
|
2014-07-30 17:53:14 -04:00
|
|
|
moduleFor("controller:create-account", "controller:create-account", {
|
2017-06-14 13:57:58 -04:00
|
|
|
beforeEach() {
|
2016-11-08 14:29:50 -05:00
|
|
|
this.registry.register("router:main", mapRoutes());
|
|
|
|
},
|
2014-08-14 12:51:16 -04:00
|
|
|
needs: ["controller:modal", "controller:login"]
|
2014-07-30 17:53:14 -04:00
|
|
|
});
|
2013-11-19 14:15:05 -05:00
|
|
|
|
2019-01-10 05:06:01 -05:00
|
|
|
test("basicUsernameValidation", async function(assert) {
|
|
|
|
const subject = this.subject;
|
2014-07-30 17:53:14 -04:00
|
|
|
|
2019-01-10 05:06:01 -05:00
|
|
|
const testInvalidUsername = async (username, expectedReason) => {
|
|
|
|
const controller = await subject({ siteSettings: Discourse.SiteSettings });
|
2013-11-19 14:15:05 -05:00
|
|
|
controller.set("accountUsername", username);
|
2019-01-10 05:06:01 -05:00
|
|
|
|
2017-06-14 13:57:58 -04:00
|
|
|
assert.equal(
|
|
|
|
controller.get("basicUsernameValidation.failed"),
|
|
|
|
true,
|
|
|
|
"username should be invalid: " + username
|
|
|
|
);
|
|
|
|
assert.equal(
|
|
|
|
controller.get("basicUsernameValidation.reason"),
|
|
|
|
expectedReason,
|
|
|
|
"username validation reason: " + username + ", " + expectedReason
|
|
|
|
);
|
2013-11-19 14:15:05 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
testInvalidUsername("", undefined);
|
|
|
|
testInvalidUsername("x", I18n.t("user.username.too_short"));
|
2014-06-09 15:27:37 -04:00
|
|
|
testInvalidUsername(
|
|
|
|
"123456789012345678901",
|
|
|
|
I18n.t("user.username.too_long")
|
|
|
|
);
|
2013-11-19 14:15:05 -05:00
|
|
|
|
2019-01-10 05:06:01 -05:00
|
|
|
const controller = await subject({ siteSettings: Discourse.SiteSettings });
|
|
|
|
controller.setProperties({
|
|
|
|
accountUsername: "porkchops",
|
|
|
|
prefilledUsername: "porkchops"
|
|
|
|
});
|
|
|
|
|
2017-06-14 13:57:58 -04:00
|
|
|
assert.equal(
|
|
|
|
controller.get("basicUsernameValidation.ok"),
|
|
|
|
true,
|
|
|
|
"Prefilled username is valid"
|
|
|
|
);
|
|
|
|
assert.equal(
|
|
|
|
controller.get("basicUsernameValidation.reason"),
|
|
|
|
I18n.t("user.username.prefilled"),
|
|
|
|
"Prefilled username is valid"
|
|
|
|
);
|
2013-11-19 14:15:05 -05:00
|
|
|
});
|
2015-02-25 11:59:57 -05:00
|
|
|
|
2019-01-10 05:06:01 -05:00
|
|
|
test("passwordValidation", async function(assert) {
|
|
|
|
const controller = await this.subject({
|
|
|
|
siteSettings: Discourse.SiteSettings
|
|
|
|
});
|
2015-02-25 11:59:57 -05:00
|
|
|
|
|
|
|
controller.set("passwordRequired", true);
|
2016-03-04 04:52:23 -05:00
|
|
|
controller.set("accountEmail", "pork@chops.com");
|
|
|
|
controller.set("accountUsername", "porkchops");
|
2015-02-25 11:59:57 -05:00
|
|
|
controller.set("prefilledUsername", "porkchops");
|
2016-03-04 04:52:23 -05:00
|
|
|
controller.set("accountPassword", "b4fcdae11f9167");
|
2019-01-10 05:06:01 -05:00
|
|
|
|
2017-06-14 13:57:58 -04:00
|
|
|
assert.equal(controller.get("passwordValidation.ok"), true, "Password is ok");
|
|
|
|
assert.equal(
|
|
|
|
controller.get("passwordValidation.reason"),
|
|
|
|
I18n.t("user.password.ok"),
|
|
|
|
"Password is valid"
|
|
|
|
);
|
2015-02-25 11:59:57 -05:00
|
|
|
|
2019-01-10 05:06:01 -05:00
|
|
|
const testInvalidPassword = (password, expectedReason) => {
|
|
|
|
controller.set("accountPassword", password);
|
|
|
|
|
2017-06-14 13:57:58 -04:00
|
|
|
assert.equal(
|
2019-01-10 05:06:01 -05:00
|
|
|
controller.get("passwordValidation.failed"),
|
2017-06-14 13:57:58 -04:00
|
|
|
true,
|
|
|
|
"password should be invalid: " + password
|
|
|
|
);
|
|
|
|
assert.equal(
|
2019-01-10 05:06:01 -05:00
|
|
|
controller.get("passwordValidation.reason"),
|
2017-06-14 13:57:58 -04:00
|
|
|
expectedReason,
|
|
|
|
"password validation reason: " + password + ", " + expectedReason
|
|
|
|
);
|
2015-02-25 11:59:57 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
testInvalidPassword("", undefined);
|
|
|
|
testInvalidPassword("x", I18n.t("user.password.too_short"));
|
|
|
|
testInvalidPassword("porkchops", I18n.t("user.password.same_as_username"));
|
2015-02-27 13:47:43 -05:00
|
|
|
testInvalidPassword("pork@chops.com", I18n.t("user.password.same_as_email"));
|
2015-02-25 11:59:57 -05:00
|
|
|
});
|
2018-11-22 14:12:04 -05:00
|
|
|
|
2019-01-10 05:06:01 -05:00
|
|
|
test("authProviderDisplayName", async function(assert) {
|
2018-11-22 14:12:04 -05:00
|
|
|
const controller = this.subject({ siteSettings: Discourse.SiteSettings });
|
|
|
|
|
|
|
|
assert.equal(
|
|
|
|
controller.authProviderDisplayName("facebook"),
|
|
|
|
I18n.t("login.facebook.name"),
|
|
|
|
"provider name is translated correctly"
|
|
|
|
);
|
2019-01-10 05:06:01 -05:00
|
|
|
|
2018-11-22 14:12:04 -05:00
|
|
|
assert.equal(
|
|
|
|
controller.authProviderDisplayName("idontexist"),
|
|
|
|
"idontexist",
|
|
|
|
"provider name falls back if not found"
|
|
|
|
);
|
|
|
|
});
|