code.gitea.io/gitea@v1.21.7/tests/integration/api_team_user_test.go (about) 1 // Copyright 2019 The Gitea Authors. All rights reserved. 2 // SPDX-License-Identifier: MIT 3 4 package integration 5 6 import ( 7 "net/http" 8 "testing" 9 "time" 10 11 auth_model "code.gitea.io/gitea/models/auth" 12 "code.gitea.io/gitea/models/db" 13 "code.gitea.io/gitea/models/unittest" 14 user_model "code.gitea.io/gitea/models/user" 15 api "code.gitea.io/gitea/modules/structs" 16 "code.gitea.io/gitea/services/convert" 17 "code.gitea.io/gitea/tests" 18 19 "github.com/stretchr/testify/assert" 20 ) 21 22 func TestAPITeamUser(t *testing.T) { 23 defer tests.PrepareTestEnv(t)() 24 25 normalUsername := "user2" 26 session := loginUser(t, normalUsername) 27 token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeReadOrganization) 28 req := NewRequest(t, "GET", "/api/v1/teams/1/members/user1?token="+token) 29 MakeRequest(t, req, http.StatusNotFound) 30 31 req = NewRequest(t, "GET", "/api/v1/teams/1/members/user2?token="+token) 32 resp := MakeRequest(t, req, http.StatusOK) 33 var user2 *api.User 34 DecodeJSON(t, resp, &user2) 35 user2.Created = user2.Created.In(time.Local) 36 user := unittest.AssertExistsAndLoadBean(t, &user_model.User{Name: "user2"}) 37 38 expectedUser := convert.ToUser(db.DefaultContext, user, user) 39 40 // test time via unix timestamp 41 assert.EqualValues(t, expectedUser.LastLogin.Unix(), user2.LastLogin.Unix()) 42 assert.EqualValues(t, expectedUser.Created.Unix(), user2.Created.Unix()) 43 expectedUser.LastLogin = user2.LastLogin 44 expectedUser.Created = user2.Created 45 46 assert.Equal(t, expectedUser, user2) 47 }