| 466 | } |
| 467 | |
| 468 | func TestHandleAction_KeyAction(t *testing.T) { |
| 469 | t.Parallel() |
| 470 | |
| 471 | logger := slogtest.Make(t, nil) |
| 472 | fake := &fakeDesktop{ |
| 473 | startCfg: agentdesktop.DisplayConfig{Width: 1920, Height: 1080}, |
| 474 | } |
| 475 | api := agentdesktop.NewAPI(logger, fake, nil) |
| 476 | defer api.Close() |
| 477 | |
| 478 | text := "Return" |
| 479 | body := agentdesktop.DesktopAction{ |
| 480 | Action: "key", |
| 481 | Text: &text, |
| 482 | } |
| 483 | b, err := json.Marshal(body) |
| 484 | require.NoError(t, err) |
| 485 | |
| 486 | rr := httptest.NewRecorder() |
| 487 | req := httptest.NewRequest(http.MethodPost, "/action", bytes.NewReader(b)) |
| 488 | req.Header.Set("Content-Type", "application/json") |
| 489 | |
| 490 | handler := api.Routes() |
| 491 | handler.ServeHTTP(rr, req) |
| 492 | |
| 493 | assert.Equal(t, http.StatusOK, rr.Code) |
| 494 | assert.Equal(t, "Return", fake.lastKey) |
| 495 | } |
| 496 | |
| 497 | func TestHandleAction_TypeAction(t *testing.T) { |
| 498 | t.Parallel() |