Skip to content

Commit

Permalink
Add published param to Page (#305)
Browse files Browse the repository at this point in the history
  • Loading branch information
k-yomo authored Sep 1, 2024
1 parent c22a746 commit 730f4f4
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 15 deletions.
25 changes: 14 additions & 11 deletions page.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 7 additions & 4 deletions page_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand Down
4 changes: 4 additions & 0 deletions util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit 730f4f4

Please sign in to comment.