From c8b4b99a30de010bd871fbec4ba6166406d89e62 Mon Sep 17 00:00:00 2001 From: Franck Franck Date: Wed, 6 Oct 2021 14:44:08 +0200 Subject: [PATCH] Added tests for realm-web[-integration] --- .../harness/index.ts | 1 + .../src/email-password-auth.test.ts | 20 +++++++++++++++++++ .../test/mocha.opts | 1 + .../src/tests/EmailPasswordAuth.test.ts | 16 +++++++++++++++ 4 files changed, 38 insertions(+) diff --git a/packages/realm-web-integration-tests/harness/index.ts b/packages/realm-web-integration-tests/harness/index.ts index 62edd60d80..8871a08a21 100644 --- a/packages/realm-web-integration-tests/harness/index.ts +++ b/packages/realm-web-integration-tests/harness/index.ts @@ -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[]) { diff --git a/packages/realm-web-integration-tests/src/email-password-auth.test.ts b/packages/realm-web-integration-tests/src/email-password-auth.test.ts index 5acbfdb223..e079c7177b 100644 --- a/packages/realm-web-integration-tests/src/email-password-auth.test.ts +++ b/packages/realm-web-integration-tests/src/email-password-auth.test.ts @@ -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 diff --git a/packages/realm-web-integration-tests/test/mocha.opts b/packages/realm-web-integration-tests/test/mocha.opts index 8ebbba744d..e9744ff7c8 100644 --- a/packages/realm-web-integration-tests/test/mocha.opts +++ b/packages/realm-web-integration-tests/test/mocha.opts @@ -1,2 +1,3 @@ --watch-extensions ts --require ts-node/register +--slow 1000 diff --git a/packages/realm-web/src/tests/EmailPasswordAuth.test.ts b/packages/realm-web/src/tests/EmailPasswordAuth.test.ts index 2723c0709e..2119a58f37 100644 --- a/packages/realm-web/src/tests/EmailPasswordAuth.test.ts +++ b/packages/realm-web/src/tests/EmailPasswordAuth.test.ts @@ -92,6 +92,22 @@ describe("EmailPasswordAuth", () => { ]); }); + it("can request a retry of custom confirmation", async () => { + // Make a request + await client.retryCustomConfirmation("gilfoyle@testing.mongodb.com"); + // 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: "gilfoyle@testing.mongodb.com", + }, + headers: SENDING_JSON_HEADERS, + }, + ]); + }); + it("can reset a password", async () => { // Make a request await client.resetPassword("token-value", "token-id-value", "my-new-password");