Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions sdk/src/test/java/com/uid2/UID2ClientTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,29 @@ class UID2ClientTest {
assertEquals(expectedIdentity, response.identity)
}

@Test
fun `test generate opt-out`() = runTest(testDispatcher) {
val client = withClient()

// Configure the network request to return a status which indicates the user has opted-out.
val unencrypted = JSONObject(TestData.REFRESH_TOKEN_OPT_OUT_DECRYPTED)
every { dataEnvelope.decrypt(any<ByteArray>(), any<String>(), any<Boolean>()) }.returns(
unencrypted.toString().toByteArray(),
)
every { networkSession.loadData(any(), any()) }.returns(NetworkResponse(200, "some data"))

val response = client.generateIdentity(
IdentityRequest.Email("[email protected]"),
SUBSCRIPTION_ID,
PUBLIC_KEY,
)
assertNotNull(response)

// Verify that we don't receive any identity but the status explicitly tells us that they have opted-out.
assertNull(response.identity)
assertEquals(IdentityStatus.OPT_OUT, response.status)
}

//endregion

//region refreshIdentity
Expand Down
23 changes: 23 additions & 0 deletions sdk/src/test/java/com/uid2/UID2ManagerTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,29 @@ class UID2ManagerTest {
assertTrue(result is GenerateIdentityResult.Error)
}

@Test
fun `generates for opt-out identity`() = runTest(testDispatcher) {
val subscriptionId = "sub"
val publicKey = "pub"

val request = IdentityRequest.Email("[email protected]")
coEvery { client.generateIdentity(request, subscriptionId, publicKey) }.returns(
ResponsePackage(null, OPT_OUT, ""),
)

// Request a new identity should be generated.
var result: GenerateIdentityResult? = null
manager.generateIdentity(request, subscriptionId, publicKey) { result = it }
testDispatcher.scheduler.advanceUntilIdle()

// Verify that after generating the identity, there is no current identity but the expected OPT_OUT status.
assertNull(manager.currentIdentity)
assertEquals(OPT_OUT, manager.currentIdentityStatus)

// Verify that the result callback was invoked.
assertTrue(result is GenerateIdentityResult.Success)
}

@Test
fun `resets identity`() = runTest(testDispatcher) {
// Verify that the initial state of the manager reflects the restored Identity.
Expand Down