mirror of
https://github.com/signalapp/Signal-Server
synced 2026-04-22 00:38:02 +01:00
Add ContactDiscoveryWriterTest based on mock.
This commit is contained in:
committed by
gram-signal
parent
894297efa9
commit
6304c84cdb
@@ -524,40 +524,6 @@ class AccountsDynamoDbTest {
|
||||
verifyStoredState("+14151112222", account.getUuid(), account, false);
|
||||
}
|
||||
|
||||
/*
|
||||
@Test
|
||||
void testContactDiscoveryWriter() throws Exception {
|
||||
Device device = generateDevice(1);
|
||||
UUID uuid = UUID.randomUUID();
|
||||
Account account = generateAccount("+14151112222", uuid, Collections.singleton(device));
|
||||
accountsDynamoDb.create(account);
|
||||
verifyStoredState("+14151112222", account.getUuid(), account, true);
|
||||
ContactDiscoveryWriter writer = new ContactDiscoveryWriter(accountsDynamoDb);
|
||||
account.setCanonicallyDiscoverable(false);
|
||||
writer.onCrawlChunk(null, List.of(account));
|
||||
account.setVersion(1);
|
||||
verifyStoredState("+14151112222", account.getUuid(), account, true);
|
||||
|
||||
// Make the stored "C" column not match reality.
|
||||
final UpdateItemRequest updateItemRequest = UpdateItemRequest.builder()
|
||||
.tableName(ACCOUNTS_TABLE_NAME)
|
||||
.key(Map.of(AccountsDynamoDb.KEY_ACCOUNT_UUID, AttributeValues.fromUUID(account.getUuid())))
|
||||
.updateExpression("SET #cds = :cds")
|
||||
.expressionAttributeNames(Map.of("#cds", AccountsDynamoDb.ATTR_CANONICALLY_DISCOVERABLE))
|
||||
.expressionAttributeValues(Map.of(
|
||||
":cds", AttributeValues.fromBool(false)))
|
||||
.build();
|
||||
dynamoDbExtension.getDynamoDbClient().updateItem(updateItemRequest);
|
||||
verifyStoredState("+14151112222", account.getUuid(), account, false);
|
||||
|
||||
// Crawl again and make sure update happened
|
||||
account.setCanonicallyDiscoverable(false);
|
||||
writer.onCrawlChunk(null, List.of(account));
|
||||
account.setVersion(2);
|
||||
verifyStoredState("+14151112222", account.getUuid(), account, true);
|
||||
}
|
||||
*/
|
||||
|
||||
private Device generateDevice(long id) {
|
||||
Random random = new Random(System.currentTimeMillis());
|
||||
SignedPreKey signedPreKey = new SignedPreKey(random.nextInt(), "testPublicKey-" + random.nextInt(), "testSignature-" + random.nextInt());
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright 2013-2021 Signal Messenger, LLC
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
||||
package org.whispersystems.textsecuregcm.storage;
|
||||
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.Arguments;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
public class ContactDiscoveryWriterTest {
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource
|
||||
void testUpdatesOnChange(boolean canonicallyDiscoverable, boolean shouldBeVisible, boolean updateCalled) throws AccountDatabaseCrawlerRestartException {
|
||||
AccountsManager mgr = mock(AccountsManager.class);
|
||||
UUID uuid = UUID.randomUUID();
|
||||
Account acct = mock(Account.class);
|
||||
when(acct.getUuid()).thenReturn(uuid);
|
||||
when(acct.isCanonicallyDiscoverable()).thenReturn(canonicallyDiscoverable);
|
||||
when(acct.shouldBeVisibleInDirectory()).thenReturn(shouldBeVisible);
|
||||
when(mgr.get(uuid)).thenReturn(Optional.of(acct));
|
||||
ContactDiscoveryWriter writer = new ContactDiscoveryWriter(mgr);
|
||||
writer.onCrawlChunk(Optional.empty(), List.of(acct));
|
||||
verify(mgr, times(updateCalled ? 1 : 0)).update(acct, ContactDiscoveryWriter.NOOP_UPDATER);
|
||||
}
|
||||
|
||||
static Stream<Arguments> testUpdatesOnChange() {
|
||||
return Stream.of(
|
||||
Arguments.of(true, true, false),
|
||||
Arguments.of(false, false, false),
|
||||
Arguments.of(true, false, true),
|
||||
Arguments.of(false, true, true));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user