| package handlers |
|
|
| import ( |
| "net/http" |
| "net/http/httptest" |
| "testing" |
|
|
| "github.com/pinchtab/pinchtab/internal/config" |
| ) |
|
|
| func TestHandleScreenshot_NoTab(t *testing.T) { |
| h := New(&mockBridge{failTab: true}, &config.RuntimeConfig{}, nil, nil, nil) |
| req := httptest.NewRequest("GET", "/screenshot", nil) |
| w := httptest.NewRecorder() |
| h.HandleScreenshot(w, req) |
| if w.Code != http.StatusNotFound { |
| t.Errorf("expected 404, got %d", w.Code) |
| } |
| } |
|
|
| func TestHandleScreenshot_InvalidQuality(t *testing.T) { |
| h := New(&mockBridge{failTab: true}, &config.RuntimeConfig{}, nil, nil, nil) |
| req := httptest.NewRequest("GET", "/screenshot?quality=abc", nil) |
| w := httptest.NewRecorder() |
| h.HandleScreenshot(w, req) |
| |
| if w.Code != http.StatusNotFound { |
| t.Errorf("expected 404, got %d", w.Code) |
| } |
| } |
|
|
| func TestHandleTabScreenshot_MissingTabID(t *testing.T) { |
| h := New(&mockBridge{}, &config.RuntimeConfig{}, nil, nil, nil) |
| req := httptest.NewRequest("GET", "/tabs//screenshot", nil) |
| w := httptest.NewRecorder() |
| h.HandleTabScreenshot(w, req) |
| if w.Code != http.StatusBadRequest { |
| t.Errorf("expected 400, got %d", w.Code) |
| } |
| } |
|
|
| func TestHandleTabScreenshot_NoTab(t *testing.T) { |
| h := New(&mockBridge{failTab: true}, &config.RuntimeConfig{}, nil, nil, nil) |
| req := httptest.NewRequest("GET", "/tabs/tab_abc/screenshot", nil) |
| req.SetPathValue("id", "tab_abc") |
| w := httptest.NewRecorder() |
| h.HandleTabScreenshot(w, req) |
| if w.Code != http.StatusNotFound { |
| t.Errorf("expected 404, got %d", w.Code) |
| } |
| } |
|
|