Skip to content

Conversation

@ksaric
Copy link
Contributor

@ksaric ksaric commented May 23, 2018

https://iohk.myjetbrains.com/youtrack/issue/CO-296

A first major refactoring. I tried to pick the simplest way of introducing mocking capabilities, required for https://iohk.myjetbrains.com/youtrack/issue/CO-289

@ksaric ksaric requested review from HirotoShioi and robcohen May 23, 2018 14:51
Copy link
Contributor

@HirotoShioi HirotoShioi left a comment

Choose a reason for hiding this comment

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

I've left some comments. Generally, I'm very interested in how this changes would enable us to do simple tests!

Nothing -> pure page0

-- | Send API request to post comment
postTicketComment
Copy link
Contributor

Choose a reason for hiding this comment

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

Since we've defined ZendeskResponse in the previous PR, we can make this function to take ZendeskResponse as an argument which will be much more simpler
postTicketComment :: (MonadIO m, MonadReader Config m) => ZendeskResponse -> m ()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nice, thanks.

{ zrComment :: Text
, zrTags :: [Text] -- TODO(ks): This should be wrapped
, zrIsPublic :: Bool
{ zrComment :: Text
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add ! to these fields?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, nice catch.

let getAgentId = zlGetAgentId . cfgZendeskLayer $ cfg'
agentId <- runApp getAgentId cfg'
let cfg = cfg' { cfgAgentId = agentId }
-- At this point, the configuration is set up and there is no point in using a pure IO.
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure what this means (Not enough haskell knowledge to understand it). Can you explain it to me?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It just means that there is no point in using IO all over the codebase since the Config is initialized and we require Config to use the App newtype.
The consequences of this are - try to see how many runApp were removed...

-- | The Zendesk API interface that we want to expose.
-- We don't want anything to leak out, so we expose only the most relevant information,
-- anything relating to how it internaly works should NOT be exposed.
data ZendeskLayer m = ZendeskLayer
Copy link
Contributor

Choose a reason for hiding this comment

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

I can see what it does but I'm not sure how this would enable us to do simple tests. (Again, now enough haskell knowledge!)

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 guess you can imagine ZendeskLayer as an object (if an object is a dictionary of functions) that we pass around.
When we want to use it we use the Reader to fetch the function we are interested in.
The enables us to replace the functions anyway we want because they are defined in the Config that Reader is using.
In other words, if we now run a test and want listTickets to return an empty list, we can, because all we need to do is construct a new configuration with that function a simple constant that returns an empty list and we can test the rest of the code.
If this is confusing, the next PR might make more sense since it will deal with tests themselves.

src/Lib.hs Outdated
import LogAnalysis.KnowledgeCSVParser
import Util
import CLI
import Zendesk
Copy link
Contributor

@HirotoShioi HirotoShioi May 24, 2018

Choose a reason for hiding this comment

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

Can you make these imports explicit?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, good catch.

Copy link
Contributor

@HirotoShioi HirotoShioi left a comment

Choose a reason for hiding this comment

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

Checked the changes. Looks good!

@ksaric ksaric merged commit 3e9b8b8 into develop May 25, 2018
@ksaric ksaric deleted the ksaric/CO-296 branch May 25, 2018 07:27
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.

3 participants