|
|
@ -18,12 +18,12 @@ func TestApi(t *testing.T) { |
|
|
|
// Create a new server
|
|
|
|
// Create a new server
|
|
|
|
config := conf.Default() |
|
|
|
config := conf.Default() |
|
|
|
config.BaseContentDir = "../../" |
|
|
|
config.BaseContentDir = "../../" |
|
|
|
config.ProdDBName = filepath.Join(os.TempDir(), "dela_test_db.db") |
|
|
|
config.ProdDBPath = filepath.Join(os.TempDir(), "dela_test_db.db") |
|
|
|
server, err := New(config) |
|
|
|
server, err := New(config) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
t.Fatalf("failed to create a new server: %s", err) |
|
|
|
t.Fatalf("failed to create a new server: %s", err) |
|
|
|
} |
|
|
|
} |
|
|
|
defer os.Remove(config.ProdDBName) |
|
|
|
defer os.Remove(config.ProdDBPath) |
|
|
|
|
|
|
|
|
|
|
|
go func() { |
|
|
|
go func() { |
|
|
|
time.Sleep(time.Second * 5) |
|
|
|
time.Sleep(time.Second * 5) |
|
|
@ -59,28 +59,28 @@ func TestApi(t *testing.T) { |
|
|
|
} |
|
|
|
} |
|
|
|
resp.Body.Close() |
|
|
|
resp.Body.Close() |
|
|
|
|
|
|
|
|
|
|
|
// Create a new TODO group and a TODO
|
|
|
|
// Create a new TODO
|
|
|
|
newGroup := db.TodoGroup{ |
|
|
|
// newGroup := db.TodoGroup{
|
|
|
|
Name: "group1", |
|
|
|
// Name: "group1",
|
|
|
|
TimeCreatedUnix: 13524534, |
|
|
|
// TimeCreatedUnix: 13524534,
|
|
|
|
OwnerUsername: newUser.Username, |
|
|
|
// OwnerUsername: newUser.Username,
|
|
|
|
} |
|
|
|
// }
|
|
|
|
newGroupBytes, err := json.Marshal(&newGroup) |
|
|
|
// newGroupBytes, err := json.Marshal(&newGroup)
|
|
|
|
if err != nil { |
|
|
|
// if err != nil {
|
|
|
|
t.Fatalf("could not marshal new user JSON: %s", err) |
|
|
|
// t.Fatalf("could not marshal new user JSON: %s", err)
|
|
|
|
} |
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
req, err := http.NewRequest("POST", fmt.Sprintf("http://localhost:%d/api/groups", config.Port), bytes.NewBuffer(newGroupBytes)) |
|
|
|
// req, err := http.NewRequest("POST", fmt.Sprintf("http://localhost:%d/api/groups", config.Port), bytes.NewBuffer(newGroupBytes))
|
|
|
|
if err != nil { |
|
|
|
// if err != nil {
|
|
|
|
t.Fatalf("failed to create a new POST request to create a new TODO group: %s", err) |
|
|
|
// t.Fatalf("failed to create a new POST request to create a new TODO group: %s", err)
|
|
|
|
} |
|
|
|
// }
|
|
|
|
req.Header.Add(RequestHeaderAuthKey, fmt.Sprintf("%s%s%s", newUser.Username, RequestHeaderAuthSeparator, newUser.Password)) |
|
|
|
// req.Header.Add(RequestHeaderAuthKey, fmt.Sprintf("%s%s%s", newUser.Username, RequestHeaderAuthSeparator, newUser.Password))
|
|
|
|
req.Header.Add(RequestHeaderEncodedB64, "false") |
|
|
|
// req.Header.Add(RequestHeaderEncodedB64, "false")
|
|
|
|
|
|
|
|
|
|
|
|
resp, err = http.DefaultClient.Do(req) |
|
|
|
// resp, err = http.DefaultClient.Do(req)
|
|
|
|
if err != nil { |
|
|
|
// if err != nil {
|
|
|
|
t.Fatalf("failed to post a new TODO group: %s", err) |
|
|
|
// t.Fatalf("failed to post a new TODO group: %s", err)
|
|
|
|
} |
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
body, err = io.ReadAll(resp.Body) |
|
|
|
body, err = io.ReadAll(resp.Body) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
@ -94,7 +94,8 @@ func TestApi(t *testing.T) { |
|
|
|
|
|
|
|
|
|
|
|
// TODO creation
|
|
|
|
// TODO creation
|
|
|
|
var newTodo db.Todo = db.Todo{ |
|
|
|
var newTodo db.Todo = db.Todo{ |
|
|
|
GroupID: newGroup.ID, |
|
|
|
// GroupID: newGroup.ID,
|
|
|
|
|
|
|
|
GroupID: 0, |
|
|
|
Text: "Do the dishes", |
|
|
|
Text: "Do the dishes", |
|
|
|
TimeCreatedUnix: uint64(time.Now().UnixMicro()), |
|
|
|
TimeCreatedUnix: uint64(time.Now().UnixMicro()), |
|
|
|
DueUnix: uint64(time.Now().Add(time.Hour * 5).UnixMicro()), |
|
|
|
DueUnix: uint64(time.Now().Add(time.Hour * 5).UnixMicro()), |
|
|
@ -106,7 +107,7 @@ func TestApi(t *testing.T) { |
|
|
|
t.Fatalf("could not marshal new Todo: %s", err) |
|
|
|
t.Fatalf("could not marshal new Todo: %s", err) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
req, err = http.NewRequest("POST", fmt.Sprintf("http://localhost:%d/api/todo", config.Port), bytes.NewBuffer(newTodoBytes)) |
|
|
|
req, err := http.NewRequest("POST", fmt.Sprintf("http://localhost:%d/api/todo", config.Port), bytes.NewBuffer(newTodoBytes)) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
t.Fatalf("failed to create a new POST request to create a new TODO: %s", err) |
|
|
|
t.Fatalf("failed to create a new POST request to create a new TODO: %s", err) |
|
|
|
} |
|
|
|
} |
|
|
|