package com.google.sps.objects;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import java.util.ArrayList;
import java.util.LinkedHashSet;
import java.util.List;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import com.google.appengine.api.datastore.DatastoreService;
import com.google.appengine.api.datastore.DatastoreServiceFactory;
import com.google.appengine.api.datastore.Entity;

import com.google.appengine.tools.development.testing.LocalDatastoreServiceTestConfig;
import com.google.appengine.tools.development.testing.LocalServiceTestHelper;
import com.google.sps.Objects.response.MemberResponse;
import com.google.sps.Objects.Badge;

/**
 * Unit tests for MemberResponse.
 *
 */
public class MemberResponseTest {

  private static final String PROFILE_PIC = "";
  private static final String FIRST_NAME = "Test";
  private static final String LAST_NAME = "User";
  private static final String USER_ID = "11111111";

  private final LocalServiceTestHelper helper =
      new LocalServiceTestHelper(
          new LocalDatastoreServiceTestConfig()
              .setDefaultHighRepJobPolicyUnappliedJobPercentage(0));

  private MemberResponse memberResponse;

  @Before
  public void setUp() {
    helper.setUp();
    memberResponse = 
      new MemberResponse(
        PROFILE_PIC, /* profilePic */ 
        FIRST_NAME, /* firstName */
        LAST_NAME, /* lastName */
        new LinkedHashSet<Badge>(), /* badges */
        USER_ID /*userId */);
  }

  @After
  public void tearDown() {
    helper.tearDown();
    memberResponse = null;
  }

  @Test
  public void getFirstNameTest() {
    assertEquals(memberResponse.getFirstName(), "Test");
  }

  @Test
  public void getLastNameTest() {
    assertEquals(memberResponse.getLastName(), "User");
  }

  @Test
  public void getStringURLTest() {
    assertEquals(memberResponse.getStringURL(), "");
  }

  @Test
  public void getBadgesTest() {
    assert memberResponse.getBadges().size() == 0;
    Badge badge = new Badge(/* challenge name */ "workout", /* icon */ null, /* timestamp */ 11111111);
    memberResponse.getBadges().add(badge);
    assert memberResponse.getBadges().size() == 1;
  }

  @Test
  public void fromEntityTest() {
    Entity entity = new Entity("MemberResponse");
    String profilePic = "";
    String firstName = "Test";
    String lastName = "User";
    String userId = "11111111";
    entity.setProperty("profilePic", profilePic);
    entity.setProperty("firstName", firstName);
    entity.setProperty("lastName", lastName);
    entity.setProperty("userId", userId);
    MemberResponse returnedMemberResponse = MemberResponse.fromEntity(entity, false);

    assertEquals(returnedMemberResponse.getFirstName(), firstName);
    assertEquals(returnedMemberResponse.getLastName(), lastName);
    assertEquals(returnedMemberResponse.getStringURL(), profilePic);
    assertEquals(returnedMemberResponse.getUserId(), userId);
  } 
}



@@ -1230,16 +1230,39 @@
 esponse;
+%0A  private Badge badge;
 %0A%0A  @Bef
@@ -1732,22 +1732,26 @@
 Name(), 
-%22Test%22
+FIRST_NAME
 );%0A  %7D%0A%0A
@@ -1839,22 +1839,25 @@
 Name(), 
-%22User%22
+LAST_NAME
 );%0A  %7D%0A%0A
@@ -1947,18 +1947,27 @@
 gURL(), 
-%22%22
+PROFILE_PIC
 );%0A  %7D%0A%0A
@@ -2061,22 +2061,16 @@
  0;%0A    
-Badge 
 badge = 
@@ -2349,129 +2349,8 @@
 %22);%0A
-    String profilePic = %22%22;%0A    String firstName = %22Test%22;%0A    String lastName = %22User%22;%0A    String userId = %2211111111%22;%0A
     
@@ -2382,26 +2382,27 @@
 lePic%22, 
-profilePic
+PROFILE_PIC
 );%0A    e
@@ -2432,25 +2432,26 @@
 tName%22, 
-firstName
+FIRST_NAME
 );%0A    e
@@ -2480,24 +2480,25 @@
 tName%22, 
-lastName
+LAST_NAME
 );%0A    e
@@ -2525,22 +2525,23 @@
 serId%22, 
-userId
+USER_ID
 );%0A    M
@@ -2678,25 +2678,26 @@
 Name(), 
-firstName
+FIRST_NAME
 );%0A    a
@@ -2746,24 +2746,25 @@
 Name(), 
-lastName
+LAST_NAME
 );%0A    a
@@ -2814,26 +2814,27 @@
 gURL(), 
-profilePic
+PROFILE_PIC
 );%0A    a
@@ -2881,22 +2881,23 @@
 erId(), 
-userId
+USER_ID
 );%0A  %7D %0A

fix member response test