Skip to content

Commit

Permalink
mobile: update auth tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ammarahm-ed authored and thecodrr committed Jan 6, 2023
1 parent e43ee80 commit dd2a273
Show file tree
Hide file tree
Showing 6 changed files with 188 additions and 56 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ dist
.DS_STORE
nx-cloud.env
.idea
.eslintcache
.eslintcache
.env.local
11 changes: 7 additions & 4 deletions apps/mobile/app/components/auth/login.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import PremiumService from "../../services/premium";
import SettingsService from "../../services/settings";
import { useThemeStore } from "../../stores/use-theme-store";
import { useUserStore } from "../../stores/use-user-store";
import { eCloseSheet } from "../../utils/events";
import { SIZE } from "../../utils/size";
import { sleep } from "../../utils/time";
import BaseDialog from "../dialog/base-dialog";
Expand Down Expand Up @@ -119,16 +120,18 @@ export const Login = ({ changeMode }) => {
} catch (e) {
callback && callback(false);
if (e.message === "invalid_grant") {
eSendEvent(eCloseProgressDialog, "two_factor_verify");
eSendEvent(eCloseSheet, "two_factor_verify");
setLoading(false);
}
}
}, mfaInfo);
}
break;
}
case LoginSteps.passwordAuth: {
await db.user.authenticatePassword(email.current, password.current);
finishLogin();
break;
}
}
setLoading(false);
Expand All @@ -140,7 +143,7 @@ export const Login = ({ changeMode }) => {
const finishWithError = async (e) => {
setLoading(false);
ToastEvent.show({
heading: user ? "Failed to sync" : "Login failed",
heading: "Login failed",
message: e.message,
type: "error",
context: "local"
Expand Down Expand Up @@ -325,8 +328,8 @@ export const Login = ({ changeMode }) => {
loading
? null
: step === LoginSteps.emailAuth
? "Login to your account"
: "Complete login"
? "Login"
: "Continue"
}
/>

Expand Down
1 change: 1 addition & 0 deletions apps/mobile/app/components/auth/two-factor.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ const TwoFactorVerification = ({ onMfaLogin, mfaInfo }) => {
placeholder={
currentMethod.method === "recoveryCode" ? "xxxxxxxx" : "xxxxxx"
}
testID={"input.totp"}
maxLength={currentMethod.method === "recoveryCode" ? 8 : 6}
fwdRef={inputRef}
textAlign="center"
Expand Down
94 changes: 44 additions & 50 deletions apps/mobile/e2e/tests/auth.e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,75 +17,69 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import { authenticator } from "otplib";
import {
tapByText,
prepare,
openSideMenu,
elementById,
visibleByText,
sleep
openSideMenu,
prepare,
sleep,
tapByText,
visibleByText
} from "./utils";

const credentials = {
username: "testaccount1@notesnook.com",
password: "testaccount@123"
import dotenv from "dotenv";
import path from "path";

dotenv.config({ path: path.join(__dirname, ".env.local") });

const USER = {
login: {
email: process.env.USER_EMAIL,
password: process.env.CURRENT_USER_PASSWORD,
key: process.env.CURRENT_USER_KEY,
totpSecret: process.env.USER_TOTP_SECRET
}
};

async function login() {
await tapByText("Login to sync your notes.");
await elementById("input.email").typeText(credentials.username);
await elementById("input.password").typeText(credentials.password);
await elementById("input.email").typeText(USER.login.email);
await tapByText("Login");
await sleep(3000);
await elementById("input.totp").typeText(
authenticator.generate(USER.login.totpSecret)
);
await sleep(3000);
await elementById("input.password").typeText(USER.login.password);
await elementById("input.password").tapReturnKey();
}

async function deleteAccount() {
await tapByText("Account Settings");
await sleep(2000);
await tapByText("Delete account");
await elementById("input-value").typeText(credentials.password);
await tapByText("Delete");
await sleep(5000);
}
// async function deleteAccount() {
// await tapByText("Account Settings");
// await sleep(2000);
// await tapByText("Delete account");
// await elementById("input-value").typeText(USER.password);
// await tapByText("Delete");
// await sleep(5000);
// }

async function signup() {
await tapByText("Login to sync your notes.");
await sleep(500);
await tapByText("Don't have an account? Sign up");
await elementById("input.email").typeText(credentials.username);
await elementById("input.password").typeText(credentials.password);
await elementById("input.confirmPassword").typeText(credentials.password);
await elementById("input.confirmPassword").tapReturnKey();
}
// async function signup() {
// await tapByText("Login to sync your notes.");
// await sleep(500);
// await tapByText("Don't have an account? Sign up");
// await elementById("input.email").typeText(USER.signup.email);
// await elementById("input.password").typeText(USER.signup.password);
// await elementById("input.confirmPassword").typeText(USER.signup.password);
// await elementById("input.confirmPassword").tapReturnKey();
// }

describe("AUTH", () => {
it("Sign up", async () => {
await prepare();
await openSideMenu();
await signup();
await sleep(5000);
await device.pressBack();
await sleep(5000);
await openSideMenu();
await visibleByText("Tap here to sync your notes.");
});

it("Login to account", async () => {
it("Login", async () => {
await prepare();
await openSideMenu();
await login();
await sleep(10000);
await openSideMenu();
await visibleByText("Tap here to sync your notes.");
});

it("Delete account", async () => {
await prepare();
await openSideMenu();
await login();
await sleep(15000);
await openSideMenu();
await tapByText("Settings");
await sleep(1000);
await deleteAccount();
});
});
132 changes: 132 additions & 0 deletions apps/mobile/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion apps/mobile/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
},
"devDependencies": {
"patch-package": "^6.4.7",
"typescript": "^4.8.2"
"typescript": "^4.8.2",
"otplib": "12.0.1"
},
"dependencies": {
"@notesnook/core": "*",
Expand Down

0 comments on commit dd2a273

Please sign in to comment.