diff --git a/page.go b/page.go index c8875b3f..4b9a82d0 100644 --- a/page.go +++ b/page.go @@ -35,17 +35,20 @@ type PageServiceOp struct { // Page represents a Shopify page. type Page struct { - Id uint64 `json:"id,omitempty"` - Author string `json:"author,omitempty"` - Handle string `json:"handle,omitempty"` - Title string `json:"title,omitempty"` - CreatedAt *time.Time `json:"created_at,omitempty"` - UpdatedAt *time.Time `json:"updated_at,omitempty"` - BodyHTML string `json:"body_html,omitempty"` - TemplateSuffix string `json:"template_suffix,omitempty"` - PublishedAt *time.Time `json:"published_at,omitempty"` - ShopId uint64 `json:"shop_id,omitempty"` - Metafields []Metafield `json:"metafields,omitempty"` + Id uint64 `json:"id,omitempty"` + Author string `json:"author,omitempty"` + Handle string `json:"handle,omitempty"` + Title string `json:"title,omitempty"` + CreatedAt *time.Time `json:"created_at,omitempty"` + UpdatedAt *time.Time `json:"updated_at,omitempty"` + BodyHTML string `json:"body_html,omitempty"` + TemplateSuffix string `json:"template_suffix,omitempty"` + PublishedAt *time.Time `json:"published_at,omitempty"` + // Published can be set when creating a new page. + // It's not returned in the response + Published *bool `json:"published,omitempty"` + ShopId uint64 `json:"shop_id,omitempty"` + Metafields []Metafield `json:"metafields,omitempty"` } // PageResource represents the result from the pages/X.json endpoint diff --git a/page_test.go b/page_test.go index 82da2378..cb992f3b 100644 --- a/page_test.go +++ b/page_test.go @@ -23,14 +23,17 @@ func TestPageList(t *testing.T) { defer teardown() httpmock.RegisterResponder("GET", fmt.Sprintf("https://fooshop.myshopify.com/%s/pages.json", client.pathPrefix), - httpmock.NewStringResponder(200, `{"pages": [{"id":1},{"id":2}]}`)) + httpmock.NewStringResponder(200, `{"pages": [{"id":1,"published_at": "2008-07-15T20:00:00Z"},{"id":2,"published_at": "2008-07-15T21:00:00Z"}]}`)) pages, err := client.Page.List(context.Background(), nil) if err != nil { t.Errorf("Page.List returned error: %v", err) } - expected := []Page{{Id: 1}, {Id: 2}} + expected := []Page{ + {Id: 1, PublishedAt: TimePtr(time.Date(2008, 7, 15, 20, 0, 0, 0, time.UTC))}, + {Id: 2, PublishedAt: TimePtr(time.Date(2008, 7, 15, 21, 0, 0, 0, time.UTC))}, + } if !reflect.DeepEqual(pages, expected) { t.Errorf("Page.List returned %+v, expected %+v", pages, expected) } @@ -77,14 +80,14 @@ func TestPageGet(t *testing.T) { defer teardown() httpmock.RegisterResponder("GET", fmt.Sprintf("https://fooshop.myshopify.com/%s/pages/1.json", client.pathPrefix), - httpmock.NewStringResponder(200, `{"page": {"id":1}}`)) + httpmock.NewStringResponder(200, `{"page": {"id":1,"published_at": "2008-07-15T20:00:00Z"}}`)) page, err := client.Page.Get(context.Background(), 1, nil) if err != nil { t.Errorf("Page.Get returned error: %v", err) } - expected := &Page{Id: 1} + expected := &Page{Id: 1, PublishedAt: TimePtr(time.Date(2008, 7, 15, 20, 0, 0, 0, time.UTC))} if !reflect.DeepEqual(page, expected) { t.Errorf("Page.Get returned %+v, expected %+v", page, expected) } diff --git a/util.go b/util.go index 3683bf7f..72623edd 100644 --- a/util.go +++ b/util.go @@ -81,3 +81,7 @@ func (c *OnlyDate) EncodeValues(key string, v *url.Values) error { func (c *OnlyDate) String() string { return `"` + c.Format("2006-01-02") + `"` } + +func TimePtr(v time.Time) *time.Time { + return &v +}