diff --git a/.github/workflows/ci_testing.yaml b/.github/workflows/ci_testing.yaml index 9cc597e5..253beaad 100644 --- a/.github/workflows/ci_testing.yaml +++ b/.github/workflows/ci_testing.yaml @@ -134,7 +134,7 @@ jobs: - name: Install dependencies run: npm ci - name: Build web app - run: npx nx affected:test --all + run: npx nx run-many --target test lint-frontend: runs-on: ubuntu-latest @@ -152,4 +152,4 @@ jobs: - name: Install dependencies run: npm ci - name: Build web app - run: npx nx affected:lint --all + run: npx nx run-many --target lint diff --git a/frontend/apps/mobile/jest.config.ts b/frontend/apps/mobile/jest.config.ts index c5683e73..2f6455af 100644 --- a/frontend/apps/mobile/jest.config.ts +++ b/frontend/apps/mobile/jest.config.ts @@ -1,4 +1,5 @@ -module.exports = { +/* eslint-disable */ +export default { displayName: "mobile", resolver: "@nx/jest/plugins/resolver", preset: "jest-expo", @@ -10,10 +11,8 @@ module.exports = { moduleNameMapper: { ".svg": "@nx/expo/plugins/jest/svg-mock", }, - transform: { - "\\.(js|ts|tsx)$": require.resolve("react-native/jest/preprocessor.js"), - "^.+\\.(bmp|gif|jpg|jpeg|mp4|png|psd|svg|webp|ttf)$": require.resolve( - "react-native/jest/assetFileTransformer.js" - ), - }, + // transform: { + // "\\.(js|ts|tsx)$": "react-native/jest/preprocessor.js", + // "^.+\\.(bmp|gif|jpg|jpeg|mp4|png|psd|svg|webp|ttf)$": "react-native/jest/assetFileTransformer.js", + // }, }; diff --git a/frontend/libs/api/project.json b/frontend/libs/api/project.json index 2df6a6df..48532f7a 100644 --- a/frontend/libs/api/project.json +++ b/frontend/libs/api/project.json @@ -11,7 +11,10 @@ "npx openapi-zod ../../../api/openapi.json --output src/lib/generated/schema.ts", "npx openapi-typescript-codegen --input ../../../api/openapi.json --output src/lib/generated --useUnionTypes --name Client --useOptions", "sed -i 's/type: any/type: \"personal\"/' src/lib/generated/models/PersonalAccount.ts", - "sed -i 's/type: any/type: \"clearing\"/' src/lib/generated/models/ClearingAccount.ts" + "sed -i 's/type: any/type: \"clearing\"/' src/lib/generated/models/ClearingAccount.ts", + "echo \"/* eslint-disable */\\n$(cat src/lib/generated/schema.ts)\" > src/lib/generated/schema.ts", + "echo \"/* tslint:disable */\\n$(cat src/lib/generated/schema.ts)\" > src/lib/generated/schema.ts", + "echo \"/* istanbul ignore file */\\n$(cat src/lib/generated/schema.ts)\" > src/lib/generated/schema.ts" ], "parallel": false, "cwd": "libs/api" diff --git a/frontend/libs/api/src/lib/generated/schema.ts b/frontend/libs/api/src/lib/generated/schema.ts index a9506f89..1a952d4c 100644 --- a/frontend/libs/api/src/lib/generated/schema.ts +++ b/frontend/libs/api/src/lib/generated/schema.ts @@ -1,3 +1,6 @@ +/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ /** * This file was auto-generated by openapi-zod. * Do not make direct changes to the file. diff --git a/frontend/libs/core/src/lib/accounts.test.ts b/frontend/libs/core/src/lib/accounts.test.ts index ec68b672..25a78333 100644 --- a/frontend/libs/core/src/lib/accounts.test.ts +++ b/frontend/libs/core/src/lib/accounts.test.ts @@ -1,49 +1,50 @@ -import { Account, AccountBalanceMap, Purchase } from "@abrechnung/types"; +import { Account, AccountBalanceMap, ClearingAccount, PersonalAccount, Transaction } from "@abrechnung/types"; import { computeAccountBalances, computeGroupSettlement } from "./accounts"; -const purchaseTemplate = { - groupID: 0, +const purchaseTemplate: Omit = { + group_id: 0, type: "purchase" as const, billed_at: "2022-10-10", - currencyConversionRate: 1.0, + currency_conversion_rate: 1.0, currency_symbol: "€", name: "foobar", description: "", + value: 0, deleted: false, - attachments: [], + file_ids: [], + files: {}, + position_ids: [], + positions: {}, tags: [], - positions: [], - hasLocalChanges: false, last_changed: new Date().toISOString(), - isWip: false, + is_wip: false, }; const accountTemplate = { name: "foobar", - groupID: 0, + group_id: 0, description: "", deleted: false, - hasLocalChanges: false, last_changed: new Date().toISOString(), - isWip: false, + is_wip: false, }; -const clearingAccountTemplate = { +const clearingAccountTemplate: Omit = { ...accountTemplate, type: "clearing" as const, - dateInfo: "2022-01-01", + date_info: "2022-01-01", tags: [], }; -const personalAccountTemplate = { +const personalAccountTemplate: Omit = { ...accountTemplate, type: "personal" as const, - owningUserID: null, + owning_user_id: null, }; describe("computeAccountBalances", () => { it("should compute the correct balance for one transaction", () => { - const t: Purchase = { + const t: Transaction = { ...purchaseTemplate, id: 0, value: 100, @@ -51,7 +52,7 @@ describe("computeAccountBalances", () => { debitor_shares: { 1: 1, 2: 2, 3: 1 }, }; - const accounts: Account[] = [ + const accounts: PersonalAccount[] = [ { ...personalAccountTemplate, id: 1, @@ -90,12 +91,12 @@ describe("computeAccountBalances", () => { }, }; - const balances = computeAccountBalances(accounts, [t], {}); + const balances = computeAccountBalances(accounts, [t]); expect(balances).toStrictEqual(expectedBalances); }); it("should compute the correct balance for one transactions and a clearing account", () => { - const t: Purchase = { + const t: Transaction = { ...purchaseTemplate, id: 0, value: 100, @@ -119,7 +120,7 @@ describe("computeAccountBalances", () => { { ...clearingAccountTemplate, id: 4, - clearingShares: { 3: 1 }, + clearing_shares: { 3: 1 }, }, ]; @@ -156,12 +157,12 @@ describe("computeAccountBalances", () => { }, }; - const balances = computeAccountBalances(accounts, [t], {}); + const balances = computeAccountBalances(accounts, [t]); expect(balances).toStrictEqual(expectedBalances); }); it("should compute the correct balance with multiple transactions and interdependent clearing accounts", () => { - const transactions: Purchase[] = [ + const transactions: Transaction[] = [ { ...purchaseTemplate, id: 0, @@ -189,52 +190,38 @@ describe("computeAccountBalances", () => { { ...personalAccountTemplate, id: 1, - type: "personal", - owningUserID: null, }, { ...personalAccountTemplate, id: 2, - type: "personal", - owningUserID: null, }, { ...personalAccountTemplate, id: 3, - type: "personal", - owningUserID: null, }, { ...clearingAccountTemplate, id: 4, - type: "clearing", - dateInfo: "2022-10-10", - tags: [], - clearingShares: { 3: 1 }, + date_info: "2022-10-10", + clearing_shares: { 3: 1 }, }, { ...clearingAccountTemplate, id: 5, - type: "clearing", - dateInfo: "2022-10-10", - tags: [], - clearingShares: { 4: 2, 1: 1, 2: 1 }, + date_info: "2022-10-10", + clearing_shares: { 4: 2, 1: 1, 2: 1 }, }, { ...clearingAccountTemplate, id: 6, - type: "clearing", - dateInfo: "2022-10-10", - tags: [], - clearingShares: { 5: 1 }, + date_info: "2022-10-10", + clearing_shares: { 5: 1 }, }, { ...clearingAccountTemplate, id: 7, - type: "clearing", - dateInfo: "2022-10-10", - tags: [], - clearingShares: {}, + date_info: "2022-10-10", + clearing_shares: {}, }, ]; @@ -290,12 +277,12 @@ describe("computeAccountBalances", () => { }, }; - const balances = computeAccountBalances(accounts, transactions, {}); + const balances = computeAccountBalances(accounts, transactions); expect(balances).toStrictEqual(expectedBalances); }); it("should also work correctly for randomly sorted interdependent clearing accounts", () => { - const transactions: Purchase[] = [ + const transactions: Transaction[] = [ { ...purchaseTemplate, id: 0, @@ -308,14 +295,10 @@ describe("computeAccountBalances", () => { { ...personalAccountTemplate, id: 1, - type: "personal", - owningUserID: null, }, { ...personalAccountTemplate, id: 2, - type: "personal", - owningUserID: null, }, ]; const nClearingAccounts = 10; @@ -323,21 +306,15 @@ describe("computeAccountBalances", () => { accounts.push({ ...clearingAccountTemplate, id: i + 3, - type: "clearing", - tags: [], - dateInfo: "2022-01-01", - clearingShares: { [i + 4]: 1 }, + clearing_shares: { [i + 4]: 1 }, }); } accounts.push({ ...clearingAccountTemplate, id: nClearingAccounts + 1, - type: "clearing", - tags: [], - dateInfo: "2022-01-01", - clearingShares: { 2: 1 }, + clearing_shares: { 2: 1 }, }); - const balances = computeAccountBalances(accounts, transactions, {}); + const balances = computeAccountBalances(accounts, transactions); expect(balances).toHaveProperty("2"); expect(balances[2]).toStrictEqual({ balance: -100, diff --git a/frontend/libs/core/src/lib/transactions.test.ts b/frontend/libs/core/src/lib/transactions.test.ts index 6e3d1c8b..204fea5f 100644 --- a/frontend/libs/core/src/lib/transactions.test.ts +++ b/frontend/libs/core/src/lib/transactions.test.ts @@ -1,10 +1,4 @@ -import { - Purchase, - TransactionBalanceEffect, - TransactionPosition, - TransactionShare, - TransactionType, -} from "@abrechnung/types"; +import { Transaction, TransactionBalanceEffect, TransactionShare, TransactionType } from "@abrechnung/types"; import { computeTransactionBalanceEffect } from "./transactions"; const generateTransaction = ( @@ -13,10 +7,10 @@ const generateTransaction = ( value: number, creditor_shares: TransactionShare, debitor_shares: TransactionShare -): any => { - const t = { +): Transaction => { + return { id: id, - groupID: 0, + group_id: 0, billed_at: "2022-01-01", deleted: false, type: type, @@ -27,20 +21,20 @@ const generateTransaction = ( description: "", tags: [], currency_symbol: "€", - currencyConversionRate: 1.0, - attachments: [], + currency_conversion_rate: 1.0, + files: {}, + file_ids: [], + position_ids: [], + positions: {}, + is_wip: false, + last_changed: "2022-01-01T12:00:00", }; - if (type === "purchase") { - return { ...t, positions: [] }; - } else { - return t; - } }; describe("computeAccountBalancesForTransaction", () => { it("should compute the balance correctly for a transaction without positions", () => { const t = generateTransaction(0, "purchase", 100, { 1: 1 }, { 1: 1, 2: 1, 3: 2 }); - const effect = computeTransactionBalanceEffect(t, []); + const effect = computeTransactionBalanceEffect(t); const expectedEffect: TransactionBalanceEffect = { 1: { commonCreditors: 100, @@ -65,28 +59,30 @@ describe("computeAccountBalancesForTransaction", () => { }); it("should compute the balance correctly for a transaction with positions", () => { - const t = generateTransaction(0, "purchase", 100, { 1: 1 }, { 1: 1, 2: 2 }) as Purchase; - t.positions = [1, 2]; - const positions: TransactionPosition[] = [ - { + const t = generateTransaction(0, "purchase", 100, { 1: 1 }, { 1: 1, 2: 2 }); + t.position_ids = [1, 2]; + t.positions = { + 1: { id: 1, - transactionID: 0, price: 20, name: "item1", communist_shares: 0, usages: { 3: 1, 1: 1 }, deleted: false, + is_changed: false, + only_local: false, }, - { + 2: { id: 2, - transactionID: 0, price: 40, name: "item2", communist_shares: 1, usages: { 2: 1 }, deleted: false, + is_changed: false, + only_local: false, }, - ]; + }; const expectedEffect: TransactionBalanceEffect = { 1: { @@ -109,7 +105,7 @@ describe("computeAccountBalancesForTransaction", () => { }, }; - const effect = computeTransactionBalanceEffect(t, positions); + const effect = computeTransactionBalanceEffect(t); expect(effect).toStrictEqual(expectedEffect); }); }); diff --git a/frontend/libs/redux/src/lib/transactions/transactionSlice.test.ts b/frontend/libs/redux/src/lib/transactions/transactionSlice.test.ts deleted file mode 100644 index 2b13d268..00000000 --- a/frontend/libs/redux/src/lib/transactions/transactionSlice.test.ts +++ /dev/null @@ -1,121 +0,0 @@ -import { configureStore } from "@reduxjs/toolkit"; -import { TransactionSliceState } from "../types"; - -import { - createTransaction, - initializeGroupState, - selectTransactionById, - selectTransactionPositions, - transactionReducer, - wipPositionAdded, - wipPositionUpdated, - wipTransactionUpdated, -} from "./transactionSlice"; - -const setupStore = () => { - const state: TransactionSliceState = { - byGroupId: {}, - nextLocalPositionId: -1, - nextLocalTransactionId: -1, - activeInstanceId: 0, - }; - initializeGroupState(state, 1); - return configureStore({ - reducer: { - transactions: transactionReducer, - }, - preloadedState: { transactions: state }, - }); -}; - -describe("transactionSlice", () => { - it("creating purchases works", async () => { - const store = setupStore(); - const { transaction } = await store.dispatch(createTransaction({ groupId: 1, type: "purchase" })).unwrap(); - expect(transaction.name).toBe(""); - expect(transaction.isWip).toBe(true); - expect(transaction.hasLocalChanges).toBe(true); - - // change it - { - store.dispatch( - wipTransactionUpdated({ - ...transaction, - name: "funny things", - value: 10, - debitor_shares: { 1: 1 }, - creditor_shares: { 2: 1 }, - }) - ); - const t = selectTransactionById({ - state: store.getState().transactions, - groupId: 1, - transactionId: transaction.id, - }); - expect(t).not.toBeUndefined(); - if (!t) { - throw new Error(); - } - expect(t.id).toBe(transaction.id); - expect(t.name).toBe("funny things"); - expect(t.value).toBe(10); - } - // add a position - let positionId: number; - { - store.dispatch( - wipPositionAdded({ - groupId: 1, - transactionId: transaction.id, - position: { - name: "", - price: 0, - communist_shares: 0, - usages: {}, - }, - }) - ); - const positions = selectTransactionPositions({ - state: store.getState().transactions, - groupId: 1, - transactionId: transaction.id, - }); - expect(positions).toHaveLength(1); - expect(positions[0].name).toBe(""); - positionId = positions[0].id; - } - - // change the position - { - store.dispatch( - wipPositionUpdated({ - groupId: 1, - transactionId: transaction.id, - position: { - id: positionId, - name: "Pizza", - transactionID: transaction.id, - price: 10, - communist_shares: 2, - usages: { 1: 1 }, - deleted: false, - }, - }) - ); - const positions = selectTransactionPositions({ - state: store.getState().transactions, - groupId: 1, - transactionId: transaction.id, - }); - expect(positions).toHaveLength(1); - expect(positions[0].name).toBe("Pizza"); - expect(positions[0].price).toBe(10); - expect(positions[0].communist_shares).toBe(2); - } - }); - - it("creating transfers works", () => { - const store = setupStore(); - // const res = await store.dispatch(createTransfer({ groupId: 1 })); - }); -});