FirebaseAuth implements RawBackgroundFunction { @Override public void accept(String json, Context context) { JsonObject body = gson.fromJson(json, JsonObject.class); if (body != null && body.has("uid")) { logger.info("Function triggered by change to user: " + body.get("uid").getAsString()); } if (body != null && body.has("metadata")) { JsonObject metadata = body.get("metadata").getAsJsonObject(); logger.info("Created at: " + metadata.get("createdAt").getAsString()); } if (body != null && body.has("email")) { logger.info("Email: " + body.get("email").getAsString()); } }  @Override void accept(String json, Context context);  }
@Test public void functionsFirebaseAuth_shouldShowUserId() { String jsonStr = gson.toJson(Map.of("uid", "foo")); new FirebaseAuth().accept(jsonStr, null); Truth.assertThat(LOG_HANDLER.getStoredLogRecords().get(0).getMessage()).isEqualTo( "Function triggered by change to user: foo"); }
@Test public void functionsFirebaseAuth_shouldShowOrigin() { String jsonStr = gson.toJson(Map.of("metadata", Map.of("createdAt", "123"))); new FirebaseAuth().accept(jsonStr, null); Truth.assertThat(LOG_HANDLER.getStoredLogRecords().get(0).getMessage()).isEqualTo( "Created at: 123"); }
@Test public void functionsFirebaseAuth_shouldShowVersion() { String jsonStr = gson.toJson(Map.of("email", "foo@google.com")); new FirebaseAuth().accept(jsonStr, null); Truth.assertThat(LOG_HANDLER.getStoredLogRecords().get(0).getMessage()).isEqualTo( "Email: foo@google.com"); }