2021-05-14 13:47:32 +02:00
|
|
|
package bolt
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/ansible-semaphore/semaphore/db"
|
|
|
|
"testing"
|
2021-05-16 23:44:42 +02:00
|
|
|
"time"
|
2021-05-14 13:47:32 +02:00
|
|
|
)
|
|
|
|
|
2021-05-16 23:44:42 +02:00
|
|
|
func TestBoltDb_UpdateProjectUser(t *testing.T) {
|
2022-01-23 14:21:27 +01:00
|
|
|
store := CreateTestStore()
|
2021-05-16 23:44:42 +02:00
|
|
|
|
|
|
|
usr, err := store.CreateUser(db.UserWithPwd{
|
|
|
|
Pwd: "123456",
|
|
|
|
User: db.User{
|
2022-01-23 14:21:27 +01:00
|
|
|
Email: "denguk@example.com",
|
|
|
|
Name: "Denis Gukov",
|
2021-05-16 23:44:42 +02:00
|
|
|
Username: "fiftin",
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
proj1, err := store.CreateProject(db.Project{
|
|
|
|
Created: time.Now(),
|
2022-01-23 14:21:27 +01:00
|
|
|
Name: "Test1",
|
2021-05-16 23:44:42 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
projUser, err := store.CreateProjectUser(db.ProjectUser{
|
|
|
|
ProjectID: proj1.ID,
|
2022-01-23 14:21:27 +01:00
|
|
|
UserID: usr.ID,
|
2023-07-07 23:15:30 +02:00
|
|
|
Role: db.ProjectOwner,
|
2021-05-16 23:44:42 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err.Error())
|
|
|
|
}
|
|
|
|
|
2023-07-07 23:15:30 +02:00
|
|
|
projUser.Role = db.ProjectOwner
|
2021-05-16 23:44:42 +02:00
|
|
|
err = store.UpdateProjectUser(projUser)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err.Error())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-14 13:47:32 +02:00
|
|
|
func TestGetUsers(t *testing.T) {
|
2022-01-23 14:21:27 +01:00
|
|
|
store := CreateTestStore()
|
2021-05-14 13:47:32 +02:00
|
|
|
|
2022-01-23 14:21:27 +01:00
|
|
|
_, err := store.CreateUser(db.UserWithPwd{
|
2021-05-14 13:47:32 +02:00
|
|
|
Pwd: "123456",
|
|
|
|
User: db.User{
|
2022-01-23 14:21:27 +01:00
|
|
|
Email: "denguk@example.com",
|
|
|
|
Name: "Denis Gukov",
|
2021-05-14 13:47:32 +02:00
|
|
|
Username: "fiftin",
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
if err != nil {
|
2021-05-16 23:44:42 +02:00
|
|
|
t.Fatal(err.Error())
|
2021-05-14 13:47:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
found, err := store.GetUsers(db.RetrieveQueryParams{})
|
|
|
|
|
|
|
|
if err != nil {
|
2021-05-16 23:44:42 +02:00
|
|
|
t.Fatal(err.Error())
|
2021-05-14 13:47:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if len(found) != 1 {
|
2021-05-16 23:44:42 +02:00
|
|
|
t.Fatal(err.Error())
|
2021-05-14 13:47:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestGetUser(t *testing.T) {
|
2022-01-23 14:21:27 +01:00
|
|
|
store := CreateTestStore()
|
2021-05-14 13:47:32 +02:00
|
|
|
|
|
|
|
usr, err := store.CreateUser(db.UserWithPwd{
|
|
|
|
Pwd: "123456",
|
|
|
|
User: db.User{
|
2022-01-23 14:21:27 +01:00
|
|
|
Email: "denguk@example.com",
|
|
|
|
Name: "Denis Gukov",
|
2021-05-14 13:47:32 +02:00
|
|
|
Username: "fiftin",
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
if err != nil {
|
2021-05-16 23:44:42 +02:00
|
|
|
t.Fatal(err.Error())
|
2021-05-14 13:47:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
found, err := store.GetUser(usr.ID)
|
|
|
|
|
|
|
|
if err != nil {
|
2021-05-16 23:44:42 +02:00
|
|
|
t.Fatal(err.Error())
|
2021-05-14 13:47:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if found.Username != "fiftin" {
|
2021-05-16 23:44:42 +02:00
|
|
|
t.Fatal(err.Error())
|
2021-05-14 13:47:32 +02:00
|
|
|
}
|
|
|
|
|
2021-05-14 13:57:51 +02:00
|
|
|
err = store.DeleteUser(usr.ID)
|
|
|
|
|
|
|
|
if err != nil {
|
2021-05-16 23:44:42 +02:00
|
|
|
t.Fatal(err.Error())
|
2021-05-14 13:57:51 +02:00
|
|
|
}
|
2021-05-14 13:47:32 +02:00
|
|
|
}
|