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

Merge Release/12.7.1 into master #10202

Merged
merged 13 commits into from
Jul 12, 2019
4 changes: 4 additions & 0 deletions RELEASE-NOTES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
* Block Editor: Performance improvements on rich text editing
* Add All-time, Today, Weekly and Minified widgets

12.7.1
------
* Fix issue where local draft with "Publish" status got automatically published

12.7
-----
* Added Post search
Expand Down
8 changes: 4 additions & 4 deletions WordPress/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ android {

defaultConfig {
applicationId "org.wordpress.android"
versionName "alpha-178"
versionCode 748
versionName "alpha-179"
versionCode 751
minSdkVersion 21
targetSdkVersion 26

Expand Down Expand Up @@ -76,8 +76,8 @@ android {
productFlavors {
vanilla { // used for release and beta
dimension "buildType"
versionName "12.8-rc-2"
versionCode 747
versionName "12.8-rc-3"
versionCode 750
}

zalpha { // alpha version - enable experimental features
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import kotlinx.coroutines.async
import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.launch
import org.wordpress.android.fluxc.model.SiteModel
import org.wordpress.android.fluxc.model.post.PostStatus
import org.wordpress.android.fluxc.store.PageStore
import org.wordpress.android.fluxc.store.PostStore
import org.wordpress.android.fluxc.store.SiteStore
Expand Down Expand Up @@ -142,6 +143,7 @@ open class LocalDraftUploadStarter @Inject constructor(
.filter {
uploadStore.getNumberOfPostUploadErrorsOrCancellations(it) < MAXIMUM_AUTO_INITIATED_UPLOAD_RETRIES
}
.filter { PostStatus.DRAFT.toString() == it.status }
.forEach { localDraft ->
uploadServiceFacade.uploadPost(
context = context,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import org.junit.runner.RunWith
import org.mockito.junit.MockitoJUnitRunner
import org.wordpress.android.fluxc.model.PostModel
import org.wordpress.android.fluxc.model.SiteModel
import org.wordpress.android.fluxc.model.post.PostStatus
import org.wordpress.android.fluxc.store.PageStore
import org.wordpress.android.fluxc.store.PostStore
import org.wordpress.android.ui.posts.PostUtilsWrapper
Expand All @@ -31,16 +32,16 @@ class LocalDraftUploadStarterConcurrentTest {
@get:Rule val rule = InstantTaskExecutorRule()

private val site = SiteModel()
private val posts = listOf(
PostModel(),
PostModel(),
PostModel(),
PostModel(),
PostModel()
private val draftPosts = listOf(
createDraftPostModel(),
createDraftPostModel(),
createDraftPostModel(),
createDraftPostModel(),
createDraftPostModel()
)

private val postStore = mock<PostStore> {
on { getLocalDraftPosts(eq(site)) } doReturn posts
on { getLocalDraftPosts(eq(site)) } doReturn draftPosts
}
private val pageStore = mock<PageStore> {
onBlocking { getLocalDraftPages(any()) } doReturn emptyList()
Expand All @@ -59,7 +60,7 @@ class LocalDraftUploadStarterConcurrentTest {
}

// Then
verify(uploadServiceFacade, times(posts.size)).uploadPost(
verify(uploadServiceFacade, times(draftPosts.size)).uploadPost(
context = any(),
post = any(),
trackAnalytics = any(),
Expand Down Expand Up @@ -94,5 +95,9 @@ class LocalDraftUploadStarterConcurrentTest {
fun createMockedPostUtilsWrapper() = mock<PostUtilsWrapper> {
on { isPublishable(any()) } doReturn true
}

fun createDraftPostModel() = PostModel().apply {
status = PostStatus.DRAFT.toString()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import org.junit.runner.RunWith
import org.mockito.junit.MockitoJUnitRunner
import org.wordpress.android.fluxc.model.PostModel
import org.wordpress.android.fluxc.model.SiteModel
import org.wordpress.android.fluxc.model.post.PostStatus
import org.wordpress.android.fluxc.store.PageStore
import org.wordpress.android.fluxc.store.PostStore
import org.wordpress.android.fluxc.store.SiteStore
Expand All @@ -43,35 +44,40 @@ class LocalDraftUploadStarterTest {
@get:Rule val rule = InstantTaskExecutorRule()

private val sites = listOf(SiteModel(), SiteModel())
private val sitesAndPosts: Map<SiteModel, List<PostModel>> = mapOf(
sites[0] to listOf(createPostModel(), createPostModel()),
private val sitesAndDraftPosts: Map<SiteModel, List<PostModel>> = mapOf(
sites[0] to listOf(createDraftPostModel(), createDraftPostModel()),
sites[1] to listOf(
createPostModel(),
createPostModel(),
createPostModel(),
createPostModel(),
createPostModel()
createDraftPostModel(),
createDraftPostModel(),
createDraftPostModel(),
createDraftPostModel(),
createDraftPostModel()
)
)
private val posts = sitesAndPosts.values.flatten()
private val draftPosts = sitesAndDraftPosts.values.flatten()

private val sitesAndPages: Map<SiteModel, List<PostModel>> = mapOf(
sites[0] to listOf(createPostModel(), createPostModel()),
sites[1] to listOf(createPostModel(), createPostModel(), createPostModel(), createPostModel())
private val sitesAndDraftPages: Map<SiteModel, List<PostModel>> = mapOf(
sites[0] to listOf(createDraftPostModel(), createDraftPostModel()),
sites[1] to listOf(
createDraftPostModel(),
createDraftPostModel(),
createDraftPostModel(),
createDraftPostModel()
)
)
private val pages = sitesAndPages.values.flatten()
private val draftPages = sitesAndDraftPages.values.flatten()

private val siteStore = mock<SiteStore> {
on { sites } doReturn sites
}
private val postStore = mock<PostStore> {
sites.forEach {
on { getLocalDraftPosts(eq(it)) } doReturn sitesAndPosts.getValue(it)
on { getLocalDraftPosts(eq(it)) } doReturn sitesAndDraftPosts.getValue(it)
}
}
private val pageStore = mock<PageStore> {
sites.forEach {
onBlocking { getLocalDraftPages(eq(it)) } doReturn sitesAndPages.getValue(it)
onBlocking { getLocalDraftPages(eq(it)) } doReturn sitesAndDraftPages.getValue(it)
}
}

Expand All @@ -95,7 +101,7 @@ class LocalDraftUploadStarterTest {
connectionStatus.postValue(AVAILABLE)

// Then
verify(uploadServiceFacade, times(posts.size + pages.size)).uploadPost(
verify(uploadServiceFacade, times(draftPosts.size + draftPages.size)).uploadPost(
context = any(),
post = any(),
trackAnalytics = any(),
Expand Down Expand Up @@ -144,7 +150,7 @@ class LocalDraftUploadStarterTest {
lifecycle.handleLifecycleEvent(Event.ON_START)

// Then
verify(uploadServiceFacade, times(posts.size + pages.size)).uploadPost(
verify(uploadServiceFacade, times(draftPosts.size + draftPages.size)).uploadPost(
context = any(),
post = any(),
trackAnalytics = any(),
Expand All @@ -167,7 +173,8 @@ class LocalDraftUploadStarterTest {
starter.queueUploadFromSite(site)

// Then
val expectedUploadPostExecutions = sitesAndPosts.getValue(site).size + sitesAndPages.getValue(site).size
val expectedUploadPostExecutions = sitesAndDraftPosts.getValue(site).size +
sitesAndDraftPages.getValue(site).size
verify(uploadServiceFacade, times(expectedUploadPostExecutions)).uploadPost(
context = any(),
post = any(),
Expand All @@ -187,7 +194,7 @@ class LocalDraftUploadStarterTest {
val postUtilsWrapper = mock<PostUtilsWrapper> {
on { isPublishable(any()) } doAnswer {
// return isPublishable = false on the first post of the site
it.getArgument<PostModel>(0) != sitesAndPosts[site]?.get(0)!!
it.getArgument<PostModel>(0) != sitesAndDraftPosts[site]?.get(0)!!
}
}

Expand All @@ -198,7 +205,8 @@ class LocalDraftUploadStarterTest {

// Then
// subtract - 1 as we've returned isPublishable = false for the first post of the site
val expectedUploadPostExecutions = sitesAndPosts.getValue(site).size + sitesAndPages.getValue(site).size - 1
val expectedUploadPostExecutions = sitesAndDraftPosts.getValue(site).size +
sitesAndDraftPages.getValue(site).size - 1
verify(uploadServiceFacade, times(expectedUploadPostExecutions)).uploadPost(
context = any(),
post = any(),
Expand All @@ -212,14 +220,14 @@ class LocalDraftUploadStarterTest {
fun `when uploading, it ignores local drafts that are already queued`() {
// Given
val site: SiteModel = sites[1]
val (expectedQueuedPosts, expectedUploadedPosts) = sitesAndPosts.getValue(site).let { posts ->
val (expectedQueuedPosts, expectedUploadedPosts) = sitesAndDraftPosts.getValue(site).let { posts ->
// Split into halves of already queued and what should be uploaded
return@let Pair(
posts.subList(0, posts.size / 2),
posts.subList(posts.size / 2, posts.size)
)
}
val (expectedQueuedPages, expectedUploadedPages) = sitesAndPages.getValue(site).let { pages ->
val (expectedQueuedPages, expectedUploadedPages) = sitesAndDraftPages.getValue(site).let { pages ->
// Split into halves of already queued and what should be uploaded
return@let Pair(
pages.subList(0, pages.size / 2),
Expand Down Expand Up @@ -252,7 +260,7 @@ class LocalDraftUploadStarterTest {
)
verify(
uploadServiceFacade,
times(sitesAndPosts.getValue(site).size + sitesAndPages.getValue(site).size)
times(sitesAndDraftPosts.getValue(site).size + sitesAndDraftPages.getValue(site).size)
).isPostUploadingOrQueued(any())
verifyNoMoreInteractions(uploadServiceFacade)
}
Expand Down Expand Up @@ -331,9 +339,10 @@ class LocalDraftUploadStarterTest {
on { this.lifecycle } doReturn lifecycle
}

fun createPostModel() = PostModel().apply {
fun createDraftPostModel() = PostModel().apply {
id = Random.nextInt()
title = UUID.randomUUID().toString()
status = PostStatus.DRAFT.toString()
}
}
}