func TestRequest_Update_Update(t *testing.T) { resource := MakeResourceAt("people") resource.Set("name", "Mat").Set("age", 29) mockedTransporter := new(api.MockedTransporter) api.ActiveLiveTransporter = mockedTransporter // make a response response := NewTestResponse(200, nil, nil, "", api.ChangeInfo(map[string]interface{}{common.ChangeInfoPublicFieldCreated: 1, common.ChangeInfoPublicFieldDeltas: []interface{}{map[string]interface{}{common.DataFieldID: "hello", common.ChangeInfoPublicFieldDeltaCreated: 123}}})) mockedTransporter.On("MakeRequest", mock.Anything).Return(response, nil) session := NewSession(TestProjectName, TestAccountName, TestAPIKey) changeInfo, err := session.At("people").Update(resource) if assert.NoError(t, err) { if assert.NotNil(t, changeInfo) { mockedTransporter.AssertExpectations(t) request := mockedTransporter.Calls[0].Arguments[0].(*api.Request) assert.Equal(t, request.HTTPMethod(), common.HTTPMethodPatch) assert.Equal(t, request.Path(), "people") assert.Equal(t, changeInfo.Created(), 1) } } }
/* Delete */ func TestRequest_Delete(t *testing.T) { mockedTransporter := new(api.MockedTransporter) api.ActiveLiveTransporter = mockedTransporter // make a response response := NewTestResponse(200, nil, nil, "", api.ChangeInfo(map[string]interface{}{common.ChangeInfoPublicFieldDeleted: 5})) mockedTransporter.On("MakeRequest", mock.Anything).Return(response, nil) session := NewSession(TestProjectName, TestAccountName, TestAPIKey) changeInfo, err := session.At("people/123").Delete() if assert.NoError(t, err) { assert.NotNil(t, changeInfo) } mockedTransporter.AssertExpectations(t) request := mockedTransporter.Calls[0].Arguments[0].(*api.Request) assert.Equal(t, request.HTTPMethod(), common.HTTPMethodDelete) assert.Equal(t, request.Path(), "people/123") assert.Equal(t, request.Body(), []byte("")) assert.Equal(t, changeInfo.Deleted(), 5) }
func TestRequest_CreateMany(t *testing.T) { var resources []*Resource resource := MakeResourceAt("people") resource.Set("name", "Mat").Set("age", 29) resources = append(resources, resource) resource = MakeResourceAt("people") resource.Set("name", "Tyler").Set("age", 28) resources = append(resources, resource) resource = MakeResourceAt("people") resource.Set("name", "Stacey").Set("age", 29) resources = append(resources, resource) resourceCollection := NewResourceCollection(resources) mockedTransporter := new(api.MockedTransporter) api.ActiveLiveTransporter = mockedTransporter // make a response response := NewTestResponse(200, nil, nil, "", api.ChangeInfo(map[string]interface{}{common.ChangeInfoPublicFieldCreated: 3, common.ChangeInfoPublicFieldDeltas: []interface{}{ map[string]interface{}{common.DataFieldID: "hello", common.ChangeInfoPublicFieldDeltaCreated: 123}, map[string]interface{}{common.DataFieldID: "goodbye", common.ChangeInfoPublicFieldDeltaCreated: 456}, map[string]interface{}{common.DataFieldID: "greetings", common.ChangeInfoPublicFieldDeltaCreated: 789}}})) mockedTransporter.On("MakeRequest", mock.Anything).Return(response, nil) session := NewSession(TestProjectName, TestAccountName, TestAPIKey) changeInfo, err := session.At("people").CreateMany(resourceCollection) if assert.NoError(t, err) { if assert.NotNil(t, changeInfo) { mockedTransporter.AssertExpectations(t) request := mockedTransporter.Calls[0].Arguments[0].(*api.Request) assert.Equal(t, request.HTTPMethod(), common.HTTPMethodPost) assert.Equal(t, request.Path(), "people") assert.Equal(t, changeInfo.Created(), 3) assert.Equal(t, resourceCollection.Resources[0].ID(), "hello") assert.Equal(t, resourceCollection.Resources[0].ResourceData()[common.ChangeInfoPublicFieldDeltaCreated].(float64), 123) assert.Equal(t, resourceCollection.Resources[1].ID(), "goodbye") assert.Equal(t, resourceCollection.Resources[1].ResourceData()[common.ChangeInfoPublicFieldDeltaCreated].(float64), 456) assert.Equal(t, resourceCollection.Resources[2].ID(), "greetings") assert.Equal(t, resourceCollection.Resources[2].ResourceData()[common.ChangeInfoPublicFieldDeltaCreated].(float64), 789) } } }