Test can now register a user and log in.
This commit is contained in:
parent
a22682878c
commit
35d1b06a79
2 changed files with 54 additions and 32 deletions
|
|
@ -60,7 +60,7 @@ func PostApiRegister(c *fiber.Ctx) error {
|
||||||
Columns("username", "email", "password").
|
Columns("username", "email", "password").
|
||||||
Values(user.Username, user.Email, user.Password).ToSql()
|
Values(user.Username, user.Email, user.Password).ToSql()
|
||||||
|
|
||||||
err = data.Insert(err, sql, args...)
|
err = data.Exec(err, sql, args...)
|
||||||
if err != nil { return IfErrNil(err, c) }
|
if err != nil { return IfErrNil(err, c) }
|
||||||
|
|
||||||
return c.Redirect("/login/")
|
return c.Redirect("/login/")
|
||||||
|
|
@ -100,7 +100,7 @@ func PostApiLink(c *fiber.Ctx) error {
|
||||||
Columns("stream_id", "url", "description").
|
Columns("stream_id", "url", "description").
|
||||||
Values(link.StreamId, link.Url, link.Description).ToSql()
|
Values(link.StreamId, link.Url, link.Description).ToSql()
|
||||||
|
|
||||||
err = data.Insert(err, sql, args...)
|
err = data.Exec(err, sql, args...)
|
||||||
if(err != nil) { goto fail }
|
if(err != nil) { goto fail }
|
||||||
|
|
||||||
return c.Redirect("/live/")
|
return c.Redirect("/live/")
|
||||||
|
|
|
||||||
|
|
@ -4,22 +4,45 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
browser "github.com/chromedp/chromedp"
|
browser "github.com/chromedp/chromedp"
|
||||||
|
"zedshaw.games/webapp/data"
|
||||||
|
sq "github.com/Masterminds/squirrel"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func deleteTestUser(username string) {
|
||||||
|
sql, args, err := sq.Delete("user").Where("username=?", username).ToSql()
|
||||||
|
data.Exec(err, sql, args...)
|
||||||
|
}
|
||||||
|
|
||||||
func TestLogin(t *testing.T) {
|
func TestLogin(t *testing.T) {
|
||||||
assert := assert.New(t)
|
assert := assert.New(t)
|
||||||
|
data.Setup("sqlite3", "./db.sqlite3")
|
||||||
|
deleteTestUser("testerzed")
|
||||||
|
|
||||||
ctx, cancel := Setup(5); defer cancel()
|
ctx, cancel := Setup(5); defer cancel()
|
||||||
|
|
||||||
|
Run(assert, ctx,
|
||||||
|
browser.Navigate(`http://127.0.0.1:5002/register/`),
|
||||||
|
browser.WaitVisible(`body > footer`),
|
||||||
|
browser.WaitVisible(`[data-testid="register-page"]`),
|
||||||
|
browser.SendKeys(`#username`, `testerzed`),
|
||||||
|
browser.SendKeys(`#email`, `zed@test.com`),
|
||||||
|
browser.SendKeys(`#password`, `iamdumb`),
|
||||||
|
browser.Click(`#register-submit`, browser.NodeVisible),
|
||||||
|
browser.WaitVisible(`body > footer`),
|
||||||
|
browser.WaitVisible(`[data-testid="login-page"]`))
|
||||||
|
|
||||||
Run(assert, ctx,
|
Run(assert, ctx,
|
||||||
browser.Navigate(`http://127.0.0.1:5002/login/`),
|
browser.Navigate(`http://127.0.0.1:5002/login/`),
|
||||||
browser.WaitVisible(`body > footer`),
|
browser.WaitVisible(`body > footer`),
|
||||||
browser.WaitVisible(`[data-testid="login-page"]`),
|
browser.WaitVisible(`[data-testid="login-page"]`),
|
||||||
browser.SendKeys(`#username`, `zedshaw`),
|
browser.SendKeys(`#username`, `testerzed`),
|
||||||
browser.SendKeys(`#password`, `1234`),
|
browser.SendKeys(`#password`, `iamdumb`),
|
||||||
browser.Click(`#login-submit`, browser.NodeVisible),
|
browser.Click(`#login-submit`, browser.NodeVisible),
|
||||||
browser.WaitVisible(`body > footer`),
|
browser.WaitVisible(`body > footer`),
|
||||||
browser.WaitVisible(`[data-testid="home-page"]`))
|
browser.WaitVisible(`[data-testid="home-page"]`))
|
||||||
|
|
||||||
|
/// delete the user here
|
||||||
|
deleteTestUser("testerzed")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestStreamPage(t *testing.T) {
|
func TestStreamPage(t *testing.T) {
|
||||||
|
|
@ -33,8 +56,7 @@ func TestStreamPage(t *testing.T) {
|
||||||
err := browser.Run(ctx,
|
err := browser.Run(ctx,
|
||||||
browser.Navigate(`http://127.0.0.1:5002`),
|
browser.Navigate(`http://127.0.0.1:5002`),
|
||||||
browser.WaitVisible(`body > footer`),
|
browser.WaitVisible(`body > footer`),
|
||||||
browser.WaitVisible(`#streams`),
|
browser.WaitVisible(`#streams`),)
|
||||||
)
|
|
||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
|
|
||||||
ClickOn(assert, ctx, `#streams`)
|
ClickOn(assert, ctx, `#streams`)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue