Skip to content

Commit

Permalink
ci: fix frontend ci jobs
Browse files Browse the repository at this point in the history
  • Loading branch information
mikonse committed Nov 5, 2023
1 parent 1d25372 commit 7c49463
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 217 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci_testing.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
13 changes: 6 additions & 7 deletions frontend/apps/mobile/jest.config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
module.exports = {
/* eslint-disable */
export default {
displayName: "mobile",
resolver: "@nx/jest/plugins/resolver",
preset: "jest-expo",
Expand All @@ -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",
// },
};
5 changes: 4 additions & 1 deletion frontend/libs/api/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
3 changes: 3 additions & 0 deletions frontend/libs/api/src/lib/generated/schema.ts
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
95 changes: 36 additions & 59 deletions frontend/libs/core/src/lib/accounts.test.ts
Original file line number Diff line number Diff line change
@@ -1,57 +1,58 @@
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<Transaction, "id" | "debitor_shares" | "creditor_shares"> = {
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<ClearingAccount, "id" | "clearing_shares"> = {
...accountTemplate,
type: "clearing" as const,
dateInfo: "2022-01-01",
date_info: "2022-01-01",
tags: [],
};

const personalAccountTemplate = {
const personalAccountTemplate: Omit<PersonalAccount, "id"> = {
...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,
creditor_shares: { 1: 1 },
debitor_shares: { 1: 1, 2: 2, 3: 1 },
};

const accounts: Account[] = [
const accounts: PersonalAccount[] = [
{
...personalAccountTemplate,
id: 1,
Expand Down Expand Up @@ -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,
Expand All @@ -119,7 +120,7 @@ describe("computeAccountBalances", () => {
{
...clearingAccountTemplate,
id: 4,
clearingShares: { 3: 1 },
clearing_shares: { 3: 1 },
},
];

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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: {},
},
];

Expand Down Expand Up @@ -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,
Expand All @@ -308,36 +295,26 @@ describe("computeAccountBalances", () => {
{
...personalAccountTemplate,
id: 1,
type: "personal",
owningUserID: null,
},
{
...personalAccountTemplate,
id: 2,
type: "personal",
owningUserID: null,
},
];
const nClearingAccounts = 10;
for (let i = 0; i < nClearingAccounts; i++) {
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,
Expand Down
50 changes: 23 additions & 27 deletions frontend/libs/core/src/lib/transactions.test.ts
Original file line number Diff line number Diff line change
@@ -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 = <T extends TransactionType>(
Expand All @@ -13,10 +7,10 @@ const generateTransaction = <T extends TransactionType>(
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,
Expand All @@ -27,20 +21,20 @@ const generateTransaction = <T extends TransactionType>(
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,
Expand All @@ -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: {
Expand All @@ -109,7 +105,7 @@ describe("computeAccountBalancesForTransaction", () => {
},
};

const effect = computeTransactionBalanceEffect(t, positions);
const effect = computeTransactionBalanceEffect(t);
expect(effect).toStrictEqual(expectedEffect);
});
});
Loading

0 comments on commit 7c49463

Please sign in to comment.