tests(db): migrate to testify
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
a69b7452ce
commit
fe81b57a34
@ -29,7 +29,7 @@ func TestNewMgr(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dbm := NewMgr(&cfg)
|
dbm := NewMgr(&cfg)
|
||||||
assert.NotNil(t, dbm, "should not be nil dbm")
|
assert.NotNil(t, dbm, "should not have nil dbm")
|
||||||
|
|
||||||
t.Run("Database", func(t *testing.T) {
|
t.Run("Database", func(t *testing.T) {
|
||||||
dt := databaseTest{t, dbm}
|
dt := databaseTest{t, dbm}
|
||||||
@ -45,7 +45,7 @@ func (dt *databaseTest) TestUser() {
|
|||||||
dt.Run("User", func(t *testing.T) {
|
dt.Run("User", func(t *testing.T) {
|
||||||
// Generate Auth Hash
|
// Generate Auth Hash
|
||||||
rawAuthHash, err := utils.GenerateToken(64)
|
rawAuthHash, err := utils.GenerateToken(64)
|
||||||
assert.Nil(t, err, "should be nil err")
|
assert.Nil(t, err, "should have nil err")
|
||||||
|
|
||||||
authHash := fmt.Sprintf("%x", rawAuthHash)
|
authHash := fmt.Sprintf("%x", rawAuthHash)
|
||||||
changed, err := dt.dbm.Queries.CreateUser(dt.dbm.Ctx, CreateUserParams{
|
changed, err := dt.dbm.Queries.CreateUser(dt.dbm.Ctx, CreateUserParams{
|
||||||
@ -54,12 +54,12 @@ func (dt *databaseTest) TestUser() {
|
|||||||
AuthHash: &authHash,
|
AuthHash: &authHash,
|
||||||
})
|
})
|
||||||
|
|
||||||
assert.Nil(t, err, "should be nil err")
|
assert.Nil(t, err, "should have nil err")
|
||||||
assert.Equal(t, int64(1), changed)
|
assert.Equal(t, int64(1), changed)
|
||||||
|
|
||||||
user, err := dt.dbm.Queries.GetUser(dt.dbm.Ctx, userID)
|
user, err := dt.dbm.Queries.GetUser(dt.dbm.Ctx, userID)
|
||||||
|
|
||||||
assert.Nil(t, err, "should be nil err")
|
assert.Nil(t, err, "should have nil err")
|
||||||
assert.Equal(t, userPass, *user.Pass)
|
assert.Equal(t, userPass, *user.Pass)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -72,21 +72,10 @@ func (dt *databaseTest) TestDocument() {
|
|||||||
Author: &documentAuthor,
|
Author: &documentAuthor,
|
||||||
})
|
})
|
||||||
|
|
||||||
if err != nil {
|
assert.Nil(t, err, "should have nil err")
|
||||||
t.Fatalf(`Expected: Document, Got: %v, Error: %v`, doc, err)
|
assert.Equal(t, documentID, doc.ID, "should have document id")
|
||||||
}
|
assert.Equal(t, documentTitle, *doc.Title, "should have document title")
|
||||||
|
assert.Equal(t, documentAuthor, *doc.Author, "should have document author")
|
||||||
if doc.ID != documentID {
|
|
||||||
t.Fatalf(`Expected: %v, Got: %v`, documentID, doc.ID)
|
|
||||||
}
|
|
||||||
|
|
||||||
if *doc.Title != documentTitle {
|
|
||||||
t.Fatalf(`Expected: %v, Got: %v`, documentTitle, *doc.Title)
|
|
||||||
}
|
|
||||||
|
|
||||||
if *doc.Author != documentAuthor {
|
|
||||||
t.Fatalf(`Expected: %v, Got: %v`, documentAuthor, *doc.Author)
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -98,21 +87,10 @@ func (dt *databaseTest) TestDevice() {
|
|||||||
DeviceName: deviceName,
|
DeviceName: deviceName,
|
||||||
})
|
})
|
||||||
|
|
||||||
if err != nil {
|
assert.Nil(t, err, "should have nil err")
|
||||||
t.Fatalf(`Expected: Device, Got: %v, Error: %v`, device, err)
|
assert.Equal(t, deviceID, device.ID, "should have device id")
|
||||||
}
|
assert.Equal(t, userID, device.UserID, "should have user id")
|
||||||
|
assert.Equal(t, deviceName, device.DeviceName, "should have device name")
|
||||||
if device.ID != deviceID {
|
|
||||||
t.Fatalf(`Expected: %v, Got: %v`, deviceID, device.ID)
|
|
||||||
}
|
|
||||||
|
|
||||||
if device.UserID != userID {
|
|
||||||
t.Fatalf(`Expected: %v, Got: %v`, userID, device.UserID)
|
|
||||||
}
|
|
||||||
|
|
||||||
if device.DeviceName != deviceName {
|
|
||||||
t.Fatalf(`Expected: %v, Got: %v`, deviceName, device.DeviceName)
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -137,15 +115,8 @@ func (dt *databaseTest) TestActivity() {
|
|||||||
EndPercentage: float64(counter+1) / 100.0,
|
EndPercentage: float64(counter+1) / 100.0,
|
||||||
})
|
})
|
||||||
|
|
||||||
// Validate No Error
|
assert.Nil(t, err, fmt.Sprintf("[%d] should have nil err for add activity", counter))
|
||||||
if err != nil {
|
assert.Equal(t, counter, activity.ID, fmt.Sprintf("[%d] should have correct id for add activity", counter))
|
||||||
t.Fatalf(`expected: rawactivity, got: %v, error: %v`, activity, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Validate Auto Increment Working
|
|
||||||
if activity.ID != counter {
|
|
||||||
t.Fatalf(`Expected: %v, Got: %v`, counter, activity.ID)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initiate Cache
|
// Initiate Cache
|
||||||
@ -158,13 +129,8 @@ func (dt *databaseTest) TestActivity() {
|
|||||||
Limit: 50,
|
Limit: 50,
|
||||||
})
|
})
|
||||||
|
|
||||||
if err != nil {
|
assert.Nil(t, err, "should have nil err for get activity")
|
||||||
t.Fatalf(`Expected: []GetActivityRow, Got: %v, Error: %v`, existsRows, err)
|
assert.Len(t, existsRows, 10, "should have correct number of rows get activity")
|
||||||
}
|
|
||||||
|
|
||||||
if len(existsRows) != 10 {
|
|
||||||
t.Fatalf(`Expected: %v, Got: %v`, 10, len(existsRows))
|
|
||||||
}
|
|
||||||
|
|
||||||
// Validate Doesn't Exist
|
// Validate Doesn't Exist
|
||||||
doesntExistsRows, err := dt.dbm.Queries.GetActivity(dt.dbm.Ctx, GetActivityParams{
|
doesntExistsRows, err := dt.dbm.Queries.GetActivity(dt.dbm.Ctx, GetActivityParams{
|
||||||
@ -175,13 +141,8 @@ func (dt *databaseTest) TestActivity() {
|
|||||||
Limit: 50,
|
Limit: 50,
|
||||||
})
|
})
|
||||||
|
|
||||||
if err != nil {
|
assert.Nil(t, err, "should have nil err for get activity")
|
||||||
t.Fatalf(`Expected: []GetActivityRow, Got: %v, Error: %v`, doesntExistsRows, err)
|
assert.Len(t, doesntExistsRows, 0, "should have no rows")
|
||||||
}
|
|
||||||
|
|
||||||
if len(doesntExistsRows) != 0 {
|
|
||||||
t.Fatalf(`Expected: %v, Got: %v`, 0, len(doesntExistsRows))
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -189,29 +150,19 @@ func (dt *databaseTest) TestDailyReadStats() {
|
|||||||
dt.Run("DailyReadStats", func(t *testing.T) {
|
dt.Run("DailyReadStats", func(t *testing.T) {
|
||||||
readStats, err := dt.dbm.Queries.GetDailyReadStats(dt.dbm.Ctx, userID)
|
readStats, err := dt.dbm.Queries.GetDailyReadStats(dt.dbm.Ctx, userID)
|
||||||
|
|
||||||
if err != nil {
|
assert.Nil(t, err, "should have nil err")
|
||||||
t.Fatalf(`Expected: []GetDailyReadStatsRow, Got: %v, Error: %v`, readStats, err)
|
assert.Len(t, readStats, 30, "should have length of 30")
|
||||||
}
|
|
||||||
|
|
||||||
// Validate 30 Days Stats
|
|
||||||
if len(readStats) != 30 {
|
|
||||||
t.Fatalf(`Expected: %v, Got: %v`, 30, len(readStats))
|
|
||||||
}
|
|
||||||
|
|
||||||
// Validate 1 Minute / Day - Last 10 Days
|
// Validate 1 Minute / Day - Last 10 Days
|
||||||
for i := 0; i < 10; i++ {
|
for i := 0; i < 10; i++ {
|
||||||
stat := readStats[i]
|
stat := readStats[i]
|
||||||
if stat.MinutesRead != 1 {
|
assert.Equal(t, int64(1), stat.MinutesRead, "should have one minute read")
|
||||||
t.Fatalf(`Day: %v, Expected: %v, Got: %v`, stat.Date, 1, stat.MinutesRead)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate 0 Minute / Day - Remaining 20 Days
|
// Validate 0 Minute / Day - Remaining 20 Days
|
||||||
for i := 10; i < 30; i++ {
|
for i := 10; i < 30; i++ {
|
||||||
stat := readStats[i]
|
stat := readStats[i]
|
||||||
if stat.MinutesRead != 0 {
|
assert.Equal(t, int64(0), stat.MinutesRead, "should have zero minutes read")
|
||||||
t.Fatalf(`Day: %v, Expected: %v, Got: %v`, stat.Date, 0, stat.MinutesRead)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -1,13 +0,0 @@
|
|||||||
# Notes
|
|
||||||
|
|
||||||
This folder consists of various notes / files that I want to save and may come back to at some point.
|
|
||||||
|
|
||||||
# Ideas / To Do
|
|
||||||
|
|
||||||
- Google Fonts -> SW Cache and/or Local
|
|
||||||
- Change Device Name / Assume Device
|
|
||||||
- Hide Document per User (Another Table?)
|
|
||||||
- Admin User?
|
|
||||||
- Reset Passwords
|
|
||||||
- Actually Delete Documents
|
|
||||||
- Activity Pagination
|
|
@ -1,74 +0,0 @@
|
|||||||
{{ $data := (GetSVGGraphData .Data.GraphData 800 150 )}}
|
|
||||||
<svg viewBox="0 0 {{ $data.Width }} {{ $data.Height }}">
|
|
||||||
<!-- Box Graph -->
|
|
||||||
{{ range $idx, $item := $data.BarPoints }}
|
|
||||||
<g class="bar" transform="translate({{ $item.X }}, 0)" fill="gray">
|
|
||||||
<rect
|
|
||||||
y="{{ $item.Y }}"
|
|
||||||
height="{{ $item.Size }}"
|
|
||||||
width="{{ $data.Offset }}"
|
|
||||||
></rect>
|
|
||||||
</g>
|
|
||||||
{{ end }}
|
|
||||||
|
|
||||||
<!-- Linear Line Graph -->
|
|
||||||
<polyline
|
|
||||||
fill="none"
|
|
||||||
stroke="black"
|
|
||||||
stroke-width="2"
|
|
||||||
points="
|
|
||||||
{{ range $item := $data.LinePoints }}
|
|
||||||
{{ $item.X }},{{ $item.Y }}
|
|
||||||
{{ end }}
|
|
||||||
"
|
|
||||||
/>
|
|
||||||
|
|
||||||
<!-- Bezier Line Graph -->
|
|
||||||
<path
|
|
||||||
fill="#316BBE"
|
|
||||||
fill-opacity="0.5"
|
|
||||||
stroke="none"
|
|
||||||
d="{{ $data.BezierPath }} {{ $data.BezierFill }}"
|
|
||||||
/>
|
|
||||||
|
|
||||||
<path fill="none" stroke="#316BBE" d="{{ $data.BezierPath }}" />
|
|
||||||
|
|
||||||
{{ range $index, $item := $data.LinePoints }}
|
|
||||||
<line
|
|
||||||
class="hover-trigger"
|
|
||||||
stroke="black"
|
|
||||||
stroke-opacity="0.0"
|
|
||||||
stroke-width="{{ $data.Offset }}"
|
|
||||||
x1="{{ $item.X }}"
|
|
||||||
x2="{{ $item.X }}"
|
|
||||||
y1="0"
|
|
||||||
y2="{{ $data.Height }}"
|
|
||||||
></line>
|
|
||||||
<g class="hover-item">
|
|
||||||
<line
|
|
||||||
class="text-black dark:text-white"
|
|
||||||
stroke-opacity="0.2"
|
|
||||||
x1="{{ $item.X }}"
|
|
||||||
x2="{{ $item.X }}"
|
|
||||||
y1="30"
|
|
||||||
y2="{{ $data.Height }}"
|
|
||||||
></line>
|
|
||||||
<text
|
|
||||||
class="text-black dark:text-white"
|
|
||||||
alignment-baseline="middle"
|
|
||||||
transform="translate({{ $item.X }}, 5) translate(-30, 8)"
|
|
||||||
font-size="10"
|
|
||||||
>
|
|
||||||
{{ (index $.Data.GraphData $index).Date }}
|
|
||||||
</text>
|
|
||||||
<text
|
|
||||||
class="text-black dark:text-white"
|
|
||||||
alignment-baseline="middle"
|
|
||||||
transform="translate({{ $item.X }}, 25) translate(-30, -2)"
|
|
||||||
font-size="10"
|
|
||||||
>
|
|
||||||
{{ (index $.Data.GraphData $index).MinutesRead }} minutes
|
|
||||||
</text>
|
|
||||||
</g>
|
|
||||||
{{ end }}
|
|
||||||
</svg>
|
|
Loading…
Reference in New Issue
Block a user