Skip to content

Conversation

Japleen-Kaur2409
Copy link
Contributor

@Japleen-Kaur2409 Japleen-Kaur2409 commented Sep 30, 2025

Proposed Changes

Added test cases for the retrieveProgram method of app/Controllers/Program.hs in backend-test/Controllers /ProgramControllerTests.hs, covering the cases:

  • Calling with a valid program code
  • Calling with an invalid program code
  • Calling with a non-existent program code

Added a helper function in backend-test/TestHelpers.hs to run ServerPartWithProgramQuery Response for retrieveProgram.

Modified insertPrograms helper - It now uses a fixed testTimestamp instead of getCurrentTime to ensure consistent JSON output for exact matching

  • Note on fixed timestamp:
    Using a fixed testTimestamp in insertPrograms is a temporary solution.

Type of Change

(Write an X or a brief description next to the type or types that best describe your changes.)

Type Applies?
🚨 Breaking change (fix or feature that would cause existing functionality to change)
New feature (non-breaking change that adds functionality)
🐛 Bug fix (non-breaking change that fixes an issue)
🎨 User interface change (change to user interface; provide screenshots)
♻️ Refactoring (internal change to codebase, without changing functionality)
🚦 Test update (change that only adds or modifies tests) X
📦 Dependency update (change that updates a dependency)
🔧 Internal (change that only affects developers or continuous integration)

Checklist

(Complete each of the following items for your pull request. Indicate that you have completed an item by changing the [ ] into a [x] in the raw text, or by clicking on the checkbox in the rendered description on GitHub.)

Before opening your pull request:

  • I have performed a self-review of my changes.
    • Check that all changed files included in this pull request are intentional changes.
    • Check that all changes are relevant to the purpose of this pull request, as described above.
  • I have added tests for my changes, if applicable.
    • This is required for all bug fixes and new features.
  • I have updated the project documentation, if applicable.
    • This is required for new features.
  • If this is my first contribution, I have added myself to the list of contributors.
  • I have updated the project Changelog (this is required for all changes).

After opening your pull request:

  • I have verified that the CircleCI checks have passed.
  • I have requested a review from a project maintainer.

@Japleen-Kaur2409 Japleen-Kaur2409 changed the title for retrieveProgram Test cases for retrieveProgram Sep 30, 2025
import Controllers.Program (index, retrieveProgram)
import qualified Data.ByteString.Lazy.Char8 as BL
import Data.List (isInfixOf)
import Data.Time.Clock (getCurrentTime)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change in import here is okay, but you shouldn't change the order (previously this was included under the Data.Text import

retrieveprogramTestCases =
[ ("Valid program code returns JSON"
, ["ASMAJ1689"]
, T.pack "ASMAJ1689"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The T.pack is unnecessary. We should have a compiler flag turned on so that any string literal is automatically inferred to have the correct type.


response <- runServerPartWithProgramQuery Controllers.Program.retrieveProgram (T.unpack queryParam)
let actual = BL.unpack $ rsBody response
case expected of
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This structure is okay but should be simplified. In all of the non-error cases, you can (and should) be asserting a match against the exact expected string, not just an expected substring.

In the non-error case, the current test is quite broad (not (null actual))). This is again a place where you should be asserting the exact error message.

Comment on lines 94 to 95
insertProgram code = do
curr <- liftIO getCurrentTime
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fixed testTimestamp to enable exact JSON string matching in tests. This is a
temporary solution to satisfy the requirement.
Is there any better testing approach I should take that can check the exact time in the JSON response?

@Japleen-Kaur2409 Japleen-Kaur2409 requested review from david-yz-liu and removed request for david-yz-liu October 9, 2025 03:33
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.

2 participants