MCPcopy Create free account
hub / github.com/GetStream/stream-go2 / TestAddCollectionObject

Function TestAddCollectionObject

collections_test.go:144–185  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

142}
143
144func TestAddCollectionObject(t *testing.T) {
145 ctx := context.Background()
146 client, requester := newClient(t)
147 testCases := []struct {
148 object stream.CollectionObject
149 collection string
150 opts []stream.AddObjectOption
151 expectedURL string
152 expectedBody string
153 }{
154 {
155 collection: "no_user_id",
156 object: stream.CollectionObject{
157 ID: "1",
158 Data: map[string]any{
159 "name": "Juniper",
160 "hobbies": []string{"playing", "sleeping", "eating"},
161 },
162 },
163 expectedURL: "https://api.stream-io-api.com/api/v1.0/collections/no_user_id/?api_key=key",
164 expectedBody: `{"data":{"hobbies":["playing","sleeping","eating"],"name":"Juniper"},"id":"1"}`,
165 },
166 {
167 collection: "with_user_id",
168 object: stream.CollectionObject{
169 ID: "1",
170 Data: map[string]any{
171 "name": "Juniper",
172 "hobbies": []string{"playing", "sleeping", "eating"},
173 },
174 },
175 opts: []stream.AddObjectOption{stream.WithUserID("user1")},
176 expectedURL: "https://api.stream-io-api.com/api/v1.0/collections/with_user_id/?api_key=key",
177 expectedBody: `{"data":{"hobbies":["playing","sleeping","eating"],"name":"Juniper"},"id":"1","user_id":"user1"}`,
178 },
179 }
180 for _, tc := range testCases {
181 _, err := client.Collections().Add(ctx, tc.collection, tc.object, tc.opts...)
182 require.NoError(t, err)
183 testRequest(t, requester.req, http.MethodPost, tc.expectedURL, tc.expectedBody)
184 }
185}
186
187func TestUpdateCollectionObject(t *testing.T) {
188 ctx := context.Background()

Callers

nothing calls this directly

Calls 4

newClientFunction · 0.85
testRequestFunction · 0.85
CollectionsMethod · 0.80
AddMethod · 0.45

Tested by

no test coverage detected