clone

a terminal ui for alamo drafthouse showtimes, as movie cards or a timeline of every screen

main
showings / internal / api / client_test.go
client_test.go 1.8K
1package api23import (4 "encoding/json"5 "net/http"6 "net/http/httptest"7 "testing"89 "github.com/dami/showings/internal/models"10)1112func TestFetchSchedule(t *testing.T) {13 expectedData := models.Data{14 Presentations: []models.Presentation{15 {16 Slug: "test-movie-2026",17 Show: models.Show{18 Title: "Test Movie (2026)",19 Certification: "PG-13",20 },21 },22 },23 Sessions: []models.Session{24 {25 SessionId: "12345",26 PresentationSlug: "test-movie-2026",27 Status: "ONSALE",28 BusinessDateClt: "2026-02-14",29 ShowTimeClt: "2026-02-14T19:00:00",30 CinemaId: "0403",31 FormatSlug: "2d-digital",32 AgePolicySlug: "rated-pg-13",33 },34 },35 Formats: []models.Format{36 {37 Slug: "2d-digital",38 Title: "2D Digital",39 },40 },41 AgePolicies: []models.AgePolicy{42 {43 Slug: "rated-pg-13",44 Name: "Rated PG-13",45 },46 },47 Market: []models.Market{48 {49 ID: "0400",50 Slug: "denver",51 Cinemas: []models.Cinema{52 {53 ID: "0403",54 Name: "Westminster",55 City: "Westminster",56 State: "CO",57 },58 },59 },60 },61 }6263 server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {64 w.Header().Set("Content-Type", "application/json")65 json.NewEncoder(w).Encode(models.APIResponse{Data: expectedData})66 }))67 defer server.Close()6869 client := NewClientWithURL(server.URL + "/")7071 result, err := client.FetchSchedule("westminster")72 if err != nil {73 t.Fatalf("FetchSchedule failed: %v", err)74 }7576 if len(result.Data.Presentations) != 1 {77 t.Errorf("Expected 1 presentation, got %d", len(result.Data.Presentations))78 }7980 if result.Data.Presentations[0].Show.Title != "Test Movie (2026)" {81 t.Errorf("Expected title 'Test Movie (2026)', got '%s'", result.Data.Presentations[0].Show.Title)82 }83}