-
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow consumers to specify the account the contact will be saved into
- Loading branch information
Showing
8 changed files
with
178 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
109 changes: 109 additions & 0 deletions
109
library/src/androidTest/java/com/alexstyl/contactstore/InsertContactToAccountTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
package com.alexstyl.contactstore | ||
|
||
import android.net.Uri | ||
import com.alexstyl.contactstore.ContactColumn.Events | ||
import com.alexstyl.contactstore.ContactColumn.ImAddresses | ||
import com.alexstyl.contactstore.ContactColumn.Mails | ||
import com.alexstyl.contactstore.ContactColumn.Names | ||
import com.alexstyl.contactstore.ContactColumn.Note | ||
import com.alexstyl.contactstore.ContactColumn.Organization | ||
import com.alexstyl.contactstore.ContactColumn.Phones | ||
import com.alexstyl.contactstore.ContactColumn.PostalAddresses | ||
import com.alexstyl.contactstore.ContactColumn.Relations | ||
import com.alexstyl.contactstore.ContactColumn.SipAddresses | ||
import com.alexstyl.contactstore.ContactColumn.WebAddresses | ||
import com.alexstyl.contactstore.Label.DateBirthday | ||
import com.alexstyl.contactstore.Label.LocationHome | ||
import com.alexstyl.contactstore.Label.PhoneNumberMobile | ||
import kotlinx.coroutines.ExperimentalCoroutinesApi | ||
import kotlinx.coroutines.flow.first | ||
import kotlinx.coroutines.runBlocking | ||
import org.junit.Test | ||
|
||
@ExperimentalCoroutinesApi | ||
internal class InsertContactToAccountTest : ContactStoreTestBase() { | ||
|
||
@Test | ||
fun insertingContactToAccountAddsAllItemsToTheSameAccount(): Unit = runBlocking { | ||
val account = InternetAccount("[email protected]", "test.com") | ||
store.execute { | ||
insert(account) { | ||
phone("555", PhoneNumberMobile) | ||
mail("[email protected]", LocationHome) | ||
event(dayOfMonth = 1, month = 1, year = 2021, DateBirthday) | ||
postalAddress( | ||
street = "Somestreet", | ||
poBox = "12345", | ||
neighborhood = "Hood", | ||
city = "City", | ||
region = "", | ||
postCode = "", | ||
country = "", | ||
label = LocationHome | ||
) | ||
webAddress(Uri.parse("https://acme.corp"), Label.WebsiteHomePage) | ||
imAddress( | ||
address = "ImAddress", | ||
protocol = "protocol", | ||
label = LocationHome | ||
) | ||
relation(name = "Person", label = Label.PhoneNumberAssistant) | ||
sipAddress(address = "123", label = LocationHome) | ||
} | ||
} | ||
|
||
val actual = store.fetchContacts(columnsToFetch = allContactColumns()).first() | ||
val expected = contact( | ||
displayName = "555", | ||
columns = allContactColumns(), | ||
phones = listOf( | ||
LabeledValue(PhoneNumber("555"), PhoneNumberMobile, null, account) | ||
), | ||
mails = listOf( | ||
LabeledValue(MailAddress("[email protected]"), LocationHome, null, account) | ||
), | ||
events = listOf( | ||
LabeledValue(EventDate(1, 1, 2021), DateBirthday, null, account) | ||
), | ||
postalAddresses = listOf( | ||
LabeledValue( | ||
PostalAddress( | ||
street = "Somestreet", | ||
poBox = "12345", | ||
neighborhood = "Hood", | ||
city = "City", | ||
region = "", | ||
postCode = "", | ||
country = "" | ||
), | ||
LocationHome, | ||
null, | ||
account | ||
) | ||
), | ||
webAddresses = listOf( | ||
LabeledValue( | ||
WebAddress(Uri.parse("https://acme.corp")), | ||
Label.WebsiteHomePage, | ||
null, | ||
account | ||
) | ||
), | ||
imAddresses = listOf( | ||
LabeledValue( | ||
ImAddress(raw = "ImAddress", protocol = "protocol"), | ||
LocationHome, | ||
null, | ||
account | ||
) | ||
), | ||
relations = listOf( | ||
LabeledValue(Relation(name = "Person"), Label.PhoneNumberAssistant, null, account) | ||
), | ||
sipAddresses = listOf( | ||
LabeledValue(SipAddress(raw = "123"), LocationHome, null, account) | ||
), | ||
) | ||
assertOnlyContact(actual = actual, expected = expected) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 4 additions & 1 deletion
5
library/src/main/java/com/alexstyl/contactstore/ContactOperation.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 43 additions & 32 deletions
75
library/src/main/java/com/alexstyl/contactstore/ContactStoreDSL.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters