Skip to content

Fix lint error and align daily-logs tests with refactored route - #17

Merged
sharf-shawon merged 2 commits into
mainfrom
copilot/fix-linting-add-tests-coverage
Mar 25, 2026
Merged

Fix lint error and align daily-logs tests with refactored route#17
sharf-shawon merged 2 commits into
mainfrom
copilot/fix-linting-add-tests-coverage

Conversation

Copilot AI commented Mar 25, 2026

Copy link
Copy Markdown
Contributor

CI was failing due to one ESLint violation and 7 test failures introduced when the daily-logs API was refactored to use an internal auto-managed account instead of a user-supplied accountId.

Lint fix — components/layout/dashboard-shell.tsx

react-hooks/set-state-in-effect flagged a synchronous setTheme() call inside useEffect. Replaced with a lazy useState initializer:

// Before — triggers the lint rule
const [theme, setTheme] = useState<string>("light");
useEffect(() => {
  const stored = localStorage.getItem("theme");
  if (stored === "dark" || stored === "light") setTheme(stored);
}, []);

// After — reads localStorage once at init, no setState-in-effect
const [theme, setTheme] = useState<string>(() => {
  if (typeof window !== "undefined") {
    const stored = localStorage.getItem("theme");
    if (stored === "dark" || stored === "light") return stored;
  }
  return "light";
});

Test fixes — __tests__/api/daily-logs.test.ts

The route now always resolves the account via getOrCreateDailyLogsAccount() (account.findFirstaccount.create). Tests were written against the old user-supplied accountId model.

  • 5 GET tests: added mockAccountFindFirst setup (required before the Promise.all data fetch); removed mockAccountFindMany calls; dropped the stale json.accounts expectation (the route no longer returns an accounts array)
  • POST "returns 400 when accountId is missing": accountId is optional in the schema and ignored by the route — updated to assert the request succeeds without it
  • POST "returns 400 when account does not belong to user": validation no longer exists — replaced with a test for the getOrCreate creation path (adds mockAccountCreate to the mock graph and asserts account.create is called with the correct Daily Logs payload)

README

Updated coverage badge and stats (100% stmts / 98.9% branches / 100% fns, 234 tests across 19 files), corrected coverage threshold (≥95%), and corrected Next.js version (16).

Original prompt

This section details on the original issue you should resolve

<issue_title>fix linting and add tests to achieve 100% coverage</issue_title>
<issue_description>I have made some changes, review all the code, analyze the project, then write tests to get maximum (~100%) coverage. Test for accuracy, correctness, functionality, usability and regression. Every calculation should be tested and validated. Also, make sure the entire project is linted and error and/or warning free. Then finally, update the readme.md file to update any inaccurate/conflicting/missing/outdated info and make sure the readme markets the entire app and its functionalities. </issue_description>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI changed the title [WIP] Fix linting and add tests for 100% coverage Fix lint error and align daily-logs tests with refactored route Mar 25, 2026
Copilot AI requested a review from sharf-shawon March 25, 2026 23:52
@sharf-shawon
sharf-shawon marked this pull request as ready for review March 25, 2026 23:54
@sharf-shawon
sharf-shawon merged commit e958655 into main Mar 25, 2026
2 checks passed
@sharf-shawon
sharf-shawon deleted the copilot/fix-linting-add-tests-coverage branch March 26, 2026 00:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix linting and add tests to achieve 100% coverage

2 participants