Allow to decide whether test contacts should have alias

This commit is contained in:
Torsten Grote
2021-03-19 14:24:19 -03:00
parent 372516646d
commit 4ca286b28e
4 changed files with 11 additions and 9 deletions

View File

@@ -116,7 +116,7 @@ public class SetupDataTest extends ScreenshotTest {
throws DbException { throws DbException {
Context ctx = getApplicationContext(); Context ctx = getApplicationContext();
String bobName = ctx.getString(R.string.screenshot_bob); String bobName = ctx.getString(R.string.screenshot_bob);
Contact bob = testDataCreator.addContact(bobName, true); Contact bob = testDataCreator.addContact(bobName, false, true);
// TODO add messages // TODO add messages

View File

@@ -24,5 +24,6 @@ public interface TestDataCreator {
int numBlogPosts, int numForums, int numForumPosts); int numBlogPosts, int numForums, int numForumPosts);
@IoExecutor @IoExecutor
Contact addContact(String name, boolean avatar) throws DbException; Contact addContact(String name, boolean alias, boolean avatar)
throws DbException;
} }

View File

@@ -158,15 +158,15 @@ public class TestDataCreatorImpl implements TestDataCreator {
LocalAuthor localAuthor = identityManager.getLocalAuthor(); LocalAuthor localAuthor = identityManager.getLocalAuthor();
for (int i = 0; i < numContacts; i++) { for (int i = 0; i < numContacts; i++) {
LocalAuthor remote = getRandomAuthor(); LocalAuthor remote = getRandomAuthor();
Contact contact = Contact contact = addContact(localAuthor.getId(), remote,
addContact(localAuthor.getId(), remote, avatarPercent); random.nextBoolean(), avatarPercent);
contacts.add(contact); contacts.add(contact);
} }
return contacts; return contacts;
} }
private Contact addContact(AuthorId localAuthorId, LocalAuthor remote, private Contact addContact(AuthorId localAuthorId, LocalAuthor remote,
int avatarPercent) throws DbException { boolean alias, int avatarPercent) throws DbException {
// prepare to add contact // prepare to add contact
SecretKey secretKey = getSecretKey(); SecretKey secretKey = getSecretKey();
long timestamp = clock.currentTimeMillis(); long timestamp = clock.currentTimeMillis();
@@ -179,7 +179,7 @@ public class TestDataCreatorImpl implements TestDataCreator {
Contact contact = db.transactionWithResult(false, txn -> { Contact contact = db.transactionWithResult(false, txn -> {
ContactId contactId = contactManager.addContact(txn, remote, ContactId contactId = contactManager.addContact(txn, remote,
localAuthorId, secretKey, timestamp, true, verified, true); localAuthorId, secretKey, timestamp, true, verified, true);
if (random.nextBoolean()) { if (alias) {
contactManager.setContactAlias(txn, contactId, contactManager.setContactAlias(txn, contactId,
getRandomAuthorName()); getRandomAuthorName());
} }
@@ -197,11 +197,12 @@ public class TestDataCreatorImpl implements TestDataCreator {
} }
@Override @Override
public Contact addContact(String name, boolean avatar) throws DbException { public Contact addContact(String name, boolean alias, boolean avatar)
throws DbException {
LocalAuthor localAuthor = identityManager.getLocalAuthor(); LocalAuthor localAuthor = identityManager.getLocalAuthor();
LocalAuthor remote = authorFactory.createLocalAuthor(name); LocalAuthor remote = authorFactory.createLocalAuthor(name);
int avatarPercent = avatar ? 100 : 0; int avatarPercent = avatar ? 100 : 0;
return addContact(localAuthor.getId(), remote, avatarPercent); return addContact(localAuthor.getId(), remote, alias, avatarPercent);
} }
private String getRandomAuthorName() { private String getRandomAuthorName() {

View File

@@ -25,7 +25,7 @@ class ContactControllerIntegrationTest: IntegrationTest() {
// add one test contact // add one test contact
val testContactName= "testContactName" val testContactName= "testContactName"
testDataCreator.addContact(testContactName, false) testDataCreator.addContact(testContactName, true, false)
// retrieve list with one test contact // retrieve list with one test contact
response = get("$url/contacts") response = get("$url/contacts")