2019-11-02 21:32:58 +07:00
|
|
|
package suites
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
|
|
|
"regexp"
|
2019-11-25 03:27:59 +07:00
|
|
|
"testing"
|
2019-11-02 21:32:58 +07:00
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
type message struct {
|
|
|
|
ID int `json:"id"`
|
|
|
|
}
|
|
|
|
|
2019-11-25 03:27:59 +07:00
|
|
|
func doGetLinkFromLastMail(t *testing.T) string {
|
|
|
|
res := doHTTPGetQuery(t, fmt.Sprintf("%s/messages", MailBaseURL))
|
2019-11-02 21:32:58 +07:00
|
|
|
messages := make([]message, 0)
|
|
|
|
err := json.Unmarshal(res, &messages)
|
2019-11-25 03:27:59 +07:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Greater(t, len(messages), 0)
|
2019-11-02 21:32:58 +07:00
|
|
|
|
|
|
|
messageID := messages[len(messages)-1].ID
|
|
|
|
|
2019-11-25 03:27:59 +07:00
|
|
|
res = doHTTPGetQuery(t, fmt.Sprintf("%s/messages/%d.html", MailBaseURL, messageID))
|
2019-11-02 21:32:58 +07:00
|
|
|
|
|
|
|
re := regexp.MustCompile(`<a href="(.+)" class="button">.*<\/a>`)
|
|
|
|
matches := re.FindStringSubmatch(string(res))
|
|
|
|
|
2019-11-25 03:27:59 +07:00
|
|
|
assert.Len(t, matches, 2, "Number of match for link in email is not equal to one")
|
2019-11-02 21:32:58 +07:00
|
|
|
return matches[1]
|
|
|
|
}
|