Skip to content

Fix the total amount the user owes/is owed for optimised debts #80

Open
@IsaacCheng9

Description

Bug Report

  • When turning on 'Smart Split', the total amount the user owes/is owed isn't always updated correctly.
  • This is likely caused by a missing await on when clearing the optimised debt model collection here.
  • However, adding an await statement causes test failures:
isaac@MBP16 server % npm test

> server@1.0.0 test
> jest --verbose --coverage

 PASS  routes/users.test.js
  Test for user routes
    ✓ GET /users (24 ms)
    ✓ POST /users (18 ms)
    ✓ GET /users/:username (6 ms)
    ✓ DELETE /users/:username (4 ms)

 PASS  routes/expenses.test.js
  Test for expense routes
    ✓ GET /expenses (20 ms)
    ✓ POST /expenses (24 ms)
    ✓ POST /expenses/settlement (6 ms)

/Users/isaac/Library/CloudStorage/OneDrive-Personal/Documents/Programming/Projects/fairsplit/server/node_modules/mongodb/lib/operations/execute_operation.js:20
                return callback(new error_1.MongoNotConnectedError('Client must be connected before running operations'));
                                ^

MongoNotConnectedError: Client must be connected before running operations
    at /Users/isaac/Library/CloudStorage/OneDrive-Personal/Documents/Programming/Projects/fairsplit/server/node_modules/mongodb/src/operations/execute_operation.ts:89:11
    at maybePromise (/Users/isaac/Library/CloudStorage/OneDrive-Personal/Documents/Programming/Projects/fairsplit/server/node_modules/mongodb/src/utils.ts:518:3)
    at executeOperation (/Users/isaac/Library/CloudStorage/OneDrive-Personal/Documents/Programming/Projects/fairsplit/server/node_modules/mongodb/src/operations/execute_operation.ts:83:22)
    at Collection.deleteMany (/Users/isaac/Library/CloudStorage/OneDrive-Personal/Documents/Programming/Projects/fairsplit/server/node_modules/mongodb/src/collection.ts:624:28)
    at NativeCollection.<computed> [as deleteMany] (/Users/isaac/Library/CloudStorage/OneDrive-Personal/Documents/Programming/Projects/fairsplit/server/node_modules/mongoose/lib/drivers/node-mongodb-native/collection.js:202:33)
    at NodeCollection.deleteMany (/Users/isaac/Library/CloudStorage/OneDrive-Personal/Documents/Programming/Projects/fairsplit/server/node_modules/mquery/lib/collection/node.js:90:21)
    at model.Query.Object.<anonymous>.Query.deleteMany (/Users/isaac/Library/CloudStorage/OneDrive-Personal/Documents/Programming/Projects/fairsplit/server/node_modules/mquery/lib/mquery.js:2661:20)
    at model.Query.<anonymous> (/Users/isaac/Library/CloudStorage/OneDrive-Personal/Documents/Programming/Projects/fairsplit/server/node_modules/mongoose/lib/query.js:3211:32)
    at model.Query._wrappedThunk [as _deleteMany] (/Users/isaac/Library/CloudStorage/OneDrive-Personal/Documents/Programming/Projects/fairsplit/server/node_modules/mongoose/lib/helpers/query/wrapThunk.js:27:8)
    at /Users/isaac/Library/CloudStorage/OneDrive-Personal/Documents/Programming/Projects/fairsplit/server/node_modules/kareem/index.js:426:25 {
  [Symbol(errorLabels)]: Set(0) {}
}

Node.js v18.2.0
/Users/isaac/Library/CloudStorage/OneDrive-Personal/Documents/Programming/Projects/fairsplit/server/node_modules/mongodb/lib/operations/execute_operation.js:20
                return callback(new error_1.MongoNotConnectedError('Client must be connected before running operations'));
                                ^

MongoNotConnectedError: Client must be connected before running operations
    at /Users/isaac/Library/CloudStorage/OneDrive-Personal/Documents/Programming/Projects/fairsplit/server/node_modules/mongodb/src/operations/execute_operation.ts:89:11
    at maybePromise (/Users/isaac/Library/CloudStorage/OneDrive-Personal/Documents/Programming/Projects/fairsplit/server/node_modules/mongodb/src/utils.ts:518:3)
    at executeOperation (/Users/isaac/Library/CloudStorage/OneDrive-Personal/Documents/Programming/Projects/fairsplit/server/node_modules/mongodb/src/operations/execute_operation.ts:83:22)
    at Collection.deleteMany (/Users/isaac/Library/CloudStorage/OneDrive-Personal/Documents/Programming/Projects/fairsplit/server/node_modules/mongodb/src/collection.ts:624:28)
    at NativeCollection.<computed> [as deleteMany] (/Users/isaac/Library/CloudStorage/OneDrive-Personal/Documents/Programming/Projects/fairsplit/server/node_modules/mongoose/lib/drivers/node-mongodb-native/collection.js:202:33)
    at NodeCollection.deleteMany (/Users/isaac/Library/CloudStorage/OneDrive-Personal/Documents/Programming/Projects/fairsplit/server/node_modules/mquery/lib/collection/node.js:90:21)
    at model.Query.Object.<anonymous>.Query.deleteMany (/Users/isaac/Library/CloudStorage/OneDrive-Personal/Documents/Programming/Projects/fairsplit/server/node_modules/mquery/lib/mquery.js:2661:20)
    at model.Query.<anonymous> (/Users/isaac/Library/CloudStorage/OneDrive-Personal/Documents/Programming/Projects/fairsplit/server/node_modules/mongoose/lib/query.js:3211:32)
    at model.Query._wrappedThunk [as _deleteMany] (/Users/isaac/Library/CloudStorage/OneDrive-Personal/Documents/Programming/Projects/fairsplit/server/node_modules/mongoose/lib/helpers/query/wrapThunk.js:27:8)
    at /Users/isaac/Library/CloudStorage/OneDrive-Personal/Documents/Programming/Projects/fairsplit/server/node_modules/kareem/index.js:426:25 {
  [Symbol(errorLabels)]: Set(0) {}
}

Node.js v18.2.0
/Users/isaac/Library/CloudStorage/OneDrive-Personal/Documents/Programming/Projects/fairsplit/server/node_modules/mongodb/lib/operations/execute_operation.js:20
                return callback(new error_1.MongoNotConnectedError('Client must be connected before running operations'));
                                ^

MongoNotConnectedError: Client must be connected before running operations
    at /Users/isaac/Library/CloudStorage/OneDrive-Personal/Documents/Programming/Projects/fairsplit/server/node_modules/mongodb/src/operations/execute_operation.ts:89:11
    at maybePromise (/Users/isaac/Library/CloudStorage/OneDrive-Personal/Documents/Programming/Projects/fairsplit/server/node_modules/mongodb/src/utils.ts:518:3)
    at executeOperation (/Users/isaac/Library/CloudStorage/OneDrive-Personal/Documents/Programming/Projects/fairsplit/server/node_modules/mongodb/src/operations/execute_operation.ts:83:22)
    at Collection.deleteMany (/Users/isaac/Library/CloudStorage/OneDrive-Personal/Documents/Programming/Projects/fairsplit/server/node_modules/mongodb/src/collection.ts:624:28)
    at NativeCollection.<computed> [as deleteMany] (/Users/isaac/Library/CloudStorage/OneDrive-Personal/Documents/Programming/Projects/fairsplit/server/node_modules/mongoose/lib/drivers/node-mongodb-native/collection.js:202:33)
    at NodeCollection.deleteMany (/Users/isaac/Library/CloudStorage/OneDrive-Personal/Documents/Programming/Projects/fairsplit/server/node_modules/mquery/lib/collection/node.js:90:21)
    at model.Query.Object.<anonymous>.Query.deleteMany (/Users/isaac/Library/CloudStorage/OneDrive-Personal/Documents/Programming/Projects/fairsplit/server/node_modules/mquery/lib/mquery.js:2661:20)
    at model.Query.<anonymous> (/Users/isaac/Library/CloudStorage/OneDrive-Personal/Documents/Programming/Projects/fairsplit/server/node_modules/mongoose/lib/query.js:3211:32)
    at model.Query._wrappedThunk [as _deleteMany] (/Users/isaac/Library/CloudStorage/OneDrive-Personal/Documents/Programming/Projects/fairsplit/server/node_modules/mongoose/lib/helpers/query/wrapThunk.js:27:8)
    at /Users/isaac/Library/CloudStorage/OneDrive-Personal/Documents/Programming/Projects/fairsplit/server/node_modules/kareem/index.js:426:25 {
  [Symbol(errorLabels)]: Set(0) {}
}

Node.js v18.2.0
/Users/isaac/Library/CloudStorage/OneDrive-Personal/Documents/Programming/Projects/fairsplit/server/node_modules/mongodb/lib/operations/execute_operation.js:20
                return callback(new error_1.MongoNotConnectedError('Client must be connected before running operations'));
                                ^

MongoNotConnectedError: Client must be connected before running operations
    at /Users/isaac/Library/CloudStorage/OneDrive-Personal/Documents/Programming/Projects/fairsplit/server/node_modules/mongodb/src/operations/execute_operation.ts:89:11
    at maybePromise (/Users/isaac/Library/CloudStorage/OneDrive-Personal/Documents/Programming/Projects/fairsplit/server/node_modules/mongodb/src/utils.ts:518:3)
    at executeOperation (/Users/isaac/Library/CloudStorage/OneDrive-Personal/Documents/Programming/Projects/fairsplit/server/node_modules/mongodb/src/operations/execute_operation.ts:83:22)
    at Collection.deleteMany (/Users/isaac/Library/CloudStorage/OneDrive-Personal/Documents/Programming/Projects/fairsplit/server/node_modules/mongodb/src/collection.ts:624:28)
    at NativeCollection.<computed> [as deleteMany] (/Users/isaac/Library/CloudStorage/OneDrive-Personal/Documents/Programming/Projects/fairsplit/server/node_modules/mongoose/lib/drivers/node-mongodb-native/collection.js:202:33)
    at NodeCollection.deleteMany (/Users/isaac/Library/CloudStorage/OneDrive-Personal/Documents/Programming/Projects/fairsplit/server/node_modules/mquery/lib/collection/node.js:90:21)
    at model.Query.Object.<anonymous>.Query.deleteMany (/Users/isaac/Library/CloudStorage/OneDrive-Personal/Documents/Programming/Projects/fairsplit/server/node_modules/mquery/lib/mquery.js:2661:20)
    at model.Query.<anonymous> (/Users/isaac/Library/CloudStorage/OneDrive-Personal/Documents/Programming/Projects/fairsplit/server/node_modules/mongoose/lib/query.js:3211:32)
    at model.Query._wrappedThunk [as _deleteMany] (/Users/isaac/Library/CloudStorage/OneDrive-Personal/Documents/Programming/Projects/fairsplit/server/node_modules/mongoose/lib/helpers/query/wrapThunk.js:27:8)
    at /Users/isaac/Library/CloudStorage/OneDrive-Personal/Documents/Programming/Projects/fairsplit/server/node_modules/kareem/index.js:426:25 {
  [Symbol(errorLabels)]: Set(0) {}
}

Node.js v18.2.0
 FAIL  routes/debts.test.js
  ● Test suite failed to run

    Jest worker encountered 4 child process exceptions, exceeding retry limit

      at ChildProcessWorker.initialize (node_modules/jest-worker/build/workers/ChildProcessWorker.js:211:21)

------------------------|---------|----------|---------|---------|-------------------------------------------
File                    | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s                         
------------------------|---------|----------|---------|---------|-------------------------------------------
All files               |   79.27 |    34.61 |   81.81 |   79.27 |                                           
 controllers            |   94.73 |       50 |     100 |   94.73 |                                           
  expense_controller.js |    91.3 |       50 |     100 |    91.3 | 10,18                                     
  user_controller.js    |     100 |      100 |     100 |     100 |                                           
 controllers/helpers    |   51.16 |    31.81 |      50 |   51.16 |                                           
  index.js              |   51.16 |    31.81 |      50 |   51.16 | ...9,43-44,53,65-74,93,96,101-107,119-138 
 models                 |     100 |      100 |     100 |     100 |                                           
  debt.js               |     100 |      100 |     100 |     100 |                                           
  expense.js            |     100 |      100 |     100 |     100 |                                           
  optimised_debt.js     |     100 |      100 |     100 |     100 |                                           
  user.js               |     100 |      100 |     100 |     100 |                                           
  user_debt.js          |     100 |      100 |     100 |     100 |                                           
 routes                 |     100 |      100 |     100 |     100 |                                           
  expenses.js           |     100 |      100 |     100 |     100 |                                           
  users.js              |     100 |      100 |     100 |     100 |                                           
------------------------|---------|----------|---------|---------|-------------------------------------------
Test Suites: 1 failed, 2 passed, 3 total
Tests:       7 passed, 7 total
Snapshots:   0 total
Time:        3.664 s
Ran all test suites.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    backendRequires attention on the backendbugSomething isn't workinghigh priorityRequires immediate attention

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions