-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathtable_test.go
93 lines (86 loc) · 2.59 KB
/
table_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
// Copyright © 2020 Mike Berezin
//
// Use of this source code is governed by an MIT license.
// Details in the LICENSE file.
package airtable
import (
"errors"
"testing"
)
func TestTable_DeleteRecords(t *testing.T) {
table := testTable()
table.client.baseURL = mockResponse("delete_records.json").URL
records, err := table.DeleteRecords([]string{"recnTq6CsvFM6vX2m", "recr3qAQbM7juKa4o"})
if err != nil {
t.Error("must be no error")
}
for _, record := range records.Records {
if !record.Deleted {
t.Errorf("expected that record will be deleted, but was: %#v", record.Deleted)
}
}
table.client.baseURL = mockErrorResponse(404).URL
_, err = table.DeleteRecords([]string{})
var e *HTTPClientError
if errors.Is(err, e) {
t.Errorf("should be an http error, but was not: %v", err)
}
}
func TestTable_AddRecords(t *testing.T) {
table := testTable()
table.client.baseURL = mockResponse("get_records_with_filter.json").URL
toSend := new(Records)
records, err := table.AddRecords(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.AddRecords(toSend)
var e *HTTPClientError
if errors.Is(err, e) {
t.Errorf("should be an http error, but was not: %v", err)
}
}
func TestTable_UpdateRecords(t *testing.T) {
table := testTable()
table.client.baseURL = mockResponse("get_records_with_filter.json").URL
toSend := new(Records)
records, err := table.UpdateRecords(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.UpdateRecords(toSend)
var e *HTTPClientError
if errors.Is(err, e) {
t.Errorf("should be an http error, but was not: %v", err)
}
}
func TestTable_UpdateRecordsPartial(t *testing.T) {
table := testTable()
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() *Table {
client := testClient()
return client.GetTable("dbName", "tableName")
}