MCPcopy Create free account
hub / github.com/algolia/cli / TestCreateApplication_Success

Function TestCreateApplication_Success

api/dashboard/client_test.go:266–294  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

264}
265
266func TestCreateApplication_Success(t *testing.T) {
267 mux := http.NewServeMux()
268 mux.HandleFunc("/1/applications", func(w http.ResponseWriter, r *http.Request) {
269 assert.Equal(t, http.MethodPost, r.Method)
270 assert.Equal(t, "Bearer test-token", r.Header.Get("Authorization"))
271 assert.Equal(t, "application/json", r.Header.Get("Content-Type"))
272
273 var payload CreateApplicationRequest
274 require.NoError(t, json.NewDecoder(r.Body).Decode(&payload))
275 assert.Equal(t, "us", payload.RegionCode)
276 assert.Equal(t, "My App", payload.Name)
277
278 w.WriteHeader(http.StatusCreated)
279 require.NoError(t, json.NewEncoder(w).Encode(SingleApplicationResponse{
280 Data: ApplicationResource{
281 ID: "NEW_APP", Type: "application",
282 Attributes: ApplicationAttributes{ApplicationID: "NEW_APP", Name: "My App"},
283 },
284 }))
285 })
286
287 ts, client := newTestClient(mux)
288 defer ts.Close()
289
290 app, err := client.CreateApplication("test-token", "us", "My App")
291 require.NoError(t, err)
292 assert.Equal(t, "NEW_APP", app.ID)
293 assert.Equal(t, "My App", app.Name)
294}
295
296func TestUpdateApplication_Success(t *testing.T) {
297 mux := http.NewServeMux()

Callers

nothing calls this directly

Calls 4

newTestClientFunction · 0.85
GetMethod · 0.80
CreateApplicationMethod · 0.80
CloseMethod · 0.65

Tested by

no test coverage detected