A fully open source & end-to-end encrypted note taking alternative to Evernote.
TypeScript asp-net-coredotnet-coreelectronfosshacktoberfestnote-managmentnote-takingnote-taking-appnotebooknotesnotes-appopen-sourceopensourceprivacyproductivityreactreact-nativereactjsself-hosted
core: fix core tests
Abdullah Atta9e66269aca57
diff --git a/packages/core/__e2e__/sync.test.js b/packages/core/__e2e__/sync.test.jsindex e9eb8e4e8..bb25831ba 100644--- a/packages/core/__e2e__/sync.test.js+++ b/packages/core/__e2e__/sync.test.js@@ -51,6 +51,7 @@ test(expect(types.every((t) => t === "download")).toBe(true);+ console.log("Case 1 log out");await cleanup(deviceA, deviceB, deviceC);},TEST_TIMEOUT@@ -78,7 +79,8 @@ test(expect(deviceA.notes.note(note1Id)).toBeTruthy();expect(deviceB.notes.note(note2Id)).toBeTruthy();- await cleanup(deviceA, deviceA);+ console.log("Case 3 log out");+ await cleanup(deviceA, deviceB);},TEST_TIMEOUT);@@ -225,7 +227,8 @@ test(expect(handler).not.toHaveBeenCalled();- await cleanup(deviceB);+ console.log("issue force sync log out");+ await cleanup(deviceA, deviceB);},TEST_TIMEOUT);@@ -264,6 +267,7 @@ test(true);+ console.log("issue colors log out");await cleanup(deviceA, deviceB);},TEST_TIMEOUT@@ -310,6 +314,7 @@ test(expect(deviceA.notebooks.notebook(id).topics.has("Topic 2")).toBeTruthy();expect(deviceB.notebooks.notebook(id).topics.has("Topic 2")).toBeTruthy();+ console.log("issue new topic log out");await cleanup(deviceA, deviceB);},TEST_TIMEOUT@@ -375,6 +380,7 @@ test(deviceB.notebooks.notebook(id).topics.topic(topic.id).totalNotes).toBe(2);+ console.log("issue assigning 2 notes log out");await cleanup(deviceA, deviceB);},TEST_TIMEOUT@@ -420,13 +426,12 @@ async function initializeDevice(id, capabilities = []) {* @param {...Database} devices*/async function cleanup(...devices) {- await Promise.all([- devices.map(async (device) => {- await device.syncer.stop();- await device.user.logout();- device.eventManager.unsubscribeAll();- })- ]);+ for (const device of devices) {+ device.disconnectSSE();+ await device.syncer.stop();+ await device.user.logout();+ device.eventManager.unsubscribeAll();+ }EV.unsubscribeAll();}diff --git a/packages/core/globals.setup.js b/packages/core/globals.setup.jsindex ab4dc7d0e..39650b37c 100644--- a/packages/core/globals.setup.js+++ b/packages/core/globals.setup.js@@ -18,11 +18,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.*/import "isomorphic-fetch";-import crypto from "crypto";import dotenv from "dotenv";import { DOMParser } from "linkedom";globalThis.DOMParser = DOMParser;require("abortcontroller-polyfill/dist/polyfill-patch-fetch");-globalThis.crypto = crypto;dotenv.config();diff --git a/packages/core/src/api/sync/index.js b/packages/core/src/api/sync/index.jsindex b8d2e6794..7d66dfc1a 100644--- a/packages/core/src/api/sync/index.js+++ b/packages/core/src/api/sync/index.js@@ -62,20 +62,23 @@ export default class SyncManager {var isHubException = e.message.includes("HubException:");if (isHubException) {var actualError = /HubException: (.*)/gm.exec(e.message);+ const errorText =+ actualError && actualError.length > 1 ? actualError[1] : e.message;// NOTE: sometimes there's the case where the user has already// confirmed their email but the server still thinks that it// isn't confirmed. This check is added to trigger a force// update of the access token.if (- actualError.includes("Please confirm your email ") &&+ (errorText.includes("Please confirm your email ") ||+ errorText.includes("Invalid token.")) &&(await this._db.user.getUser()).isEmailConfirmed) {await this._db.user.tokenManager._refreshToken(true);return false;}- if (actualError.length > 1) throw new Error(actualError[1]);+ throw new Error(errorText);}throw e;}diff --git a/packages/core/src/api/token-manager.js b/packages/core/src/api/token-manager.jsindex 878c3935c..733f68e5f 100644--- a/packages/core/src/api/token-manager.js+++ b/packages/core/src/api/token-manager.js@@ -85,6 +85,7 @@ class TokenManager {this.logger.info("Refreshing access token");const token = await this.getToken(false, false);+ if (!token) throw new Error("No access token found to refresh.");if (!forceRenew && !this._isTokenExpired(token)) {return;}@@ -113,6 +114,7 @@ class TokenManager {if (!token) return;const { access_token } = token;+ await this._storage.remove("token");await http.post(`${constants.AUTH_HOST}${ENDPOINTS.logout}`,null,