Skip to content

test: bring the test suite back in line with the API and run it in CI - #30

Open
Abhist17 wants to merge 1 commit into
sugarlabs:mainfrom
Abhist17:fix/stale-tests
Open

Abhist17 wants to merge 1 commit into
sugarlabs:mainfrom
Abhist17:fix/stale-tests

Conversation

@Abhist17

@Abhist17 Abhist17 commented Oct 3, 2026

Copy link
Copy Markdown

npm test on main fails 17 of 129 tests, and two suites (createProject, getProjectData) don't compile. Nothing runs the tests in CI, so they drifted after the API hardening in #24 and #25. This PR brings them back in line with the current behaviour and adds a workflow so it stays that way.

Test updates (no src/ changes):

  • getCommits / getProjectData: the controllers now answer 400 { message: "repoName query parameter is required" } and a fixed 500 message instead of the raw error object. getProjectData returns the encoded project string (Promise<string>), so the mocks now resolve that string.

  • createRepo: the request uses has_projects. The tests still expected the old hash_projects typo.

  • createMetaData: includes projectName, updatedAt, originalCreator, isMigrated and isMusicBlocks, plus the 'default' theme fallback, with one new test for the name/creator arguments. Mocks are restored in an afterEach, because a failing assertion skipped the inline restoreAllMocks() and left Date mocked for the next test.

  • createProject: rewritten against the current controller. It covers:

    • the sanitised repo name (-, not _) and the timestamp default,
    • projectName/creatorName,
    • the PNG thumbnail filter,
    • the unpublished SQLite row,
    • the 400/500 responses, including a failing insert.

    db is mocked there. 15 tests.

Test hygiene: src/utils/db.ts opens SQLITE_PATH, which defaults to ../../../projects.sqlite, as soon as it's imported. So every test run created a real projects.sqlite next to the repo. tests/setup.ts now sets SQLITE_PATH=':memory:' first.

CI: a new .github/workflows/test.yml runs npm ci && npm test on pull requests and pushes to main, with Node 20 like the Dockerfile.

Result: 9/9 suites, 167/167 tests pass. npm run test:type-check and eslint tests report the same 13 / 6 pre-existing errors as main, so I left them out of this PR.

- getCommits/getProjectData: the hardened controllers return
  "repoName query parameter is required" and a fixed 500 message
  instead of the raw error, and getProjectData returns the encoded
  project string.
- createRepo: has_projects (the tests still had the old hash_projects typo).
- createMetaData: include the fields added for the SQLite migration and
  the 'default' theme fallback; restore mocks after each test so a
  failure can't leave Date mocked for the next one.
- createProject: rewritten against the current controller (sanitised repo
  names, timestamp default, projectName/creatorName, thumbnail, the
  SQLite row), with db mocked.
- Point SQLITE_PATH at :memory: in the test setup; db.ts otherwise
  creates projects.sqlite outside the repo on every run.
- Add a workflow that runs npm test on pull requests and pushes to main.
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.

1 participant