stub_handler_test.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package webapi
  2. import (
  3. "encoding/json"
  4. "net/http"
  5. "net/http/httptest"
  6. "testing"
  7. "github.com/stretchr/testify/assert"
  8. "github.com/stretchr/testify/require"
  9. )
  10. // AIM Express asks for the service list at sign-on and reads every field of
  11. // each entry, so the payload names them all rather than omitting the false ones.
  12. func TestGetServicesAdvertisesAIMAlone(t *testing.T) {
  13. h := &UserInfoStubHandler{}
  14. rr := httptest.NewRecorder()
  15. h.GetServices(rr, httptest.NewRequest(http.MethodGet, "/getServices?f=json&r=1", nil))
  16. require.Equal(t, http.StatusOK, rr.Code)
  17. var body struct {
  18. Response struct {
  19. StatusCode int `json:"statusCode"`
  20. Data struct {
  21. Services []map[string]any `json:"services"`
  22. } `json:"data"`
  23. } `json:"response"`
  24. }
  25. require.NoError(t, json.Unmarshal(rr.Body.Bytes(), &body), "body: %s", rr.Body.String())
  26. assert.Equal(t, 200, body.Response.StatusCode)
  27. require.Len(t, body.Response.Data.Services, 1)
  28. svc := body.Response.Data.Services[0]
  29. assert.Equal(t, "aim", svc["name"])
  30. assert.Equal(t, "aim", svc["service"])
  31. assert.Equal(t, true, svc["associated"])
  32. assert.Equal(t, true, svc["online"])
  33. // A roster here means a third-party friend list to import, not the buddy list.
  34. assert.Equal(t, false, svc["roster"])
  35. assert.Equal(t, false, svc["haveRoster"])
  36. for _, field := range []string{"autoLogin", "signupURL"} {
  37. assert.Contains(t, svc, field, "client reads %s unconditionally", field)
  38. }
  39. }