Sha256: e3a4bbc971962252d4abcc96bbda0e923ee33582b0a94433403e82a6f0667081

Contents?: true

Size: 1.19 KB

Versions: 1

Compression:

Stored size: 1.19 KB

Contents

require File.expand_path("../../spec_helper", __FILE__)

describe "client" do
  describe "access token" do
    it "get access token" do
      client = SimpleWechat::Client.new("APPID", "APPSECRET")

      body = %Q({"access_token":"ACCESS_TOKEN", "expires_in":7200})
      stub_request(:get, "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=APPID&secret=APPSECRET").to_return(body: body)

      access_token = client.get_access_token

      expect(access_token).not_to be_nil
      expect(access_token.access_token).to eq("ACCESS_TOKEN")
      expect(access_token.expires_in).to eq(7200)
    end

    it "get error code and msg if get error from response" do
      client = SimpleWechat::Client.new("APPID", "APPSECRET")

      body = %Q({"errcode":40013,"errmsg":"invalid appid"})
      stub_request(:get, "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=APPID&secret=APPSECRET").to_return(body: body)

      access_token = client.get_access_token

      expect(access_token).not_to be_nil
      expect(access_token.access_token).to be_nil
      expect(access_token.errcode).to eq(40013)
      expect(access_token.errmsg).to eq("invalid appid")
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
simple_wechat-0.0.1 spec/simple_wechat/client_spec.rb