Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify debts + group balances #197

Open
wants to merge 29 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
209b669
Add a simplify debts field to groups
krokosik Feb 6, 2025
cbd67de
Do not return undefined in trpc query to silence console error
krokosik Feb 6, 2025
1a7e9b2
Add a switch component and add now required shadcn aliases
krokosik Feb 6, 2025
3f154e8
Add a simplify debts toggle to UI
krokosik Feb 6, 2025
17227f4
Fix list key errors on group page
krokosik Feb 12, 2025
13cf771
Show per group member balances
krokosik Feb 12, 2025
07128bd
Process group balances with useMemo
krokosik Feb 12, 2025
b4bfe7e
Add dinic algorithm package
krokosik Feb 13, 2025
b849d7d
Remove the client side simplify stub, as it should be done server side
krokosik Feb 13, 2025
2a74981
Move expense list to a shared component
krokosik Feb 16, 2025
34bf1f9
Add accordion component
krokosik Feb 16, 2025
ad1b15f
Balance list with totals
krokosik Feb 16, 2025
1596409
Use number type for group/friend id in ExpenseList
krokosik Feb 16, 2025
f549b37
Complete BalanceList
krokosik Feb 16, 2025
be5f3b1
Add Jest and move dev dependencies to proper dep group
krokosik Feb 17, 2025
511b102
Create a basic test suite for simplifyDebts based on the examples in …
krokosik Feb 17, 2025
42b49ce
Implement the debt simplification algorithm and adjust test cases
krokosik Feb 17, 2025
14e345e
Use the simplify algorithm in API
krokosik Feb 17, 2025
a8d0fe0
Handle multiple currencies and use node indices for Dinic
krokosik Feb 17, 2025
1c11bba
Do not list to many personal balances
krokosik Feb 17, 2025
1f5ee3c
Run auto format on tailwind config post shadcn CLI
krokosik Feb 18, 2025
c32250f
Add more unit tests
krokosik Feb 18, 2025
1f9e37f
Make sure the timestamps are different in test examples to make sure …
krokosik Feb 18, 2025
444952c
Simplify example generation
krokosik Feb 18, 2025
2b55ac9
Fix rounding issue in balance calculations for simplifyDebts tests
krokosik Feb 18, 2025
66833d0
Fix getFlows to only get finished edges that form a full path to sink
krokosik Feb 18, 2025
b5bddc6
Take only initial edges in getFlows, skipping those added by Dinic
krokosik Feb 18, 2025
f3fced4
Use a simpler and more efficient algorithm
krokosik Feb 18, 2025
dbf6f75
Fix linting errors
krokosik Feb 19, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion components.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
},
"aliases": {
"components": "~/components",
"utils": "~/lib/utils"
"utils": "~/lib/utils",
"ui": "~/components/ui",
"hooks": "~/hooks",
"lib": "~/lib"
}
}
205 changes: 205 additions & 0 deletions jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,205 @@
/**
* For a detailed explanation regarding each configuration property, visit:
* https://jestjs.io/docs/configuration
*/

import type { Config } from 'jest';
import nextJest from 'next/jest.js';

const createJestConfig = nextJest({
// Provide the path to your Next.js app to load next.config.js and .env files in your test environment
dir: './',
});

const config: Config = {
// All imported modules in your tests should be mocked automatically
// automock: false,

// Stop running tests after `n` failures
// bail: 0,

// The directory where Jest should store its cached dependency information
// cacheDirectory: "C:\\Users\\Wiktor\\AppData\\Local\\Temp\\jest",

// Automatically clear mock calls, instances, contexts and results before every test
// clearMocks: false,

// Indicates whether the coverage information should be collected while executing the test
// collectCoverage: false,

// An array of glob patterns indicating a set of files for which coverage information should be collected
// collectCoverageFrom: undefined,

// The directory where Jest should output its coverage files
// coverageDirectory: undefined,

// An array of regexp pattern strings used to skip coverage collection
// coveragePathIgnorePatterns: [
// "\\\\node_modules\\\\"
// ],

// Indicates which provider should be used to instrument code for coverage
coverageProvider: 'v8',

// A list of reporter names that Jest uses when writing coverage reports
// coverageReporters: [
// "json",
// "text",
// "lcov",
// "clover"
// ],

// An object that configures minimum threshold enforcement for coverage results
// coverageThreshold: undefined,

// A path to a custom dependency extractor
// dependencyExtractor: undefined,

// Make calling deprecated APIs throw helpful error messages
// errorOnDeprecated: false,

// The default configuration for fake timers
// fakeTimers: {
// "enableGlobally": false
// },

// Force coverage collection from ignored files using an array of glob patterns
// forceCoverageMatch: [],

// A path to a module which exports an async function that is triggered once before all test suites
// globalSetup: undefined,

// A path to a module which exports an async function that is triggered once after all test suites
// globalTeardown: undefined,

// A set of global variables that need to be available in all test environments
// globals: {},

// The maximum amount of workers used to run your tests. Can be specified as % or a number. E.g. maxWorkers: 10% will use 10% of your CPU amount + 1 as the maximum worker number. maxWorkers: 2 will use a maximum of 2 workers.
// maxWorkers: "50%",

// An array of directory names to be searched recursively up from the requiring module's location
// moduleDirectories: [
// "node_modules"
// ],

// An array of file extensions your modules use
// moduleFileExtensions: [
// "js",
// "mjs",
// "cjs",
// "jsx",
// "ts",
// "tsx",
// "json",
// "node"
// ],

// A map from regular expressions to module names or to arrays of module names that allow to stub out resources with a single module
// moduleNameMapper: {},

// An array of regexp pattern strings, matched against all module paths before considered 'visible' to the module loader
// modulePathIgnorePatterns: [],

// Activates notifications for test results
// notify: false,

// An enum that specifies notification mode. Requires { notify: true }
// notifyMode: "failure-change",

// A preset that is used as a base for Jest's configuration
// preset: undefined,

// Run tests from one or more projects
// projects: undefined,

// Use this configuration option to add custom reporters to Jest
// reporters: undefined,

// Automatically reset mock state before every test
// resetMocks: false,

// Reset the module registry before running each individual test
// resetModules: false,

// A path to a custom resolver
// resolver: undefined,

// Automatically restore mock state and implementation before every test
// restoreMocks: false,

// The root directory that Jest should scan for tests and modules within
// rootDir: undefined,

// A list of paths to directories that Jest should use to search for files in
// roots: [
// "<rootDir>"
// ],

// Allows you to use a custom runner instead of Jest's default test runner
// runner: "jest-runner",

// The paths to modules that run some code to configure or set up the testing environment before each test
// setupFiles: [],

// A list of paths to modules that run some code to configure or set up the testing framework before each test
// setupFilesAfterEnv: [],

// The number of seconds after which a test is considered as slow and reported as such in the results.
// slowTestThreshold: 5,

// A list of paths to snapshot serializer modules Jest should use for snapshot testing
// snapshotSerializers: [],

// The test environment that will be used for testing
testEnvironment: 'jsdom',

// Options that will be passed to the testEnvironment
// testEnvironmentOptions: {},

// Adds a location field to test results
// testLocationInResults: false,

// The glob patterns Jest uses to detect test files
// testMatch: [
// "**/__tests__/**/*.[jt]s?(x)",
// "**/?(*.)+(spec|test).[tj]s?(x)"
// ],

// An array of regexp pattern strings that are matched against all test paths, matched tests are skipped
// testPathIgnorePatterns: [
// "\\\\node_modules\\\\"
// ],

// The regexp pattern or array of patterns that Jest uses to detect test files
// testRegex: [],

// This option allows the use of a custom results processor
// testResultsProcessor: undefined,

// This option allows use of a custom test runner
// testRunner: "jest-circus/runner",

// A map from regular expressions to paths to transformers
// transform: undefined,

// An array of regexp pattern strings that are matched against all source file paths, matched files will skip transformation
// transformIgnorePatterns: [
// "\\\\node_modules\\\\",
// "\\.pnp\\.[^\\\\]+$"
// ],

// An array of regexp pattern strings that are matched against all modules before the module loader will automatically return a mock for them
// unmockedModulePathPatterns: undefined,

// Indicates whether each individual test should be reported during the run
// verbose: undefined,

// An array of regexp patterns that are matched against all source file paths before re-running tests in watch mode
// watchPathIgnorePatterns: [],

// Whether to use watchman for file crawling
// watchman: true,
};

export default createJestConfig(config);
20 changes: 14 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
"d": "pnpm dx && pnpm dev",
"dx": "pnpm i && pnpm dx:up && pnpm db:dev",
"dx:up": "docker compose -f docker/dev/compose.yml up -d",
"dx:down": "docker compose -f docker/dev/compose.yml down"
"dx:down": "docker compose -f docker/dev/compose.yml down",
"test": "jest",
"test:watch": "jest --watch"
},
"dependencies": {
"@aws-sdk/client-s3": "^3.515.0",
Expand All @@ -29,6 +31,7 @@
"@hookform/resolvers": "^3.3.4",
"@next-auth/prisma-adapter": "^1.0.7",
"@prisma/client": "^5.9.1",
"@radix-ui/react-accordion": "^1.2.3",
"@radix-ui/react-alert-dialog": "^1.0.5",
"@radix-ui/react-avatar": "^1.0.4",
"@radix-ui/react-checkbox": "^1.0.4",
Expand All @@ -37,17 +40,16 @@
"@radix-ui/react-popover": "^1.0.7",
"@radix-ui/react-separator": "^1.0.3",
"@radix-ui/react-slot": "^1.0.2",
"@radix-ui/react-switch": "^1.1.3",
"@radix-ui/react-tabs": "^1.0.4",
"@t3-oss/env-nextjs": "^0.11.1",
"@tanstack/react-query": "^4.36.1",
"@trpc/client": "^10.43.6",
"@trpc/next": "^10.43.6",
"@trpc/react-query": "^10.43.6",
"@trpc/server": "^10.43.6",
"babel-loader": "^9.1.3",
"boring-avatars": "^1.10.1",
"class-variance-authority": "^0.7.0",
"clsx": "^2.1.0",
"cmdk": "^0.2.0",
"date-fns": "^3.3.1",
"framer-motion": "^11.0.3",
Expand All @@ -70,15 +72,14 @@
"sharp": "0.32.6",
"sonner": "^1.4.0",
"superjson": "^2.2.1",
"tailwind-merge": "^2.2.0",
"tailwindcss-animate": "^1.0.7",
"vaul": "^0.8.9",
"web-push": "^3.6.7",
"zod": "^3.22.4",
"zustand": "^4.5.0"
},
"devDependencies": {
"@types/eslint": "^8.44.7",
"@types/jest": "^29.5.14",
"@types/next-pwa": "^5.6.9",
"@types/node": "^18.17.0",
"@types/nodemailer": "^6.4.15",
Expand All @@ -88,13 +89,20 @@
"@typescript-eslint/eslint-plugin": "^6.11.0",
"@typescript-eslint/parser": "^6.11.0",
"autoprefixer": "^10.4.14",
"babel-loader": "^9.1.3",
"clsx": "^2.1.0",
"eslint": "^8.54.0",
"eslint-config-next": "^14.0.4",
"jest": "^29.7.0",
"jest-environment-jsdom": "^29.7.0",
"postcss": "^8.4.31",
"prettier": "^3.1.0",
"prettier-plugin-tailwindcss": "^0.5.7",
"prisma": "^5.9.1",
"tailwind-merge": "^2.2.0",
"tailwindcss": "^3.3.5",
"tailwindcss-animate": "^1.0.7",
"ts-node": "^10.9.2",
"tsx": "^4.7.1",
"typescript": "^5.1.6"
},
Expand All @@ -105,4 +113,4 @@
"seed": "tsx prisma/seed.ts"
},
"packageManager": "pnpm@8.9.2"
}
}
Loading