Skip to content

Commit 83655aa

Browse files
committed
groupware: improve tests
* jmap: add UpdateContactCard and UpdateCalendarEvent funcs * use JSON marshalling and unmarshalling into a map for toPatch() implementations * add updating ContactCards and CalendarEvents to tests * add deleting ContactCards and CalendarEvents to tests * make query response totals work when the value is 0 * tests: use CreateContactCard and CreateCalendarEvent funcs to create objects in tests instead of using a different JMAP stack that works with untyped maps
1 parent 92fc3c5 commit 83655aa

11 files changed

Lines changed: 805 additions & 569 deletions

pkg/jmap/api_contact.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ func (j *Client) QueryContactCards(accountIds []string,
7676
Results: get.List,
7777
CanCalculateChanges: query.CanCalculateChanges,
7878
Position: query.Position,
79-
Total: uintPtrIf(query.Total, calculateTotal),
79+
Total: uintPtrIfPtr(query.Total, calculateTotal),
8080
Limit: query.Limit,
8181
}
8282
},
@@ -114,3 +114,18 @@ func (j *Client) DeleteContactCard(accountId string, destroyIds []string, ctx Co
114114
ctx,
115115
)
116116
}
117+
118+
func (j *Client) UpdateContactCard(accountId string, id string, changes ContactCardChange, ctx Context) (ContactCard, SessionState, State, Language, Error) {
119+
return update(j, "UpdateContactCard", ContactCardType,
120+
func(update map[string]PatchObject) ContactCardSetCommand {
121+
return ContactCardSetCommand{AccountId: accountId, Update: update}
122+
},
123+
func(id string) ContactCardGetCommand {
124+
return ContactCardGetCommand{AccountId: accountId, Ids: []string{id}}
125+
},
126+
func(resp ContactCardSetResponse) map[string]SetError { return resp.NotUpdated },
127+
func(resp ContactCardGetResponse) ContactCard { return resp.List[0] },
128+
id, changes,
129+
ctx,
130+
)
131+
}

pkg/jmap/api_event.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func (j *Client) QueryCalendarEvents(accountIds []string, //NOSONAR
2929
Results: get.List,
3030
CanCalculateChanges: query.CanCalculateChanges,
3131
Position: query.Position,
32-
Total: uintPtrIf(query.Total, calculateTotal),
32+
Total: uintPtrIfPtr(query.Total, calculateTotal),
3333
Limit: query.Limit,
3434
}
3535
},
@@ -103,3 +103,18 @@ func (j *Client) DeleteCalendarEvent(accountId string, destroyIds []string, ctx
103103
ctx,
104104
)
105105
}
106+
107+
func (j *Client) UpdateCalendarEvent(accountId string, id string, changes CalendarEventChange, ctx Context) (CalendarEvent, SessionState, State, Language, Error) {
108+
return update(j, "UpdateCalendarEvent", CalendarEventType,
109+
func(update map[string]PatchObject) CalendarEventSetCommand {
110+
return CalendarEventSetCommand{AccountId: accountId, Update: update}
111+
},
112+
func(id string) CalendarEventGetCommand {
113+
return CalendarEventGetCommand{AccountId: accountId, Ids: []string{id}}
114+
},
115+
func(resp CalendarEventSetResponse) map[string]SetError { return resp.NotUpdated },
116+
func(resp CalendarEventGetResponse) CalendarEvent { return resp.List[0] },
117+
id, changes,
118+
ctx,
119+
)
120+
}

pkg/jmap/error.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ const (
3939
JmapErrorSocketPushUnsupported
4040
JmapErrorMissingCreatedObject
4141
JmapInvalidObjectState
42+
JmapPatchObjectSerialization
4243
)
4344

4445
var (

0 commit comments

Comments
 (0)