2020-11-08 14:46:12 +03:00
|
|
|
package models
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestHeartbeat_Valid_Success(t *testing.T) {
|
|
|
|
sut := &Heartbeat{
|
|
|
|
User: &User{
|
|
|
|
ID: "johndoe@example.org",
|
|
|
|
},
|
|
|
|
UserID: "johndoe@example.org",
|
|
|
|
Time: CustomTime(time.Now()),
|
|
|
|
}
|
|
|
|
assert.True(t, sut.Valid())
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestHeartbeat_Valid_MissingUser(t *testing.T) {
|
|
|
|
sut := &Heartbeat{
|
|
|
|
Time: CustomTime(time.Now()),
|
|
|
|
}
|
|
|
|
assert.False(t, sut.Valid())
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestHeartbeat_Augment(t *testing.T) {
|
|
|
|
testMappings := map[string]string{
|
2021-03-24 22:43:49 +03:00
|
|
|
"py": "Python3",
|
|
|
|
"foo": "Foo Script",
|
|
|
|
"blade.php": "Blade",
|
2020-11-08 14:46:12 +03:00
|
|
|
}
|
|
|
|
|
2021-03-24 22:43:49 +03:00
|
|
|
sut1, sut2 := &Heartbeat{
|
2020-11-08 14:46:12 +03:00
|
|
|
Entity: "~/dev/file.py",
|
|
|
|
Language: "Python",
|
2021-03-24 22:43:49 +03:00
|
|
|
}, &Heartbeat{
|
|
|
|
Entity: "~/dev/file.blade.php",
|
|
|
|
Language: "unknown",
|
2020-11-08 14:46:12 +03:00
|
|
|
}
|
|
|
|
|
2021-03-24 22:43:49 +03:00
|
|
|
sut1.Augment(testMappings)
|
|
|
|
sut2.Augment(testMappings)
|
2020-11-08 14:46:12 +03:00
|
|
|
|
2021-03-24 22:43:49 +03:00
|
|
|
assert.Equal(t, "Python3", sut1.Language)
|
|
|
|
assert.Equal(t, "Blade", sut2.Language)
|
2020-11-08 14:46:12 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestHeartbeat_GetKey(t *testing.T) {
|
|
|
|
sut := &Heartbeat{
|
|
|
|
Project: "wakapi",
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.Equal(t, "wakapi", sut.GetKey(SummaryProject))
|
|
|
|
assert.Equal(t, UnknownSummaryKey, sut.GetKey(SummaryOS))
|
|
|
|
assert.Equal(t, UnknownSummaryKey, sut.GetKey(SummaryMachine))
|
|
|
|
assert.Equal(t, UnknownSummaryKey, sut.GetKey(SummaryLanguage))
|
|
|
|
assert.Equal(t, UnknownSummaryKey, sut.GetKey(SummaryEditor))
|
|
|
|
assert.Equal(t, UnknownSummaryKey, sut.GetKey(255))
|
|
|
|
}
|