core: fix e2e tests

This commit is contained in:
Abdullah Atta
2025-10-03 13:54:17 +05:00
parent 6ae1674de5
commit 2949fcde38
7 changed files with 44 additions and 84 deletions

View File

@@ -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>,
}
`;

View File

@@ -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
);
});

View File

@@ -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`
);
}
);
}
);

View File

@@ -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,

View File

@@ -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,

View File

@@ -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,

View File

@@ -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;
}