mirror of https://github.com/go-gitea/gitea
Git with a cup of tea, painless self-hosted git service
Mirror for internal git.with.parts use
https://git.with.parts
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
113 lines
2.8 KiB
113 lines
2.8 KiB
4 years ago
|
// Copyright 2021 The Gitea Authors. All rights reserved.
|
||
|
// Use of this source code is governed by a MIT-style
|
||
|
// license that can be found in the LICENSE file.
|
||
|
|
||
2 years ago
|
package integration
|
||
4 years ago
|
|
||
|
import (
|
||
|
"net/http"
|
||
|
"testing"
|
||
|
|
||
|
api "code.gitea.io/gitea/modules/structs"
|
||
2 years ago
|
"code.gitea.io/gitea/tests"
|
||
4 years ago
|
|
||
|
"github.com/stretchr/testify/assert"
|
||
|
)
|
||
|
|
||
|
func TestAPIListEmails(t *testing.T) {
|
||
2 years ago
|
defer tests.PrepareTestEnv(t)()
|
||
4 years ago
|
|
||
|
normalUsername := "user2"
|
||
|
session := loginUser(t, normalUsername)
|
||
|
token := getTokenForLoggedInUser(t, session)
|
||
|
|
||
|
req := NewRequest(t, "GET", "/api/v1/user/emails?token="+token)
|
||
|
resp := session.MakeRequest(t, req, http.StatusOK)
|
||
|
|
||
|
var emails []*api.Email
|
||
|
DecodeJSON(t, resp, &emails)
|
||
|
|
||
|
assert.EqualValues(t, []*api.Email{
|
||
|
{
|
||
|
Email: "user2@example.com",
|
||
|
Verified: true,
|
||
|
Primary: true,
|
||
|
},
|
||
|
{
|
||
3 years ago
|
Email: "user2-2@example.com",
|
||
4 years ago
|
Verified: false,
|
||
|
Primary: false,
|
||
|
},
|
||
|
}, emails)
|
||
|
}
|
||
|
|
||
|
func TestAPIAddEmail(t *testing.T) {
|
||
2 years ago
|
defer tests.PrepareTestEnv(t)()
|
||
4 years ago
|
|
||
|
normalUsername := "user2"
|
||
|
session := loginUser(t, normalUsername)
|
||
|
token := getTokenForLoggedInUser(t, session)
|
||
|
|
||
|
opts := api.CreateEmailOption{
|
||
|
Emails: []string{"user101@example.com"},
|
||
|
}
|
||
|
|
||
|
req := NewRequestWithJSON(t, "POST", "/api/v1/user/emails?token="+token, &opts)
|
||
|
session.MakeRequest(t, req, http.StatusUnprocessableEntity)
|
||
|
|
||
|
opts = api.CreateEmailOption{
|
||
3 years ago
|
Emails: []string{"user2-3@example.com"},
|
||
4 years ago
|
}
|
||
|
req = NewRequestWithJSON(t, "POST", "/api/v1/user/emails?token="+token, &opts)
|
||
|
resp := session.MakeRequest(t, req, http.StatusCreated)
|
||
|
|
||
|
var emails []*api.Email
|
||
|
DecodeJSON(t, resp, &emails)
|
||
|
assert.EqualValues(t, []*api.Email{
|
||
|
{
|
||
3 years ago
|
Email: "user2-3@example.com",
|
||
4 years ago
|
Verified: true,
|
||
|
Primary: false,
|
||
|
},
|
||
|
}, emails)
|
||
3 years ago
|
|
||
|
opts = api.CreateEmailOption{
|
||
|
Emails: []string{"notAEmail"},
|
||
|
}
|
||
|
req = NewRequestWithJSON(t, "POST", "/api/v1/user/emails?token="+token, &opts)
|
||
|
session.MakeRequest(t, req, http.StatusUnprocessableEntity)
|
||
4 years ago
|
}
|
||
|
|
||
|
func TestAPIDeleteEmail(t *testing.T) {
|
||
2 years ago
|
defer tests.PrepareTestEnv(t)()
|
||
4 years ago
|
|
||
|
normalUsername := "user2"
|
||
|
session := loginUser(t, normalUsername)
|
||
|
token := getTokenForLoggedInUser(t, session)
|
||
|
|
||
|
opts := api.DeleteEmailOption{
|
||
3 years ago
|
Emails: []string{"user2-3@example.com"},
|
||
4 years ago
|
}
|
||
|
req := NewRequestWithJSON(t, "DELETE", "/api/v1/user/emails?token="+token, &opts)
|
||
|
session.MakeRequest(t, req, http.StatusNotFound)
|
||
|
|
||
|
opts = api.DeleteEmailOption{
|
||
3 years ago
|
Emails: []string{"user2-2@example.com"},
|
||
4 years ago
|
}
|
||
|
req = NewRequestWithJSON(t, "DELETE", "/api/v1/user/emails?token="+token, &opts)
|
||
|
session.MakeRequest(t, req, http.StatusNoContent)
|
||
|
|
||
|
req = NewRequest(t, "GET", "/api/v1/user/emails?token="+token)
|
||
|
resp := session.MakeRequest(t, req, http.StatusOK)
|
||
|
|
||
|
var emails []*api.Email
|
||
|
DecodeJSON(t, resp, &emails)
|
||
|
assert.EqualValues(t, []*api.Email{
|
||
|
{
|
||
|
Email: "user2@example.com",
|
||
|
Verified: true,
|
||
|
Primary: true,
|
||
|
},
|
||
|
}, emails)
|
||
|
}
|