package cn.binarywang.wx.miniapp.api.impl;

import org.apache.commons.lang3.StringUtils;
import org.testng.annotations.*;

import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.config.WxMaConfig;
import cn.binarywang.wx.miniapp.test.ApiTestModule;
import com.google.inject.Inject;
import me.chanjar.weixin.common.error.WxErrorException;

import static org.assertj.core.api.Assertions.assertThat;
import static org.testng.Assert.*;

/**
 * @author <a href="https://github.com/binarywang">Binary Wang</a>
 */
@Test
@Guice(modules = ApiTestModule.class)
public class WxMaServiceImplTest {

  @Inject
  private WxMaService wxService;

  public void testRefreshAccessToken() throws WxErrorException {
    WxMaConfig configStorage = this.wxService.getWxMaConfig();
    String before = configStorage.getAccessToken();
    this.wxService.getAccessToken(false);

    String after = configStorage.getAccessToken();
    assertNotEquals(before, after);
    assertTrue(StringUtils.isNotBlank(after));
  }

  @Test(expectedExceptions = {WxErrorException.class})
  public void testGetPaidUnionId() throws WxErrorException {
    final String unionId = this.wxService.getPaidUnionId("1", null, "3", "4");
    assertThat(unionId).isNotEmpty();
  }
}

@@ -1249,11 +1249,599 @@
 y();%0A  %7D
+%0A%0A  @Test%0A  public void testPost() throws WxErrorException %7B%0A    final String postResult = this.wxService.post(%22https://api.weixin.qq.com/wxa/setdynamicdata%22, %22%7B%5Cn%22 +%0A      %22    %5C%22data%5C%22: %5C%22%7B%5C%5C%5C%22items%5C%5C%5C%22: %5B%7B%5C%5C%5C%22from%5C%5C%5C%22:%7B%5C%5C%5C%22city_name_cn%5C%5C%5C%22:%5C%5C%5C%22%E5%B9%BF%E5%B7%9E%E5%B8%82%5C%5C%5C%22%7D,%5C%5C%5C%22to%5C%5C%5C%22:%7B%5C%5C%5C%22city_name_cn%5C%5C%5C%22:%5C%5C%5C%22%E5%8C%97%E4%BA%AC%E5%B8%82%5C%5C%5C%22%7D%7D%5D, %5C%5C%5C%22attribute%5C%5C%5C%22: %7B%5C%5C%5C%22count%5C%5C%5C%22: 1, %5C%5C%5C%22totalcount%5C%5C%5C%22: 100, %5C%5C%5C%22id%5C%5C%5C%22: %5C%5C%5C%221%5C%5C%5C%22, %5C%5C%5C%22seq%5C%5C%5C%22: 0%7D%7D%5C%22,%5Cn%22 +%0A      %22    %5C%22lifespan%5C%22: 86400,%5Cn%22 +%0A      %22    %5C%22query%5C%22: %5C%22%7B%5C%5C%5C%22type%5C%5C%5C%22:100005%7D%5C%22,%5Cn%22 +%0A      %22    %5C%22scene%5C%22: 1%5Cn%22 +%0A      %22%7D%22);%0A%0A    System.out.println(postResult);%0A  %7D
 %0A%7D%0A

add test for post method