Skip to content

Commit

Permalink
Added tests for realm-web[-integration]
Browse files Browse the repository at this point in the history
  • Loading branch information
Franck Franck committed Oct 7, 2021
1 parent edc960e commit c8b4b99
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/realm-web-integration-tests/harness/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ const EXPECTED_ISSUES = [
"Failed to load resource: the server responded with a status of 400 (Bad Request)",
"Failed to load resource: the server responded with a status of 400 (Bad Request)",
"Failed to load resource: the server responded with a status of 400 (Bad Request)",
"Failed to load resource: the server responded with a status of 400 (Bad Request)",
];

function checkIssues(issues: string[]) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,26 @@ describe("EmailPasswordAuth", () => {
}
});

it("retry custom confirmation", async () => {
const app = createApp();
// Prepare email and password
const now = new Date();
const nonce = now.getTime();
const email = `gilfoil-${nonce}@testing.mongodb.com`;
const password = "my-super-secret-password";
// Register a user
await app.emailPasswordAuth.registerUser(email, password);
// Ask for a new confirmation email
try {
await app.emailPasswordAuth.retryCustomConfirmation(email);
} catch (err) {
// We expect this to throw, since the app does not currently have custom confirmation enabled
// TODO: import an app with custom confirmation enabled
expect(err).instanceOf(MongoDBRealmError);
expect(err.error).equals(`cannot run confirmation for ${email}: automatic confirmation is enabled`);
}
});

it("can request a password reset", async () => {
const app = createApp();
// Prepare email and password
Expand Down
1 change: 1 addition & 0 deletions packages/realm-web-integration-tests/test/mocha.opts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
--watch-extensions ts
--require ts-node/register
--slow 1000
16 changes: 16 additions & 0 deletions packages/realm-web/src/tests/EmailPasswordAuth.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,22 @@ describe("EmailPasswordAuth", () => {
]);
});

it("can request a retry of custom confirmation", async () => {
// Make a request
await client.retryCustomConfirmation("[email protected]");
// Expect something of the request
expect(fetcher.requests).deep.equals([
{
method: "POST",
url: "http://localhost:1337/api/client/v2.0/app/mocked-app-id/auth/providers/local-userpass/confirm/call",
body: {
email: "[email protected]",
},
headers: SENDING_JSON_HEADERS,
},
]);
});

it("can reset a password", async () => {
// Make a request
await client.resetPassword("token-value", "token-id-value", "my-new-password");
Expand Down

0 comments on commit c8b4b99

Please sign in to comment.