feat(t224): add incremental freight sync
This commit is contained in:
@@ -395,6 +395,89 @@ func TestAdminFreightAPIImportsAllItemsWithoutPII(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestAdminFreightDateSyncAdvancesInspectableWatermark(t *testing.T) {
|
||||
fixture := newAdminIntegrationFixture(t)
|
||||
location, err := time.LoadLocation("Asia/Shanghai")
|
||||
if err != nil {
|
||||
t.Fatalf("LoadLocation() error = %v", err)
|
||||
}
|
||||
today := time.Now().In(location).Format(time.DateOnly)
|
||||
body := fmt.Sprintf(
|
||||
`{"mode":"CREATED_RANGE","created_from":%q,"created_to":%q}`,
|
||||
today,
|
||||
today,
|
||||
)
|
||||
create := performAdminRequest(
|
||||
t,
|
||||
fixture.router,
|
||||
http.MethodPost,
|
||||
"/api/v1/freight-syncs",
|
||||
"application/json",
|
||||
strings.NewReader(body),
|
||||
"freight-date-sync-1",
|
||||
)
|
||||
requireAdminStatus(t, create, http.StatusAccepted)
|
||||
var created struct {
|
||||
Sync struct {
|
||||
ID string `json:"id"`
|
||||
} `json:"sync"`
|
||||
}
|
||||
decodeResponse(t, create, &created)
|
||||
var status *httptest.ResponseRecorder
|
||||
for attempt := 0; attempt < 50; attempt++ {
|
||||
status = performAdminRequest(
|
||||
t,
|
||||
fixture.router,
|
||||
http.MethodGet,
|
||||
"/api/v1/freight-syncs/"+created.Sync.ID,
|
||||
"",
|
||||
nil,
|
||||
"",
|
||||
)
|
||||
if strings.Contains(status.Body.String(), `"status":"SUCCEEDED"`) {
|
||||
break
|
||||
}
|
||||
time.Sleep(10 * time.Millisecond)
|
||||
}
|
||||
requireAdminStatus(t, status, http.StatusOK)
|
||||
if !strings.Contains(status.Body.String(), `"mode":"CREATED_RANGE"`) ||
|
||||
!strings.Contains(status.Body.String(), `"created_from":"`+today+`"`) ||
|
||||
!strings.Contains(status.Body.String(), `"order_count":0`) {
|
||||
t.Fatalf("date sync response = %s", status.Body)
|
||||
}
|
||||
|
||||
watermark := performAdminRequest(
|
||||
t,
|
||||
fixture.router,
|
||||
http.MethodGet,
|
||||
"/api/v1/freight-sync-watermark",
|
||||
"",
|
||||
nil,
|
||||
"",
|
||||
)
|
||||
requireAdminStatus(t, watermark, http.StatusOK)
|
||||
if !strings.Contains(
|
||||
watermark.Body.String(),
|
||||
`"last_successful_run_id":"`+created.Sync.ID+`"`,
|
||||
) || strings.Contains(watermark.Body.String(), "receiver") {
|
||||
t.Fatalf("watermark response = %s", watermark.Body)
|
||||
}
|
||||
|
||||
mixed := performAdminRequest(
|
||||
t,
|
||||
fixture.router,
|
||||
http.MethodPost,
|
||||
"/api/v1/freight-syncs",
|
||||
"application/json",
|
||||
strings.NewReader(
|
||||
`{"mode":"CREATED_RANGE","order_number":"must-not-be-ignored",`+
|
||||
`"created_from":"`+today+`","created_to":"`+today+`"}`,
|
||||
),
|
||||
"freight-date-mixed",
|
||||
)
|
||||
requireAdminStatus(t, mixed, http.StatusUnprocessableEntity)
|
||||
}
|
||||
|
||||
func TestAdminProcurementAPIProducesImmutablePendingTask(t *testing.T) {
|
||||
fixture := newAdminIntegrationFixture(t)
|
||||
createSync := performAdminRequest(
|
||||
@@ -708,6 +791,9 @@ func TestAdminOrderAuthorizationIsIdempotentAndRevisioned(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("migration.New() error = %v", err)
|
||||
}
|
||||
if err := runner.Down(context.Background()); err != nil {
|
||||
t.Fatalf("date sync migration down: %v", err)
|
||||
}
|
||||
if err := runner.Down(context.Background()); err != nil {
|
||||
t.Fatalf("procurement migration down: %v", err)
|
||||
}
|
||||
@@ -1125,6 +1211,21 @@ func (staticFreightSource) QueryOrder(
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (staticFreightSource) QueryCreatedRange(
|
||||
_ context.Context,
|
||||
createdFrom, createdTo string,
|
||||
) (domain.FreightSourceBatch, error) {
|
||||
return domain.FreightSourceBatch{
|
||||
SchemaVersion: 1,
|
||||
Query: domain.FreightSourceQuery{
|
||||
Mode: domain.FreightSyncCreatedRange,
|
||||
CreatedFrom: &createdFrom,
|
||||
CreatedTo: &createdTo,
|
||||
},
|
||||
Orders: []domain.FreightSourceOrder{},
|
||||
}, nil
|
||||
}
|
||||
|
||||
func mustDecodeAny(
|
||||
t *testing.T,
|
||||
response *httptest.ResponseRecorder,
|
||||
|
||||
Reference in New Issue
Block a user