-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#Added Tests for Messages data-model and CRUD
- Loading branch information
1 parent
27f42e6
commit 8da33ea
Showing
1 changed file
with
50 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package model | ||
func TestSaveMessages(t *testing.T) { | ||
msg := &Messages{ | ||
MsgId: "123", | ||
SenderId: "sender", | ||
ReceiverId: "receiver", | ||
Types: "text", | ||
Content: "hello", | ||
SentTime: 123456, | ||
LastEdit: 123456, | ||
DeleteTime: "2022-01-01", | ||
Status: true, | ||
Attachment: "attachment", | ||
Reaction: "reaction", | ||
} | ||
|
||
err := msg.SaveMessages(1) | ||
if err != nil { | ||
t.Errorf("SaveMessages returned an error: %v", err) | ||
} | ||
|
||
// Verify that the message was saved correctly | ||
db, err := durable.CreateDatabase("Database/", "Common", "Shard_1.sqlite") | ||
if err != nil { | ||
t.Errorf("Failed to open database: %v", err) | ||
} | ||
defer db.Close() | ||
|
||
var savedMsg Messages | ||
err = db.QueryRow("SELECT * FROM MESSAGE WHERE MsgId=?", msg.MsgId).Scan( | ||
&savedMsg.MsgId, | ||
&savedMsg.SenderId, | ||
&savedMsg.ReceiverId, | ||
&savedMsg.Types, | ||
&savedMsg.Content, | ||
&savedMsg.SentTime, | ||
&savedMsg.LastEdit, | ||
&savedMsg.DeleteTime, | ||
&savedMsg.Status, | ||
&savedMsg.Attachment, | ||
&savedMsg.Reaction, | ||
) | ||
if err != nil { | ||
t.Errorf("Failed to retrieve saved message: %v", err) | ||
} | ||
|
||
if !reflect.DeepEqual(msg, &savedMsg) { | ||
t.Errorf("Saved message does not match original message. Expected: %v, got: %v", msg, &savedMsg) | ||
} | ||
} |