mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-20 13:31:56 +00:00
FIX[BE]: period without autoincrement
This commit is contained in:
@@ -22,12 +22,11 @@ func TestProjectFlockSummary(t *testing.T) {
|
||||
kandangID := createKandang(t, app, "Kandang Summary", locationID, 1)
|
||||
|
||||
createPayload := map[string]any{
|
||||
"flock_id": flockID,
|
||||
"flock_id": flockID,
|
||||
"area_id": areaID,
|
||||
"product_category_id": categoryID,
|
||||
"fcr_id": fcrID,
|
||||
"location_id": locationID,
|
||||
"period": 1,
|
||||
"kandang_ids": []uint{kandangID},
|
||||
}
|
||||
resp, body := doJSONRequest(t, app, http.MethodPost, "/api/production/project_flocks", createPayload)
|
||||
@@ -37,14 +36,9 @@ func TestProjectFlockSummary(t *testing.T) {
|
||||
|
||||
var createResp struct {
|
||||
Data struct {
|
||||
Id uint `json:"id"`
|
||||
FlockId uint `json:"flock_id"`
|
||||
AreaId uint `json:"area_id"`
|
||||
ProductCategoryId uint `json:"product_category_id"`
|
||||
FcrId uint `json:"fcr_id"`
|
||||
LocationId uint `json:"location_id"`
|
||||
Period int `json:"period"`
|
||||
Flock struct {
|
||||
Id uint `json:"id"`
|
||||
Period int `json:"period"`
|
||||
Flock struct {
|
||||
Id uint `json:"id"`
|
||||
Name string `json:"name"`
|
||||
} `json:"flock"`
|
||||
@@ -82,18 +76,47 @@ func TestProjectFlockSummary(t *testing.T) {
|
||||
if err := json.Unmarshal(body, &createResp); err != nil {
|
||||
t.Fatalf("failed to parse create response: %v", err)
|
||||
}
|
||||
if createResp.Data.FlockId != flockID || createResp.Data.Flock.Name == "" {
|
||||
if createResp.Data.Flock.Id != flockID || createResp.Data.Flock.Name == "" {
|
||||
t.Fatalf("expected flock detail to be present, got %+v", createResp.Data.Flock)
|
||||
}
|
||||
if createResp.Data.AreaId != areaID || createResp.Data.Area.Name == "" {
|
||||
if createResp.Data.Area.Id != areaID || createResp.Data.Area.Name == "" {
|
||||
t.Fatalf("expected area detail to be present, got %+v", createResp.Data.Area)
|
||||
}
|
||||
if createResp.Data.LocationId != locationID || createResp.Data.Location.Name == "" {
|
||||
if createResp.Data.Location.Id != locationID || createResp.Data.Location.Name == "" {
|
||||
t.Fatalf("expected location detail to be present, got %+v", createResp.Data.Location)
|
||||
}
|
||||
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.Period != 1 {
|
||||
t.Fatalf("expected period 1 to be assigned automatically, got %d", createResp.Data.Period)
|
||||
}
|
||||
|
||||
secondKandangID := createKandang(t, app, "Kandang Summary 2", locationID, 1)
|
||||
secondPayload := map[string]any{
|
||||
"flock_id": flockID,
|
||||
"area_id": areaID,
|
||||
"product_category_id": categoryID,
|
||||
"fcr_id": fcrID,
|
||||
"location_id": locationID,
|
||||
"kandang_ids": []uint{secondKandangID},
|
||||
}
|
||||
resp, body = doJSONRequest(t, app, http.MethodPost, "/api/production/project_flocks", secondPayload)
|
||||
if resp.StatusCode != fiber.StatusCreated {
|
||||
t.Fatalf("expected 201 when creating second project flock, got %d: %s", resp.StatusCode, string(body))
|
||||
}
|
||||
var createRespSecond struct {
|
||||
Data struct {
|
||||
Id uint `json:"id"`
|
||||
Period int `json:"period"`
|
||||
} `json:"data"`
|
||||
}
|
||||
if err := json.Unmarshal(body, &createRespSecond); err != nil {
|
||||
t.Fatalf("failed to parse second create response: %v", err)
|
||||
}
|
||||
if createRespSecond.Data.Period != 2 {
|
||||
t.Fatalf("expected second period to be 2, got %d", createRespSecond.Data.Period)
|
||||
}
|
||||
|
||||
resp, body = doJSONRequest(t, app, http.MethodGet, "/api/production/project_flocks/flocks/"+uintToString(flockID)+"/periods", nil)
|
||||
if resp.StatusCode != fiber.StatusOK {
|
||||
@@ -109,8 +132,31 @@ func TestProjectFlockSummary(t *testing.T) {
|
||||
t.Fatalf("failed to parse summary response: %v", err)
|
||||
}
|
||||
|
||||
if summary.Data.NextPeriod != 2 {
|
||||
t.Fatalf("expected next_period 2, got %d", summary.Data.NextPeriod)
|
||||
if summary.Data.NextPeriod != 3 {
|
||||
t.Fatalf("expected next_period 3, got %d", summary.Data.NextPeriod)
|
||||
}
|
||||
|
||||
resp, body = doJSONRequest(t, app, http.MethodDelete, "/api/production/project_flocks/"+uintToString(createResp.Data.Id), nil)
|
||||
if resp.StatusCode != fiber.StatusOK {
|
||||
t.Fatalf("expected 200 when deleting first project flock, got %d: %s", resp.StatusCode, string(body))
|
||||
}
|
||||
|
||||
resp, body = doJSONRequest(t, app, http.MethodDelete, "/api/production/project_flocks/"+uintToString(createRespSecond.Data.Id), nil)
|
||||
if resp.StatusCode != fiber.StatusOK {
|
||||
t.Fatalf("expected 200 when deleting second project flock, got %d: %s", resp.StatusCode, string(body))
|
||||
}
|
||||
|
||||
resp, body = doJSONRequest(t, app, http.MethodGet, "/api/production/project_flocks/flocks/"+uintToString(flockID)+"/periods", nil)
|
||||
if resp.StatusCode != fiber.StatusOK {
|
||||
t.Fatalf("expected 200 when fetching summary after delete, got %d: %s", resp.StatusCode, string(body))
|
||||
}
|
||||
|
||||
if err := json.Unmarshal(body, &summary); err != nil {
|
||||
t.Fatalf("failed to parse summary response after delete: %v", err)
|
||||
}
|
||||
|
||||
if summary.Data.NextPeriod != 1 {
|
||||
t.Fatalf("expected next_period 1 after soft deletes, got %d", summary.Data.NextPeriod)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user