Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

core: fix e2e tests

Abdullah Atta2949fcde386e
diff --git a/packages/core/__e2e__/__snapshots__/pricing.test.js.snap b/packages/core/__e2e__/__snapshots__/pricing.test.js.snap
index 49e608e4c..7a9823d0f 100644
--- a/packages/core/__e2e__/__snapshots__/pricing.test.js.snap
+++ b/packages/core/__e2e__/__snapshots__/pricing.test.js.snap
@@ -1,82 +1,52 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
-exports[`get android pricing tier > get monthly android tier > monthly-android-pricing 1`] = `
+exports[`get apple pricing tier > get monthly apple tier > monthly-apple-pricing 1`] = `
{
"country": Any<String>,
"countryCode": Any<String>,
- "discount": Any<Number>,
"sku": Any<String>,
}
`;
-exports[`get android pricing tier > get yearly android tier > yearly-android-pricing 1`] = `
+exports[`get apple pricing tier > get yearly apple tier > yearly-apple-pricing 1`] = `
{
"country": Any<String>,
"countryCode": Any<String>,
- "discount": Any<Number>,
+ "discount": 50,
"sku": Any<String>,
}
`;
-exports[`get ios pricing tier > get monthly ios tier > monthly-ios-pricing 1`] = `
+exports[`get google pricing tier > get monthly google tier > monthly-google-pricing 1`] = `
{
"country": Any<String>,
"countryCode": Any<String>,
- "discount": Any<Number>,
"sku": Any<String>,
}
`;
-exports[`get ios pricing tier > get yearly ios tier > yearly-ios-pricing 1`] = `
+exports[`get google pricing tier > get yearly google tier > yearly-google-pricing 1`] = `
{
"country": Any<String>,
"countryCode": Any<String>,
- "discount": Any<Number>,
+ "discount": 50,
"sku": Any<String>,
}
`;
-exports[`get monthly price > monthly-pricing 1`] = `
+exports[`get paddle pricing tier > get monthly paddle tier > monthly-paddle-pricing 1`] = `
{
"country": Any<String>,
"countryCode": Any<String>,
- "discount": Any<Number>,
- "price": Any<Number>,
-}
-`;
-
-exports[`get undefined price > monthly-pricing 1`] = `
-{
- "country": Any<String>,
- "countryCode": Any<String>,
- "discount": Any<Number>,
- "price": Any<Number>,
-}
-`;
-
-exports[`get web pricing tier > get monthly web tier > monthly-web-pricing 1`] = `
-{
- "country": Any<String>,
- "countryCode": Any<String>,
- "discount": Any<Number>,
"sku": Any<String>,
}
`;
-exports[`get web pricing tier > get yearly web tier > yearly-web-pricing 1`] = `
+exports[`get paddle pricing tier > get yearly paddle tier > yearly-paddle-pricing 1`] = `
{
"country": Any<String>,
"countryCode": Any<String>,
- "discount": Any<Number>,
+ "discount": 50,
"sku": Any<String>,
}
`;
-
-exports[`get yearly price > yearly-pricing 1`] = `
-{
- "country": Any<String>,
- "countryCode": Any<String>,
- "discount": Any<Number>,
- "price": Any<Number>,
-}
-`;
diff --git a/packages/core/__e2e__/offers.test.js b/packages/core/__e2e__/offers.test.js
index 6ab658081..c131b912a 100644
--- a/packages/core/__e2e__/offers.test.js
+++ b/packages/core/__e2e__/offers.test.js
@@ -30,7 +30,7 @@ test("get offer code", async () => {
test("get invalid offer code", async () => {
hosts.SUBSCRIPTIONS_HOST = "https://subscriptions.streetwriters.co";
- await expect(() => Offers.getCode("INVALIDOFFER", "android")).rejects.toThrow(
- /Not found/i
+ await expect(Offers.getCode("INVALIDOFFER", "android")).rejects.toThrow(
+ /Request failed with status code: 404./i
);
});
diff --git a/packages/core/__e2e__/pricing.test.js b/packages/core/__e2e__/pricing.test.js
index 6e335f516..a4f9442b2 100644
--- a/packages/core/__e2e__/pricing.test.js
+++ b/packages/core/__e2e__/pricing.test.js
@@ -20,33 +20,22 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
import { Pricing } from "../src/api/pricing.ts";
import { test, expect, describe } from "vitest";
-test.each(["monthly", "yearly", undefined])(`get %s price`, async (period) => {
- const price = await Pricing.price(period);
- expect(price).toMatchSnapshot(
- {
- country: expect.any(String),
- countryCode: expect.any(String),
- discount: expect.any(Number),
- price: expect.any(Number)
- },
- `${period || "monthly"}-pricing`
- );
-});
-
-describe.each(["android", "ios", "web"])(`get %s pricing tier`, (platform) => {
- test.each(["monthly", "yearly"])(
- `get %s ${platform} tier`,
- async (period) => {
- const price = await Pricing.sku(platform, period);
- expect(price).toMatchSnapshot(
- {
- country: expect.any(String),
- countryCode: expect.any(String),
- discount: expect.any(Number),
- sku: expect.any(String)
- },
- `${period}-${platform}-pricing`
- );
- }
- );
-});
+describe.each(["google", "apple", "paddle"])(
+ `get %s pricing tier`,
+ (platform) => {
+ test.each(["monthly", "yearly"])(
+ `get %s ${platform} tier`,
+ async (period) => {
+ const price = await Pricing.sku(platform, period, "pro");
+ expect(price).toMatchSnapshot(
+ {
+ country: expect.any(String),
+ countryCode: expect.any(String),
+ sku: expect.any(String)
+ },
+ `${period}-${platform}-pricing`
+ );
+ }
+ );
+ }
+);
diff --git a/packages/core/__e2e__/sync.test.js b/packages/core/__e2e__/sync.test.js
index 90a8785dc..47be56779 100644
--- a/packages/core/__e2e__/sync.test.js
+++ b/packages/core/__e2e__/sync.test.js
@@ -17,7 +17,7 @@ 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 { CHECK_IDS, EV, EVENTS } from "../src/common.ts";
+import { EV, EVENTS } from "../src/common.ts";
import { test, expect, vitest } from "vitest";
import { login } from "./utils.js";
import { databaseTest } from "../__tests__/utils/index.ts";
@@ -418,8 +418,8 @@ test(
"issue: colors are not properly created if multiple notes are synced together",
async (t) => {
const [deviceA, deviceB] = await Promise.all([
- initializeDevice("deviceA", [CHECK_IDS.noteColor]),
- initializeDevice("deviceB", [CHECK_IDS.noteColor])
+ initializeDevice("deviceA"),
+ initializeDevice("deviceB")
]);
t.onTestFinished(async () => {
@@ -476,16 +476,11 @@ test(
* @param {string} id
* @returns {Promise<Database>}
*/
-async function initializeDevice(id, capabilities = []) {
+async function initializeDevice(id) {
// initialize(new NodeStorageInterface(), false);
console.time(`Init ${id}`);
- EV.subscribe(EVENTS.userCheckStatus, async (type) => {
- return {
- type,
- result: capabilities.indexOf(type) > -1
- };
- });
+
EV.subscribe(EVENTS.syncCheckStatus, async (type) => {
return {
type,
diff --git a/packages/core/src/api/monographs.ts b/packages/core/src/api/monographs.ts
index f0f30dd21..1d254b2c2 100644
--- a/packages/core/src/api/monographs.ts
+++ b/packages/core/src/api/monographs.ts
@@ -127,6 +127,7 @@ export class Monographs {
const method = update ? http.patch.json : http.post.json;
const deviceId = await this.db.kv().read("deviceId");
+ console.log("PUBLISHING", monograph);
const { id, datePublished } = await method(
`${Constants.API_HOST}/monographs?deviceId=${deviceId}`,
monograph,
diff --git a/packages/core/src/database/sanitizer.ts b/packages/core/src/database/sanitizer.ts
index 0d135c7d6..dd3ecac44 100644
--- a/packages/core/src/database/sanitizer.ts
+++ b/packages/core/src/database/sanitizer.ts
@@ -53,7 +53,9 @@ export class Sanitizer {
for (const key in item) {
if (schema.has(key)) continue;
if (process.env.NODE_ENV === "test")
- throw new Error(`Found invalid key in item ${key} (${table})`);
+ throw new Error(
+ `Found invalid key in item ${key} (${table}) ${JSON.stringify(item)}`
+ );
else
this.logger.debug("Found invalid key in item", {
table,
diff --git a/packages/core/src/utils/http.ts b/packages/core/src/utils/http.ts
index bc4e79bef..032a502d2 100644
--- a/packages/core/src/utils/http.ts
+++ b/packages/core/src/utils/http.ts
@@ -176,12 +176,15 @@ async function handleResponse(response: Response) {
throw new Error("Unauthorized.");
} else
throw new Error(
- `Request failed with status code: ${response.status} ${response.statusText}.`
+ `Request failed with status code: ${response.status} ${
+ response.url
+ } ${await response.text()}.`
);
}
} catch (e) {
logger.error(e, "Error while sending request:", {
- url: response.url
+ url: response.url,
+ body: response.bodyUsed ? undefined : await response.text()
});
throw e;
}