Exemplo n.º 1
0
func assertUserEqualsWithoutToken(t *testing.T, expect, actual *models.User) {
	assert.Equal(t, expect.Id, actual.Id)

	assert.Equal(t, expect.Uid, actual.Uid)
	assert.True(t, utils.AreStringEquals(actual.Phone, expect.Phone))
	assert.True(t, utils.AreStringEquals(actual.WeiXin, expect.WeiXin))
	assert.True(t, utils.AreStringEquals(actual.WeiBo, expect.WeiBo))
	assert.True(t, utils.AreStringEquals(actual.QQ, expect.QQ))

	assert.Equal(t, expect.Password, actual.Password)
	assert.Equal(t, expect.Nickname, actual.Nickname)
	assert.Equal(t, expect.QQNickName, actual.QQNickName)
	assert.Equal(t, expect.WeiBoNickName, actual.WeiBoNickName)
	assert.Equal(t, expect.WeiXinNickName, actual.WeiXinNickName)
	assert.Equal(t, expect.Gender, actual.Gender)
	assert.Equal(t, expect.Avatar, actual.Avatar)

	assert.Equal(t, expect.CreateAt, actual.CreateAt)
	assert.Equal(t, expect.UpdateAt, actual.UpdateAt)
}
Exemplo n.º 2
0
func TestUserDeSerial(t *testing.T) {
	mock := "{\"nickname\":\"Piasy\",\"phone\":\"18801234567\",\"uid\":1905378617}"
	phone := "18801234567"
	var user models.User
	err := json.Unmarshal([]byte(mock), &user)

	assert.Nil(t, err)

	assert.Equal(t, "Piasy", user.Nickname)
	assert.True(t, utils.AreStringEquals(user.Phone, &phone))
	assert.Equal(t, int64(1905378617), user.Uid)

	assert.Empty(t, user.Id)
	assert.Empty(t, user.Password)
}
Exemplo n.º 3
0
func soUserShouldEqual(actual, expect *models.User) {
	So(actual.Uid, ShouldEqual, expect.Uid)

	So(utils.AreStringEquals(actual.Phone, expect.Phone), ShouldBeTrue)
	So(utils.IsEmptyString(actual.WeiXin), ShouldBeTrue)
	So(utils.IsEmptyString(actual.WeiBo), ShouldBeTrue)
	So(utils.IsEmptyString(actual.QQ), ShouldBeTrue)

	So(actual.Nickname, ShouldEqual, expect.Nickname)
	So(actual.QQNickName, ShouldEqual, expect.QQNickName)
	So(actual.WeiBoNickName, ShouldEqual, expect.WeiBoNickName)
	So(actual.WeiXinNickName, ShouldEqual, expect.WeiXinNickName)
	So(actual.Gender, ShouldEqual, expect.Gender)
	So(actual.Avatar, ShouldEqual, expect.Avatar)

	So(actual.CreateAt, ShouldEqual, expect.CreateAt)
	So(actual.UpdateAt, ShouldEqual, expect.UpdateAt)
}
Exemplo n.º 4
0
func TestCreateUserByPhone(t *testing.T) {
	initORM()

	phone := "18801234567"
	secret := "8428d916f8cca9ba5971bf58b34d38da20bc3dff"
	password := "******"

	// insert one
	user, err := models.CreateUserByPhone(&phone, secret)
	assert.NotNil(t, user)
	assert.Zero(t, err)
	assert.Empty(t, user.Nickname)
	assert.True(t, user.Uid >= utils.USER_MIN_UID)
	assert.Equal(t, password, user.Password)
	assert.True(t, len(user.Token) == 40)
	assert.True(t, utils.AreStringEquals(user.Phone, &phone))
	now := utils.GetTimeMillis()
	assert.True(t, now-1000 < user.CreateAt)
	assert.True(t, user.CreateAt < now+1000)

	// get it by phone
	getByPhone, err := models.GetUserByUid(user.Uid)
	assert.Zero(t, err)
	assertUserEquals(t, user, getByPhone)

	// get it by uid
	getByUid, err := models.GetUserByUid(user.Uid)
	assert.Zero(t, err)
	assertUserEquals(t, user, getByUid)

	// get it by token
	getByToken, err := models.GetUserByToken(user.Token)
	assert.Zero(t, err)
	assertUserEquals(t, user, getByToken)

	// clean up
	deleteUser(t, user.Id)

	// no such user after delete
	user, err = models.GetUserByUid(user.Uid)
	assert.Nil(t, user)
	assert.Equal(t, utils.ERROR_CODE_USERS_USER_NOT_EXISTS, err)
}