From 3f592ccdc84e20373e8f8d1c5c3c364a4407a748 Mon Sep 17 00:00:00 2001 From: Mike Jensen Date: Tue, 5 Dec 2023 09:33:36 +0100 Subject: [PATCH 1/3] Fixed routing + npm install --- app/(login)/LoginScreen.tsx | 2 +- package-lock.json | 6 ------ 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/app/(login)/LoginScreen.tsx b/app/(login)/LoginScreen.tsx index 467138e..5f86a76 100644 --- a/app/(login)/LoginScreen.tsx +++ b/app/(login)/LoginScreen.tsx @@ -33,7 +33,7 @@ export default function loginScreen () { router.replace('/GroupScreen'); } else { console.log("Group found"); - router.replace('../(tabs)/ShoppingList/index'); + router.replace('../(tabs)/shoppingList/'); } }); diff --git a/package-lock.json b/package-lock.json index c02f35d..2a6f44f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -6737,12 +6737,6 @@ "@types/node": "*" } }, - "node_modules/@types/gun": { - "version": "0.9.6", - "resolved": "https://registry.npmjs.org/@types/gun/-/gun-0.9.6.tgz", - "integrity": "sha512-h82pNZZeJ1iLdnbgqDRnzuuc+Ip9plNtOOqB3qjqBcL6BazvduiIlLaD2pOB8ozaECGPOTxl23OthODovmiD3Q==", - "dev": true - }, "node_modules/@types/hammerjs": { "version": "2.0.45", "resolved": "https://registry.npmjs.org/@types/hammerjs/-/hammerjs-2.0.45.tgz", From 31923e8b7527d2838e54e8a067754955657c50bf Mon Sep 17 00:00:00 2001 From: Mike Jensen Date: Tue, 5 Dec 2023 10:06:58 +0100 Subject: [PATCH 2/3] Unit tests that covers most cases + exported type expense, which should be moved to a seperate file --- __tests__/unitTests/CalculateBalance.test.ts | 73 ++++++++++++++++++++ helpers/calculateBalance.tsx | 2 +- 2 files changed, 74 insertions(+), 1 deletion(-) create mode 100644 __tests__/unitTests/CalculateBalance.test.ts diff --git a/__tests__/unitTests/CalculateBalance.test.ts b/__tests__/unitTests/CalculateBalance.test.ts new file mode 100644 index 0000000..be6235b --- /dev/null +++ b/__tests__/unitTests/CalculateBalance.test.ts @@ -0,0 +1,73 @@ +import { calculateBalance, Expense } from '../../helpers/calculateBalance'; + +describe('calculateExpenses', () => { + it('should handle no balances', () => { + const result = calculateBalance([]); + expect(result).toEqual([]); + }); + + it('should handle a single user balance', () => { + const expenses: Expense[] = [ + { user: 'Alice', amount: 50 }, + ]; + const expectedBalance: Expense[] = [ + { user: 'Alice', amount: 0 } + ]; + const result = calculateBalance(expenses); + expect(result).toEqual(expect.arrayContaining(expectedBalance)); + }); + + it('should handle multiple user balances', () => { + const expenses: Expense[] = [ + { user: 'Alice', amount: 50 }, + { user: 'Bob', amount: 0 }, + ]; + const expectedBalance: Expense[] = [ + { user: 'Alice', amount: 25 }, + { user: 'Bob', amount: -25 }, + ]; + const result = calculateBalance(expenses); + expect(result).toEqual(expect.arrayContaining(expectedBalance)); + }); + + it('should handle multiple users with no balance', () => { + const expenses: Expense[] = [ + { user: 'Alice', amount: 0 }, + { user: 'Bob', amount: 0 }, + { user: 'Charlie', amount: 0 }, + ]; + const expectedBalance: Expense[] = [ + { user: 'Alice', amount: 0 }, + { user: 'Bob', amount: 0 }, + { user: 'Charlie', amount: 0 }, + ]; + const result = calculateBalance(expenses); + expect(result).toEqual(expect.arrayContaining(expectedBalance)); + }); + + it('should handle multiple user balances', () => { + const expenses: Expense[] = [ + { user: 'Alice', amount: 50 }, + { user: 'Bob', amount: 0 }, + ]; + const expectedBalance: Expense[] = [ + { user: 'Alice', amount: 25 }, + { user: 'Bob', amount: -25 }, + ]; + const result = calculateBalance(expenses); + expect(result).toEqual(expect.arrayContaining(expectedBalance)); + }); + + it('should handle large numbers', () => { + const expenses: Expense[] = [ + { user: 'Alice', amount: Number.MAX_VALUE }, + { user: 'Bob', amount: 0 }, + ]; + const expectedBalance: Expense[] = [ + { user: 'Alice', amount: Number.MAX_VALUE/2 }, + { user: 'Bob', amount: -Number.MAX_VALUE/2 }, + ]; + const result = calculateBalance(expenses); + expect(result).toEqual(expect.arrayContaining(expectedBalance)); + }); +}); \ No newline at end of file diff --git a/helpers/calculateBalance.tsx b/helpers/calculateBalance.tsx index ea2b227..1bfbba0 100644 --- a/helpers/calculateBalance.tsx +++ b/helpers/calculateBalance.tsx @@ -1,4 +1,4 @@ -type Expense = { +export type Expense = { user: string; amount: number; }; From d5aeaf529611c7ef5d0f761527bfed834a7ab593 Mon Sep 17 00:00:00 2001 From: Mike Jensen Date: Wed, 6 Dec 2023 10:25:10 +0100 Subject: [PATCH 3/3] Removed duplicate unit test and fixed title --- __tests__/unitTests/CalculateBalance.test.ts | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/__tests__/unitTests/CalculateBalance.test.ts b/__tests__/unitTests/CalculateBalance.test.ts index be6235b..f0d447e 100644 --- a/__tests__/unitTests/CalculateBalance.test.ts +++ b/__tests__/unitTests/CalculateBalance.test.ts @@ -1,6 +1,6 @@ import { calculateBalance, Expense } from '../../helpers/calculateBalance'; -describe('calculateExpenses', () => { +describe('calculateBalance', () => { it('should handle no balances', () => { const result = calculateBalance([]); expect(result).toEqual([]); @@ -45,19 +45,6 @@ describe('calculateExpenses', () => { expect(result).toEqual(expect.arrayContaining(expectedBalance)); }); - it('should handle multiple user balances', () => { - const expenses: Expense[] = [ - { user: 'Alice', amount: 50 }, - { user: 'Bob', amount: 0 }, - ]; - const expectedBalance: Expense[] = [ - { user: 'Alice', amount: 25 }, - { user: 'Bob', amount: -25 }, - ]; - const result = calculateBalance(expenses); - expect(result).toEqual(expect.arrayContaining(expectedBalance)); - }); - it('should handle large numbers', () => { const expenses: Expense[] = [ { user: 'Alice', amount: Number.MAX_VALUE },