package com.red.circle.other.inner.model.cmd.user;

import static org.junit.Assert.assertEquals;

import com.red.circle.framework.core.dto.ReqSysOrigin;
import com.red.circle.other.inner.enums.user.AuthTypeEnum;
import com.red.circle.other.inner.model.cmd.user.account.CreateAccountCmd;
import org.junit.Test;

public class UserOpenIdNormalizeTest {

  @Test
  public void channelLoginAppendsOriginWhenGoogleOpenIdContainsUnderscore() {
    UserChannelCredentialCmd cmd = new UserChannelCredentialCmd();
    cmd.setAuthType(AuthTypeEnum.GOOGLE);
    cmd.setOpenId("google_open_id");
    cmd.setReqSysOrigin(ReqSysOrigin.of("LIKEI"));

    assertEquals("google_open_id_LIKEI", cmd.openId());
  }

  @Test
  public void channelLoginDoesNotAppendOriginTwice() {
    UserChannelCredentialCmd cmd = new UserChannelCredentialCmd();
    cmd.setAuthType(AuthTypeEnum.GOOGLE);
    cmd.setOpenId("google_open_id_LIKEI");
    cmd.setReqSysOrigin(ReqSysOrigin.of("LIKEI"));

    assertEquals("google_open_id_LIKEI", cmd.openId());
  }

  @Test
  public void accountCreateDoesNotAppendOriginTwice() {
    CreateAccountCmd cmd = new CreateAccountCmd();
    cmd.setType(AuthTypeEnum.GOOGLE.name());
    cmd.setOpenId("google_open_id_LIKEI");
    cmd.setReqSysOrigin(ReqSysOrigin.of("LIKEI"));
    cmd.changeOpenId();

    assertEquals("google_open_id_LIKEI", cmd.getOpenId());
  }
}
