mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-20 13:31:56 +00:00
FIX[BE]: period and adjustment helper to function
This commit is contained in:
@@ -13,6 +13,7 @@ import (
|
||||
type KandangBaseDTO struct {
|
||||
Id uint `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Status string `json:"status"`
|
||||
Location *locationDTO.LocationBaseDTO `json:"location"`
|
||||
Pic *userDTO.UserBaseDTO `json:"pic"`
|
||||
}
|
||||
@@ -46,6 +47,7 @@ func ToKandangBaseDTO(e entity.Kandang) KandangBaseDTO {
|
||||
return KandangBaseDTO{
|
||||
Id: e.Id,
|
||||
Name: e.Name,
|
||||
Status: e.Status,
|
||||
Location: location,
|
||||
Pic: pic,
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package test
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"testing"
|
||||
|
||||
@@ -17,13 +18,24 @@ func TestKandangIntegration(t *testing.T) {
|
||||
t.Run("create kandang success", func(t *testing.T) {
|
||||
resp, body := doJSONRequest(t, app, http.MethodPost, "/api/master-data/kandangs", map[string]any{
|
||||
"name": "Kandang OK",
|
||||
"status": "ACTIVE",
|
||||
"location_id": locationID,
|
||||
"pic_id": 1,
|
||||
})
|
||||
if resp.StatusCode != fiber.StatusCreated {
|
||||
t.Fatalf("expected 201, got %d: %s", resp.StatusCode, string(body))
|
||||
}
|
||||
|
||||
var createResp struct {
|
||||
Data struct {
|
||||
Status string `json:"status"`
|
||||
} `json:"data"`
|
||||
}
|
||||
if err := json.Unmarshal(body, &createResp); err != nil {
|
||||
t.Fatalf("failed to parse create response: %v", err)
|
||||
}
|
||||
if createResp.Data.Status == "" {
|
||||
t.Fatalf("expected default status to be returned, got empty")
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("create kandang with unknown location fails", func(t *testing.T) {
|
||||
|
||||
@@ -88,6 +88,9 @@ func TestProjectFlockSummary(t *testing.T) {
|
||||
if len(createResp.Data.Kandangs) != 1 || createResp.Data.Kandangs[0].Id != kandangID {
|
||||
t.Fatalf("expected kandang detail to be present, got %+v", createResp.Data.Kandangs)
|
||||
}
|
||||
if createResp.Data.Kandangs[0].Status == "" {
|
||||
t.Fatalf("expected kandang status to be present, got %+v", createResp.Data.Kandangs[0])
|
||||
}
|
||||
if createResp.Data.Period != 1 {
|
||||
t.Fatalf("expected period 1 to be assigned automatically, got %d", createResp.Data.Period)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user