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

Add unit tests for UploadActionUseCase #10392

Merged
merged 3 commits into from
Aug 20, 2019

Conversation

malinajirka
Copy link
Contributor

This PR adds unit tests for UploadActionUseCase class.

To test:
CircleCI will take care of running the tests.

Update release notes:

  • There are no user facing changes

@peril-wordpress-mobile
Copy link

Warnings
⚠️ PR has more than 500 lines of code changing. Consider splitting into smaller PRs if possible.

Generated by 🚫 dangerJS

@shiki shiki self-assigned this Aug 19, 2019
Copy link
Member

@shiki shiki left a comment

Choose a reason for hiding this comment

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

This looks great, @malinajirka! 🎉 It looks like you covered this 100%. I have a small suggestion for one of the test methods for your consideration. Feel free to deal with it however you want though. 😄 This is already perfect for me. Please merge whenever you're ready.

}

@Test
fun `autoUploadAction is DO NOTHING when the post is older than 2 days`() {
Copy link
Member

Choose a reason for hiding this comment

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

I had expected that we would sill upload local drafts but I guess DO_NOTHING is safer. In any case, I think we should cover permutations that we consider as important. For this test, what do you think of this?

    @Test
    fun `autoUploadAction is DO NOTHING when the post is older than 2 days`() {
        // Arrange
        val uploadActionUseCase = createUploadActionUseCase()

        val twoDaysAgoTimestamp = run {
            val twoDaysInSeconds = 60 * 60 * 24 * 2
            val twoDaysAgo = (Date().time / 1000) - twoDaysInSeconds
            DateTimeUtils.iso8601FromTimestamp(twoDaysAgo)
        }

        val posts = listOf(
                createPostModel(dateLocallyChanged = twoDaysAgoTimestamp),
                createPostModel(dateLocallyChanged = twoDaysAgoTimestamp, isLocalDraft = true, changesConfirmed = true),
                createPostModel(dateLocallyChanged = twoDaysAgoTimestamp, isLocalDraft = false, changesConfirmed = true)
        )

        val siteModel: SiteModel = createSiteModel()

        // Act and Assert
        assertThat(posts).allSatisfy { post ->
            val action = uploadActionUseCase.getAutoUploadAction(post, siteModel)

            assertThat(action).isEqualTo(UploadAction.DO_NOTHING)
        }
    }

Copy link
Contributor Author

@malinajirka malinajirka Aug 20, 2019

Choose a reason for hiding this comment

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

I had expected that we would sill upload local drafts

My understanding was that one of the main reasons why we want to have this "2 day" guard is that if the upload doesn't work and the user decides to update the post on the web, we don't want to override the remote post after that. If we uploaded it as a draft we might "un-publish" a post. So as you said I think it's safer to simply ignore it.

I think we should cover permutations that we consider as important. For this test, what do you think of this?

Tbh I'm not sure about it. Can you elaborate why you think it's important to test the permutations just for this specific scenario and not for all the others (especially since the 2 day guard is just additional guard which isn't critical at all)? I mean ideally we'd cover 100% of all the possible scenarios, but I don't think it's the goal of our unit tests. I agree that you could change the getAutoUploadAction so the tests would still succeed and the logic would be broken, but you would need to put an effort into it - eg. add conditions like if(isOlderThan2Days && !isLocalDraft) or similar.
Either case I added the new test as it can't hurt us to have more unit tests. I'd still like to hear your opinion;). Thanks

Copy link
Member

Choose a reason for hiding this comment

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

Thank you, @malinajirka.

I don't think it's important to cover all scenarios. Just the important ones. And, for me, it's important to cover the scenario that “local drafts will also not be automatically uploaded if they're 2 days old”. This felt important to me because when reviewing this, as I mentioned, I had expected that local drafts will always be automatically uploaded. But apparently, we don't.

And it's fine that we don't auto-upload, I just requested that it will be added in the test to document that this is how we intended it to work. 🙂

Please let me know if I didn't explain this well. 😅

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Makes sense;). Thanks for the clarification!

@malinajirka
Copy link
Contributor Author

Thanks @shiki ;)!

Copy link
Member

@shiki shiki left a comment

Choose a reason for hiding this comment

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

Thank you, @malinajirka! 🚢

@shiki shiki merged commit 83c2bbd into master-auto-upload Aug 20, 2019
@shiki shiki deleted the upload-action-use-case-tests branch August 20, 2019 13:51
@malinajirka malinajirka modified the milestones: 13.2, 13.3 Aug 26, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants