feat: add bulk partial update method and tests
This commit is contained in:
14
table.go
14
table.go
@@ -75,6 +75,20 @@ func (t *Table) UpdateRecords(records *Records) (*Records, error) {
|
||||
return response, nil
|
||||
}
|
||||
|
||||
// UpdateRecordsPartial partial update records
|
||||
func (t *Table) UpdateRecordsPartial(records *Records) (*Records, error) {
|
||||
response := new(Records)
|
||||
err := t.client.patch(t.dbName, t.tableName, records, response)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, record := range response.Records {
|
||||
record.client = t.client
|
||||
record.table = t
|
||||
}
|
||||
return response, nil
|
||||
}
|
||||
|
||||
// DeleteRecords delete records by recordID
|
||||
func (t *Table) DeleteRecords(recordIDs []string) (*Records, error) {
|
||||
response := new(Records)
|
||||
|
||||
@@ -68,6 +68,25 @@ func TestTable_UpdateRecords(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestTable_UpdateRecordsPartial(t *testing.T) {
|
||||
table := testTable(t)
|
||||
table.client.baseURL = mockResponse("get_records_with_filter.json").URL
|
||||
toSend := new(Records)
|
||||
records, err := table.UpdateRecordsPartial(toSend)
|
||||
if err != nil {
|
||||
t.Error("must be no error")
|
||||
}
|
||||
if len(records.Records) != 3 {
|
||||
t.Errorf("should be 3 records in result, but was: %v", len(records.Records))
|
||||
}
|
||||
table.client.baseURL = mockErrorResponse(404).URL
|
||||
_, err = table.UpdateRecordsPartial(toSend)
|
||||
var e *HTTPClientError
|
||||
if errors.Is(err, e) {
|
||||
t.Errorf("should be an http error, but was not: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func testTable(t *testing.T) *Table {
|
||||
client := testClient(t)
|
||||
return client.GetTable("dbName", "tableName")
|
||||
|
||||
Reference in New Issue
Block a user