Backend: Add unit tests for internal/entity
This commit is contained in:
parent
15d66fc304
commit
131e822a58
2 changed files with 160 additions and 22 deletions
|
@ -20,18 +20,87 @@ func TestNewFileShare(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestFirstOrCreateFileShare(t *testing.T) {
|
||||
fileShare := &FileShare{FileID: 123, AccountID: 888, RemoteName: "test888"}
|
||||
result := FirstOrCreateFileShare(fileShare)
|
||||
t.Run("not yet existing", func(t *testing.T) {
|
||||
fileShare := &FileShare{FileID: 123, AccountID: 888, RemoteName: "test888"}
|
||||
result := FirstOrCreateFileShare(fileShare)
|
||||
|
||||
if result == nil {
|
||||
t.Fatal("result share should not be nil")
|
||||
}
|
||||
if result == nil {
|
||||
t.Fatal("result share should not be nil")
|
||||
}
|
||||
|
||||
if result.FileID != fileShare.FileID {
|
||||
t.Errorf("FileID should be the same: %d %d", result.FileID, fileShare.FileID)
|
||||
}
|
||||
if result.FileID != fileShare.FileID {
|
||||
t.Errorf("FileID should be the same: %d %d", result.FileID, fileShare.FileID)
|
||||
}
|
||||
|
||||
if result.AccountID != fileShare.AccountID {
|
||||
t.Errorf("AccountID should be the same: %d %d", result.AccountID, fileShare.AccountID)
|
||||
}
|
||||
if result.AccountID != fileShare.AccountID {
|
||||
t.Errorf("AccountID should be the same: %d %d", result.AccountID, fileShare.AccountID)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("existing", func(t *testing.T) {
|
||||
fileShare := NewFileShare(778, 999, "NameForRemote")
|
||||
result := FirstOrCreateFileShare(fileShare)
|
||||
|
||||
if result == nil {
|
||||
t.Fatal("result share should not be nil")
|
||||
}
|
||||
|
||||
if result.FileID != fileShare.FileID {
|
||||
t.Errorf("FileID should be the same: %d %d", result.FileID, fileShare.FileID)
|
||||
}
|
||||
|
||||
if result.AccountID != fileShare.AccountID {
|
||||
t.Errorf("AccountID should be the same: %d %d", result.AccountID, fileShare.AccountID)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func TestFileShare_Updates(t *testing.T) {
|
||||
t.Run("success", func(t *testing.T) {
|
||||
fileShare := NewFileShare(123, 123, "NameBeforeUpdate")
|
||||
|
||||
assert.Equal(t, "NameBeforeUpdate", fileShare.RemoteName)
|
||||
assert.Equal(t, uint(0x7b), fileShare.AccountID)
|
||||
|
||||
err := fileShare.Updates(FileShare{RemoteName: "NameAfterUpdate", AccountID: 999})
|
||||
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
assert.Equal(t, "NameAfterUpdate", fileShare.RemoteName)
|
||||
assert.Equal(t, uint(0x3e7), fileShare.AccountID)
|
||||
})
|
||||
}
|
||||
|
||||
func TestFileShare_Update(t *testing.T) {
|
||||
t.Run("success", func(t *testing.T) {
|
||||
fileShare := NewFileShare(123, 123, "NameBeforeUpdate2")
|
||||
assert.Equal(t, "NameBeforeUpdate2", fileShare.RemoteName)
|
||||
assert.Equal(t, uint(0x7b), fileShare.AccountID)
|
||||
|
||||
err := fileShare.Update("RemoteName", "new-name")
|
||||
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
assert.Equal(t, "new-name", fileShare.RemoteName)
|
||||
assert.Equal(t, uint(0x7b), fileShare.AccountID)
|
||||
})
|
||||
}
|
||||
|
||||
func TestFileShare_Save(t *testing.T) {
|
||||
t.Run("success", func(t *testing.T) {
|
||||
fileShare := NewFileShare(123, 123, "Nameavc")
|
||||
|
||||
initialDate := fileShare.UpdatedAt
|
||||
|
||||
err := fileShare.Save()
|
||||
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
afterDate := fileShare.UpdatedAt
|
||||
|
||||
assert.True(t, afterDate.After(initialDate))
|
||||
})
|
||||
}
|
||||
|
|
|
@ -19,18 +19,87 @@ func TestNewFileSync(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestFirstOrCreateFileSync(t *testing.T) {
|
||||
fileSync := &FileSync{AccountID: 123, FileID: 888, RemoteName: "test123"}
|
||||
result := FirstOrCreateFileSync(fileSync)
|
||||
t.Run("not yet existing", func(t *testing.T) {
|
||||
fileSync := &FileSync{AccountID: 123, FileID: 888, RemoteName: "test123"}
|
||||
result := FirstOrCreateFileSync(fileSync)
|
||||
|
||||
if result == nil {
|
||||
t.Fatal("result should not be nil")
|
||||
}
|
||||
if result == nil {
|
||||
t.Fatal("result should not be nil")
|
||||
}
|
||||
|
||||
if result.FileID != fileSync.FileID {
|
||||
t.Errorf("FileID should be the same: %d %d", result.FileID, fileSync.FileID)
|
||||
}
|
||||
if result.FileID != fileSync.FileID {
|
||||
t.Errorf("FileID should be the same: %d %d", result.FileID, fileSync.FileID)
|
||||
}
|
||||
|
||||
if result.AccountID != fileSync.AccountID {
|
||||
t.Errorf("AccountID should be the same: %d %d", result.AccountID, fileSync.AccountID)
|
||||
}
|
||||
if result.AccountID != fileSync.AccountID {
|
||||
t.Errorf("AccountID should be the same: %d %d", result.AccountID, fileSync.AccountID)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("existing", func(t *testing.T) {
|
||||
fileSync := NewFileSync(778, "NameForRemote")
|
||||
result := FirstOrCreateFileSync(fileSync)
|
||||
|
||||
if result == nil {
|
||||
t.Fatal("result share should not be nil")
|
||||
}
|
||||
|
||||
if result.FileID != fileSync.FileID {
|
||||
t.Errorf("FileID should be the same: %d %d", result.FileID, fileSync.FileID)
|
||||
}
|
||||
|
||||
if result.AccountID != fileSync.AccountID {
|
||||
t.Errorf("AccountID should be the same: %d %d", result.AccountID, fileSync.AccountID)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func TestFileSync_Updates(t *testing.T) {
|
||||
t.Run("success", func(t *testing.T) {
|
||||
fileSync := NewFileSync(123, "NameBeforeUpdate")
|
||||
|
||||
assert.Equal(t, "NameBeforeUpdate", fileSync.RemoteName)
|
||||
assert.Equal(t, uint(0x7b), fileSync.AccountID)
|
||||
|
||||
err := fileSync.Updates(FileSync{RemoteName: "NameAfterUpdate", AccountID: 999})
|
||||
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
assert.Equal(t, "NameAfterUpdate", fileSync.RemoteName)
|
||||
assert.Equal(t, uint(0x3e7), fileSync.AccountID)
|
||||
})
|
||||
}
|
||||
|
||||
func TestFileSync_Update(t *testing.T) {
|
||||
t.Run("success", func(t *testing.T) {
|
||||
fileSync := NewFileSync(123, "NameBeforeUpdate2")
|
||||
assert.Equal(t, "NameBeforeUpdate2", fileSync.RemoteName)
|
||||
assert.Equal(t, uint(0x7b), fileSync.AccountID)
|
||||
|
||||
err := fileSync.Update("RemoteName", "new-name")
|
||||
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
assert.Equal(t, "new-name", fileSync.RemoteName)
|
||||
assert.Equal(t, uint(0x7b), fileSync.AccountID)
|
||||
})
|
||||
}
|
||||
|
||||
func TestFileSync_Save(t *testing.T) {
|
||||
t.Run("success", func(t *testing.T) {
|
||||
fileSync := NewFileSync(123, "Nameavc")
|
||||
|
||||
initialDate := fileSync.UpdatedAt
|
||||
|
||||
err := fileSync.Save()
|
||||
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
afterDate := fileSync.UpdatedAt
|
||||
|
||||
assert.True(t, afterDate.After(initialDate))
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue