Example #1
0
func TestNewUserResponse(t *testing.T) {
	testUser := &accounts.User{
		OauthUser: new(oauth.User),
	}

	// Create user response
	response, err := accounts.NewUserResponse(testUser)

	// Error should be nil
	assert.Nil(t, err)

	// Test self link
	selfLink, err := response.GetLink("self")
	if assert.Nil(t, err) {
		assert.Equal(t, fmt.Sprintf("/v1/users/%d", testUser.ID), selfLink.Href)
	}
}
func (suite *AccountsTestSuite) TestListUsers() {
	var users []*accounts.User
	err := accounts.UserPreload(suite.db).Order("id").Find(&users).Error
	assert.NoError(suite.T(), err, "Fetching test users should not fail")

	userResponses := make([]interface{}, len(users))

	for i, user := range users {
		userResponse, err := accounts.NewUserResponse(user)
		assert.NoError(suite.T(), err, "Creating user response should not fail")
		userResponses[i] = userResponse
	}

	testutil.TestListValidResponse(
		suite.T(),
		suite.router,
		"users",                // path
		"users",                // entity
		"test_superuser_token", // from fixtures
		userResponses,
		suite.assertMockExpectations,
	)
}