mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-24 15:25:43 +00:00
FIX[BE]: period and adjustment helper to function
This commit is contained in:
@@ -13,6 +13,7 @@ import (
|
|||||||
type KandangBaseDTO struct {
|
type KandangBaseDTO struct {
|
||||||
Id uint `json:"id"`
|
Id uint `json:"id"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
|
Status string `json:"status"`
|
||||||
Location *locationDTO.LocationBaseDTO `json:"location"`
|
Location *locationDTO.LocationBaseDTO `json:"location"`
|
||||||
Pic *userDTO.UserBaseDTO `json:"pic"`
|
Pic *userDTO.UserBaseDTO `json:"pic"`
|
||||||
}
|
}
|
||||||
@@ -46,6 +47,7 @@ func ToKandangBaseDTO(e entity.Kandang) KandangBaseDTO {
|
|||||||
return KandangBaseDTO{
|
return KandangBaseDTO{
|
||||||
Id: e.Id,
|
Id: e.Id,
|
||||||
Name: e.Name,
|
Name: e.Name,
|
||||||
|
Status: e.Status,
|
||||||
Location: location,
|
Location: location,
|
||||||
Pic: pic,
|
Pic: pic,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package test
|
package test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"net/http"
|
"net/http"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
@@ -17,13 +18,24 @@ func TestKandangIntegration(t *testing.T) {
|
|||||||
t.Run("create kandang success", func(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{
|
resp, body := doJSONRequest(t, app, http.MethodPost, "/api/master-data/kandangs", map[string]any{
|
||||||
"name": "Kandang OK",
|
"name": "Kandang OK",
|
||||||
"status": "ACTIVE",
|
|
||||||
"location_id": locationID,
|
"location_id": locationID,
|
||||||
"pic_id": 1,
|
"pic_id": 1,
|
||||||
})
|
})
|
||||||
if resp.StatusCode != fiber.StatusCreated {
|
if resp.StatusCode != fiber.StatusCreated {
|
||||||
t.Fatalf("expected 201, got %d: %s", resp.StatusCode, string(body))
|
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) {
|
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 {
|
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)
|
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 {
|
if createResp.Data.Period != 1 {
|
||||||
t.Fatalf("expected period 1 to be assigned automatically, got %d", createResp.Data.Period)
|
t.Fatalf("expected period 1 to be assigned automatically, got %d", createResp.Data.Period)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user