diff --git a/src/utils/transaction.test.ts b/src/utils/transaction.test.ts index 8fd193d..aace472 100644 --- a/src/utils/transaction.test.ts +++ b/src/utils/transaction.test.ts @@ -185,12 +185,17 @@ describe("Firestore Transaction Tests", () => { // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-expect-error await overwriteTransactionsBatched(user, transactions_with_doc.map((t) => t.forceGetDocName()), transactions_with_doc); - + + const sleep = (milliseconds: number) => { + return new Promise(resolve => setTimeout(resolve, milliseconds)) + }; + await sleep(1000); + // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-expect-error const overwritten_transactions = await getTransactionsFilterOrderBy(user, where("name", "==", new_transaction_name)); - expect(overwritten_transactions.reduce((curr, t) => curr && (t.name == new_transaction_name), true)).toBeTruthy(); + expect(overwritten_transactions.length).toBe(transactions.length); await t.cleanup(); }, 40_000); diff --git a/src/utils/transaction.ts b/src/utils/transaction.ts index 71923c5..c2887b7 100644 --- a/src/utils/transaction.ts +++ b/src/utils/transaction.ts @@ -181,7 +181,7 @@ export async function overwriteTransaction(user: User, docName: string, transact // Writes a batch of transactions to Firestore export async function writeNewTransactionsBatched(user: User, transactions: Transaction[]): Promise { - for (let i = 0; i < transactions.length; i+=500) { + for (let i = 0; i < transactions.length; i += MAX_BATCH_SIZE) { const batch = writeBatch(db); const chunk = transactions.slice(i, i + MAX_BATCH_SIZE); chunk.forEach((transaction) => { @@ -198,14 +198,14 @@ export async function writeNewTransactionsBatched(user: User, transactions: Tran // Overwrites a batch of existing transactions in Firestore export async function overwriteTransactionsBatched(user: User, docName: string[], transactions: Transaction[]): Promise { - for (let i = 0; i < transactions.length; i += 500) { + for (let i = 0; i < transactions.length; i += MAX_BATCH_SIZE) { const batch = writeBatch(db); const chunk = transactions.slice(i, i + MAX_BATCH_SIZE); - chunk.forEach((transaction) => { + chunk.forEach((transaction, j) => { if (user.uid != transaction.uid) { throw Error(`Current user is '${user.uid}' however transaction is '${transaction.uid}'`); } - const newTransactionRef = doc(collection(db, "Transactions"), docName[i]); + const newTransactionRef = doc(collection(db, "Transactions"), docName[i + j]); batch.set(newTransactionRef, transaction.toSendObject()); }); diff --git a/src/utils/user_prefs.test.ts b/src/utils/user_prefs.test.ts index 1e71ca3..33f77c6 100644 --- a/src/utils/user_prefs.test.ts +++ b/src/utils/user_prefs.test.ts @@ -9,7 +9,7 @@ import {setTestDBContext} from "./firebase.ts"; describe("Firestore UserPrefs Tests", () => { test("Category Integrity Test", () => { - expect(_.isEqual(new Set(Object.keys(Categories)), TransactionCategories), "Emoji keys do not match transaction categories").toBeTruthy(); + expect(_.isEqual(new Set(Object.keys(Categories)), TransactionCategories), "Category keys do not match transaction categories").toBeTruthy(); }); test("Read/Write/Default Value Test", async () => { const t = await getTestEnv();