This repository has been archived by the owner on Oct 31, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 22
/
bulkRequest_test.go
71 lines (59 loc) · 1.99 KB
/
bulkRequest_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
package main
import (
"fmt"
"testing"
"os"
"github.com/kintone-labs/go-kintone"
)
func newAppTest(id uint64) *kintone.App {
return &kintone.App{
Domain: os.Getenv("KINTONE_DOMAIN"),
User: os.Getenv("KINTONE_USERNAME"),
Password: os.Getenv("KINTONE_PASSWORD"),
AppId: id,
}
}
func TestRequest(t *testing.T) {
bulkReq := &BulkRequests{}
app := newAppTest(16)
bulkReq.Requests = make([]*BulkRequestItem, 0)
/// INSERT
records := make([]*kintone.Record, 0)
record1 := kintone.NewRecord(map[string]interface{}{
"Text": kintone.SingleLineTextField("test 11!"),
"_2": kintone.SingleLineTextField("test 21!"),
})
records = append(records, record1)
record2 := kintone.NewRecord(map[string]interface{}{
"Text": kintone.SingleLineTextField("test 22!"),
"_2": kintone.SingleLineTextField("test 22!"),
})
records = append(records, record2)
dataPOST := &DataRequestRecordsPOST{app.AppId, records}
postRecords := &BulkRequestItem{"POST", "/k/v1/records.json", dataPOST}
bulkReq.Requests = append(bulkReq.Requests, postRecords)
/// UPDATE
recordsUpdate := make([]interface{}, 0)
recordsUpdate1 := kintone.NewRecordWithId(4902, map[string]interface{}{
"Text": kintone.SingleLineTextField("test NNN!"),
"_2": kintone.SingleLineTextField("test MMM!"),
})
fmt.Println(recordsUpdate1)
recordsUpdate = append(recordsUpdate, &DataRequestRecordPUT{ID: recordsUpdate1.Id(),
Record: recordsUpdate1})
recordsUpdate2 := kintone.NewRecordWithId(4903, map[string]interface{}{
"Text": kintone.SingleLineTextField("test 123!"),
"_2": kintone.SingleLineTextField("test 234!"),
})
recordsUpdate = append(recordsUpdate, &DataRequestRecordPUT{
ID: recordsUpdate2.Id(), Record: recordsUpdate2})
dataPUT := &DataRequestRecordsPUT{app.AppId, recordsUpdate}
putRecords := &BulkRequestItem{"PUT", "/k/v1/records.json", dataPUT}
bulkReq.Requests = append(bulkReq.Requests, putRecords)
rs, err := bulkReq.Request(app)
if err != nil {
t.Error(" failed", err)
} else {
t.Log(rs)
}
}