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

Improved testing functionality #1146

Merged
merged 8 commits into from Oct 17, 2021
Merged

Improved testing functionality #1146

merged 8 commits into from Oct 17, 2021

Conversation

mpscholten
Copy link
Member

Main change is that now every test is running inside it's own isolated test database

Main change is that now every test is running inside it's own isolated test database

-- | Create contexts that can be used for mocking
mockContext :: (InitControllerContext application) => application -> ConfigBuilder -> IO (MockContext application)
mockContext application configBuilder = do
withIHPApp :: (InitControllerContext application) => application -> ConfigBuilder -> (MockContext application -> IO ()) -> IO ()
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe keep the word Mock, so it's clear it's not a real app? withMockedIHPApp

Copy link
Member Author

Choose a reason for hiding this comment

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

IMO it's not really mocked anymore as we're now using the real database and action lifecycle for testing

Copy link
Collaborator

Choose a reason for hiding this comment

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

👍

@@ -53,11 +58,13 @@ mockContext application configBuilder = do
let requestContext = RequestContext
{ request = defaultRequest {vault = sessionVault}
, requestBody = FormBody [] []
, respond = \resp -> pure ResponseReceived
, respond = undefined
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is it undefined so it would error out if response is not filled in?

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed now :) Leftover from testing

@mpscholten mpscholten merged commit 564ce30 into master Oct 17, 2021
@mpscholten mpscholten deleted the testing-improvements branch October 17, 2021 10:37
frameworkConfig@(FrameworkConfig {dbPoolMaxConnections, dbPoolIdleTime, databaseUrl}) <- FrameworkConfig.buildFrameworkConfig configBuilder
databaseConnection <- connectPostgreSQL databaseUrl

testDatabase <- Database.createTestDatabase databaseUrl
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider using bracket to ensure things get cleaned up if there is an exception.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point 👍 6dd1b6e

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.

None yet

3 participants