Skip to content

Commit

Permalink
Update expected error messages (#6674)
Browse files Browse the repository at this point in the history
  • Loading branch information
kneth authored May 23, 2024
1 parent 915ede7 commit 27908f3
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion integration-tests/tests/src/tests/sync/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ describe("App", () => {
const credentials = Realm.Credentials.emailPassword("me", "secret");
let didFail = false;
const user = await this.app.logIn(credentials).catch((err) => {
expect(err.message).equals("invalid username/password");
expect(err.message).equals("unauthorized");
expect(err.code).equals(4349);
didFail = true;
});
Expand Down
20 changes: 10 additions & 10 deletions integration-tests/tests/src/tests/sync/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ describe("User", () => {

it("login with non existing user throws", async function (this: AppContext & RealmContext) {
const credentials = Realm.Credentials.emailPassword({ email: "foo", password: "pass" });
await expect(this.app.logIn(credentials)).to.be.rejectedWith("invalid username/password");
await expect(this.app.logIn(credentials)).to.be.rejectedWith("unauthorized");
});

it("email password authprovider is correct instance", async function (this: AppContext & RealmContext) {
Expand All @@ -122,28 +122,28 @@ describe("User", () => {

it("invalid email, invalid password", async function (this: AppContext & RealmContext) {
const credentials = Realm.Credentials.emailPassword({ email: invalidEmail, password: invalidPassword });
await expect(this.app.logIn(credentials)).to.be.rejectedWith("invalid username/password"); // this user does not exist yet
await expect(this.app.logIn(credentials)).to.be.rejectedWith("unauthorized"); // this user does not exist yet
await expect(
this.app.emailPasswordAuth.registerUser({ email: invalidEmail, password: invalidPassword }),
).to.eventually.be.rejectedWith("password must be between 6 and 128 characters");
await expect(this.app.logIn(credentials)).to.be.rejectedWith("invalid username/password"); // this user did not register
await expect(this.app.logIn(credentials)).to.be.rejectedWith("unauthorized"); // this user did not register
});

it("valid email, invalid password", async function (this: AppContext & RealmContext) {
const credentials = Realm.Credentials.emailPassword({ email: validEmail, password: invalidPassword });
await expect(this.app.logIn(credentials)).to.be.rejectedWith("invalid username/password"); // this user does not exist yet
await expect(this.app.logIn(credentials)).to.be.rejectedWith("unauthorized"); // this user does not exist yet
await expect(
this.app.emailPasswordAuth.registerUser({ email: validEmail, password: invalidPassword }),
).to.eventually.be.rejectedWith("password must be between 6 and 128 characters");
await expect(this.app.logIn(credentials)).to.be.rejectedWith("invalid username/password"); // this user did not register
await expect(this.app.logIn(credentials)).to.be.rejectedWith("unauthorized"); // this user did not register
});

it("valid email, valid password", async function (this: AppContext & RealmContext) {
const validEmail = randomVerifiableEmail();
const validPassword = "password123456";

const credentials = Realm.Credentials.emailPassword({ email: validEmail, password: validPassword });
await expect(this.app.logIn(credentials)).to.be.rejectedWith("invalid username/password"); // this user does not exist yet
await expect(this.app.logIn(credentials)).to.be.rejectedWith("unauthorized"); // this user does not exist yet
await this.app.emailPasswordAuth.registerUser({ email: validEmail, password: validPassword });
const user = await this.app.logIn(credentials);
expectIsUser(user);
Expand All @@ -155,7 +155,7 @@ describe("User", () => {
it("valid email, valid password", async function (this: AppContext & RealmContext) {
removeExistingUsers();
const credentials = Realm.Credentials.emailPassword({ email: validEmail, password: validPassword });
await expect(this.app.logIn(credentials)).to.be.rejectedWith("invalid username/password"); // this user does not exist yet
await expect(this.app.logIn(credentials)).to.be.rejectedWith("unauthorized"); // this user does not exist yet
await this.app.emailPasswordAuth.registerUser({ email: validEmail, password: validPassword });
const user = await this.app.logIn(credentials);
expectIsUser(user);
Expand Down Expand Up @@ -360,7 +360,7 @@ describe("User", () => {
const user2 = await this.app
.logIn(Realm.Credentials.emailPassword({ email: validEmail, password: validPassword }))
.catch((err) => {
expect(err.message).equals("invalid username/password");
expect(err.message).equals("unauthorized");
expect(err.code).equals(4349);
didFail = true;
});
Expand Down Expand Up @@ -609,11 +609,11 @@ describe("User", () => {
const validPassword = "password123456";

const credentials = Realm.Credentials.emailPassword({ email: invalidEmail, password: validPassword });
await expect(this.app.logIn(credentials)).to.be.rejectedWith("invalid username/password"); // this user does not exist yet
await expect(this.app.logIn(credentials)).to.be.rejectedWith("unauthorized"); // this user does not exist yet
expect(
this.app.emailPasswordAuth.registerUser({ email: invalidEmail, password: validPassword }),
).to.eventually.be.rejectedWith(`failed to confirm user "${invalidEmail}"`);
await expect(this.app.logIn(credentials)).to.be.rejectedWith("invalid username/password"); // this user did not register
await expect(this.app.logIn(credentials)).to.be.rejectedWith("unauthorized"); // this user did not register
});

it("reset password function works", async function (this: AppContext & RealmContext) {
Expand Down
2 changes: 1 addition & 1 deletion packages/realm-web-integration-tests/src/user.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ describe("User", () => {
throw new Error("Expected an error!");
} catch (err) {
if (err instanceof Error) {
expect(err.message).contains("invalid username/password");
expect(err.message).contains("unauthorized");
} else {
throw err;
}
Expand Down

0 comments on commit 27908f3

Please sign in to comment.